Skip to content

Commit

Permalink
feat: add support for backtick escaped variables (Camunda extension)
Browse files Browse the repository at this point in the history
* Adds `camunda` dialect
* Adds support for backtick escaped variables, i.e. foo.`boo ba`
* Must be explicitly enabled via `camunda` dialect

Closes #36
  • Loading branch information
makepanic authored and nikku committed Aug 21, 2024
1 parent 4f9b608 commit ee59237
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/feel.grammar
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@dialects { camunda }

@precedence {
name,
type,
Expand Down Expand Up @@ -322,8 +324,12 @@ Identifier {
identifier | nameIdentifier
}

BacktickIdentifier {
backtickIdentifier
}

VariableName {
(!name Identifier ~ident)+
(!name Identifier ~ident)+ | BacktickIdentifier
}

AdditionalIdentifier[@name=Identifier] {
Expand Down Expand Up @@ -453,6 +459,10 @@ commaSep<Expr> {
(digits ("." digits)? | "." digits)
}

backtickIdentifier[@dialect=camunda] {
"`" (![\\\n`] | "\\" _)* "`"
}

@precedence { BlockComment, LineComment, divide }

@precedence {
Expand Down
13 changes: 13 additions & 0 deletions test/camunda.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# VariableName (backtick escaped) { "top": "Expressions", "dialect": "camunda" }

`foo`;
foo.`bar`;
foo.`bar-baz`;

==>

Expressions(
VariableName(BacktickIdentifier(...)),
PathExpression(VariableName(...), VariableName(BacktickIdentifier(...))),
PathExpression(VariableName(...), VariableName(BacktickIdentifier(...)))
)
15 changes: 15 additions & 0 deletions test/expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2619,4 +2619,19 @@ foo[[[[[[[(1..10).start included]]]]]]]

Expression(
FilterExpression(VariableName(...), List(...))
)


# Backtick escaped variables (Camunda) { "top": "Expressions", "dialect": "camunda" }

`foo`;
foo.`bar`;
foo.`bar-baz`;

==>

Expressions(
VariableName(...),
PathExpression(VariableName(...), VariableName(...)),
PathExpression(VariableName(...), VariableName(...))
)
2 changes: 1 addition & 1 deletion test/test-feel.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ for (const file of fs.readdirSync(caseDir)) {
}) : parser;
};

const contextTracker = /expressions|unary-test/.test(fileName)
const contextTracker = /expressions|unary-test|camunda/.test(fileName)
? trackVariables
: null;

Expand Down

0 comments on commit ee59237

Please sign in to comment.