[antlr-interest] Token Names

Adam Connelly adam.rpconnelly at googlemail.com
Thu Jan 10 14:58:31 PST 2008


After discussing this with a colleague, we've come up with the following
idea:

Create a ErrorHandler interface that handles reporting errors.  The parser
accepts an ErrorHandler as an argument, and overrides the error
handling/reporting methods with calls to the ErrorHandler.  The handler is
generated from the list of tokens, and possibly altered by hand to specify
what text should be shown for which token (or maybe there can be something
more automatic).

This means that you could easily provide support for multiple languages, you
can tailor the error reporting without altering either the lexer or parser,
and regenerating the parser doesn't lose any changes you made to the token
names.

Does that seem sensible or am I imagining a problem that doesn't exist?

It would be nice to have some syntax in the lexer that let you specify the
textual representation of a token, for example (bearing in mind that I'm not
proposing the following syntax, just something that has this effect):

MYTOKEN
options { altName="my token"; }
: 'token'
;

Cheers,

Adam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080110/da26bd21/attachment.html 


More information about the antlr-interest mailing list