softdevteam / grmtools

Rust grammar tool libraries and binaries
Other
494 stars 32 forks source link

lrpar lose info about debug #446

Closed liluyue closed 2 months ago

liluyue commented 2 months ago

I execute "cargo run",get info :

  called `Result::unwrap()` on an `Err` value: CTConflictsError{0 Reduce/Reduce, 2 Shift/Reduce}

It is too vague,I wish can get below info for I fix the issue:

sequence.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
sequence.y: warning: 2 reduce/reduce conflicts [-Wconflicts-rr]
sequence.y: warning: shift/reduce conflict on token "word" [-Wcounterexamples]
  Example: • "word"
  Shift derivation
    sequence
    ↳ 2: maybeword
          ↳ 5: • "word"
  Example: • "word"
  Reduce derivation
    sequence
    ↳ 3: sequence "word"
          ↳ 1: •
ratmice commented 2 months ago

The most user friendly errors that we currently have can be seen by running the nimbleparse tool (unless using a hand-written lexer)... But it has been a bit difficult trying to find the right abstraction boundary to be able to leverage this from within the CTParserBuilder used by cargo. However that still doesn't have a counterexample generator, but should at least show a bit more info about source locations of the conflicts.

liluyue commented 2 months ago

I doubt the reliability of the nimbleparse. I use test the nimbleparse by calc exmaple :

markdown_parser git:(master) ✗ nimbleparse src/calc.l src/calc.y a.txt 
src/calc.y: [Error] Missing ':' at line 3 column 6

but calc actually is not bad:

%start Expr
%%
Expr -> Result<u64, ()>:
      Expr '+' Term { Ok($1? + $3?) }
    | Expr '-' Term { Ok($1? - $3?) }
    | Term { $1 }
    ;

so,I hope can find the state table for analysis the problem

ratmice commented 2 months ago

It looks like you need to pass the -y grmtools flag to nimbleparse, in this case to set the yacc format. Because the original format isn't expecting the type -> Result<u64, ()>

liluyue commented 2 months ago

that is valid.Thanks!

ratmice commented 2 months ago

I also notice that the output of nimbleparse in the above error that you quoted doesn't include inline source code. This was added in https://github.com/softdevteam/grmtools/pull/439 and contains some more information about conflicts. It seems like that hasn't made it into a release. So perhaps it would be good to try grmtools git (I'm assuming you are currently running a crates.io version). Also interested in feedback on the errors that produces.

liluyue commented 2 months ago

Understood, thank you for the reminder

ltratt commented 2 months ago

There's now a new release of grmtools out with this functionality in. Thanks @ratmice!