Antlr - Channel

Card Puncher Data Processing

About

When you don't want to check for non-semantic rule such as comments / whitespace, you can throw them away with → skip but if you want to preserve them, you use channels.

Syntax

Declaration

Only lexer grammars can contain custom channels specifications

channels {
  WHITESPACE_CHANNEL,
  COMMENTS_CHANNEL
}

Usage

Those channels can then be used like enums within lexer rules:

WS : [ \r\t\n]+ -> channel(WHITESPACE_CHANNEL) ;

Built-in

  • HIDDEN





Discover More
Card Puncher Data Processing
Antlr - (Grammar|Lexicon) (g4)

Grammar in the context of Antlr. The grammar definition of Antlr is called a antlr/antlr4/blob/master/doc/lexicon.mdLexicon because the grammar is used by the lexer (hence the lexer grammar) See: ...
Card Puncher Data Processing
Antlr - Lexer Grammar

The grammar file of the lexer is composed of lexer rule, optionally broken into multiple lexical modes grammar file Only lexer grammars can contain: mode specifications. custom channels specifications...



Share this page:
Follow us:
Task Runner