开发者

Packrat parser conflict

开发者 https://www.devze.com 2023-02-10 16:26 出处:网络
Suppose I try to parse a string abc with a Packrat Parser: lazy val abc: PackratParser[AnyRef] = ab ~ \"c\"

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[A开发者_开发问答nyRef] = ab ~ "b" | "a"


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号