Syntax error handling?
justinmchase opened this issue · 2 comments
I'm looking at your error docs on syntax errors here:
https://github.com/ohmjs/ohm/blob/main/doc/errors.md#grammar-syntax-error
And it uses this example grammar:
G {
start = *x
}
With this error message
Expected "~", "&", "#", an identifier, """, a number, "(", "[", "``", "{", "--", "|", or "}"
I'm wondering how syntax errors are calculated in general? As in, what is the strategy for determining the true error?
Could it simply be described as:
A summary of all patterns which failed to match the right-most position of the input?
From that right-most failure position how are you determining what was "expected"? When you have a complex set of rules parsing a position (and failing) are all failing patterns useful or only terminals?
Hi Justin! Yes, that's pretty much it.
For cleaner errors, it helps you to use rule descriptions (e.g. an identifier
or a number
):
You can read more in #302.
thanks