mna / pigeon

Command pigeon generates parsers in Go from a PEG grammar.
BSD 3-Clause "New" or "Revised" License
822 stars 66 forks source link

Provide rule and no-match indicators in parserErr #112

Open flowchartsman opened 1 year ago

flowchartsman commented 1 year ago

The docs indicate that the prefix refers to the rule in which the error occurred, but I have not found this to be the case. It appears to only be the position in the parsed data. Allowing the programmer to access the enclosing failing rule would help in shimming in more useful error messages without having to resort to hacks like some of the solutions to #72, since you could just make a quick map of rule names to error messages and, with a little inspection, figure out a way to give your users something more useful.

As a side note, it would also be helpful to be able to identify no match errors without the string inspection that's now necessary since the message is hard-coded This could help provide a way to squash the error message as a fallback and only use the position to highlight where the parsing stopped, indicating something (hopfully) intuitive like an improperly-formatted statement when used in conjunction with more robust errors elsewhere.

fy0 commented 2 months ago

I don't completely understand without example. Maybe parser.rstack is what you want.