Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ANTLR 4: Avoid error printing to console

Tags:

antlr

antlr4

With ANTLR I parse a grammar. The ANTLR errors are indicated in a custom editor for the grammar. However I would like to disable the printing of error messages to a Java console.

I've implemented my own BaseErrorListener and removed the default as described in the ANTLR book:

MyErrorListener errList=new MyErrorListener ();
lexer.removeErrorListeners();
lexer.addErrorListener(errList);
parser.removeErrorListeners();   
parser.addErrorListener(errList);

Still I get printed outputs to my Java console (connected to the Java output and error stream).

How can I disable the printing to the console in ANTLR?

like image 392
Marcel Avatar asked Sep 23 '14 08:09

Marcel


1 Answers

By default, ConsoleListener is activated [1].

You can remove it in your code:

lexer.removeErrorListener(ConsoleErrorListener.INSTANCE);

[1] https://github.com/antlr/antlr4/blob/master/runtime/Java/src/org/antlr/v4/runtime/Recognizer.java#L56 (see add(ConsoleErrorListener.INSTANCE);)

like image 177
uwolfer Avatar answered Sep 22 '22 14:09

uwolfer