The above code represents a valid enum type declaration. If we remove the enum values like so:
E = enum {}
Then we'll get an inconvenient error message:
unexpected token 'E' at file.gapi:1:1
which is not very helpful, instead I’d like to get something like:
enum type E is missing values at file.gapi:1:1
Proposal
Instead of directly returning an UnexpectedToken error the parser should try to match the user-defined error-pattern. If the error pattern is matched then its action should be executed and the returned error should then be returned instead.
This feature would require a slight breaking change to the API:
Currently, we need to allow the wrong syntax (with no values) in the grammar and check whether there are any values in the Action which makes the actions unnecessarily complicated.
This is a real-world situation from romshark/gapi:
The above code represents a valid enum type declaration. If we remove the enum values like so:
Then we'll get an inconvenient error message:
which is not very helpful, instead I’d like to get something like:
Proposal
Instead of directly returning an
UnexpectedToken
error the parser should try to match the user-defined error-pattern. If the error pattern is matched then its action should be executed and the returned error should then be returned instead.This feature would require a slight breaking change to the API:
Current Workaround
Currently, we need to allow the wrong syntax (with no values) in the grammar and check whether there are any values in the Action which makes the actions unnecessarily complicated.