Edit (to generalize the problem):
I'd like to parse a grammar, where
<prefix> ::= [a-z]*
<middle> ::= xxx
<suffix> ::= b+
<grammar> ::= <prefix><middle><suffix>
I expect (for example) the following words to pass: aaaaxxxbb
, axxxaaxxxbbb
, xxxxxxbb
Original post:
I expected the following parser to backtrack and find a solution in the end:
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)
}
Instead it looks like the before
part greedily parses all the text, and the parser fails without backtracking.
Am I missing something?