title: ANTLR4 - parse a file line-by-line
body: <p>I try to write a grammar to parse a file line by line.</p>
  
  <p>My grammar looks like this:</p>
  
  <pre><code>grammar simple;
  
  parse: (line NL)* EOF
  line    
       : statement1     
       | statement2 
       |            // empty line           
       ;
  
  statement1 : KW1 (INT|FLOAT);
  statement2 : KW2 INT;
  
  ... 
  
  NL          : '\r'? '\n';
  WS          : (' '|'\t')-&gt; skip; // toss out whitespace
  </code></pre>
  
  <p>If the last line in my input file does <strong>not</strong> have a newline, I get the following error message:</p>
  
  <pre><code>line xx:37 missing NL at &lt;EOF&gt;
  </code></pre>
  
  <p>Can somebody please explain, how to write a grammar that actually accepts the last line without newline</p>