[antlr-interest] Exception on obscure char but then continue
demakov at ispras.ru
Mon Aug 1 02:41:44 PDT 2005
You can define lexer rule that accepts any wrong chars.
The action for this rule should report error and skip
wrong token. It is very similar to comment handling
except for error reporting.
protected ERROR: "¤"
// report error
So, in case of "func¤tion" parser will receive
two ID tokens: "func" and "tion".
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: Monday, August 01, 2005 1:33 PM
Subject: [antlr-interest] Exception on obscure char but then continue lexing?
> I'm using an ANTLR parser to detect syntax errors in a c-like language.
> Currently if the lexer runs into for instance the char "¤" (which is not a
> part of my language) it will throw a NoViableAltForCharException which is
> then wrapped into a TokenStreamRecognitionException. I catch this and
> display the syntax error in my editor.
> The problem is that ANTLR seems to stop parsing too at this time. Instead
> I would like it to throw an exception as above, but then just ignore that
> character and resume lexing more or less as if the erroneous char never
> appeared (it should also, if possible, start over with flushed buffer so
> that the chars "func¤tion" will not be interpretted as a valid "function"
> Is this possible with ANTLR 2.7.5 ? Are there any examples of this?
More information about the antlr-interest