Skip to content

Commit b24d205

Browse files
authored
LG/Expression parity with C# (till Nov 25) (#1453)
* init * finisn expression sync * init lg * forward * fix test errors * forward * rename test file * fix comments * refine
1 parent f5f81ae commit b24d205

File tree

100 files changed

+3464
-2568
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+3464
-2568
lines changed

libraries/botbuilder-lg/src/LGFileLexer.g4

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ fragment U: 'u' | 'U';
3636
fragment W: 'w' | 'W';
3737

3838
fragment STRING_LITERAL : ('\'' (~['\r\n])* '\'') | ('"' (~["\r\n])* '"');
39+
fragment EXPRESSION_FRAGMENT : '@' '{' (STRING_LITERAL| ~[\r\n{}'"] )*? '}';
40+
fragment ESCAPE_CHARACTER_FRAGMENT : '\\' ~[\r\n]?;
3941
4042
COMMENTS
4143
: ('>'|'$') ~('\r'|'\n')+ NEWLINE? -> skip
@@ -60,6 +62,7 @@ DASH
6062
LEFT_SQUARE_BRACKET
6163
: '[' -> pushMode(STRUCTURED_TEMPLATE_BODY_MODE)
6264
;
65+
6366
RIGHT_SQUARE_BRACKET
6467
: ']'
6568
;
@@ -121,6 +124,10 @@ WS_IN_BODY
121124
: WHITESPACE+ -> type(WS)
122125
;
123126
127+
MULTILINE_PREFIX
128+
: '```' -> pushMode(MULTILINE)
129+
;
130+
124131
NEWLINE_IN_BODY
125132
: '\r'? '\n' {this.ignoreWS = true;} -> type(NEWLINE), popMode
126133
;
@@ -146,31 +153,19 @@ CASE
146153
;
147154
148155
DEFAULT
149-
: D E F A U L T WHITESPACE* ':' {this.expectKeywords}? {this.ignoreWS = true;}
150-
;
151-
152-
MULTI_LINE_TEXT
153-
: '```' .*? '```' { this.ignoreWS = false; this.expectKeywords = false;}
156+
: D E F A U L T WHITESPACE* ':' {this.expectKeywords}? { this.ignoreWS = true;}
154157
;
155158
156159
ESCAPE_CHARACTER
157-
: '\\{' | '\\[' | '\\\\' | '\\'[rtn\]}] { this.ignoreWS = false; this.expectKeywords = false;}
160+
: ESCAPE_CHARACTER_FRAGMENT { this.ignoreWS = false; this.expectKeywords = false;}
158161
;
159162
160163
EXPRESSION
161-
: '@'? '{' (~[\r\n{}'"] | STRING_LITERAL)*? '}' { this.ignoreWS = false; this.expectKeywords = false;}
162-
;
163-
164-
TEMPLATE_REF
165-
: '[' (~[\r\n[\]] | TEMPLATE_REF)* ']' { this.ignoreWS = false; this.expectKeywords = false;}
166-
;
167-
168-
TEXT_SEPARATOR
169-
: [\t\r\n{}[\]()] { this.ignoreWS = false; this.expectKeywords = false;}
164+
: EXPRESSION_FRAGMENT { this.ignoreWS = false; this.expectKeywords = false;}
170165
;
171166
172167
TEXT
173-
: ~[\t\r\n{}[\]()]+? { this.ignoreWS = false; this.expectKeywords = false;}
168+
: ~[\r\n]+? { this.ignoreWS = false; this.expectKeywords = false;}
174169
;
175170
176171
mode STRUCTURED_TEMPLATE_BODY_MODE;
@@ -190,7 +185,25 @@ STRUCTURED_NEWLINE
190185
STRUCTURED_TEMPLATE_BODY_END
191186
: WS_IN_STRUCTURED? RIGHT_SQUARE_BRACKET WS_IN_STRUCTURED? -> popMode
192187
;
193-
188+
194189
STRUCTURED_CONTENT
195190
: ~[\r\n]+
191+
;
192+
193+
mode MULTILINE;
194+
195+
MULTILINE_SUFFIX
196+
: '```' -> popMode
197+
;
198+
199+
MULTILINE_ESCAPE_CHARACTER
200+
: ESCAPE_CHARACTER_FRAGMENT -> type(ESCAPE_CHARACTER)
201+
;
202+
203+
MULTILINE_EXPRESSION
204+
: EXPRESSION_FRAGMENT -> type(EXPRESSION)
205+
;
206+
207+
MULTILINE_TEXT
208+
: (('\r'? '\n') | ~[\r\n])+? -> type(TEXT)
196209
;

libraries/botbuilder-lg/src/LGFileParser.g4

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
parser grammar LGFileParser;
2-
32
options { tokenVocab=LGFileLexer; }
43

54
file
@@ -41,11 +40,11 @@ parameters
4140
;
4241

4342
templateBody
44-
: normalTemplateBody #normalBody
45-
| ifElseTemplateBody #ifElseBody
43+
: normalTemplateBody #normalBody
44+
| ifElseTemplateBody #ifElseBody
4645
| switchCaseTemplateBody #switchCaseBody
4746
| structuredTemplateBody #structuredBody
48-
;
47+
;
4948

5049
structuredTemplateBody
5150
: structuredBodyNameLine structuredBodyContentLine? structuredBodyEndLine
@@ -73,12 +72,12 @@ templateString
7372
;
7473

7574
normalTemplateString
76-
: DASH (WS|TEXT|EXPRESSION|TEMPLATE_REF|TEXT_SEPARATOR|MULTI_LINE_TEXT|ESCAPE_CHARACTER)*
75+
: DASH (WS|TEXT|EXPRESSION|ESCAPE_CHARACTER|MULTILINE_SUFFIX|MULTILINE_PREFIX)*
7776
;
7877

7978
errorTemplateString
80-
: INVALID_TOKEN_DEFAULT_MODE+
81-
;
79+
: INVALID_TOKEN_DEFAULT_MODE+
80+
;
8281

8382
ifElseTemplateBody
8483
: ifConditionRule+

0 commit comments

Comments
 (0)