-
Notifications
You must be signed in to change notification settings - Fork 441
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
34 changed files
with
424 additions
and
451 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
modules/core/src/main/antlr4/org/apache/synapse/util/synapse_expression/ExpressionParser.g4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
parser grammar ExpressionParser; | ||
|
||
options { | ||
tokenVocab = ExpressionLexer; | ||
} | ||
|
||
expression | ||
: comparisonExpression | ||
| conditionalExpression | ||
| EOF | ||
; | ||
|
||
conditionalExpression | ||
: comparisonExpression (QUESTION expression COLON expression)? | ||
; | ||
|
||
comparisonExpression | ||
: logicalExpression ( (GT | LT | GTE | LTE | EQ | NEQ) logicalExpression )* | ||
| logicalExpression (EQ | NEQ) NULL_LITERAL | ||
; | ||
|
||
logicalExpression | ||
: arithmeticExpression (AND logicalExpression | OR logicalExpression)? | ||
; | ||
|
||
arithmeticExpression | ||
: term ( (PLUS | MINUS) term )* | ||
; | ||
|
||
term | ||
: factor ( (ASTERISK | DIV | MODULO) factor )* | ||
; | ||
|
||
factor | ||
: literal | ||
| functionCall | ||
| variableAccess | ||
| payloadAccess | ||
| headerAccess | ||
| configAccess | ||
| attributeAccess | ||
| LPAREN expression RPAREN | ||
; | ||
|
||
configAccess | ||
: CONFIG propertyName | ||
; | ||
|
||
headerAccess | ||
: HEADERS propertyName | ||
; | ||
|
||
attributeAccess | ||
: ATTRIBUTES (DOT ID propertyName) | ||
; | ||
|
||
propertyName | ||
: DOT ID | ||
| (DOT)? LBRACKET STRING_LITERAL RBRACKET | ||
; | ||
|
||
literal | ||
: arrayLiteral | ||
| BOOLEAN_LITERAL | ||
| NUMBER | ||
| STRING_LITERAL | ||
| NULL_LITERAL | ||
; | ||
|
||
jsonPathExpression | ||
:( DOT JSONPATH_FUNCTIONS | ||
|DOUBLE_DOT ASTERISK | ||
| DOUBLE_DOT ID | ||
| DOT ID | ||
| (DOT)? LBRACKET arrayIndex RBRACKET | ||
| DOT ASTERISK | ||
| DOUBLE_DOT ID (LBRACKET arrayIndex RBRACKET)?)+ | ||
; | ||
|
||
|
||
variableAccess | ||
: VAR ( DOT ID | ||
| DOT STRING_LITERAL | ||
| (DOT)? LBRACKET STRING_LITERAL RBRACKET // Bracket notation: var["variableName"] | ||
) | ||
( jsonPathExpression )? | ||
; | ||
|
||
arrayLiteral | ||
: LBRACKET (expression (COMMA expression)*)? RBRACKET // Array with zero or more literals, separated by commas | ||
; | ||
|
||
payloadAccess | ||
: PAYLOAD ( jsonPathExpression)? | ||
; | ||
|
||
arrayIndex | ||
: NUMBER | ||
| STRING_LITERAL | ||
| expression | ||
| multipleArrayIndices | ||
| sliceArrayIndex | ||
| expression ( (PLUS | MINUS | ASTERISK | DIV ) expression)* | ||
| ASTERISK | ||
| QUESTION? filterExpression | ||
; | ||
|
||
multipleArrayIndices | ||
: expression (COMMA expression)+ | ||
; | ||
|
||
sliceArrayIndex | ||
: signedExpressions? COLON signedExpressions? (COLON signedExpressions?)? | ||
; | ||
|
||
signedExpressions | ||
: MINUS? expression | ||
; | ||
|
||
filterExpression | ||
: (filterComponent)+ | ||
; | ||
|
||
filterComponent | ||
: variableAccess | ||
| payloadAccess | ||
| headerAccess | ||
| configAccess | ||
| attributeAccess | ||
| functionCall | ||
| stringOrOperator | ||
; | ||
|
||
stringOrOperator | ||
: QUESTION | AT | JSONPATH_PARAMS | STRING_LITERAL |NUMBER | BOOLEAN_LITERAL | ID | GT | LT | GTE | LTE | EQ | NEQ | ||
| PLUS | MINUS | DIV | LPAREN | RPAREN | DOT | COMMA | COLON | WS | AND | OR | NOT | ASTERISK | ||
; | ||
|
||
|
||
functionCall | ||
: ID LPAREN (expression (COMMA expression)*)? RPAREN functionCallSuffix? | ||
; | ||
|
||
functionCallSuffix | ||
: DOT ID LPAREN (expression (COMMA expression)*)? RPAREN // Method chaining | ||
| jsonPathExpression | ||
; |
Oops, something went wrong.