Syntax error handling?
justinmchase opened this issue · 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
):
![CleanShot 2024-02-25 at 07 36 55@2x](https://private-user-images.githubusercontent.com/17293/307571748-535d9667-5a18-4d67-a07f-5f4c2a01eee9.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTI4NjUyMzYsIm5iZiI6MTcxMjg2NDkzNiwicGF0aCI6Ii8xNzI5My8zMDc1NzE3NDgtNTM1ZDk2NjctNWExOC00ZDY3LWEwN2YtNWY0YzJhMDFlZWU5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA0MTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNDExVDE5NDg1NlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWM1MjVjZGEyNTRmY2Q3YmU0YWViNmZkZGFmMWQ0OGIwMjBlZmM4M2Q2MGE0NWMxMzM0YmFjMTA5MzA3YzJiZTkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.EWVWkIEg_n0GjNjXvMqsaM_B6TkBC7gXjouL5hcMq4s)
You can read more in #302.
thanks