title: Antlr4: How can I match end of lines inside multiline comments?
body: <p>I have to create a program that counts lines of code ignoring those inside a comment. I'm a <em>newbie</em> working with Antlr, and after trying a lot, the nearest I came to a solution is this erroneous grammar:</p>
  
  <pre><code>grammar Comments;
  comment         :   startc content endc;
  startc          :   '/*';
  endc            :   '*/';
  content         :   newline | contenttext;
  contenttext     :   CONTENTCHARS+;
  newline         :   '\r\n';
  CONTENTCHARS
      :   ~'*' '/'
      |   ~'/' .
      ;
  WS              :   [ \r\t]+ -&gt; skip;
  </code></pre>
  
  <p>If I try with <code>/*hello\r\nworld*/</code> the parser recognizes this, which is erroneous:</p>
  
  <p><a href="https://i.stack.imgur.com/eVhsn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eVhsn.png" alt="enter image description here"></a></p>
  
  <p>In order to count lines, the parser needs to detect newline characters, inside and outside multiline comments. I think my problem is that I don't know how to say "match everything inside <code>/*</code> and <code>*/</code> <strong>except</strong> <code>\r\n</code>.</p>
  
  <p>Please, can you point me in the right direction? Any help will be appreciated.</p>