Fastparse doesn't backtrack
<p><em>Edit (to generalize the problem):</em></p>

<p>I'd like to parse a grammar, where</p>

<pre><code>&lt;prefix&gt; ::= [a-z]*
&lt;middle&gt; ::= xxx
&lt;suffix&gt; ::= b+
&lt;grammar&gt; ::= &lt;prefix&gt;&lt;middle&gt;&lt;suffix&gt;
</code></pre>

<p>I expect (for example) the following words to pass: <code>aaaaxxxbb</code>, <code>axxxaaxxxbbb</code>, <code>xxxxxxbb</code></p>

<p><em>Original post:</em></p>

<p>I expected the following parser to backtrack and find a solution in the end:</p>

<pre><code>val before = P(AnyChar.rep.!)
val content = P("xxx".!)
val after = P("b".rep.!)
val all = P(before ~ content ~ after ~ End)
def test() = {
  val r = all.parse("aaaaxxxbbb")
  println(r)
}
</code></pre>

<p>Instead it looks like the <code>before</code> part greedily parses all the text, and the parser fails without backtracking.</p>

<p>Am I missing something?</p>