title: Access Channels in ANTLR 4 and Parse them separately
body: <p>I have included my comments in to a separate channel in ANTLR 4. In my case it is channel 2.</p>
  <p>This is my lexer grammar.</p>
  <pre><code>COMMENT: '/*' .*? '*/' -&gt; channel(2) 
         ;
  </code></pre>
  <p>I want to access this channel 2 and do a parse on this channel to accumulate comments. So I included that as in parsing grammar as below:</p>
  <pre><code>comment
  :COMMENT
  ;
  </code></pre>
  <p>In the program</p>
  <pre><code>        string s = &quot; paring string&quot;
          AntlrInputStream input = new AntlrInputStream(s);
          CSSLexer lexer = new CSSLexer(input); 
         
          CommonTokenStream tokens = new CommonTokenStream(lexer,2);
  </code></pre>
  <p>Then I want to do the parsing on the tokens</p>
  <pre><code>var xr = parser.comment().GetRuleContexts&lt;CommentContext&gt;();
  </code></pre>
  <p>because I want to get the information from the CommentContext object such as <code>Start.Column</code> etc.</p>
  <p>EDIT:</p>
  <p>This is the improved question</p>
  <p>To be more specific, I want to get all the tokens in channel 2 and parse them using comment grammar to get all the comments to a list(<code>IReadOnly&lt;CommentContext&gt;</code>) so that I can iterate through each of these and access the information such as, start line, start column, end line end column, and the token text.</p>
  <pre><code>CommonTokenStream tokens = new CommonTokenStream(lexer,2);
  </code></pre>
  <p>This is not giving me the tokens in channel 2. And another thing I discovered is until these tokens are passed as arguments to the parser construct <code>XParser parser = new XParser(tokens);</code></p>
  <p>Then only I can access the the tokens by calling <code>GetTokens()</code>.In the tokes I can see that there are comments identified as tokens and is in the channel 2. Even though <code>CommentTokenStrem</code> species the channel number as above. it contains all the tokens.</p>
  <ol>
  <li><p>What is the reason of not able to access the tokens until the parser object is created using the tokens?</p>
  </li>
  <li><p>I want to get a <code>CommentTokenStrem</code> in channel 2 and pass the to the XParser object creation to parse these tokens using my <code>comment</code> grammar.
  What is the best way of doing this in ANTLR 4 API?</p>
  </li>
  </ol>