pest icon indicating copy to clipboard operation
pest copied to clipboard

Very unhelpful error messages for unmapped prefix operators in pratt parsers

Open rscarson opened this issue 1 year ago • 3 comments

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

rscarson avatar Feb 15 '24 14:02 rscarson

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.

de-sh avatar Jun 02 '25 20:06 de-sh

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!).

tomtau avatar Jun 03 '25 05:06 tomtau

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())
  ..
  }
}

de-sh avatar Jun 03 '25 18:06 de-sh