Skip to content

Commit 5bd9a23

Browse files
authored
fix(engine): add reserved keywords (camunda#399)
* add the reserved keywords: "and", "or" * avoid that a conjunction/disjunction is parsed as function name * change the parsing behavior to avoid that a function name contains a reserved keyword like "and"/"or"
1 parent 7d7092e commit 5bd9a23

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/main/scala/org/camunda/feel/impl/parser/FeelParser.scala

+11-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ object FeelParser {
147147
"return",
148148
"then",
149149
"else",
150-
"satisfies"
150+
"satisfies",
151+
"and",
152+
"or"
151153
)
152154
).!
153155

@@ -490,7 +492,7 @@ object FeelParser {
490492

491493
private def functionInvocation[_: P]: P[Exp] =
492494
P(
493-
(identifierWithWhitespaces
495+
((identifierWithWhitespaces | functionNameWithReservedWord)
494496
.map(List(_)) | qualifiedName) ~ "(" ~ functionParameters.? ~ ")"
495497
).map {
496498
case (name :: Nil, None) =>
@@ -507,6 +509,13 @@ object FeelParser {
507509
parameters)
508510
}
509511

512+
// List all built-in function names that contains a reserved word. These names are not allowed as
513+
// regular function names.
514+
private def functionNameWithReservedWord[_: P]: P[String] =
515+
P(
516+
"and" | "or" | "date and time" | "years and months duration"
517+
).!
518+
510519
private def functionParameters[_: P]: P[FunctionParameters] =
511520
namedParameters | positionalParameters
512521

src/test/scala/org/camunda/feel/impl/interpreter/InterpreterBooleanExpressionTest.scala

+14
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ class InterpreterBooleanExpressionTest
7575
ValBoolean(true))
7676
}
7777

78+
it should "be in conjunction (with parentheses)" in {
79+
eval("x and (y)", Map("x" -> true, "y" -> false)) should be(
80+
ValBoolean(false))
81+
82+
eval("(x) and y", Map("x" -> true, "y" -> false)) should be(
83+
ValBoolean(false))
84+
}
85+
7886
it should "be in disjunction" in {
7987

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

102+
it should "be in disjunction (with parentheses)" in {
103+
eval("x or (y)", Map("x" -> false, "y" -> true)) should be(ValBoolean(true))
104+
105+
eval("(x) or y", Map("x" -> false, "y" -> true)) should be(ValBoolean(true))
106+
}
107+
94108
it should "be in disjunction with comparison" in {
95109
eval("1 = 1 or 1 = 2") should be(ValBoolean(true))
96110
}

0 commit comments

Comments
 (0)