[antlr-interest] Grammar for block comments?

Gavin Lambert antlr at mirality.co.nz
Tue Jul 15 13:40:58 PDT 2008


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; };



More information about the antlr-interest mailing list