[antlr-interest] Q: Advice on localizing lexer [correction]

C. Mundi cmundi at gmail.com
Sun Jun 14 16:03:13 PDT 2009


On Sun, Jun 14, 2009 at 1:49 PM, David-Sarah Hopwood <
david-sarah at jacaranda.org> wrote:

> David-Sarah Hopwood wrote:
> > Identifier
> >   : IdentifierStartASCII IdentifierRest
> >   | { if (!isIdentifierStart(input.LA(1))) throw new
> NoViableAltException();
> >       matchAny(); mIdentifierRest(); }
> >   ;
>
> This will work, but because the 'input' IntStream is not passed to
> NoViableAltException, some of the information that would normally be
> available to construct error messages is missing. Use this instead,
> with the rest of the code as in my previous post:
>
> Identifier
>  : IdentifierStartASCII IdentifierRest
>  | { if (!isIdentifierStart(input.LA(1))) {
>        throw new NoViableAltException("identifier start", 0, 0, input);
>      }
>      matchAny(); mIdentifierRest(); }
>  ;
>

I would not have thought of that.  Thanks!

CM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090614/3b57e771/attachment.html 


More information about the antlr-interest mailing list