[antlr-interest] Grammar for block comments?
Andy Doddington
andy at doddington.net
Wed Jul 16 10:53:22 PDT 2008
Gavin Lambert wrote:
> At 05:45 16/07/2008, Andy Doddington wrote:
> > COMMENT: '/*' ( options {greedy=false;} : . )* '*/' {
> >_channel=99; };
>
> That's a little out of date -- the "_channel=99" bit should actually
> be "$channel=HIDDEN", and the "greedy=false" option is unnecessary --
> ".*" matching is always nongreedy by default.
>
> >Unfortunately, when this encounters a comment containing asterisks,
> >I get the error:
> >
> > line <line>:<column> mismatched character '*' expecting
> >'/'
> >
> >Is there any better solution, that avoids this problem?
>
> You could be more explicit about it:
>
> COMMENT: '/*' (~'*' | '*' ~'/')* '*/' { $channel = HIDDEN; };
>
>
Your suggestion made a lot of sense - however, it doesn't seem to have
had any effect on my problem, which seems
strange - even the error message is identical :-(
AD
More information about the antlr-interest
mailing list