-
Notifications
You must be signed in to change notification settings - Fork 131
Open
@LPeter1997
Description
I've isolated a 3-rule pattern, where I'd expect the parser to succeed for a given input, but it fails instead. The sample grammar:
RuleA ::= RuleB.
RuleB ::= IDENTIFIER
| RuleC '.' IDENTIFIER
.
RuleC ::= RuleB
| RuleA
.
The implementation:
import scala.util.parsing.combinator._ import scala.util.parsing.combinator.syntactical.StandardTokenParsers object SimpleParser extends StandardTokenParsers with PackratParsers { lexical.delimiters ++= List(".", "$") lazy val ruleA: PackratParser[String] = ruleB <~ "$" lazy val ruleB: PackratParser[String] = (ident ||| ruleC ~> "." ~> ident) lazy val ruleC: PackratParser[String] = (ruleB ||| ruleA) def main(args: Array[String]) = { println(ruleA(new PackratReader(new lexical.Scanner("x.x$")))) } }
It fails for input x.x$
, telling me that it expects a $
instead of the .
.
For me, this seems to be a problem with how indirect left-recursion is handled. I'm not sure if the original algorithm is incapable of handling this pattern, or this is an implementation bug.
Edit:
I've accidentally used |
(first matching alt.) instead of |||
(longest matching alt.), I've fixed that in the code, but doesn't change the outcome.
Metadata
Metadata
Assignees
Labels
No labels