Pattern for returning errors from ANTLR in data structures, not STDERR

Skip to end of metadata
Go to start of metadata

My ANTLR parser is embedded in other code. I've decided that reporting errors out of the parser would be better handled as a list of errors instead of having them sent to stderr.

In the v4 prerelease stuff, there is an example. Tool.java has

Tool.java

using ANTLRToolListener.java then in ToolANTLRParser.java I do:

which forces all msgs from antlr to shunt to Tool.error(), which announces to listeners.

For testing, i have unit tests use this ErrorQueue.java as a listener to the tool like so:

Labels: