[antlr-interest] error handling
Bryan Ewbank
ewbank at gmail.com
Tue Apr 5 02:05:52 PDT 2005
I use a different approach, because catching exceptions outside the
parser means your customer only get the first syntax error each time.
I'd prefer to give them as many as possible...
I tell antlr to disable exceptions for most productions, then enable
exceptions for a few key production recovery points (statement,
expression, and a few others), then have my own reportError() method
that keeps a running count of errors seen:
MyParser extends Parser;
options { defaultErrorHandler=false; }
...
expression
options {defaultErrorHandler=true;}
:
expr { ## = #( #[EXPR,"EXPR"], ## ); }
;
The top level routine in my parser returns true/false based on the
number of errors:
parseme
returns [bool r = true]
:
realParseProduction
{ if (nerr > 0) r = false; }
;
More information about the antlr-interest
mailing list