You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importcats.Evalimportparseback._importparseback.ast._importparseback.compat.cats._objectTestcaseextendsApp {
sealedtraitExprextendsNodecaseclassIdentifier(name: String) extendsExprwithLeafNodecaseclassApplication(left: Expr, right: Expr) extendsExprwithBinaryNode {
overridedefassocLeft:Boolean=trueoverridedefsym:Symbol='app
}
lazyvalexpr:Parser[Expr] = (
"""[a-zA-Z0-9]+""".r ^^ { (_, name) =>Identifier(name) }
| expr ~""~ expr ^^ { (_, fun, _, arg) =>Application(fun, arg) }
|"("~> expr <~")"
) filter prec(Application)
// Test 1, correct: gives the left assoc. AST
println(expr(LineStream[Eval]("function1 function2 argument")).value.map(_.toList))
// Test 2, bug? gives no error but an empty list of ASTs
println(expr(LineStream[Eval]("function1 (function2 argument)")).value.map(_.toList))
}
where we define a simple grammar with just Identifiers and function Application. I intend application to be left-associative and thus write filter prec(Application) with BinaryNode and def assocLeft: Boolean = true.
The first example works fine, only the left-associative AST is returned. However, in the second example where we use parentheses, an empty list is returned (where we would expect the right-associative AST).
Am I using filter and/or BinaryNode wrong? Or is this a bug?
The text was updated successfully, but these errors were encountered:
Hey! I'm back. :-) Sorry, longest not-seeing-of-an-issue ever. This definitely looks like a bug to me. You're using things correctly. Honestly, an empty list of results should never happen. The disambiguation filters are designed in such a way that they should never eliminate all results unless the grammar itself encodes precedence in an opposite way from the filters (that isn't happening here). I'll look into it.
Given the following test case
where we define a simple grammar with just
Identifier
s and functionApplication
. I intend application to be left-associative and thus writefilter prec(Application)
withBinaryNode
anddef assocLeft: Boolean = true
.The first example works fine, only the left-associative AST is returned. However, in the second example where we use parentheses, an empty list is returned (where we would expect the right-associative AST).
Am I using
filter
and/orBinaryNode
wrong? Or is this a bug?The text was updated successfully, but these errors were encountered: