mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-29 04:24:43 +00:00
Refactor
Add `ASTBuilder`, `Checker`
This commit is contained in:
parent
f12c2ba723
commit
d8799f0895
14 changed files with 254 additions and 104 deletions
|
@ -2,6 +2,7 @@
|
|||
//!
|
||||
//! パーサーが出すエラーを定義
|
||||
use erg_common::astr::AtomicStr;
|
||||
use erg_common::color::{RED, RESET};
|
||||
use erg_common::config::Input;
|
||||
use erg_common::error::{ErrorCore, ErrorDisplay, ErrorKind::*, Location, MultiErrorDisplay};
|
||||
use erg_common::traits::Stream;
|
||||
|
@ -82,6 +83,35 @@ impl LexError {
|
|||
) -> Self {
|
||||
Self::new(ErrorCore::new(errno, SyntaxWarning, loc, desc, hint))
|
||||
}
|
||||
|
||||
pub fn no_var_error(
|
||||
errno: usize,
|
||||
loc: Location,
|
||||
name: &str,
|
||||
similar_name: Option<String>,
|
||||
) -> Self {
|
||||
let hint = similar_name.map(|n| {
|
||||
switch_lang!(
|
||||
"japanese" => format!("似た名前の変数があります: {n}"),
|
||||
"simplified_chinese" => format!("存在相同名称变量:{n}"),
|
||||
"traditional_chinese" => format!("存在相同名稱變量:{n}"),
|
||||
"english" => format!("exists a similar name variable: {n}"),
|
||||
)
|
||||
.into()
|
||||
});
|
||||
Self::new(ErrorCore::new(
|
||||
errno,
|
||||
NameError,
|
||||
loc,
|
||||
switch_lang!(
|
||||
"japanese" => format!("{RED}{name}{RESET}という変数は定義されていません"),
|
||||
"simplified_chinese" => format!("{RED}{name}{RESET}未定义"),
|
||||
"traditional_chinese" => format!("{RED}{name}{RESET}未定義"),
|
||||
"english" => format!("{RED}{name}{RESET} is not defined"),
|
||||
),
|
||||
hint,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub type LexResult<T> = Result<T, LexError>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue