Skip to content

Commit 01b6667

Browse files
committed
Generate SyntaxError at integer starting with 0
Generate syntaxError at integer starting with 0, not zero Fixes #1422
1 parent 3856e93 commit 01b6667

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

parser/src/lexer.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use std::str::FromStr;
1515
use unic_emoji_char::is_emoji_presentation;
1616
use unicode_xid::UnicodeXID;
1717
use wtf8;
18+
use num_traits::identities::Zero;
1819

1920
#[derive(Clone, Copy, PartialEq, Debug, Default)]
2021
struct IndentationLevel {
@@ -352,7 +353,7 @@ where
352353
/// Lex a normal number, that is, no octal, hex or binary number.
353354
fn lex_normal_number(&mut self) -> LexResult {
354355
let start_pos = self.get_pos();
355-
356+
let start_is_zero = self.chr0 == Some('0');
356357
// Normal number:
357358
let mut value_text = self.radix_run(10);
358359

@@ -403,6 +404,12 @@ where
403404
} else {
404405
let end_pos = self.get_pos();
405406
let value = value_text.parse::<BigInt>().unwrap();
407+
if start_is_zero && !value.is_zero() {
408+
return Err(LexicalError {
409+
error: LexicalErrorType::OtherError("Invalid Token".to_string()),
410+
location: self.get_pos(),
411+
});
412+
}
406413
Ok((start_pos, Tok::Int { value }, end_pos))
407414
}
408415
}

0 commit comments

Comments
 (0)