Skip to content

Commit

Permalink
Showing 7 changed files with 261 additions and 216 deletions.
4 changes: 2 additions & 2 deletions libraries/adaptive-expressions/src/parser/expressionParser.ts
Original file line number Diff line number Diff line change
@@ -107,7 +107,7 @@ export class ExpressionParser implements ExpressionParserInterface {
return new Constant(numberValue);
}

throw Error(`${ context.text } is not a number.`);
throw new Error(`${ context.text } is not a number.`);
}

public visitParenthesisExp = (context: ep.ParenthesisExpContext): Expression => this.visit(context.expression());
@@ -183,7 +183,7 @@ export class ExpressionParser implements ExpressionParserInterface {

private readonly makeExpression = (functionType: string, ...children: Expression[]): Expression => {
if (!this._lookupFunction(functionType)) {
throw Error(`${ functionType } does not have an evaluator, it's not a built-in function or a custom function.`);
throw new Error(`${ functionType } does not have an evaluator, it's not a built-in function or a custom function.`);
}

return Expression.makeExpression(functionType, this._lookupFunction(functionType), ...children);
3 changes: 1 addition & 2 deletions libraries/botbuilder-lg/src/LGFileParser.g4
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ templateBody
;

structuredTemplateBody
: structuredBodyNameLine ((structuredBodyContentLine STRUCTURED_NEWLINE)+)? structuredBodyEndLine?
: structuredBodyNameLine (((structuredBodyContentLine? STRUCTURED_NEWLINE) | errorStructureLine)+)? structuredBodyEndLine?
;

structuredBodyNameLine
@@ -60,7 +60,6 @@ errorStructuredName
structuredBodyContentLine
: keyValueStructureLine
| objectStructureLine
| errorStructureLine
;

errorStructureLine
419 changes: 224 additions & 195 deletions libraries/botbuilder-lg/src/generated/LGFileParser.ts

Large diffs are not rendered by default.

34 changes: 20 additions & 14 deletions libraries/botbuilder-lg/src/staticChecker.ts
Original file line number Diff line number Diff line change
@@ -123,27 +123,33 @@ export class StaticChecker extends AbstractParseTreeVisitor<Diagnostic[]> implem
result.push(this.buildLGDiagnostic(TemplateErrors.missingStrucEnd, undefined, context));
}

const bodys = context.structuredBodyContentLine();
if (!bodys || bodys.length === 0) {
result.push(this.buildLGDiagnostic(TemplateErrors.emptyStrucContent, undefined, context));
const errors = context.errorStructureLine();
if (errors && errors.length > 0){
for (const error of errors) {
result.push(this.buildLGDiagnostic(TemplateErrors.invalidStrucBody, undefined, error));
}
} else {
for (const body of bodys) {
if (body.errorStructureLine() !== undefined) {
result.push(this.buildLGDiagnostic(TemplateErrors.invalidStrucBody, undefined, body.errorStructureLine()));
} else if (body.objectStructureLine() !== undefined) {
result = result.concat(this.checkExpression(body.objectStructureLine().text, body.objectStructureLine()));
} else {
const structureValues = body.keyValueStructureLine().keyValueStructureValue();
const errorPrefix = `Property '` + body.keyValueStructureLine().text + `':`;
for (const structureValue of structureValues) {
for (const expr of structureValue.EXPRESSION_IN_STRUCTURE_BODY()) {
result = result.concat(this.checkExpression(expr.text, structureValue, errorPrefix));
const bodys = context.structuredBodyContentLine();
if (!bodys || bodys.length === 0) {
result.push(this.buildLGDiagnostic(TemplateErrors.emptyStrucContent, undefined, context));
} else {
for (const body of bodys) {
if (body.objectStructureLine() !== undefined) {
result = result.concat(this.checkExpression(body.objectStructureLine().text, body.objectStructureLine()));
} else {
const structureValues = body.keyValueStructureLine().keyValueStructureValue();
const errorPrefix = `Property '` + body.keyValueStructureLine().text + `':`;
for (const structureValue of structureValues) {
for (const expr of structureValue.EXPRESSION_IN_STRUCTURE_BODY()) {
result = result.concat(this.checkExpression(expr.text, structureValue, errorPrefix));
}
}
}
}
}
}


return result;
}

10 changes: 8 additions & 2 deletions libraries/botbuilder-lg/tests/lgDiagnostic.test.js
Original file line number Diff line number Diff line change
@@ -85,7 +85,7 @@ describe(`LGExceptionTest`, function() {
it(`TestErrorStructuredTemplate`, function() {
var diagnostics = GetDiagnostics(`ErrorStructuredTemplate.lg`);

assert.strictEqual(5, diagnostics.length);
assert.strictEqual(8, diagnostics.length);
assert.strictEqual(DiagnosticSeverity.Error, diagnostics[0].severity);
assert.strictEqual(diagnostics[0].message.includes(TemplateErrors.invalidStrucBody), true);
assert.strictEqual(DiagnosticSeverity.Error, diagnostics[1].severity);
@@ -96,6 +96,12 @@ describe(`LGExceptionTest`, function() {
assert.strictEqual(diagnostics[3].message.includes(`Error occurred when parsing expression 'NOTemplate()'. NOTemplate does not have an evaluator`), true);
assert.strictEqual(DiagnosticSeverity.Error, diagnostics[4].severity);
assert.strictEqual(diagnostics[4].message.includes(TemplateErrors.invalidStrucName), true);
assert.strictEqual(DiagnosticSeverity.Error, diagnostics[5].severity);
assert.strictEqual(diagnostics[5].message.includes(TemplateErrors.invalidStrucName), true);
assert.strictEqual(DiagnosticSeverity.Error, diagnostics[6].severity);
assert.strictEqual(diagnostics[6].message.includes(TemplateErrors.missingStrucEnd), true);
assert.strictEqual(DiagnosticSeverity.Error, diagnostics[7].severity);
assert.strictEqual(diagnostics[7].message.includes(TemplateErrors.invalidStrucBody), true);
});

it(`TestErrorTemplateName`, function() {
@@ -230,7 +236,7 @@ describe(`LGExceptionTest`, function() {

assert.throws(() => templates.evaluate(`structured2`), Error(`'dialog.abc' evaluated to null. [template1] Error occurred when evaluating '-I want \${dialog.abc}'. [structured2] Property 'Text': Error occurred when evaluating 'Text=I want \${template1()}'. `));

assert.throws(() => templates.evaluate(`structured3`), Error(`'dialog.abc' evaluated to null. [template1] Error occurred when evaluating '-I want \${dialog.abc}'. [structured2] Property 'Text': Error occurred when evaluating 'Text=I want \${template1()}'. [structured3] Error occurred when evaluating '\${structured2()}'. `))
assert.throws(() => templates.evaluate(`structured3`), Error(`'dialog.abc' evaluated to null. [template1] Error occurred when evaluating '-I want \${dialog.abc}'. [structured2] Property 'Text': Error occurred when evaluating 'Text=I want \${template1()}'. [structured3] Error occurred when evaluating '\${structured2()}'. `));

assert.throws(() => templates.evaluate(`switchcase1`, { turn : { testValue : 1 } }), Error(`'dialog.abc' evaluated to null. [switchcase1] Case '\${1}': Error occurred when evaluating '-I want \${dialog.abc}'. `));

Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
# AskForAge.prompt
[Activity
Text = ${GetAge()}

> this is a comment about this specific property
Speak = ${GetAge()}
]
Original file line number Diff line number Diff line change
@@ -22,4 +22,8 @@
# errorStructuredType
[Activity%
Text = hi
]
]

# ErrorTemplate1
[Activity]
- hi

0 comments on commit 9d768ed

Please sign in to comment.