textX / Arpeggio

Parser interpreter based on PEG grammars written in Python http://textx.github.io/Arpeggio/
Other
270 stars 55 forks source link

WIP: Optional feature: More verbose failed expression reporting #114

Open stanislaw opened 1 year ago

stanislaw commented 1 year ago

The verbose=False/True option is added to the Parser class. This option is disabled by default, and the existing behavior is fully preserved.

When the option is enabled, the final expected message is extended with extra information about the previously "weakly failed" rules. This way, not only the last failed NoMatch exception and its failing rules are displayed but also all the rules that were not matched during the whole parsing process.

Open points:


Will be done after/if the approach is confirmed.

Code review checklist

stanislaw commented 1 year ago

I have hit another problem with this approach, though. If everything is written to the buffer, then during the report time, also the exceptions that were eventually matched on a higher level are printed.

I have solved this problem by introducing the so-called markers, which help me to exclude the failed nodes that should not be printed. I hope that my code, in spite of it being messy, is easy to understand.

What I also found is that it could even make sense to print everything of Match* that is found in the deque because it gives a very nice presentation of what the grammar is capable of within the context of a currently edited file.

igordejanovic commented 1 year ago

@stanislaw Just a head up. I've been experimenting with this branch today. The experiment consisted of running examples (bibtex and simple) with verbose2 flag set and introducing syntax errors at various places.

The reports I got were quite unintuitive, at least for me. The master branch still provides a simple but more to the point report. What are your thoughts? Does this give any better messages in the context of StrictDoc?

I still find much easier to understand what is going on by running the parser with debug=True.