[antlr-interest] adding enum token types output for java target
Brent Yates
brent.yates at gmail.com
Mon May 26 12:17:29 PDT 2008
I would prefer the Token.MINUS form (even if it breaks existing code) just
to resolve name conflicts that often arise.
Brent Yates
On Mon, May 26, 2008 at 3:13 PM, Terence Parr <parrt at cs.usfca.edu> wrote:
> RatherThem a separate file, it seems like the Tokens enough and should be
> generated within the class itself like this:
>
> enum Tokens {
> FUNC_DEF(8);
> T__23(23);
> WS(20);
> CHAR(15);
> EQ(11);
> EOF(-1);
> ...
> public final int tokenNum;
> public Tokens(int tokenNum) { this.tokenNum = tokenNum; }
> }
>
> all I did was add
>
> enum Tokens {
> <tokens:{<it.name>(<it.type>);}; separator="\n">
> public final int tokenNum;
> public Tokens(int tokenNum) { this.tokenNum = tokenNum; }
> }
>
> to the output template.
>
> The problem is that we have some duplication; I generate the following as
> well:
>
> public static final int Inputcharacter=31;
> public static final int COMMA=14;
> public static final int MINUS=21;
>
> So really, it should be a replacement not an addition. That unfortunately
> makes it ickier to reference token types. you would have to use Tokens.MINUS
> instead of MINUS within the code and, externally, one would have to use
> MyParser.Tokens.MINUS. well, I guess it reads well, but I'm worried about
> such a widespread ( albeit simple) change to the code generation. each
> reference to a token type would have to have the Tokens. prefix on the
> front.
>
> Ter
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080526/d4320fe3/attachment.html
More information about the antlr-interest
mailing list