mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 10:49:54 +00:00
fix(parser): #245
This commit is contained in:
parent
8d723aed88
commit
1ff53f4669
2 changed files with 59 additions and 10 deletions
|
@ -387,6 +387,23 @@ impl LexError {
|
|||
Self::new(ErrorCore::new(vec![sub], msg, errno, SyntaxError, loc))
|
||||
}
|
||||
|
||||
pub fn invalid_colon_style(errno: usize, loc: Location) -> ParseError {
|
||||
let desc = switch_lang!(
|
||||
"japanese" => "コロンの後ろでカンマを使った区切りは使うことができません",
|
||||
"simplified_chinese" => "冒号后不能使用逗号分隔符",
|
||||
"traditional_chinese" => "冒號後不能使用逗號分隔符",
|
||||
"english" => "comma delimiters cannot be used after a colon",
|
||||
);
|
||||
let hint = switch_lang!(
|
||||
"japanese" => "カンマを削除してください",
|
||||
"simplified_chinese" => "逗号应该去掉",
|
||||
"traditional_chinese" => "逗號應該去掉",
|
||||
"english" => "comma should be removed",
|
||||
)
|
||||
.to_string();
|
||||
Self::syntax_error(errno, loc, desc, Some(hint))
|
||||
}
|
||||
|
||||
pub fn unclosed_error(errno: usize, loc: Location, closer: &str, ty: &str) -> ParseError {
|
||||
let msg = switch_lang!(
|
||||
"japanese" => format!("{ty}が{closer}で閉じられていません"),
|
||||
|
|
|
@ -934,8 +934,12 @@ impl Parser {
|
|||
Some(Comma) => {
|
||||
self.skip();
|
||||
if style.is_colon() || self.cur_is(Comma) {
|
||||
let err = self.skip_and_throw_syntax_err(line!(), caused_by!());
|
||||
let caused_by = caused_by!();
|
||||
log!(err "error caused by: {caused_by}");
|
||||
let loc = self.peek().map(|t| t.loc()).unwrap_or_default();
|
||||
let err = ParseError::invalid_colon_style(line!() as usize, loc);
|
||||
self.errs.push(err);
|
||||
self.until_dedent();
|
||||
debug_exit_info!(self);
|
||||
return Err(());
|
||||
}
|
||||
|
@ -987,6 +991,17 @@ impl Parser {
|
|||
}
|
||||
Some(Newline) => {
|
||||
if !style.is_colon() {
|
||||
if style.needs_parens() && !style.is_multi_comma() {
|
||||
let err = self.skip_and_throw_invalid_seq_err(
|
||||
caused_by!(),
|
||||
line!() as usize,
|
||||
&[")"],
|
||||
Newline,
|
||||
);
|
||||
self.errs.push(err);
|
||||
debug_exit_info!(self);
|
||||
return Err(());
|
||||
}
|
||||
if style.is_multi_comma() {
|
||||
self.skip();
|
||||
while self.cur_is(Dedent) {
|
||||
|
@ -1036,9 +1051,7 @@ impl Parser {
|
|||
debug_exit_info!(self);
|
||||
return Err(());
|
||||
}
|
||||
_ => {
|
||||
break;
|
||||
}
|
||||
_ => break,
|
||||
}
|
||||
}
|
||||
debug_exit_info!(self);
|
||||
|
@ -2123,13 +2136,32 @@ impl Parser {
|
|||
}
|
||||
self.stack_dec(fn_name!())
|
||||
})?;
|
||||
while self.cur_is(Newline) {
|
||||
self.skip();
|
||||
if line_break {
|
||||
while self.cur_is(Newline) {
|
||||
self.skip();
|
||||
}
|
||||
if self.cur_is(Dedent) {
|
||||
self.skip();
|
||||
}
|
||||
}
|
||||
if self.cur_is(Dedent) {
|
||||
self.skip();
|
||||
}
|
||||
let rparen = self.lpop();
|
||||
let rparen = match self.peek_kind() {
|
||||
Some(RParen) => self.lpop(),
|
||||
Some(_) => {
|
||||
let err = self.skip_and_throw_invalid_unclosed_err(
|
||||
caused_by!(),
|
||||
line!(),
|
||||
")",
|
||||
"tuple",
|
||||
);
|
||||
self.errs.push(err);
|
||||
return Err(());
|
||||
}
|
||||
None => {
|
||||
self.errs.push(self.unexpected_none(line!(), caused_by!()));
|
||||
debug_exit_info!(self);
|
||||
return Err(());
|
||||
}
|
||||
};
|
||||
if let Expr::Tuple(Tuple::Normal(tup)) = &mut expr {
|
||||
tup.elems.paren = Some((lparen, rparen));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue