2

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"
Mike Samuel
  • 118,113
  • 30
  • 216
  • 245
Nutel
  • 2,244
  • 2
  • 27
  • 50

1 Answers1

1

A Packrat parser supports left recursion, but does it support cycles between rules (without progress).

That's what you have here: abc calls ab which can call abc.

Maybe you should try putting the | in the abc rule to avoid the cycle.

David Pierre
  • 9,459
  • 4
  • 40
  • 32