Suppose I try to parse a string abc with a Packrat Parser:
lazy val abc: PackratParser[AnyRef] = ab ~ "c"
lazy val ab: PackratParser[AnyRef] = (ab | abc) ~ "b" | "a"
def parse(in: String) = parseAll(abc, in)
Here I use left recursion supported by Packrat parser, but I do not understand why it fails. According to Parser documentation P | Q equals P if P succeeds, so in this case ab
should be replaced with "ab" instead of "a" as it does if I replace ab
with:
lazy val ab: PackratParser[AnyRef] = ab ~ "b" | "a"