[antlr-interest] Lexing problem

Kay Roepke kroepke at classdump.org
Fri Oct 13 09:21:25 PDT 2006


On 13. Oct 2006, at 17:34 Uhr, Emond Papegaaij wrote:

> Hello,
>
> I'm trying to match a multiline c-style comment into a COMMENT token
> without the opening and closing '/*' and '*/'. This is how I would  
> do it
> in ANTLRv2:
> COMMENT: '/*'! ( options {greedy=false;} : . )*  '*/'!;
>
> However the '!' does not work in v3. So I tried all of the following:
>
> COMMENT: '/*' contents=(( options {greedy=false;} : . )*) '*/'
>          { setText($contents.text); };

it's easier to just strip off the '/*' and '*/' characters:
COMMENT: '/*' ( options {greedy=false;} : . )* '*/'
          { setText(getText().substring(2, getText().length()-2)); }
         ;

why it complains about the newline character, I can't say offhand.

this should work.

HTH,
-k


-- 
Kay Röpke <kroepke at classdump.org>
classdump Software
Key fingerprint = A849 0F2C C322 4022 379E  8661 7E1B FE0D 4CD2 A6D0





More information about the antlr-interest mailing list