mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 10:49:54 +00:00
fix(parser): fix #400
This commit is contained in:
parent
b97afb04af
commit
a07ab4637e
3 changed files with 89 additions and 108 deletions
|
@ -11,6 +11,8 @@ use erg_common::style::{Attribute, Color, StyledStr, StyledString, StyledStrings
|
|||
use erg_common::traits::Stream;
|
||||
use erg_common::{fmt_iter, impl_display_and_error, impl_stream, switch_lang};
|
||||
|
||||
use crate::token::TokenKind;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct LexError(Box<ErrorCore>); // ErrorCore is large, so use Box
|
||||
|
||||
|
@ -127,6 +129,26 @@ impl LexError {
|
|||
))
|
||||
}
|
||||
|
||||
pub fn unexpected_token<S: fmt::Display>(
|
||||
errno: usize,
|
||||
loc: Location,
|
||||
expected: S,
|
||||
got: TokenKind,
|
||||
) -> Self {
|
||||
Self::new(ErrorCore::new(
|
||||
vec![SubMessage::ambiguous_new(loc, vec![], None)],
|
||||
switch_lang!(
|
||||
"japanese" => format!("{expected}が期待されましたが、{got}となっています"),
|
||||
"simplified_chinese" => format!("期待: {expected},得到: {got}"),
|
||||
"traditional_chinese" => format!("期待: {expected},得到: {got}"),
|
||||
"english" => format!("expected: {expected}, got: {got}"),
|
||||
),
|
||||
errno,
|
||||
SyntaxError,
|
||||
loc,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn syntax_warning<S: Into<String>>(
|
||||
errno: usize,
|
||||
loc: Location,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue