[antlr-interest] Pattern for returning errors from ANTLR in data structures, not STDERR

Arthur Goldberg goldberg at cbio.mskcc.org
Tue Nov 30 17:13:29 PST 2010


Hello All

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, 
not exceptions, so that the parse is allowed to recover from errors and 
complete, if possible.
Does anyone have a working pattern for returning errors from ANTLR in a 
list, not STDERR?
In more detail, I'd run it in two modes:
1) testing: call some rule other than the root
In this case, I will let the rule report an error via an exception.

2) production: call the root rule
In this case, a newReportError() in

     catch (RecognitionException re) {
         newReportError(re);
         recover(input,re);
     }

would catch exceptions thrown by other rules, and store them in a list. 
When the root rule returns, it returns the list of errors, along with 
the results of the parse.

If someone can help me with this, I'll make it worth your while. I'm 
running out of time for messing with ANTLR.

Thanks
Arthur



More information about the antlr-interest mailing list