fix(parser): fix #400

This commit is contained in:
Shunsuke Shibayama 2023-02-27 19:52:24 +09:00
parent b97afb04af
commit a07ab4637e
3 changed files with 89 additions and 108 deletions

View file

@ -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,