inkytonik / kiama

A Scala library for language processing.
Mozilla Public License 2.0
47 stars 15 forks source link

Indirect left recursion doesn't work in some cases #1

Open inkytonik opened 4 years ago

inkytonik commented 4 years ago

(Reported by Nicholas Weston.)

The parser p defined as follows doesn’t successfully parse ab.

lazy val p: PackratParser[Any] = q | "a"
lazy val q: PackratParser[Any] = p ~ "b"

The parse result is

Failure(end of input expected,Input(StringSource(ab,),1))

It works if q is a regular Parser. It also works if p is directly recursive as follows.

lazy val p: PackratParser[Any] = p ~ "b" | "a"

It also happens in 2.3.0-SNAPSHOT but not when using the standard Scala parser combinator library.

See attached project.

inkytonik commented 4 years ago

parsing-bug.zip