title: ANTLR Grammar line 1:6 mismatched input '<EOF>' expecting '.'
body: <p>I am playing with antlr4 grammar files, and I wanted to write my own <a href="https://support.smartbear.com/alertsite/docs/monitors/api/endpoint/jsonpath.html" rel="nofollow noreferrer">jsonpath</a> grammar.</p>
  
  <p>I've comeup with this:</p>
  
  <pre><code>grammar ObjectPath;
  
  objectPath      : dnot;
  
  dnot            : ROOT expr ('.' expr)
                  | EOF
                  ;
  
  expr            : select #selectExpr
                  | ID #idExpr
                  ;
  
  select          : ID '[]' #selectAll
                  | ID '[' INT ']' #selectIndex
                  | ID '[' INT (',' INT)* ']' #selectIndexes
                  | ID '[' INT ':' INT ']' #selectRange
                  | ID '[' INT ':]' #selectFrom
                  | ID '[:' INT ']' #selectUntil
                  | ID '[-' INT ':]' #selectLast
                  | ID '[?(' query ')]' #selectQuery
                  ;
  
  query           : expr (AND|OR) expr # andOr
                  | ALL # all
                  | QPREF ID # prop
                  | QPREF ID GT INT # gt
                  | QPREF ID LT INT # lt
                  | QPREF ID EQ INT # eq
                  | QPREF ID GTE INT # gte
                  | QPREF ID LTE INT # lte
                  ;
  
  /** Lexer **/
  ROOT    : '$.' ;
  QPREF   : '@.' ;
  ID      : [a-zA-Z][a-zA-Z0-9]* ;
  INT     : '0' | [1-9][0-9]* ;
  AND     : '&amp;&amp;' ;
  OR      : '||' ;
  GT      : '&gt;'  ;
  LT      : '&lt;'  ;
  EQ      : '==' ;
  GTE     : '&gt;=' ;
  LTE     : '&lt;=' ;
  ALL     : '*'  ;
  </code></pre>
  
  <p>After running this on a simple expression:</p>
  
  <pre><code>CharStream input = CharStreams.fromString("$.name");
  ObjectPathLexer lexer = new ObjectPathLexer(input);
  CommonTokenStream tokens = new CommonTokenStream(lexer);
  
  ObjectPathParser parser = new ObjectPathParser(tokens);
  ParseTree parseTree = parser.dnot();
  ObjectPathDefaultVisitor visitor = ...
  System.out.println(visitor.visit(parseTree));
  System.out.println(parseTree.toStringTree(parser));
  </code></pre>
  
  <p>The output is ok, meaning that the "name" is actually retrieved from the json, but there's a warning I cannot explain:</p>
  
  <pre><code>line 1:6 mismatched input '&lt;EOF&gt;' expecting '.'
  </code></pre>
  
  <p>I've read that I need to explicitly have an EOF rule added to my starting one (<code>dnot</code>), but this doesn't seem to work.</p>
  
  <p>Any idea what can I do ?</p>