ANTLR4: Whitespace handling
I have seen many ANTLR grammars that use whitespace handling like this: WS: [ \n\t\r]+ -> skip; // or WS: [ \n\t\r]+ -> channel(HIDDEN); So the whitespaces are thrown away respectively send to the hidden channel. With a grammar like this: grammar Not; start: expression; expression: NOT expression | (TRUE | FALSE); NOT: 'not'; TRUE: 'true'; FALSE: 'false'; WS: [ \n\t\r]+ -> skip; valid inputs are ' not true ' or ' not false ' but also ' nottrue ' which is not a desired result. Changing the grammar to: grammar Not; start: expression; expression: NOT WS+ expression | (TRUE | FALSE); NOT: 'not';