Very unhelpful error messages for unmapped prefix operators in pratt parsers
Describe the bug
Unmapped prefix operators panic at 'expected operator, found
For example "-1" panics with:
Expected operator, found int_literal
Instead of something like expected operator, found PREFIX_NEG
To Reproduce
- Create a grammar with a prefix operator, for example "-", and a literal
- Do not map this operator with pratt
- Attempt to use the operator; "-1" for example
Expected behavior The error message should report the correct symbol in the grammar, not the next one
Hi, been experimenting with the library and ran into the same issue. Has there been any progress made since pest = "2.7.4" that I might be missing out on, otherwise, would love to contribute some time to fixing this.
Hi @de-sh, the versions since 2.7.4 haven't touched PrattParser. Version v2.7.10 had pest::set_error_detail(true) which can improve error messages, but I think it doesn't have an effect on this particular issue related to Pratt parsers (but I haven't verified that though!).
An update on my troubles, I solved it by figuring out that my evaluation logic had a bug which looked like:
PrattParser::new().map_primary(|primary| match primary.as_rule() {
..
Rule::some_function => parse(primary.into_inner())
..
});
..
fn parse(pairs: Pairs<Rule>) -> T {
for pair in pairs {
..
// line with issue in it
- parse(pairs.clone)
+ parse(pair.into_inner())
..
}
}