How to selectively use whitespace in Antlr3?
Hi,
I have a grammar that requires a white space ' ' in one of my lexer rules. However, I wish to ignore whitespace ' ' everywhere else because I don't want the parser to be whitespace sensitive. I understand that using $channel=HIDDEN is sending the WS characters to the hidden channel so that the parser doesn't see them. This worked just fine until I realized that I needed to support having 1 or more spaces in the middle of my NAME lexer rule. I have yet to find the proper way for handling this in ANTLR 3.1.3. Perhaps some type of predicate? having the parser look at the hidden channel? Maybe not hiding ' ' and mucking up my parser syntax to look for ' ' when possible? Hopefully not the last as it doesn't seem very pretty. Any detailed help would be greatly appreciated. I am using the C target.
I've provided this example as a very stripped down version of my grammar and the basic issue.
program  : start+;
start:Â Â cmd1 | cmd2;
cmd1 : 'exec' NAME;
cmd2 : 'debug' NAME DIGIT;
NAMEÂ Â Â Â :Â ('A'..'Z'|'a'..'z') (' '|'A'..'Z'|'a'..'z')+Â ('A'..'Z'|'a'..'z');
DIGIT Â Â : Â ('0'..'9');
WSÂ Â Â :Â Â Â (' '|'\t'|NEWLINE|FORMFEED)+ {$channel=HIDDEN;};
-Tom