[antlr-interest] Lexer exception?
Alexey Demakov
demakov at ispras.ru
Sun Feb 19 23:08:20 PST 2006
Hi Jens,
Aa I wrote recently, it is the bug in antlr.
http://www.antlr.org/pipermail/antlr-interest/2006-February/015417.html
Define this method in your lexer code:
public void recover( RecognitionException ex, BitSet tokenSet ) throws CharStreamException
{
saveConsumedInput = false;
consume();
consumeUntil( tokenSet );
saveConsumedInput = true;
}
But if you want completly skip malformed token, you have to define custom exception handler
with $setType( Token.SKIP ) for each lexer rule. :(
---
Alexey Demakov
TreeDL: Tree Description Language: http://treedl.sourceforge.net
RedVerst Group: http://www.unitesk.com
From: "Jens Bartelheimer" <jens.bartelheimer at gmx.de>
> Hi Martin,
>
> thanks for your reply but if I turn off the option there are no
> additional exceptions.
>
> If I turn it on explicit I have the following error in the Lexer:
>
> My error message:
> The method recover(RecognitionException, BitSet) is undefined for the
> type UMLLexer
>
> Why? Is there a mistake in my Lexer?
>
> Jens
>
>
> Martin Probst wrote:
> >> how can I catch such an exception? I do not found something in the
> >> documentation.
> >>
> >> line 1:1: unexpected token: 111
> >>
> >
> > You have to turn off the default error handler, e.g. in your options
> > section of the lexer "defaultErrorHandler = false". Afterwards you can
> > catch exceptions. All of them extend ANTLRException, the manual contains
> > a part called "Exception hierarchy".
More information about the antlr-interest
mailing list