[antlr-interest] Match any node/subtree

UW Student uw.anon at gmail.com
Sat Jul 5 08:16:44 PDT 2008


Johannes Luber wrote:
 > UW Student schrieb:
 >>>> I would really prefer to have a single token.  Is it possible to
 >>>> modify Johannes' version to handle that?
 >>  >
 >>> Try this:
 >>>
 >>> TERM1: '.' ( ('.')=> '.' {$type = TERM2;} )* ;
 >>
 >> Will that ensure that the number of DOTs consumed is even?  If I
 >> understand correctly, it will simply catch any sequence of more than
 >> one DOT.
 >>
 >> -Andrew
 >>
 >
 > No, it won't. Try this:
 >
 > TERM1: '.' ( ('.')=> '.' {$type = TERM2;} '..'* ) ;
 >
 > But I wonder: Do you really need to create such a rule for a particular
 > language? Doing some regex should be faster there anywhere.
 >
 > Johannes
 >

Doesn't that have the original problem?  If there are three DOTs, then 
it will fail with a mismatched token exception, won't it?

The '...'+ tokens are filler (like whitespace or comments) in the 
language I'm translating.  It would be much easier to look past them if 
they were lumped together.

I agree that a regex would be a good solution for matching this token. 
I was hoping the Antlr lexer provided that kind of regex support.

Thanks,
Andrew

p.s. Is this thread starting to clutter the mailing list?  At what point 
is it appropriate to take it offline?


More information about the antlr-interest mailing list