Skip to content

Commit

Permalink
update: invalid convert error
Browse files Browse the repository at this point in the history
  • Loading branch information
GreasySlug committed Apr 1, 2023
1 parent b0959b1 commit 1979e95
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 12 deletions.
73 changes: 61 additions & 12 deletions crates/erg_parser/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,14 @@ impl Parser {
Ok(sig)
}
other => {
debug_exit_info!(self);
let err = ParseError::simple_syntax_error(line!() as usize, other.loc());
let err = ParseError::invalid_convert_error(
line!() as usize,
other.loc(),
"rhs",
"signature",
);
self.errs.push(err);
debug_exit_info!(self);
Err(())
}
}
Expand All @@ -88,7 +93,12 @@ impl Parser {
Ok(VarSignature::new(pat, None))
}
other => {
let err = ParseError::simple_syntax_error(line!() as usize, other.loc());
let err = ParseError::invalid_convert_error(
line!() as usize,
other.loc(),
"accessor",
"variable signature",
);
self.errs.push(err);
debug_exit_info!(self);
Err(())
Expand All @@ -110,7 +120,12 @@ impl Parser {
vars.push(v);
}
Signature::Subr(subr) => {
let err = ParseError::simple_syntax_error(line!() as usize, subr.loc());
let err = ParseError::invalid_convert_error(
line!() as usize,
subr.loc(),
"array",
"array pattern",
);
self.errs.push(err);
debug_exit_info!(self);
return Err(());
Expand Down Expand Up @@ -221,8 +236,12 @@ impl Parser {
vars.push(var);
}
other => {
let err =
ParseError::simple_syntax_error(line!() as usize, other.loc());
let err = ParseError::invalid_convert_error(
line!() as usize,
other.loc(),
"Tuple",
"Tuple pattern",
);
self.errs.push(err);
debug_exit_info!(self);
return Err(());
Expand Down Expand Up @@ -268,7 +287,12 @@ impl Parser {
.convert_accessor_to_ident(acc)
.map_err(|_| self.stack_dec(fn_name!()))?,
other => {
let err = ParseError::simple_syntax_error(line!() as usize, other.loc());
let err = ParseError::invalid_convert_error(
line!() as usize,
other.loc(),
"call",
"subroutine signature",
);
self.errs.push(err);
debug_exit_info!(self);
return Err(());
Expand Down Expand Up @@ -305,7 +329,12 @@ impl Parser {
(ident, bounds)
}
other => {
let err = ParseError::simple_syntax_error(line!() as usize, other.loc());
let err = ParseError::invalid_convert_error(
line!() as usize,
other.loc(),
"accessor",
"indemnifier",
);
self.errs.push(err);
debug_exit_info!(self);
return Err(());
Expand Down Expand Up @@ -356,7 +385,12 @@ impl Parser {
Ok(bound)
}
other => {
let err = ParseError::simple_syntax_error(line!() as usize, other.loc());
let err = ParseError::invalid_convert_error(
line!() as usize,
other.loc(),
"type argument",
"bound",
);
self.errs.push(err);
Err(())
}
Expand Down Expand Up @@ -499,7 +533,12 @@ impl Parser {
}
},
other => {
let err = ParseError::simple_syntax_error(line!() as usize, other.loc());
let err = ParseError::invalid_convert_error(
line!() as usize,
other.loc(),
"right hand side",
"parameter",
);
self.errs.push(err);
debug_exit_info!(self);
Err(())
Expand Down Expand Up @@ -694,7 +733,12 @@ impl Parser {
Ok(sig)
}
other => {
let err = ParseError::simple_syntax_error(line!() as usize, other.loc());
let err = ParseError::invalid_convert_error(
line!() as usize,
other.loc(),
"right hand side",
"lambda signature",
);
self.errs.push(err);
debug_exit_info!(self);
Err(())
Expand All @@ -718,7 +762,12 @@ impl Parser {
Ok(NonDefaultParamSignature::new(pat, None))
}
other => {
let err = ParseError::simple_syntax_error(line!() as usize, other.loc());
let err = ParseError::invalid_convert_error(
line!() as usize,
other.loc(),
"accessor",
"parameter signature",
);
self.errs.push(err);
debug_exit_info!(self);
Err(())
Expand Down
14 changes: 14 additions & 0 deletions crates/erg_parser/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,20 @@ impl LexError {
))
}

pub fn invalid_convert_error(errno: usize, loc: Location, from: &str, to: &str) -> ParseError {
Self::syntax_error(
errno,
loc,
switch_lang!(
"japanese" => format!("{}から{}に変換するのに失敗しました", from, to),
"simplified_chinese" => format!("无法将{}转换为{}", from, to),
"traditional_chinese" => format!("無法將{}轉換為{}", from, to),
"english" => format!("failed to convert {} to {}",from, to),
),
None,
)
}

pub fn no_var_error(
errno: usize,
loc: Location,
Expand Down

0 comments on commit 1979e95

Please sign in to comment.