ANTLR Lexer rules in v4 Lexer commands


Example

A lexer rule can have associated commands:

WHITESPACE: [ \r\n] -> skip;

Commands are defined after a -> at the end of the rule.

  • skip: Skips the matched text, no token will be emited
  • channel(n): Emits the token on a different channel
  • type(n): Changes the emitted token type
  • mode(n), pushMode(n), popMode, more: Controls lexer modes