[antlr-interest] Lexing problem

Emond Papegaaij e.papegaaij at student.utwente.nl
Sun Oct 15 00:48:40 PDT 2006


On Friday 13 October 2006 18:55, Terence Parr wrote:
> On Oct 13, 2006, at 8:34 AM, 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=COMMENT_BODY '*/' { setText($contents.text); };
> > COMMENT_BODY: ( options {greedy=false;} : . )*;
>
> Make that rule a "fragment".
>
Doh, I did write it with 'fragment' in the ANTLR file, but not in the 
email :) The rule with 'fragment' gives me the following warning:
nl/utwente/ewi/tpl/grammar/TPLLogic.g:173:54: The following alternatives 
are unreachable: 1

Kay Roepke suggested to use the following:
COMMENT: '/*' ( options {greedy=false;} : . )* '*/'
          { setText(getText().substring(2, getText().length()-2)); }
         ;

Which I'm using now, but still I would like to know what is wrong with the 
other approaches.

Best regards,
Emond Papegaaij


More information about the antlr-interest mailing list