pest-parser / pest

The Elegant Parser
https://pest.rs
Apache License 2.0
4.67k stars 262 forks source link

Expected operator, found EOI #943

Open lambdaknight opened 1 year ago

lambdaknight commented 1 year ago

Describe the bug Pratt parser fails to parse a set of Pairs if EOI is included in them.

To Reproduce Steps to reproduce the behavior: 1) Modify the derive/examples/calc.rs example to not do the calls on lines 93-98.

Expected behavior It should work?

Additional context Seems like EOI should be ignored or handled in some other way than requiring you to manually handle the parse tree for one level.

lambdaknight commented 1 year ago

Also of note is that it seems like going one level deep into the parse tree isn't enough. A call to pairs.next().unwrap().into_inner() returns the expr just below program, but it still has the EOI token in the Pairs

tomtau commented 1 year ago

@segeljakt

tenstad commented 8 months ago

.op(Op::postfix(Rule::EOI))

and

.map_postfix(|lhs, op| match op.as_rule() {
    Rule::EOI => lhs,

seems to work :smile: