[antlr-interest] Parser Problem for comment

Michael micha-1 at fantasymail.de
Tue Jun 9 03:59:55 PDT 2009


Am Tuesday 09 June 2009 12:01:41 schrieb virg g:
> Hi,
>
> COMMENT : '\'' ~('\n'|'\r')* {$channel=HIDDEN;} ;
>
> This is working well, if there is no single quote occurs within the
> instruction. If single quote occurs in the instruction other than at the
> beginning of the file, the text after single quote is treating as a
> comment. So How to write a rule only if line starts with single quote then
> it is comment not any where else? please help me.

do you have a rule for NL? Something like
NL: '\r'? '\n' ;  // or similar...

does it work to change it to:
NL: ('\r'? '\n')+ (  '\'' ~('\n'|'\r')* )?  ;  // to include a following 
comment

or a semantic predicate which tests the column number

or maybe it's easier to use a  file reader which just drops the lines 
beginning with a '   :-)

cheers,
 Michael




More information about the antlr-interest mailing list