[antlr-interest] enums in v4 ANTLR Java code generation considered useless

Scott Stanchfield scott at javadude.com
Wed May 19 11:54:24 PDT 2010


Hmmm... that's evil, ya know that ;)  Good to catch that now, though...

Probably LITERAL_1, LITERAL_2, etc. To make it easier for
debugging/printing/reporting you could add a pattern property (hmmm...
the more I think about it the more I like it... if there's a
description it could be printed w/ the error message, otherwise the
pattern. both could be useful for other purposes)

  public enum FooParserTokens implements TokenType {
    IDENT("('a'..'z')('a'..'z'|'A'..'Z')*", "an identifier ..."),
    LITERAL_1(";", null),
    LITERAL_2("+", null);
    private String pattern;
    private String description;
    private FooParserTokens(String pattern, String description) {
      this.pattern = pattern;
      this.description = description;
    }
  }

-- Scott

----------------------------------------
Scott Stanchfield
http://javadude.com



On Wed, May 19, 2010 at 2:42 PM, Terence Parr <parrt at cs.usfca.edu> wrote:
>
> On May 19, 2010, at 11:39 AM, Scott Stanchfield wrote:
>
>> You can still define the match in the superclass -- just use an
>> interface like Edgar mentioned and I demonstrated in the
>> "clarification" note I sent.
>
> oh right.
>
>> I think the big value here would be that it forces every place that
>> uses the token types to use the enum names (as there are no integer
>> values). I think that would help debugging enormously (rather than
>> seeing '4' as the value in the variables window, you'd see 'IDENT').
>
> what about ';' token?  What's it's label?
> T
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>


More information about the antlr-interest mailing list