[antlr-interest] adding enum token types output for java target

Terence Parr parrt at cs.usfca.edu
Mon May 26 14:56:43 PDT 2008


On May 26, 2008, at 2:27 PM, Brian Goetz wrote:

> Think of the enum as a form of "reflection for ANTLR grammars."  Its  
> not required that you actually have to USE the generated enum; its a  
> way for third-party code to enumerate the tokens, including their  
> names.  The enums can also be used as keys in hashmaps.
>
> If you import another grammar, and therefore its tokens become  
> yours, you can simply "inline" the set of tokens at each level of  
> the hierarchy.  (In that case, you could include as a constructor  
> param the grammar from which they are imported, to further preserve  
> the provenance.)

So we'd leave everything as-is, just provide a new enum as a  
reflection thing.  I could buy that.  I'd make it in a separate file  
though like a .h file so it wouldn't look weird (i.e., like a dup) in  
the parser file.  It'd be XTokens.java for recognizer X.  Would that  
work for everybody?

Ter


More information about the antlr-interest mailing list