title: extra channels in antlr 4.5
body: <p>I am using antlr 4.5 to build a parser for a language with several special comment formats, which I would like to stream to different channels.</p>
  
  <p>It seems antlr 4.5 has been extended with a new construct for declaring extra lexer channels:</p>
  
  <p>extract from doc <a href="https://theantlrguy.atlassian.net/wiki/display/ANTLR4/Lexer+Rules" rel="noreferrer">https://theantlrguy.atlassian.net/wiki/display/ANTLR4/Lexer+Rules</a></p>
  
  <blockquote>
    <p>As of 4.5, you can also define channel names like you enumerations
    with the following construct above the lexer rules:</p>
    
    <p>channels { WSCHANNEL, MYHIDDEN }</p>
  </blockquote>
  
  <p>My lexing and parsing rules are in a single file, and my code looks like this:</p>
  
  <pre><code>    channels {
         ANNOT_CHANNEL,
         FORMAL_SPEC_CHANNEL,
         DOC_CHANNEL,
         COMMENT_CHANNEL,
         PRAGMAS_CHANNEL
      }
  </code></pre>
  
  <p>... parsing rules ...</p>
  
  <pre><code>// expression annotation (sent to a special channel)
      ANNOT: (EOL_ANNOT | LUS_ANNOT | C_ANNOT) -&gt; channel(ANNOT_CHANNEL) ;
      fragment LUS_ANNOT: '(*!' ( COMMENT | . )*? '*)' ;
      fragment C_ANNOT: '/*!' ( COMMENT | . )*? '*/' ;
      fragment EOL_ANNOT: ('--!' | '//!') .*? EOL ;
  
      // formal specification annotations (sent to a special channel)
      FORMAL_SPEC: (EOL_SPEC | LUS_SPEC | C_SPEC ) -&gt; channel(FORMAL_SPEC_CHANNEL) ;
      fragment LUS_SPEC: '(*@' ( COMMENT | . )*? '*)' ;
      fragment C_SPEC: '/*@' ( COMMENT | . )*? '*/' ;
      fragment EOL_SPEC: ('--@' | '//@' | '--%') .*? EOL;
  
      // documentation annotation (sent to a special channel)
      DOC: ( EOL_DOC |LUS_DOC | C_DOC ) -&gt; channel(DOC_CHANNEL);
      fragment LUS_DOC: '(**' ( COMMENT | . )*? '*)' ;
      fragment C_DOC: '/**' ( COMMENT | . )*? '*/' ;
      fragment EOL_DOC: ('--*' | '//*') .*? EOL;
  
      // standard comment (sent to a special channel)
      COMMENT: ( EOL_COMMENT | LUS_COMMENT | C_COMMENT ) -&gt; channel(COMMENT_CHANNEL);
      fragment LUS_COMMENT: '(*' ( COMMENT | . )*? '*)' ;
      fragment C_COMMENT: '/*' ( COMMENT |. )*? '*/' ;
      fragment EOL_COMMENT: ('--' | '//') .*? EOL;
  
      // pragmas are sent to a special channel
      PRAGMA: '#pragma' CHARACTER* '#end' -&gt; channel(PRAGMAS_CHANNEL);
  </code></pre>
  
  <p>however I am still getting this 4.4-like error</p>
  
  <pre><code>warning(155): Scade6.g4:550:52: rule ANNOT contains a lexer command with an unrecognized constant value; lexer interpreters may produce incorrect output
  warning(155): Scade6.g4:556:56: rule FORMAL_SPEC contains a lexer command with an unrecognized constant value; lexer interpreters may produce incorrect output
  warning(155): Scade6.g4:562:45: rule DOC contains a lexer command with an unrecognized constant value; lexer interpreters may produce incorrect output
  warning(155): Scade6.g4:568:62: rule COMMENT contains a lexer command with an unrecognized constant value; lexer interpreters may produce incorrect output
  warning(155): Scade6.g4:574:47: rule PRAGMA contains a lexer command with an unrecognized constant value; lexer interpreters may produce incorrect output
  </code></pre>
  
  <p>If I split lexer and parser in two distinct files and use an import statement to import the lexer in the parser I still get the same error as above,</p>
  
  <p>Using integer constants instead of names with a combined grammar</p>
  
  <pre><code>-&gt; channel(10000)
  </code></pre>
  
  <p>yields the following error </p>
  
  <pre><code>error(164): Scade6.g4:8:0: custom channels are not supported in combined grammars
  </code></pre>
  
  <p>If I split lexer and parser apart in two files and use integer constants no warning, however it is not really satisfactory for readability.</p>
  
  <p>Is there anything I can do to have extra channels named properly? (with either combined or separate lexer/parser specs, no preference) </p>
  
  <p>Regards,</p>