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

David-Sarah Hopwood david-sarah at jacaranda.org
Sun Jun 14 13:49:43 PDT 2009


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(); }
  ;

-- 
David-Sarah Hopwood  ⚥  http://davidsarah.livejournal.com



More information about the antlr-interest mailing list