title: proto token candidates ordering
body: <p>How does perl6 decide which <code>proto</code> <code>token</code> to match against first?</p>
  
  <p>The below code works as expected, it matches the string <code>1234</code>, and <code>Grammar::Tracer</code> shows that the first token matched against is <code>s:sym&lt;d&gt;</code>, which makes sense since it's the longest token.</p>
  
  <p>However, if I changed a literal to token, for example, changing <code>token</code> <code>three</code> form <code>'3'</code> to <code>&lt;digit&gt;</code>, it fails to match, and <code>Grammar::Tracer</code> shows that <code>s:sym&lt;b&gt;</code> is being matched against first.</p>
  
  <p>Moving <code>s:sym&lt;d&gt;</code> to the top, matches the string in both cases, but what is the explanation for that behavior?</p>
  
  <pre><code>#!/usr/bin/env perl6
  no precompilation;
  use Grammar::Tracer;
  
  grammar G {
  
    token TOP { &lt;s&gt; }
  
    proto token s { * }
  
    token s:sym&lt;a&gt; { &lt;one&gt; }
    token s:sym&lt;b&gt; { &lt;one&gt; &lt;two&gt; }
    token s:sym&lt;c&gt; { &lt;one&gt; &lt;two&gt; &lt;three&gt; }
    token s:sym&lt;d&gt; { &lt;one&gt; &lt;two&gt; &lt;three&gt; &lt;four&gt; }
  
    token one   { '1' }
    token two   { '2' }
    token three { '3' }
    token four  { '4' }
  }
  
  my $g = G.new;
  
  say $g.parse: '1234';
  </code></pre>
  
  <pre><code># Output: Match
  # token three { '3' }
  
  TOP
  |  s
  |  |  s:sym&lt;d&gt;
  |  |  |  one
  </code></pre>
  
  <pre><code># Output No Match
  # token three { &lt;digit&gt; }
  
  TOP
  |  s
  |  |  s:sym&lt;b&gt;
  |  |  |  one
  </code></pre>