[antlr-interest] Cust error recovery
Alexey Demakov
demakov at ispras.ru
Wed Jul 27 01:24:19 PDT 2005
Please read sections "Parser Exception Handling"
and "Specifying Parser Exception-Handlers"
in ANTLR documentation:
http://www.antlr.org/doc/err.html#ParserExceptionHandling
"The default exception handler will report an error,
sync to the follow set of the rule, and return from that rule."
Example from generated code:
catch (RecognitionException ex) {
if (inputState.guessing==0) {
reportError(ex);
recover(ex,_tokenSet_5);
} else {
throw ex;
}
}
where recover() calls consumeUntil():
public void recover(RecognitionException ex,
BitSet tokenSet) throws TokenStreamException {
consume();
consumeUntil(tokenSet);
}
And you can override recover()...
"Second, you may specify your own exception handlers
in a variety of ways, as described later."
And you can specify your own code that will be executed instead of
reportError(ex);
recover(ex,_tokenSet_5);
Regards,
Alexey
-----
Alexey Demakov
TreeDL: Tree Description Language: http://treedl.sourceforge.net
RedVerst Group: http://www.unitesk.com
----- Original Message -----
From: "Martin Olsson" <mnemo at minimum.se>
To: <antlr-interest at antlr.org>
Sent: Tuesday, July 26, 2005 2:20 PM
Subject: [antlr-interest] Cust error recovery
> Hi (again :o),
>
> When ANTLR runs into a parse error I would like it to skip chars/tokens
> until a specific char/token is seen. After digging a while in the ANTLR
> source I noticed that there is a method called consumeUntil() which seems
> to do what I what.
>
> The problem is, when should I call it? How can I hook my own stuff into
> the lexer's bad-token-found code?
>
> And if I do this must I set the defaultErrorHandler=false option? Because
> it's not everywhere in the lexer I want to change the recovery procedure.
>
>
> sincerly,
> martin
>
>
More information about the antlr-interest
mailing list