mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-29 20:34:44 +00:00
Implement todo!() part of Parser
This commit is contained in:
parent
d1fc1eb0ca
commit
5e4337cde1
1 changed files with 78 additions and 17 deletions
|
@ -145,6 +145,12 @@ impl Parser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn throw_syntax_err<L: Locational>(&mut self, l: &L, caused_by: &str) -> ParseError {
|
||||||
|
log!(err "error caused by: {caused_by}");
|
||||||
|
self.next_expr();
|
||||||
|
ParseError::simple_syntax_error(0, l.loc())
|
||||||
|
}
|
||||||
|
|
||||||
fn skip_and_throw_syntax_err(&mut self, caused_by: &str) -> ParseError {
|
fn skip_and_throw_syntax_err(&mut self, caused_by: &str) -> ParseError {
|
||||||
let loc = self.peek().unwrap().loc();
|
let loc = self.peek().unwrap().loc();
|
||||||
log!(err "error caused by: {caused_by}");
|
log!(err "error caused by: {caused_by}");
|
||||||
|
@ -1565,7 +1571,12 @@ impl Parser {
|
||||||
self.level -= 1;
|
self.level -= 1;
|
||||||
Ok(sig)
|
Ok(sig)
|
||||||
}
|
}
|
||||||
other => todo!("{other}"), // Error
|
other => {
|
||||||
|
self.level -= 1;
|
||||||
|
let err = self.throw_syntax_err(&other, caused_by!());
|
||||||
|
self.errs.push(err);
|
||||||
|
Err(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1585,7 +1596,12 @@ impl Parser {
|
||||||
self.level -= 1;
|
self.level -= 1;
|
||||||
Ok(VarSignature::new(pat, None))
|
Ok(VarSignature::new(pat, None))
|
||||||
}
|
}
|
||||||
other => todo!("{other}"),
|
other => {
|
||||||
|
self.level -= 1;
|
||||||
|
let err = self.throw_syntax_err(&other, caused_by!());
|
||||||
|
self.errs.push(err);
|
||||||
|
Err(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1657,7 +1673,12 @@ impl Parser {
|
||||||
Expr::Accessor(acc) => self
|
Expr::Accessor(acc) => self
|
||||||
.convert_accessor_to_ident(acc)
|
.convert_accessor_to_ident(acc)
|
||||||
.map_err(|_| self.stack_dec())?,
|
.map_err(|_| self.stack_dec())?,
|
||||||
other => todo!("{other}"), // Error
|
other => {
|
||||||
|
self.level -= 1;
|
||||||
|
let err = self.throw_syntax_err(&other, caused_by!());
|
||||||
|
self.errs.push(err);
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
let params = self
|
let params = self
|
||||||
.convert_args_to_params(call.args)
|
.convert_args_to_params(call.args)
|
||||||
|
@ -1674,7 +1695,12 @@ impl Parser {
|
||||||
Accessor::Public(public) => {
|
Accessor::Public(public) => {
|
||||||
Identifier::new(Some(public.dot), VarName::new(public.symbol))
|
Identifier::new(Some(public.dot), VarName::new(public.symbol))
|
||||||
}
|
}
|
||||||
other => todo!("{other}"), // Error
|
other => {
|
||||||
|
self.level -= 1;
|
||||||
|
let err = self.throw_syntax_err(&other, caused_by!());
|
||||||
|
self.errs.push(err);
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
self.level -= 1;
|
self.level -= 1;
|
||||||
Ok(ident)
|
Ok(ident)
|
||||||
|
@ -1684,9 +1710,9 @@ impl Parser {
|
||||||
debug_call_info!(self);
|
debug_call_info!(self);
|
||||||
let (pos_args, kw_args, parens) = args.deconstruct();
|
let (pos_args, kw_args, parens) = args.deconstruct();
|
||||||
let mut params = Params::new(vec![], None, vec![], parens);
|
let mut params = Params::new(vec![], None, vec![], parens);
|
||||||
for arg in pos_args.into_iter() {
|
for (i, arg) in pos_args.into_iter().enumerate() {
|
||||||
let nd_param = self
|
let nd_param = self
|
||||||
.convert_pos_arg_to_non_default_param(arg)
|
.convert_pos_arg_to_non_default_param(arg, i == 0)
|
||||||
.map_err(|_| self.stack_dec())?;
|
.map_err(|_| self.stack_dec())?;
|
||||||
params.non_defaults.push(nd_param);
|
params.non_defaults.push(nd_param);
|
||||||
}
|
}
|
||||||
|
@ -1701,19 +1727,33 @@ impl Parser {
|
||||||
Ok(params)
|
Ok(params)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn convert_pos_arg_to_non_default_param(&mut self, arg: PosArg) -> ParseResult<ParamSignature> {
|
fn convert_pos_arg_to_non_default_param(
|
||||||
|
&mut self,
|
||||||
|
arg: PosArg,
|
||||||
|
allow_self: bool,
|
||||||
|
) -> ParseResult<ParamSignature> {
|
||||||
debug_call_info!(self);
|
debug_call_info!(self);
|
||||||
let param = self
|
let param = self
|
||||||
.convert_rhs_to_param(arg.expr)
|
.convert_rhs_to_param(arg.expr, allow_self)
|
||||||
.map_err(|_| self.stack_dec())?;
|
.map_err(|_| self.stack_dec())?;
|
||||||
self.level -= 1;
|
self.level -= 1;
|
||||||
Ok(param)
|
Ok(param)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn convert_rhs_to_param(&mut self, expr: Expr) -> ParseResult<ParamSignature> {
|
fn convert_rhs_to_param(
|
||||||
|
&mut self,
|
||||||
|
expr: Expr,
|
||||||
|
allow_self: bool,
|
||||||
|
) -> ParseResult<ParamSignature> {
|
||||||
debug_call_info!(self);
|
debug_call_info!(self);
|
||||||
match expr {
|
match expr {
|
||||||
Expr::Accessor(Accessor::Local(local)) => {
|
Expr::Accessor(Accessor::Local(local)) => {
|
||||||
|
if &local.inspect()[..] == "self" && !allow_self {
|
||||||
|
self.level -= 1;
|
||||||
|
let err = self.throw_syntax_err(&local, caused_by!());
|
||||||
|
self.errs.push(err);
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
let name = VarName::new(local.symbol);
|
let name = VarName::new(local.symbol);
|
||||||
let pat = ParamPattern::VarName(name);
|
let pat = ParamPattern::VarName(name);
|
||||||
let param = ParamSignature::new(pat, None, None);
|
let param = ParamSignature::new(pat, None, None);
|
||||||
|
@ -1755,7 +1795,7 @@ impl Parser {
|
||||||
}
|
}
|
||||||
Expr::TypeAsc(tasc) => {
|
Expr::TypeAsc(tasc) => {
|
||||||
let param = self
|
let param = self
|
||||||
.convert_type_asc_to_param_pattern(tasc)
|
.convert_type_asc_to_param_pattern(tasc, allow_self)
|
||||||
.map_err(|_| self.stack_dec())?;
|
.map_err(|_| self.stack_dec())?;
|
||||||
self.level -= 1;
|
self.level -= 1;
|
||||||
Ok(param)
|
Ok(param)
|
||||||
|
@ -1782,11 +1822,26 @@ impl Parser {
|
||||||
self.level -= 1;
|
self.level -= 1;
|
||||||
Ok(param)
|
Ok(param)
|
||||||
}
|
}
|
||||||
other => todo!("{other}"),
|
_other => {
|
||||||
|
self.level -= 1;
|
||||||
|
let err = self.throw_syntax_err(&local, caused_by!());
|
||||||
|
self.errs.push(err);
|
||||||
|
Err(())
|
||||||
|
}
|
||||||
},
|
},
|
||||||
other => todo!("{other}"),
|
other => {
|
||||||
|
self.level -= 1;
|
||||||
|
let err = self.throw_syntax_err(&other, caused_by!());
|
||||||
|
self.errs.push(err);
|
||||||
|
Err(())
|
||||||
|
}
|
||||||
},
|
},
|
||||||
other => todo!("{other}"), // Error
|
other => {
|
||||||
|
self.level -= 1;
|
||||||
|
let err = self.throw_syntax_err(&other, caused_by!());
|
||||||
|
self.errs.push(err);
|
||||||
|
Err(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1826,10 +1881,11 @@ impl Parser {
|
||||||
fn convert_type_asc_to_param_pattern(
|
fn convert_type_asc_to_param_pattern(
|
||||||
&mut self,
|
&mut self,
|
||||||
tasc: TypeAscription,
|
tasc: TypeAscription,
|
||||||
|
allow_self: bool,
|
||||||
) -> ParseResult<ParamSignature> {
|
) -> ParseResult<ParamSignature> {
|
||||||
debug_call_info!(self);
|
debug_call_info!(self);
|
||||||
let param = self
|
let param = self
|
||||||
.convert_rhs_to_param(*tasc.expr)
|
.convert_rhs_to_param(*tasc.expr, allow_self)
|
||||||
.map_err(|_| self.stack_dec())?;
|
.map_err(|_| self.stack_dec())?;
|
||||||
let param = ParamSignature::new(param.pat, Some(tasc.t_spec), None);
|
let param = ParamSignature::new(param.pat, Some(tasc.t_spec), None);
|
||||||
self.level -= 1;
|
self.level -= 1;
|
||||||
|
@ -1879,7 +1935,12 @@ impl Parser {
|
||||||
self.level -= 1;
|
self.level -= 1;
|
||||||
Ok(sig)
|
Ok(sig)
|
||||||
}
|
}
|
||||||
other => todo!("{other}"), // Error
|
other => {
|
||||||
|
self.level -= 1;
|
||||||
|
let err = self.throw_syntax_err(&other, caused_by!());
|
||||||
|
self.errs.push(err);
|
||||||
|
Err(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1897,9 +1958,9 @@ impl Parser {
|
||||||
Tuple::Normal(tup) => {
|
Tuple::Normal(tup) => {
|
||||||
let (pos_args, kw_args, paren) = tup.elems.deconstruct();
|
let (pos_args, kw_args, paren) = tup.elems.deconstruct();
|
||||||
let mut params = Params::new(vec![], None, vec![], paren);
|
let mut params = Params::new(vec![], None, vec![], paren);
|
||||||
for arg in pos_args {
|
for (i, arg) in pos_args.into_iter().enumerate() {
|
||||||
let param = self
|
let param = self
|
||||||
.convert_pos_arg_to_non_default_param(arg)
|
.convert_pos_arg_to_non_default_param(arg, i == 0)
|
||||||
.map_err(|_| self.stack_dec())?;
|
.map_err(|_| self.stack_dec())?;
|
||||||
params.non_defaults.push(param);
|
params.non_defaults.push(param);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue