Enhanced error reporting -- extending LineCol + extras
Hi,
I've really enjoyed the package -- it's quite convenient to generate grammars in this way. My only complaint is that it is difficult to create nice error messages using only LineCol -- because really, I'd like information to accumulate out of a series of rule applications.
E.g. if the trace looks like:
Rule 1 : 0 -> Line 1, Char 3
Rule 1 : 1 -> Line 1, Char 7
Rule 1 : 2 -> Line 1, Char 9 (FAIL)
Assuming there are no alternatives, it would be nice to know that the topmost rule starts at Line 1, Char 3, the innermost successful starts at Line 1, Char 7, and the failure is at Line 1, Char 9 (for example).
I don't think this sort of propagation is supported yet? Or, if it is, I'd love for a reference.
Also, is there a convenient way to organize my grammars such that parsing is robust -- e.g. failure can be recovered from, by looking for a finish this rule token and continuing? This use case most prominently occurs in programming language parsers, where (down the line) - the developer may want to setup LSP and failure at a single point is not ideal.
Thank you for your time, if you happen to see this.
The error position reported is the maximum input position the parser reached. It may reach that position multiple times when trying different alternatives, so there's not a single stack trace of how it got there. It collects all the tokens that failed at that position, and that's the expected set of tokens that would have allowed it to advance.
However, your second question about LSP is the more interesting one, and I think that solving that one by producing a partial syntax tree with error nodes is probably the better answer to your first question as well. I've started a discussion thread with some ideas there.
@kevinmehall Thank you for the response! I'll read the discussion thread.