Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax error handling? #466

Closed
justinmchase opened this issue Jan 14, 2024 · 2 comments
Closed

Syntax error handling? #466

justinmchase opened this issue Jan 14, 2024 · 2 comments

Comments

@justinmchase
Copy link
Contributor

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?

@pdubroy
Copy link
Contributor

pdubroy commented Feb 25, 2024

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 #302.

@justinmchase
Copy link
Contributor Author

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants