title: How to use the ANTLR 4 TestRig to show which lexer rule is used when tokenizing input?
body: <p>I have an ANTLR 4 lexer grammar with a BEGIN lexer rule and an ID lexer rule:</p>
  
  <pre><code>lexer grammar Begin;                  
  
  BEGIN : 'begin' ;
  ID  : [a-z]+ ;
  
  WS  : [ \t\r\n]+ -&gt; skip ;
  </code></pre>
  
  <p>After generating the lexer and compiling, I ran the ANTLR TestRig tool with input <code>'begin'</code>:</p>
  
  <pre><code>grun Begin tokens -tokens
  begin
  ^Z
  </code></pre>
  
  <p>I got this output:</p>
  
  <pre><code>[@0,0:4='begin',&lt;1&gt;,1:0]
  [@1,7:6='&lt;EOF&gt;',&lt;-1&gt;,2:0]
  </code></pre>
  
  <p>Notice the token type is 1 (as &lt;1> indicates).</p>
  
  <p>I ran it again, this time with input <code>'beginning'</code>:</p>
  
  <pre><code>grun Begin tokens -tokens
  beginning
  ^Z
  </code></pre>
  
  <p>I got this output:</p>
  
  <pre><code>[@0,0:8='beginning',&lt;1&gt;,1:0]
  [@1,11:10='&lt;EOF&gt;',&lt;-1&gt;,2:0]
  </code></pre>
  
  <p>Why do I get the same token type? Does that mean the lexer is using the same lexer rule for both inputs?</p>
  
  <p>How do I get TestRig to show me that the lexer uses this rule: <code>BEGIN : 'begin' ;</code></p>
  
  <p>for tokenizing this input: <code>begin</code></p>
  
  <p>and this rule: <code>ID  : [a-z]+ ;</code></p>
  
  <p>for tokenizing this input: <code>beginning</code></p>