ohm icon indicating copy to clipboard operation
ohm copied to clipboard

Syntax error handling?

Open justinmchase opened this issue 1 year ago • 1 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?

justinmchase avatar Jan 14 '24 23:01 justinmchase

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):

CleanShot 2024-02-25 at 07 36 55@2x

You can read more in https://github.com/ohmjs/ohm/issues/302.

pdubroy avatar Feb 25 '24 06:02 pdubroy

thanks

justinmchase avatar Mar 21 '24 02:03 justinmchase