-
Notifications
You must be signed in to change notification settings - Fork 201
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
Customizable error messages. #500
Comments
Can you provide a code snippet demonstrating what you are trying to achieve? |
Thanks for the quick reply. I am trying to implement a parser using Chevrotain. I like to add my own custom error message for each rule.
This is the sample rule for defining a variable (without space) If semicolon gets missed at the end the statement, then it is throwing error as Instead of using above message, can i implement my own custom message ? Thanks in advance. |
Current StatusThere is some ability to customize error messages.
Requested FeatureThe capability you are requesting is not currently supported. A naive implementation would just support providing the desired string by the end users. $.RULE("statement", function () {
$.CONSUME(variable, "missing variable name in assignment statement");
$.CONSUME(equals, "missing operator of assignment statement");
$.CONSUME(StringLiteral, "missing RHS of assignment statement");
$.CONSUME(terminal, "Missing ";" at the end of the statement");
}); A better solution would probably be to provide the parser with an "ErrorMessageCustomizer" Given an Error type (MismatchedTokenException/NoViableAltException/...) and the position in the grammar this customize should produce the appropriate error message.
|
Basically the existing hardcoded error message building need to be refactored to use some sort of |
Thank you for considering this. |
I'm playing around with implementing this. If you don't want to wait for the official API Unfortunately this seems like the only easy one to override. |
No description provided.
The text was updated successfully, but these errors were encountered: