title: Parser grammar rule is being ignored
body: <h1>The Goal</h1>
  <p>The goal is interpret plain text content and recognise patterns e.g. Arithmetic, Comments, Units of Measurements.</p>
  <h1>Example Input</h1>
  <p>This would be entered by a user.</p>
  <pre><code># This is an example comment
  10 + 10
  // Another comment
  This is one line of text
  Tested
  </code></pre>
  <h1>Expected Parse Tree</h1>
  <p>The goal of my grammar is to generate a tree that would look like this (if anyone has a better method I'd be interested to hear).</p>
  <p><strong>Note:</strong> The <code>10 + 10</code> is being recognised as an <code>arithmetic</code> rule.</p>
  <p><a href="https://i.stack.imgur.com/jfy05.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jfy05.png" alt="Goal output" /></a></p>
  <h1>Current Parse Tree aka The Problem</h1>
  <p>Below is the current output from the lexer and parser.</p>
  <p><strong>Note:</strong> The <code>10 + 10</code> is being recognised as an <code>text</code> and not the <code>arithmetic</code> rule.</p>
  <p><a href="https://i.stack.imgur.com/EI7sZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EI7sZ.png" alt="Current Output" /></a></p>
  <h1>Grammar Definition</h1>
  <p>The logic of the grammar at a high levels is as follows:</p>
  <ol>
  <li>Parse line by line</li>
  <li>Determine the line content if not fall back to text</li>
  </ol>
  <pre><code>grammar ContentParser;
  
  /*
   * Tokens
   */
  NUMBER: '-'? [0-9]+;
  LPARAN: '(';
  RPARAN: ')';
  POW: '^';
  MUL: '*';
  DIV: '/';
  ADD: '+';
  SUB: '-';
  
  LINE_COMMENT: '#' TEXT | '//' TEXT;
  TEXT: ~[\n\r]+;
  EOL: '\r'? '\n';
  
  /*
   * Rules
   */
  start: file;
  file: line+ EOF;
  line: content EOL;
  
  content
      : comment 
      | arithmetic 
      | text
      ;
  
  // Custom Content Types
  comment: LINE_COMMENT;
  
  /// Example taken from ANTLR Docs
  arithmetic:
      NUMBER                                                          # Number
      | LPARAN inner = arithmetic RPARAN                              # Parentheses
      | left = arithmetic operator = POW right = arithmetic           # Power
      | left = arithmetic operator = (MUL | DIV) right = arithmetic   # MultiplicationOrDivision
      | left = arithmetic operator = (ADD | SUB) right = arithmetic   # AdditionOrSubtraction;
  
  text: TEXT;
  </code></pre>
  <h1>My Understanding</h1>
  <p>The <code>content</code> rule should check for a match of the <code>comment</code> rule then followed by the <code>arithmetic</code> rule and finally falling back to the <code>text</code> rule which matches any character apart from newlines.</p>
  <p>However, I believe that the lexer is being greedy on the <code>TEXT</code> tokens which is causing issues but I'm not sure.</p>
  <p>(I'm still learning ANTLR)</p>