[antlr-interest] good error handling

Terence Parr parrt at cs.usfca.edu
Sat Feb 20 15:22:27 PST 2010


Hi,

As I rebuild ANTLR (v4) using v3, I'm trying to do a good job of their recovery.  adding my notes here:

http://www.antlr.org/wiki/display/~admin/Gracefully+handling+syntax+errors

Just added to that page some nice sample code that I'm using. For input:

grammar A;
a : b
   catch [Exception e] {...}
b : B ;

ANTLR v4 gives the tasty error message:

{code}
error(17): A.g:2:4: unterminated rule (missing ';') detected at 'b catch' while looking for rule element
{code}

Oh, and it correctly recovers from the disastrous rule 'a' to create the AST for rule 'b'.

(COMBINED_GRAMMAR A
 (RULES <mismatched token: [@17,46:46='b',<63>,4:0], resync=a : b catch Exception e {...}>
  (RULE b (BLOCK (ALT B)))
 )
)

Ter


More information about the antlr-interest mailing list