Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions packages/lu/src/parser/lufile/LUFileLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,8 @@ AT
: '@' -> pushMode(NEW_ENTITY_MODE)
;

IMPORT_DESC
: '[' .*? ']'
;

IMPORT_PATH
: '(' .*? ')'
IMPORT
: '[' ~[\r\n[\]]*? ']' '(' ~[\r\n()]*? ')'
;

FILTER_MARK
Expand Down
2 changes: 1 addition & 1 deletion packages/lu/src/parser/lufile/LUFileParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ importSection
;

importDefinition
: IMPORT_DESC IMPORT_PATH
: WS* IMPORT WS*
;

qnaSection
Expand Down
9 changes: 3 additions & 6 deletions packages/lu/src/parser/lufile/generated/LUFileLexer.interp

Large diffs are not rendered by default.

936 changes: 467 additions & 469 deletions packages/lu/src/parser/lufile/generated/LUFileLexer.js

Large diffs are not rendered by default.

65 changes: 32 additions & 33 deletions packages/lu/src/parser/lufile/generated/LUFileLexer.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,37 @@ HASH=7
DASH=8
DOLLAR=9
AT=10
IMPORT_DESC=11
IMPORT_PATH=12
FILTER_MARK=13
QNA_ID_MARK=14
MULTI_LINE_TEXT=15
PROMPT_MARK=16
INVALID_TOKEN_DEFAULT_MODE=17
EQUAL=18
COMMA=19
HAS_ROLES_LABEL=20
HAS_FEATURES_LABEL=21
NEW_ENTITY_TYPE_IDENTIFIER=22
NEW_COMPOSITE_ENTITY=23
NEW_REGEX_ENTITY=24
NEW_ENTITY_IDENTIFIER=25
NEW_ENTITY_IDENTIFIER_WITH_WS=26
NEWLINE_IN_NAME=27
IDENTIFIER=28
DOT=29
ESCAPE_CHARACTER=30
EXPRESSION=31
TEXT=32
NEWLINE_IN_ENTITY=33
COMPOSITE_ENTITY=34
REGEX_ENTITY=35
ENTITY_TEXT=36
COLON_MARK=37
NEWLINE_IN_QNA=38
QNA_TEXT=39
IMPORT=11
FILTER_MARK=12
QNA_ID_MARK=13
MULTI_LINE_TEXT=14
PROMPT_MARK=15
INVALID_TOKEN_DEFAULT_MODE=16
EQUAL=17
COMMA=18
HAS_ROLES_LABEL=19
HAS_FEATURES_LABEL=20
NEW_ENTITY_TYPE_IDENTIFIER=21
NEW_COMPOSITE_ENTITY=22
NEW_REGEX_ENTITY=23
NEW_ENTITY_IDENTIFIER=24
NEW_ENTITY_IDENTIFIER_WITH_WS=25
NEWLINE_IN_NAME=26
IDENTIFIER=27
DOT=28
ESCAPE_CHARACTER=29
EXPRESSION=30
TEXT=31
NEWLINE_IN_ENTITY=32
COMPOSITE_ENTITY=33
REGEX_ENTITY=34
ENTITY_TEXT=35
COLON_MARK=36
NEWLINE_IN_QNA=37
QNA_TEXT=38
'$'=9
'@'=10
'='=18
','=19
'.'=29
':'=37
'='=17
','=18
'.'=28
':'=36
6 changes: 2 additions & 4 deletions packages/lu/src/parser/lufile/generated/LUFileParser.interp

Large diffs are not rendered by default.

1,030 changes: 533 additions & 497 deletions packages/lu/src/parser/lufile/generated/LUFileParser.js

Large diffs are not rendered by default.

65 changes: 32 additions & 33 deletions packages/lu/src/parser/lufile/generated/LUFileParser.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,37 @@ HASH=7
DASH=8
DOLLAR=9
AT=10
IMPORT_DESC=11
IMPORT_PATH=12
FILTER_MARK=13
QNA_ID_MARK=14
MULTI_LINE_TEXT=15
PROMPT_MARK=16
INVALID_TOKEN_DEFAULT_MODE=17
EQUAL=18
COMMA=19
HAS_ROLES_LABEL=20
HAS_FEATURES_LABEL=21
NEW_ENTITY_TYPE_IDENTIFIER=22
NEW_COMPOSITE_ENTITY=23
NEW_REGEX_ENTITY=24
NEW_ENTITY_IDENTIFIER=25
NEW_ENTITY_IDENTIFIER_WITH_WS=26
NEWLINE_IN_NAME=27
IDENTIFIER=28
DOT=29
ESCAPE_CHARACTER=30
EXPRESSION=31
TEXT=32
NEWLINE_IN_ENTITY=33
COMPOSITE_ENTITY=34
REGEX_ENTITY=35
ENTITY_TEXT=36
COLON_MARK=37
NEWLINE_IN_QNA=38
QNA_TEXT=39
IMPORT=11
FILTER_MARK=12
QNA_ID_MARK=13
MULTI_LINE_TEXT=14
PROMPT_MARK=15
INVALID_TOKEN_DEFAULT_MODE=16
EQUAL=17
COMMA=18
HAS_ROLES_LABEL=19
HAS_FEATURES_LABEL=20
NEW_ENTITY_TYPE_IDENTIFIER=21
NEW_COMPOSITE_ENTITY=22
NEW_REGEX_ENTITY=23
NEW_ENTITY_IDENTIFIER=24
NEW_ENTITY_IDENTIFIER_WITH_WS=25
NEWLINE_IN_NAME=26
IDENTIFIER=27
DOT=28
ESCAPE_CHARACTER=29
EXPRESSION=30
TEXT=31
NEWLINE_IN_ENTITY=32
COMPOSITE_ENTITY=33
REGEX_ENTITY=34
ENTITY_TEXT=35
COLON_MARK=36
NEWLINE_IN_QNA=37
QNA_TEXT=38
'$'=9
'@'=10
'='=18
','=19
'.'=29
':'=37
'='=17
','=18
'.'=28
':'=36
41 changes: 23 additions & 18 deletions packages/lu/src/parser/lufile/importSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,37 @@ class ImportSection {
*/
constructor(parseTree) {
this.ParseTree = parseTree;
this.Errors = []
this.SectionType = LUSectionTypes.IMPORTSECTION;
this.Description = this.ExtractDescription(parseTree);
let result = this.ExtractPath(parseTree);
this.Path = result.importPath;
this.Errors = result.errors;
let result = this.ExtractDescriptionAndPath(parseTree);
this.Description = result.description;
this.Path = result.path;
this.Id = `${this.SectionType}_${this.Path}`;;
}

ExtractDescription(parseTree) {
return parseTree.importDefinition().IMPORT_DESC().getText();
}
ExtractDescriptionAndPath(parseTree) {
let importRegex = new RegExp(/\[([^\]]*)\]\(([^\)]*)\)/);
let importStr = parseTree.importDefinition().IMPORT().getText();

let description
let path

ExtractPath(parseTree) {
let errors = [];
let importPath = parseTree.importDefinition().IMPORT_PATH().getText().replace('(', '').replace(')', '');
if (importPath === undefined || importPath === '') {
let errorMsg = `LU file reference path is empty: "${parseTree.getText()}"`;
let error = BuildDiagnostic({
message: errorMsg,
context: parseTree
})
let groups = importStr.match(importRegex);
if (groups && groups.length === 3) {
description = groups[1].trim();
path = groups[2].trim();
if (path === undefined || path === '') {
let errorMsg = `LU file reference path is empty: "${parseTree.getText()}"`;
let error = BuildDiagnostic({
message: errorMsg,
context: parseTree
})

errors.push(error);
this.Errors.push(error);
}
}

return { importPath, errors };
return { description, path }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('QnA document', function() {
luMerger.Build([new luObj(qnaContent, new luOptions('stdin'))], false, undefined, findLuFiles)
.then(res => done(res))
.catch(err => {
assert(err.text.includes("line 7:18 - line 7:19"))
assert(err.text.includes("line 9:12 - line 9:15"))
done()
})
})
Expand Down
24 changes: 24 additions & 0 deletions packages/lu/test/parser/lufile/sectionapi.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,28 @@ describe('Section CRUD tests for entity', () => {
assert.equal(luresource.Sections[1].UtteranceAndEntitiesMap.length, 1);
assert.equal(luresource.Sections[1].UtteranceAndEntitiesMap[0].utterance, 'hi');
});
});

describe('Section CRUD tests for error import in utterances', () => {
let luresource = undefined;

it('init section test', () => {
let fileContent =
`# Greeting
- hi
[]
[
]
> @ ml city
# Cancel
- cancel that`;

luresource = luparser.parse(fileContent);
assert.equal(luresource.Errors.length, 1);
assert.equal(luresource.Errors[0].Message, 'Invalid intent body line, did you miss \'-\' at line begin')
assert.equal(luresource.Sections.length, 2);
assert.equal(luresource.Sections[0].Body, `- hi${NEWLINE}[]${NEWLINE}[${NEWLINE}]${NEWLINE}> @ ml city`);
assert.equal(luresource.Sections[1].Name, 'Cancel')
assert.equal(luresource.Sections[1].Body, '- cancel that')
});
});