-
i'm using the PrattParser to parse an expression, i have some parsers that might return an error (for example in this case the parse_function_call checks for the number of arguments or if the function name exists) but the .map_primary, and the rest of the mapping functions, don't accept a result, how should i do it? or is this something that could be added to the pratt parser? let parser = PrattParser::new()
.op(
Op::infix(Rule::add, Assoc::Left) |
Op::infix(Rule::sub, Assoc::Left) |
Op::infix(Rule::div, Assoc::Left) |
Op::infix(Rule::mul, Assoc::Left)
)
.op(Op::prefix(Rule::sub));
parser
.map_primary(|exp| {
let span = InputSpan::from_pair(&exp);
match exp.as_rule() {
Rule::function => {
let fn_call = parse_function_call(&exp)?; //<--- how?
PreExp::FunctionCall(Spanned::new(fn_call , span))
}
_ => /*other rules...*/
}
) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
@segeljakt I think this may be possible as what's returned by @Specy I think you can put |
Beta Was this translation helpful? Give feedback.
I tried that out and it worked flawlessly! Code is here.
The compiler also managed to infer the result type