Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expression with conjunction/disjunction (and/or) fails if it contains parentheses #399

Merged
merged 1 commit into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/main/scala/org/camunda/feel/impl/parser/FeelParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ object FeelParser {
"return",
"then",
"else",
"satisfies"
"satisfies",
"and",
"or"
)
).!

Expand Down Expand Up @@ -490,7 +492,7 @@ object FeelParser {

private def functionInvocation[_: P]: P[Exp] =
P(
(identifierWithWhitespaces
((identifierWithWhitespaces | functionNameWithReservedWord)
.map(List(_)) | qualifiedName) ~ "(" ~ functionParameters.? ~ ")"
).map {
case (name :: Nil, None) =>
Expand All @@ -507,6 +509,13 @@ object FeelParser {
parameters)
}

// List all built-in function names that contains a reserved word. These names are not allowed as
// regular function names.
private def functionNameWithReservedWord[_: P]: P[String] =
P(
"and" | "or" | "date and time" | "years and months duration"
).!

private def functionParameters[_: P]: P[FunctionParameters] =
namedParameters | positionalParameters

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ class InterpreterBooleanExpressionTest
ValBoolean(true))
}

it should "be in conjunction (with parentheses)" in {
eval("x and (y)", Map("x" -> true, "y" -> false)) should be(
ValBoolean(false))

eval("(x) and y", Map("x" -> true, "y" -> false)) should be(
ValBoolean(false))
}

it should "be in disjunction" in {

eval("false or true") should be(ValBoolean(true))
Expand All @@ -91,6 +99,12 @@ class InterpreterBooleanExpressionTest
eval("2 or 4") should be(ValNull)
}

it should "be in disjunction (with parentheses)" in {
eval("x or (y)", Map("x" -> false, "y" -> true)) should be(ValBoolean(true))

eval("(x) or y", Map("x" -> false, "y" -> true)) should be(ValBoolean(true))
}

it should "be in disjunction with comparison" in {
eval("1 = 1 or 1 = 2") should be(ValBoolean(true))
}
Expand Down