0
votes

While lexing/parsing an input for an antlr grammar I would like to have an exception on errors which are the same errors as when using the grun alias from the antlr websites quickstart window.

I deactivated both parser and lexer error listeners with

lexer.removeErrorListeners();
parser.removeErrorListeners();

because they reported ambiguities and other stuff which I do not care about since the parsing process was successful.

How can I devise an error listener which reports errors which come from unsuccessful parsing?

1

1 Answers

1
votes

You can create your own error listener. Simply create a class that derives from the base error listener class, create an instance and add that via parser.addErrorListener().

Side note: usually there is no error listener for a lexer, as with ANTLR4 the preferred handling is to let lexer errors be handled via the always following parser errors.