Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 77567ef

Browse files
support special chars in intent name for lu antlr parser (#1058)
Co-authored-by: Emilio Munoz <[email protected]>
1 parent 454bc64 commit 77567ef

File tree

12 files changed

+1312
-1291
lines changed

12 files changed

+1312
-1291
lines changed

packages/lu/src/parser/lufile/LUFileLexer.g4

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ fragment X: 'x' | 'X';
2828
fragment Y: 'y' | 'Y';
2929
fragment Z: 'z' | 'Z';
3030

31-
fragment LETTER: 'a'..'z' | 'A'..'Z';
32-
fragment NUMBER: '0'..'9';
33-
3431
fragment WHITESPACE
3532
: ' '|'\t'|'\ufeff'|'\u00a0'
3633
;
@@ -169,11 +166,7 @@ NEWLINE_IN_NAME
169166
;
170167

171168
IDENTIFIER
172-
: (LETTER | NUMBER | '_') (LETTER | NUMBER | '-' | '_')*
173-
;
174-
175-
DOT
176-
: '.'
169+
: ~[ \t\r\n]+
177170
;
178171

179172
mode LIST_BODY_MODE;

packages/lu/src/parser/lufile/LUFileParser.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ nestedIntentName
4242
;
4343

4444
nameIdentifier
45-
: IDENTIFIER (DOT IDENTIFIER)*
45+
: IDENTIFIER
4646
;
4747

4848
nestedIntentBodyDefinition

packages/lu/src/parser/lufile/generated/LUFileLexer.interp

Lines changed: 1 addition & 6 deletions
Large diffs are not rendered by default.

packages/lu/src/parser/lufile/generated/LUFileLexer.js

Lines changed: 464 additions & 476 deletions
Large diffs are not rendered by default.

packages/lu/src/parser/lufile/generated/LUFileLexer.tokens

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,18 @@ NEW_ENTITY_IDENTIFIER=26
2727
NEW_ENTITY_IDENTIFIER_WITH_WS=27
2828
NEWLINE_IN_NAME=28
2929
IDENTIFIER=29
30-
DOT=30
31-
ESCAPE_CHARACTER=31
32-
EXPRESSION=32
33-
TEXT=33
34-
NEWLINE_IN_ENTITY=34
35-
COMPOSITE_ENTITY=35
36-
REGEX_ENTITY=36
37-
ENTITY_TEXT=37
38-
COLON_MARK=38
39-
NEWLINE_IN_QNA=39
40-
QNA_TEXT=40
30+
ESCAPE_CHARACTER=30
31+
EXPRESSION=31
32+
TEXT=32
33+
NEWLINE_IN_ENTITY=33
34+
COMPOSITE_ENTITY=34
35+
REGEX_ENTITY=35
36+
ENTITY_TEXT=36
37+
COLON_MARK=37
38+
NEWLINE_IN_QNA=38
39+
QNA_TEXT=39
4140
'$'=9
4241
'@'=10
4342
'='=18
4443
','=19
45-
'.'=30
46-
':'=38
44+
':'=37

packages/lu/src/parser/lufile/generated/LUFileParser.interp

Lines changed: 1 addition & 3 deletions
Large diffs are not rendered by default.

packages/lu/src/parser/lufile/generated/LUFileParser.js

Lines changed: 733 additions & 771 deletions
Large diffs are not rendered by default.

packages/lu/src/parser/lufile/generated/LUFileParser.tokens

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,18 @@ NEW_ENTITY_IDENTIFIER=26
2727
NEW_ENTITY_IDENTIFIER_WITH_WS=27
2828
NEWLINE_IN_NAME=28
2929
IDENTIFIER=29
30-
DOT=30
31-
ESCAPE_CHARACTER=31
32-
EXPRESSION=32
33-
TEXT=33
34-
NEWLINE_IN_ENTITY=34
35-
COMPOSITE_ENTITY=35
36-
REGEX_ENTITY=36
37-
ENTITY_TEXT=37
38-
COLON_MARK=38
39-
NEWLINE_IN_QNA=39
40-
QNA_TEXT=40
30+
ESCAPE_CHARACTER=30
31+
EXPRESSION=31
32+
TEXT=32
33+
NEWLINE_IN_ENTITY=33
34+
COMPOSITE_ENTITY=34
35+
REGEX_ENTITY=35
36+
ENTITY_TEXT=36
37+
COLON_MARK=37
38+
NEWLINE_IN_QNA=38
39+
QNA_TEXT=39
4140
'$'=9
4241
'@'=10
4342
'='=18
4443
','=19
45-
'.'=30
46-
':'=38
44+
':'=37

packages/lu/test/parser/lufile/parseFileContents.parseFile.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,4 +1076,18 @@ describe('parseFile correctly parses utterances', function () {
10761076
})
10771077
.catch(err => done(err))
10781078
})
1079+
1080+
it ('Correctly parses intent name with special chars', function(done){
1081+
let testLU = `
1082+
# test'á
1083+
- Hello world
1084+
`;
1085+
parseFile.parseFile(testLU)
1086+
.then(res => {
1087+
assert.equal(res.LUISJsonStructure.intents.length, 1);
1088+
assert.equal(res.LUISJsonStructure.intents[0].name, "test'á");
1089+
done();
1090+
})
1091+
.catch(err => done(err))
1092+
})
10791093
})

packages/luis/test/commands/luis/convert.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,13 @@ describe('luis:convert', () => {
402402
let parsedObjects = await parseJsonFiles('./../../../results/root41.json', './../../fixtures/verified/merge_intents_disabled.json')
403403
expect(parsedObjects[0]).to.deep.equal(parsedObjects[1])
404404
})
405+
406+
test
407+
.stdout()
408+
.command(['luis:convert', '--in', `${path.join(__dirname, './../../fixtures/testcases/intent_name_with_special_chars.json')}`, '--out', './results/root36.lu',])
409+
.it('luis:convert lu file with special chars in intent name', async () => {
410+
expect(await compareLuFiles('./../../../results/root36.lu', './../../fixtures/verified/intent_name_with_special_chars.lu')).to.be.true
411+
})
405412
})
406413

407414

0 commit comments

Comments
 (0)