[antlr-interest] Newbie trying to tame lexer

forumer at smartmobili.com forumer at smartmobili.com
Fri Aug 3 15:58:23 PDT 2012


Hi,

I would like to use antlr to generate a lexer to highlight some keyword 
and comments and so far
everything is fine as long as I don't try to handle multiline comments.
To solve my problem I wrote the following lines :


BLOCK_COMMENT
     : '/*'
	;

CONTINUE_COMMENT
     : ~('*/')*            // DOESN'T WORK
     ;

END_BLOCK_COMMENT
     :   '*/'
	;

LINE_COMMENT
     :   '//' ~('\n'|'\r')*  ('\r\n' | '\r' | '\n')
             {
                  $channel = Hidden;
             }
     |   '//' ~('\n'|'\r')*     // a line comment could appear at the 
end of the file without CR/LF
             {
                  $channel = Hidden;
             }
     ;

The problem is with BLOCK_COMMENT, CONTINUE_COMMENT and  
END_BLOCK_COMMENT rules so my question is:

Once the lexer is inside BLOCK_COMMENT how do I tell him to pass to 
CONTINUE_COMMENT rule
and then how do I tell CONTINUE_COMMENT to eat everything except '*/' ?



Thanks



More information about the antlr-interest mailing list