You code your rules for predictable errors, including an empty alt for lack
of closing quote:
LIT
@init
{
int startCol = getCharPostionInLine();
}
: '"' ~NLCHARS* ('"' | { error(MISSING_QUOTE, startPos, $pos .... etc) }) ;
You should encapsulate all such errors that you can and try and avoid
letting the error handler catch errors (not always possible) and anyway you
should be overriding the default error handler. You can also override the
recovery mechanism when you know you can do better than reporting a missing
character or consuming the unexpected character.
Jim
> -----Original Message-----
> From: [email protected] [mailto:antlr-interest-
> [email protected]] On Behalf Of Robert Parks
> Sent: Monday, November 22, 2010 12:56 PM
> To: [email protected]
> Subject: [antlr-interest] Improving lexer error messages for missing
> end quotes
>
> * Sorry if this is a dupe - I posted through google groups first then
> read that you're are not supposed to do that *
>
> Hi,
> I am negative testing my lexer and finding that it doesn't handle
> missing end quotes on literal strings as well as I would like. It
> throws a MismatchedTokenException saying that it is expecting end quote
> found EOF which is correct but I would like it to say the line/ offset
> of the starting quote. Is there a way to get this information?
> Thanks,
> Rob
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en.