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

Unable to customize error messages on top of error messages generated by ANTLR4 Parser #4612

Open
ViswaTejaKommireddy opened this issue May 10, 2024 · 1 comment

Comments

@ViswaTejaKommireddy
Copy link

Generating custom error messages on top of error messages generated by ANTLR4

I am trying to customize the error messages generated by ANTLR4 by categorizing them. I am using syntax error generated by ErrorListner in ANTLR4
class CustomErrorListener<TSymbol = any> implements ErrorListener<TSymbol> { private syntaxErrors: { line: number; column: number; lastCharPosition: number; message: string }[] = []; syntaxError( recognizer: Recognizer<TSymbol>, offendingSymbol: TSymbol, line: number, column: number, message: string, exception?: RecognitionException ): void {}

But I am unable to distinguish the exceptions using the Exception types. Please refer the below code
if (exception instanceof RecognitionException) {
message = "Recoginition Error: " + message;
}
if (exception instanceof NoViableAltException) {
message = "No Viable Alternative Error: " + message;
}

Please let me know if there are any ways to customize the error messages

@kaby76
Copy link
Contributor

kaby76 commented May 10, 2024

I was just looking at error reporting. #3700 (comment). You have to override the error strategy as well since that is where the error message is constructed from the parser state.

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