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?
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);
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With