-
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.
Merge branch 'master' of https://github.com/wso2/wso2-synapse
- Loading branch information
Showing
69 changed files
with
4,648 additions
and
69 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
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
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
80 changes: 80 additions & 0 deletions
80
modules/core/src/main/antlr4/org/apache/synapse/util/synapse_expression/ExpressionLexer.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,80 @@ | ||
lexer grammar ExpressionLexer; | ||
|
||
JSONPATH_PARAMS: 'in' | 'nin' | 'subsetof' | 'anyof' | 'noneof' | 'size' | 'empty' | '=~'; | ||
|
||
JSONPATH_FUNCTIONS: 'length()' | 'size()' | 'min()' | 'max()' | 'avg()' | 'sum()' | 'stddev()' | 'keys()' | 'first()' | 'last()'; | ||
|
||
// Tokens for identifiers, operators, and keywords | ||
VAR: 'var'; | ||
PAYLOAD: 'payload' | '$'; | ||
HEADERS: 'headers'; | ||
CONFIG: 'config'; | ||
ATTRIBUTES: 'attributes' | 'attr'; | ||
AND: 'and' | '&&'; | ||
OR: 'or' | '||'; | ||
NOT: '!'; | ||
|
||
DOUBLE_DOT : '..'; | ||
ASTERISK : '*'; | ||
|
||
// Operators | ||
PLUS: '+'; | ||
MINUS: '-'; | ||
DIV: '/'; | ||
MODULO: '%'; | ||
EQ: '=='; | ||
NEQ: '!='; | ||
GT: '>'; | ||
LT: '<'; | ||
GTE: '>='; | ||
LTE: '<='; | ||
|
||
// Delimiters | ||
LPAREN: '('; | ||
RPAREN: ')'; | ||
LBRACKET: '['; | ||
RBRACKET: ']'; | ||
DOT: '.'; | ||
COMMA: ','; | ||
COLON: ':'; | ||
QUOTE: '"' | '\''; | ||
|
||
// Literals | ||
BOOLEAN_LITERAL: 'true' | 'false'; | ||
NUMBER: '-'? [0-9]+ ('.' [0-9]+)?; | ||
|
||
|
||
STRING_LITERAL : ('"' (ESC | ~["\\])* '"' | '\'' (ESC | ~['\\])* '\''); | ||
|
||
|
||
fragment ESC | ||
: '\\' [btnfr"'\\/] // Basic escape sequences | ||
| UNICODE_ESC | ||
| OCTAL_ESC | ||
; | ||
fragment UNICODE_ESC | ||
: '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT | ||
; | ||
fragment OCTAL_ESC | ||
: '\\' [0-3]? [0-7] [0-7] | ||
; | ||
fragment HEX_DIGIT | ||
: [0-9a-fA-F] | ||
; | ||
NULL_LITERAL | ||
: 'null' // Define null as a recognized keyword | ||
; | ||
// Identifiers | ||
ID: [a-zA-Z_][a-zA-Z_0-9]*; | ||
// Special symbols for JSONPath filter expressions | ||
QUESTION: '?'; | ||
AT: '@'; | ||
// Whitespace | ||
WS: [ \t\n\r]+ -> skip; |
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 | ||
; |
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
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
Oops, something went wrong.