[antlr-interest] Minor suggestion re. Java output
jimi at temporal-wave.com
Mon Feb 4 08:39:49 PST 2008
> -----Original Message-----
> From: Guntis Ozols [mailto:guntiso at latnet.lv]
> Sent: Sunday, February 03, 2008 1:38 PM
> To: Jim Idle
> Cc: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Minor suggestion re. Java output
> > A tree is not guaranteed to be any particular type or interface as
> > tree adaptor can produce anything it likes. Hence it must be an
> > This is explained in the code etc.
> > Jim
> Casting tree once is not that big of a deal, but tons of casting could
> eliminated, plus there is no need for an option, if
> returned CommonTree.
> Covariant return types are available since java 1.5 (Sept 2004).
> Also, how about using enum for tokens? It would free client code of
> prefixes in
> switch statements, plus toString() would be available and more.
The original code was 1.4 compliant - I don't know how Ter feels about
being 1.5+ compliant but it is probably OK these days. However to b
co-variant you must be able to return things that or more or less
derived and an adapter can do anything it likes including ignoring
CommonTree and so on. What you probably want to do is just derive from
CommonTree and add the method yourself. The generated code will carry on
using (cast) but your code can use your own methods.
I think using enums is a reasonable suggestion, but I seemed to think
that there was some reason not to do it and I don't remember what it
More information about the antlr-interest