Update lex.rs

This commit is contained in:
Shunsuke Shibayama 2022-09-16 14:57:58 +09:00
parent 369b57d441
commit 5b5ffb1fb6

View file

@ -558,14 +558,25 @@ impl Lexer /*<'a>*/ {
if c == '\\' { if c == '\\' {
let next_c = self.consume().unwrap(); let next_c = self.consume().unwrap();
match next_c { match next_c {
'0' => s.push('\0'),
'r' => s.push('\r'),
'n' => s.push('\n'), 'n' => s.push('\n'),
'\'' => s.push('\''), '\'' => s.push('\''),
't' => s.push_str(" "), // tab is invalid, so changed into 4 whitespace 't' => s.push_str(" "), // tab is invalid, so changed into 4 whitespace
'\\' => s.push('\\'),
_ => { _ => {
s.push(next_c); let token = self.emit_token(Illegal, &format!("\\{next_c}"));
if Self::is_bidi(next_c) { return Err(LexError::syntax_error(
return Err(self._invalid_unicode_character(&s)); 0,
} token.loc(),
switch_lang!(
"japanese" => format!("不正なエスケープシーケンスです: \\{}", next_c),
"simplified_chinese" => format!("不合法的转义序列: \\{}", next_c),
"traditional_chinese" => format!("不合法的轉義序列: \\{}", next_c),
"english" => format!("illegal escape sequence: \\{}", next_c),
),
None,
));
} }
} }
} else { } else {