Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple lines Expression in LG file #1921

Merged
merged 10 commits into from
Mar 18, 2020
2 changes: 1 addition & 1 deletion libraries/botbuilder-lg/src/LGFileLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fragment STRING_LITERAL : ('\'' (~['\r\n])* '\'') | ('"' (~["\r\n])* '"');

fragment STRING_INTERPOLATION : '`' ('\\`' | ~'`')* '`';

fragment EXPRESSION_FRAGMENT : '$' '{' (STRING_LITERAL | STRING_INTERPOLATION | EMPTY_OBJECT | ~[\r\n{}'"`] )+ '}'?;
fragment EXPRESSION_FRAGMENT : '$' '{' (STRING_LITERAL | STRING_INTERPOLATION | EMPTY_OBJECT | ~[}'"`] )+ '}'?;

fragment ESCAPE_CHARACTER_FRAGMENT : '\\' ~[\r\n]?;

Expand Down
250 changes: 125 additions & 125 deletions libraries/botbuilder-lg/src/generated/LGFileLexer.ts

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions libraries/botbuilder-lg/tests/lg.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ describe('LG', function() {
assert.strictEqual(evaled === 'Good evening' || evaled === 'Evening! ', true, `Evaled is ${ evaled }`);
});

it('TestMultiLineExprLG', function() {
let templates = Templates.parseFile(GetExampleFilePath('MultiLineExpr.lg'));

let evaled = templates.evaluate('ExprInCondition', { userName: 'Henry', day: 'Monday' });
assert.strictEqual(evaled === 'Not today', true, `Evaled is ${ evaled }`);

evaled = templates.evaluate('definition');
assert.strictEqual(evaled, 10);

evaled = templates.evaluate('template');
assert.strictEqual(evaled, '15');


});

it('TestBasicConditionalTemplateWithoutDefault', function() {
let templates = Templates.parseFile(GetExampleFilePath('5.lg'));

Expand Down
18 changes: 18 additions & 0 deletions libraries/botbuilder-lg/tests/lgDiagnostic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,22 @@ it(`TestExpressionFormatError`, function() {
var diagnostics = GetDiagnostics(`ExpressionFormatError.lg`);
assert.strictEqual(diagnostics.length, 1);
assert.strictEqual(diagnostics[0].message.includes(`Close } is missing in Expression`), true);
});

it(`TestMultiLineExpressionInLG`, function() {
var diagnostics = GetDiagnostics(`MultiLineExprError.lg`);
assert.strictEqual(diagnostics.length, 1);
assert.strictEqual(diagnostics[0].message.includes(`Close } is missing in Expression`), true);

diagnostics = Templates.parseText('#Demo2\r\n- ${createArray(1,\r\n, 2,3)').diagnostics;
assert.strictEqual(diagnostics.length, 1);
assert.strictEqual(diagnostics[0].message.includes(`Close } is missing in Expression`), true);

diagnostics = Templates.parseText('#Demo4\r\n- ${createArray(1,\r\n2,3)\r\n> this is a comment').diagnostics;
assert.strictEqual(diagnostics.length, 1);
assert.strictEqual(diagnostics[0].message.includes(`Close } is missing in Expression`), true);

diagnostics = Templates.parseText('#Demo4\r\n- ${createArray(1,\r\n2,3)\r\n#AnotherTemplate').diagnostics;
assert.strictEqual(diagnostics.length, 1);
assert.strictEqual(diagnostics[0].message.includes(`Close } is missing in Expression`), true);
});
26 changes: 26 additions & 0 deletions libraries/botbuilder-lg/tests/testData/examples/MultiLineExpr.lg
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
>Demo How LG can evalute a multiple line defined expression
#definition
- ${count(concat('hello',
'world'))}

# definition2
- this is book list: ${join(createArray("Ender's Game",
"Dune")
, ", ")}

#ExprInCondition
- IF: ${userName.length < 5 ||
day == "Monday"}
- Not today
-ELSE:
- Nice Try

#template
-${sum(
createArray(
1,
2,
3,
4,
5)
)}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#Demo
- ${createArray(1,2
2,3)
[import](5.lg)

#Demo2
- ${createArray(1,
2,3)

#Demo3
- IF ${32.5 > 14.1 ||
userName == 'doskey' ||
day = 'Monday'
- good day

#Demo4
- ${createArray(1,
2,3)
> this is a comment