[antlr-interest] Why isn't Token an interface?

David Holroyd dave at badgers-in-foil.co.uk
Fri Sep 1 00:51:11 PDT 2006


On Thu, Aug 31, 2006 at 09:29:20AM -0700, Terence Parr wrote:
> 
> On Aug 31, 2006, at 8:57 AM, David Holroyd wrote:
> 
> >...it's not that this is a problem for me at the moment, but the Token
> >class seems to be begging to become an interface.
> >
> >Just out of interest, why does this class have the slightly odd
> >structure that it does?
> 
> Can you be more specific?

Well, all the methods are abstract apart from setText(), which is
implemented as a no-op.  That's why I said 'slightly odd', because I
can't see a pattern there.  Probably I'm just being dim :)

Apart from that non-abstract method (and all the existing code that
'extends Token' rather than 'implements Token), I can't see any reason
for Token being a class rather than an interface.

I can imagine Token becoming an interface being useful for people
wanting to do hackery like retrofitting existing types of object also be
ANTLR tokens, and so on.  Possibly it's a bit late in the release cycle
for such a change though, so maybe something to consider for ANTLR 4? ;)

ta,
dave

-- 
http://david.holroyd.me.uk/


More information about the antlr-interest mailing list