How to selectively use whitespace in Antlr3?


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