I am trying to write a grammar in antlr4. But i am not able to selectively ignore whitespaces in my rules. Attaching my grammar. Here I should allow a space(a token of WHITESPACE) if the token matches alphaNumericWSC but at all other places i want to skip the WHITESPACE.
WHITESPACE : [ \t\n\r]+ -> skip
alphaNumericWSC : AlphaNumeric (',' AlphaNumeric)*
| AlphaNumeric (' ' AlphaNumeric)*
;
In other words I want to not ignore the whitespace only in this rule alphaNumericWSC.
Thanks in advance for the help.
string: '"' ~'"' '"'
(note '"' is ' " ' without spaces). The greediness of ANTLR's lexer will do the job. – Mephy