erikrose / parsimonious

The fastest pure-Python PEG parser I can muster
MIT License
1.8k stars 126 forks source link

Grammar debugging? #164

Open davaya opened 4 years ago

davaya commented 4 years ago

I'd like to use Parsimonious because of its goals - a lightweight parser to handle fairly simple grammars. But it isn't being actively developed, so the "Amazing grammar debugging" that was to be coming soon as of 2014, likely won't.

Situation: I have a toy grammar and test data, which gives an error like:

parsimonious.exceptions.ParseError: Rule 'start' didn't match at '
blah blah blah' (line 1, column 1).

(The specifics don't matter, I can debug this grammar. I'm looking for a process to debug real grammars.) I imagine that the parser is working through various rules, trying, failing, backtracking, trying again, but I have no visibility into the specific rule and it's text that I think should match but don't.

Lark (an Earley parser) is remarkably forgiving of errors and helpful at finding them. But I'm looking for the simplest lightest-weight parsing engine to use at runtime, and I'm guessing that PEG fits that bill. If only there were a PEG debugger.

So does anyone have a recommendation for an amazing PEG debugger? After developing a working grammar in an unconstrained environment, Parsimonious could still be used as a lightweight tool to parse the data.

===== Edit ===== Found it at http://textx.github.io/Arpeggio/stable/debugging/. But Parsimonious fails on some grammars that work in Arpeggio for reasons that are not yet clear. Grammars aren't identical but the translation seems straightforward (add an EOF token, replace regex flag~ with r).