mirror of
https://github.com/erg-lang/erg.git
synced 2025-10-02 21:44:34 +00:00
Do cargo fmt
This commit is contained in:
parent
e320bd6cdd
commit
6726d93f65
48 changed files with 7294 additions and 3469 deletions
|
@ -1,11 +1,11 @@
|
|||
//! defines `ParseError` and others.
|
||||
//!
|
||||
//! パーサーが出すエラーを定義
|
||||
use erg_common::{impl_stream_for_wrapper, switch_lang};
|
||||
use erg_common::Str;
|
||||
use erg_common::config::Input;
|
||||
use erg_common::error::{ErrorCore, ErrorDisplay, MultiErrorDisplay, Location, ErrorKind::*};
|
||||
use erg_common::error::{ErrorCore, ErrorDisplay, ErrorKind::*, Location, MultiErrorDisplay};
|
||||
use erg_common::traits::Stream;
|
||||
use erg_common::Str;
|
||||
use erg_common::{impl_stream_for_wrapper, switch_lang};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct LexError(ErrorCore);
|
||||
|
@ -16,7 +16,9 @@ pub struct LexErrors(Vec<LexError>);
|
|||
impl_stream_for_wrapper!(LexErrors, LexError);
|
||||
|
||||
impl LexError {
|
||||
pub const fn new(core: ErrorCore) -> Self { Self(core) }
|
||||
pub const fn new(core: ErrorCore) -> Self {
|
||||
Self(core)
|
||||
}
|
||||
|
||||
pub fn compiler_bug(errno: usize, loc: Location, fn_name: &str, line: u32) -> Self {
|
||||
Self::new(ErrorCore::new(errno, CompilerSystemError, loc, switch_lang!(
|
||||
|
@ -26,21 +28,43 @@ impl LexError {
|
|||
}
|
||||
|
||||
pub fn feature_error(errno: usize, loc: Location, name: &str) -> Self {
|
||||
Self::new(ErrorCore::new(errno, FeatureError, loc, switch_lang!(
|
||||
format!("this feature({name}) is not implemented yet"),
|
||||
format!("この機能({name})はまだ正式に提供されていません")
|
||||
), None))
|
||||
Self::new(ErrorCore::new(
|
||||
errno,
|
||||
FeatureError,
|
||||
loc,
|
||||
switch_lang!(
|
||||
format!("this feature({name}) is not implemented yet"),
|
||||
format!("この機能({name})はまだ正式に提供されていません")
|
||||
),
|
||||
None,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn simple_syntax_error(errno: usize, loc: Location) -> Self {
|
||||
Self::new(ErrorCore::new(errno, SyntaxError, loc, switch_lang!("invalid syntax", "不正な構文です"), None))
|
||||
Self::new(ErrorCore::new(
|
||||
errno,
|
||||
SyntaxError,
|
||||
loc,
|
||||
switch_lang!("invalid syntax", "不正な構文です"),
|
||||
None,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn syntax_error<S: Into<Str>>(errno: usize, loc: Location, desc: S, hint: Option<Str>) -> Self {
|
||||
pub fn syntax_error<S: Into<Str>>(
|
||||
errno: usize,
|
||||
loc: Location,
|
||||
desc: S,
|
||||
hint: Option<Str>,
|
||||
) -> Self {
|
||||
Self::new(ErrorCore::new(errno, SyntaxError, loc, desc, hint))
|
||||
}
|
||||
|
||||
pub fn syntax_warning<S: Into<Str>>(errno: usize,loc: Location, desc: S, hint: Option<Str>) -> Self {
|
||||
pub fn syntax_warning<S: Into<Str>>(
|
||||
errno: usize,
|
||||
loc: Location,
|
||||
desc: S,
|
||||
hint: Option<Str>,
|
||||
) -> Self {
|
||||
Self::new(ErrorCore::new(errno, SyntaxWarning, loc, desc, hint))
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +81,9 @@ pub struct DesugaringError {
|
|||
}
|
||||
|
||||
impl DesugaringError {
|
||||
pub const fn new(core: ErrorCore) -> Self { Self{ core }}
|
||||
pub const fn new(core: ErrorCore) -> Self {
|
||||
Self { core }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -74,14 +100,24 @@ pub struct ParserRunnerError {
|
|||
}
|
||||
|
||||
impl ErrorDisplay for ParserRunnerError {
|
||||
fn core(&self) -> &ErrorCore { &self.core }
|
||||
fn input(&self) -> &Input { &self.input }
|
||||
fn caused_by(&self) -> &str { "" }
|
||||
fn ref_inner(&self) -> Option<&Box<Self>> { None }
|
||||
fn core(&self) -> &ErrorCore {
|
||||
&self.core
|
||||
}
|
||||
fn input(&self) -> &Input {
|
||||
&self.input
|
||||
}
|
||||
fn caused_by(&self) -> &str {
|
||||
""
|
||||
}
|
||||
fn ref_inner(&self) -> Option<&Box<Self>> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl ParserRunnerError {
|
||||
pub const fn new(core: ErrorCore, input: Input) -> Self { Self{ core, input } }
|
||||
pub const fn new(core: ErrorCore, input: Input) -> Self {
|
||||
Self { core, input }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -93,7 +129,11 @@ impl MultiErrorDisplay<ParserRunnerError> for ParserRunnerErrors {}
|
|||
|
||||
impl ParserRunnerErrors {
|
||||
pub fn convert(input: &Input, errs: ParseErrors) -> Self {
|
||||
Self(errs.into_iter().map(|err| ParserRunnerError::new(err.0, input.clone())).collect())
|
||||
Self(
|
||||
errs.into_iter()
|
||||
.map(|err| ParserRunnerError::new(err.0, input.clone()))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue