-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
263 additions
and
96 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
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.
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
82 changes: 82 additions & 0 deletions
82
libraries/Microsoft.Bot.Expressions/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 { | ||
bool ignoreWS = true; // usually we ignore whitespace, but inside stringInterpolation, whitespace is significant | ||
} | ||
|
||
fragment LETTER : [a-zA-Z]; | ||
fragment DIGIT : [0-9]; | ||
|
||
STRING_INTERPOLATION_START : '`' { 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') {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 : '`' {ignoreWS = true;} -> type(STRING_INTERPOLATION_START), popMode; | ||
|
||
TEMPLATE : '@' '{' (STRING | ~[\r\n{}'"])*? '}'; | ||
ESCAPE_CHARACTER : '\\' ~[\r\n]?; | ||
TEXT_CONTENT : '\\`' | ~[\r\n]; | ||
38 changes: 38 additions & 0 deletions
38
libraries/Microsoft.Bot.Expressions/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,38 @@ | ||
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 | TEXT_CONTENT)+ STRING_INTERPOLATION_START | ||
; | ||
|
||
argsList | ||
: expression (COMMA expression)* | ||
; |
Oops, something went wrong.