parse
.
parseOnly
i am having trouble with recursive parsers, i am doing something like
def op[A](lhs: Parser[A], t: String, rhs: Parser[A]): Parser[(A, A)] =
(lhs, token(string(t)), rhs).mapN { case (lhs, _, rhs) => (lhs, rhs) }
def exprParser: Parser[Expr] = delay {
op(exprParser, "&&", exprParser).map { case (l, r) => Expr.And(l, r) } | // the recursive case
op(node, "<", node).map { case (l, r) => Expr.Lt(l, r) } | // the simple case
..
}
but when I try to do say exprParser.parseOnly("x > 0 && x < 5")
I get what I assume to be infinite loop
<
branch and then treat the remaining && x < 5
as remaining input :/
Hi, I'm having a bit of trouble with reporting back the precise cause of parsing failures. I've got something like this:
val expr = ifExpr | letExpr | ... | identifier | literal
If my ifExpr
or letExpr
parser successfully parses the 'if' or 'let' token but fails later, I'd like to report this as the reason of the failure. Is there a way to achieve this?