-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Expression]add string interpolation feature (#1759)
- Loading branch information
Showing
19 changed files
with
1,371 additions
and
739 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 was deleted.
Oops, something went wrong.
82 changes: 82 additions & 0 deletions
82
libraries/adaptive-expressions/src/parser/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,82 @@ | ||
lexer grammar ExpressionLexer; | ||
|
||
@lexer::members { | ||
ignoreWS = true; // usually we ignore whitespace, but inside stringInterpolation, whitespace is significant | ||
} | ||
|
||
fragment LETTER : [a-zA-Z]; | ||
fragment DIGIT : [0-9]; | ||
|
||
STRING_INTERPOLATION_START : '`' { this.ignoreWS = false;} -> pushMode(STRING_INTERPOLATION_MODE); | ||
|
||
// operators | ||
PLUS: '+'; | ||
|
||
SUBSTRACT: '-'; | ||
|
||
NON: '!'; | ||
|
||
XOR: '^'; | ||
|
||
ASTERISK: '*'; | ||
|
||
SLASH: '/'; | ||
|
||
PERCENT: '%'; | ||
|
||
DOUBLE_EQUAL: '=='; | ||
|
||
NOT_EQUAL: '!=' | '<>'; | ||
|
||
SINGLE_AND: '&'; | ||
|
||
DOUBLE_AND: '&&'; | ||
|
||
DOUBLE_VERTICAL_CYLINDER: '||'; | ||
|
||
LESS_THAN: '<'; | ||
|
||
MORE_THAN: '>'; | ||
|
||
LESS_OR_EQUAl: '<='; | ||
|
||
MORE_OR_EQUAL: '>='; | ||
|
||
OPEN_BRACKET: '('; | ||
|
||
CLOSE_BRACKET: ')'; | ||
|
||
DOT: '.'; | ||
|
||
OPEN_SQUARE_BRACKET: '['; | ||
|
||
CLOSE_SQUARE_BRACKET: ']'; | ||
|
||
COMMA: ','; | ||
|
||
|
||
NUMBER : DIGIT + ( '.' DIGIT +)? ; | ||
|
||
WHITESPACE : (' '|'\t'|'\ufeff'|'\u00a0') {this.ignoreWS}? -> skip; | ||
|
||
IDENTIFIER : (LETTER | '_' | '#' | '@' | '@@' | '$' | '%') (LETTER | DIGIT | '-' | '_')* '!'?; | ||
|
||
NEWLINE : '\r'? '\n' -> skip; | ||
|
||
STRING : ('\'' (~'\'')* '\'') | ('"' (~'"')* '"'); | ||
|
||
CONSTANT : ('[' WHITESPACE* ']') | ('{' WHITESPACE* '}'); | ||
|
||
INVALID_TOKEN_DEFAULT_MODE : . ; | ||
|
||
mode STRING_INTERPOLATION_MODE; | ||
|
||
STRING_INTERPOLATION_END : '`' {this.ignoreWS = true;} -> type(STRING_INTERPOLATION_START), popMode; | ||
|
||
TEMPLATE : '$' '{' (STRING | ~[\r\n{}'"])*? '}'; | ||
ESCAPE_CHARACTER : '\\' ~[\r\n]?; | ||
TEXT_CONTENT : '\\`' | ~[\r\n]; | ||
42 changes: 42 additions & 0 deletions
42
libraries/adaptive-expressions/src/parser/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,42 @@ | ||
parser grammar ExpressionParser; | ||
|
||
options { tokenVocab=ExpressionLexer; } | ||
|
||
file: expression EOF; | ||
|
||
expression | ||
: (NON|SUBSTRACT|PLUS) expression #unaryOpExp | ||
| <assoc=right> expression XOR expression #binaryOpExp | ||
| expression (ASTERISK|SLASH|PERCENT) expression #binaryOpExp | ||
| expression (PLUS|SUBSTRACT) expression #binaryOpExp | ||
| expression (DOUBLE_EQUAL|NOT_EQUAL) expression #binaryOpExp | ||
| expression (SINGLE_AND) expression #binaryOpExp | ||
| expression (LESS_THAN|LESS_OR_EQUAl|MORE_THAN|MORE_OR_EQUAL) expression #binaryOpExp | ||
| expression DOUBLE_AND expression #binaryOpExp | ||
| expression DOUBLE_VERTICAL_CYLINDER expression #binaryOpExp | ||
| primaryExpression #primaryExp | ||
; | ||
|
||
primaryExpression | ||
: OPEN_BRACKET expression CLOSE_BRACKET #parenthesisExp | ||
| CONSTANT #constantAtom | ||
| NUMBER #numericAtom | ||
| STRING #stringAtom | ||
| IDENTIFIER #idAtom | ||
| stringInterpolation #stringInterpolationAtom | ||
| primaryExpression DOT IDENTIFIER #memberAccessExp | ||
| primaryExpression OPEN_BRACKET argsList? CLOSE_BRACKET #funcInvokeExp | ||
| primaryExpression OPEN_SQUARE_BRACKET expression CLOSE_SQUARE_BRACKET #indexAccessExp | ||
; | ||
|
||
stringInterpolation | ||
: STRING_INTERPOLATION_START (ESCAPE_CHARACTER | TEMPLATE | textContent)+ STRING_INTERPOLATION_START | ||
; | ||
|
||
textContent | ||
: TEXT_CONTENT+ | ||
; | ||
|
||
argsList | ||
: expression (COMMA expression)* | ||
; |
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.