[antlr-interest] When a comment not a comment

Peterson, Joe joe.peterson at intel.com
Wed Feb 18 10:51:56 PST 2009


Hello all,

I have a need to have an exception to my comment rule that I want to know the best way to handle.  Basically, I need to not treat something that starts with, say, #ABCD as not a comment. (This is for backward compatibility.)

For example:
# This is a comment
Something = value;
#ABCD This = that
This needs to treat the third line as if the #ABCD didn't exist.  So I'm trying something like this:

fragment  NONCOMMENT :  '#ABCD' ;

COMMENT
     :   NONCOMMENT  { $channel=HIDDEN; }
    |   '#' ~('\r' | '\n')* { $channel=HIDDEN; };

This seems to work fine, but when I check the grammar, I get a warning that #ABCD can match multiple alternatives and so the second alternative is disabled.  This is the desired behavior, of course, but since it gives me a warning, I wonder if there a better way to switch off treating this thing that looks like a comment as a comment.

Thanks,
-JEEP
Joe Peterson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090218/c9ecaec5/attachment.html 


More information about the antlr-interest mailing list