Fix: crash with invalid decimal literal in expo

This commit is contained in:
GreasySlug 2022-10-10 10:54:57 +09:00
parent e0f0f0ee9e
commit db3adec34d

View file

@ -461,15 +461,30 @@ impl Lexer /*<'a>*/ {
let mut num = mantissa; let mut num = mantissa;
debug_power_assert!(self.peek_cur_ch(), ==, Some('e')); debug_power_assert!(self.peek_cur_ch(), ==, Some('e'));
num.push(self.consume().unwrap()); // e num.push(self.consume().unwrap()); // e
num.push(self.consume().unwrap()); // + | - if self.peek_cur_ch().is_some() {
while let Some(cur) = self.peek_cur_ch() { num.push(self.consume().unwrap()); // + | -
if cur.is_ascii_digit() || cur == '_' { while let Some(cur) = self.peek_cur_ch() {
num.push(self.consume().unwrap()); if cur.is_ascii_digit() || cur == '_' {
} else { num.push(self.consume().unwrap());
break; } else {
break;
}
} }
Ok(self.emit_token(RatioLit, &num))
} else {
let token = self.emit_token(RatioLit, &num);
Err(LexError::syntax_error(
0,
token.loc(),
switch_lang!(
"japanese" => format!("`{}`は無効な十進数リテラルです", &token.content),
"simplified_chinese" => format!("`{}`是无效的十进制字词", &token.content),
"traditional_chinese" => format!("`{}`是無效的十進製文字", &token.content),
"english" => format!("`{}` is invalid decimal literal", &token.content),
),
None,
))
} }
Ok(self.emit_token(RatioLit, &num))
} }
/// `_` will be removed at compiletime /// `_` will be removed at compiletime