java - Correct way to add custom exception to Lexer/Parser files in antlr4 -
i have custom parsingexception(string message, int location, string offendingtext)
i want parser throw exception when parsing / lexing error encountered.
is correct ?
@parser::members { @override public void notifyerrorlisteners(token offendingtoken, string msg, recognitionexception ex) { throw new parsingexception(msg,offendingtoken.getstartindex(),offendingtoken.gettext()); } } @lexer::members { @override public void recover(recognitionexception ex) { throw new parsingexception(ex.getmessage(),getcharpositioninline(),ex.getoffendingtoken().gettext()); } }
i unhandledexception error this.
you should override syntaxerror
method of baseerrorlistener
instead of notifyerrorlisteners
, recover
decribed here: handling errors in antlr4.
123.hp.com/setup 3721
ReplyDelete