Skip to content

Commit 28d5acc

Browse files
Merge pull request RustPython#552 from AaronRocinante/lexer_handle_random_byte
add lexer error
2 parents f8e9639 + 267934b commit 28d5acc

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

parser/src/lexer.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pub struct Lexer<T: Iterator<Item = char>> {
5555
pub enum LexicalError {
5656
StringError,
5757
NestingError,
58+
UnrecognizedToken { tok: char },
5859
}
5960

6061
#[derive(Clone, Debug, Default, PartialEq)]
@@ -687,7 +688,9 @@ where
687688

688689
match self.chr0 {
689690
Some('0'..='9') => return Some(self.lex_number()),
690-
Some('_') | Some('a'..='z') | Some('A'..='Z') => return Some(self.lex_identifier()),
691+
Some('_') | Some('a'..='z') | Some('A'..='Z') => {
692+
return Some(self.lex_identifier());
693+
}
691694
Some('#') => {
692695
self.lex_comment();
693696
continue;
@@ -1033,7 +1036,7 @@ where
10331036
None => return None,
10341037
_ => {
10351038
let c = self.next_char();
1036-
panic!("Not impl {:?}", c)
1039+
return Some(Err(LexicalError::UnrecognizedToken { tok: c.unwrap() }));
10371040
} // Ignore all the rest..
10381041
}
10391042
}

0 commit comments

Comments
 (0)