8000 Minor tweak on lexer to fix the REPL. · rmliddle/RustPython@255b744 · GitHub
[go: up one dir, main page]

Skip to content

Commit 255b744

Browse files
committed
Minor tweak on lexer to fix the REPL.
1 parent c7ffa2e commit 255b744

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

parser/src/lexer.rs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,22 @@ where
636636
}
637637
}
638638

639+
/// This is the main entry point. Call this function to retrieve the next token.
640+
/// This function is used by the iterator implementation.
641+
fn inner_next(&mut self) -> LexResult {
642+
// top loop, keep on processing, until we have something pending.
643+
while self.pending.is_empty() {
644+
// Detect indentation levels
645+
if self.at_begin_of_line {
646+
self.handle_indentations()?;
647+
}
648+
649+
self.consume_normal()?;
650+
}
651+
652+
Ok(self.pending.remove(0))
653+
}
654+
639655
/// Given we are at the start of a line, count the number of spaces and/or tabs until the first character.
640656
fn eat_indentation(&mut self) -> Result<IndentationLevel, LexicalError> {
641657
// Determine indentation:
@@ -684,7 +700,11 @@ where
684700
spaces = 0;
685701
tabs = 0;
686702
}
703+
None => {
704+
break;
705+
}
687706
_ => {
707+
self.at_begin_of_line = false;
688708
break;
689709
}
690710
}
@@ -693,23 +713,6 @@ where
693713
Ok(IndentationLevel { spaces, tabs })
694714
}
695715

696-
/// This is the main entry point. Call this function to retrieve the next token.
697-
/// This function is used by the iterator implementation.
698-
fn inner_next(&mut self) -> LexResult {
699-
// top loop, keep on processing, until we have something pending.
700-
while self.pending.is_empty() {
701-
// Detect indentation levels
702-
if self.at_begin_of_line {
703-
self.at_begin_of_line = false;
704-
self.handle_indentations()?;
705-
}
706-
707-
self.consume_normal()?;
708-
}
709-
710-
Ok(self.pending.remove(0))
711-
}
712-
713716
fn handle_indentations(&mut self) -> Result<(), LexicalError> {
714717
let indentation_level = self.eat_indentation()?;
715718

@@ -756,7 +759,7 @@ where
756759
location: self.get_pos(),
757760
});
758761
}
759-
};
762+
}
760763
}
761764
}
762765
}
@@ -1456,7 +1459,6 @@ mod tests {
14561459
Tok::Int { value: BigInt::from(99) },
14571460
Tok::Newline,
14581461
Tok::Dedent,
1459-
Tok::Newline,
14601462
]
14611463
);
14621464
}
@@ -1501,7 +1503,6 @@ mod tests {
15011503
Tok::Newline,
15021504
Tok::Dedent,
15031505
Tok::Dedent,
1504-
Tok::Newline,
15051506
]
15061507
);
15071508
}
@@ -1540,7 +1541,6 @@ mod tests {
15401541
Tok::Newline,
15411542
Tok::Dedent,
15421543
Tok::Dedent,
1543-
Tok::Newline,
15441544
]
15451545
);
15461546
}
@@ -1580,7 +1580,6 @@ mod tests {
15801580
Tok::Int { value: BigInt::from(2) },
15811581
Tok::Rsqb,
15821582
Tok::Newline,
1583-
Tok::Newline,
15841583
]
15851584
);
15861585
}

0 commit comments

Comments
 (0)
0