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?
beforein such a way that it parses any text, you shouldn't be surprised.aaaaxxxbbbas well asxxxxxxxbbb? (But keeping in mind, that I might have multiple "keyword" for content in the future other thanxxx, and I wouldn't want to list them all if possible)