How to recover from parser error? #1792
-
In our grammar, if there is parser error such as a random string without semicolon, the validator will fail for the current document. Can I define a rule to parse the random strings in the grammar? If so, how should define this rule? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
Hey @durianwaffle, without diving to deep into parsing theory: There are some kinds of parser errors that are hard to recover from, due to the way how recursive descent parsers work. You're encountering one because the parser fails to perform its lookahead function, which in turn prevents the parser from identifying which rule to parse. Usually, the parser then attempts to skip tokens to recover from this error, but this doesn't always work.
I don't think that's possible, at least not to my knowledge. I would assume that even if you were able to define such a rule, you would likely run into unexpected side effects. |
Beta Was this translation helpful? Give feedback.
Because the lookahead is instantly aborted once a token is identified that doesn't fit any of the given alternatives. See also here.
No, because the entry point of the grammar already appeared, and so it will just result in more errors for all non-trivial grammars.
I guess you would need to look at the errors in the document? I'm not entirely sure.
Maybe? I nee…