Generate SyntaxError at integer starting with 0

Generate syntaxError at integer starting with 0,
not zero

Fixes #1422
This commit is contained in:
HyeockJinKim committed 2019-09-29 01:12:07 +09:00
1 parent 3856e9373d
commit c8d0f5c956
1 file changed
+8 -1
+8 -1
View File
@@ -8,6 +8,7 @@ pub use super::token::Tok;
use crate::error::{LexicalError, LexicalErrorType};
use crate::location::Location;
use num_bigint::BigInt;
use num_traits::identities::Zero;
use num_traits::Num;
use std::cmp::Ordering;
use std::collections::HashMap;
@@ -352,7 +353,7 @@ where
/// Lex a normal number, that is, no octal, hex or binary number.
fn lex_normal_number(&mut self) -> LexResult {
let start_pos = self.get_pos();
let start_is_zero = self.chr0 == Some('0');
// Normal number:
let mut value_text = self.radix_run(10);
@@ -403,6 +404,12 @@ where
} else {
let end_pos = self.get_pos();
let value = value_text.parse::<BigInt>().unwrap();
if start_is_zero && !value.is_zero() {
return Err(LexicalError {
error: LexicalErrorType::OtherError("Invalid Token".to_string()),
location: self.get_pos(),
});
}
Ok((start_pos, Tok::Int { value }, end_pos))
}
}