[antlr-interest] [newbie] Lexer Confusion

Johannes Luber jaluber at gmx.de
Sat Jul 5 08:11:41 PDT 2008


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


More information about the antlr-interest mailing list