mirror of
https://github.com/erg-lang/erg.git
synced 2025-10-03 05:54:33 +00:00
Clean: extract unicode errors for strings
This commit is contained in:
parent
d2ad7caaab
commit
d6be5380aa
1 changed files with 21 additions and 12 deletions
|
@ -555,20 +555,13 @@ impl Lexer /*<'a>*/ {
|
|||
return Ok(token);
|
||||
} else {
|
||||
let c = self.consume().unwrap();
|
||||
if Self::is_bidi(next_c) {
|
||||
return Err(self._invalid_unicode_character(&s));
|
||||
}
|
||||
s.push(c);
|
||||
if Self::is_bidi(c) {
|
||||
let token = self.emit_token(Illegal, &s);
|
||||
return Err(LexError::syntax_error(
|
||||
0,
|
||||
token.loc(),
|
||||
switch_lang!(
|
||||
"japanese" => "不正なユニコード文字(双方向オーバーライド)が文字列中に使用されています",
|
||||
"simplified_chinese" => "注释中使用了非法的unicode字符(双向覆盖)",
|
||||
"traditional_chinese" => "註釋中使用了非法的unicode字符(雙向覆蓋)",
|
||||
"english" => "invalid unicode character (bi-directional override) in string literal",
|
||||
),
|
||||
None,
|
||||
));
|
||||
return Err(self._invalid_unicode_character(&s));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -585,6 +578,22 @@ impl Lexer /*<'a>*/ {
|
|||
None,
|
||||
))
|
||||
}
|
||||
|
||||
// for single strings and multi strings
|
||||
fn _invalid_unicode_character(&mut self, s: &str) -> LexError {
|
||||
let token = self.emit_token(Illegal, s);
|
||||
LexError::syntax_error(
|
||||
0,
|
||||
token.loc(),
|
||||
switch_lang!(
|
||||
"japanese" => "不正なユニコード文字(双方向オーバーライド)が文字列中に使用されています",
|
||||
"simplified_chinese" => "注释中使用了非法的unicode字符(双向覆盖)",
|
||||
"traditional_chinese" => "註釋中使用了非法的unicode字符(雙向覆蓋)",
|
||||
"english" => "invalid unicode character (bi-directional override) in string literal",
|
||||
),
|
||||
None,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Iterator for Lexer /*<'a>*/ {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue