From cd652a3e672e3d60bf649168161650dc280828da Mon Sep 17 00:00:00 2001 From: Hongyang Date: Wed, 5 Feb 2020 08:46:47 +0800 Subject: [PATCH 1/2] fix structure value with equals mark bug --- .../LGFileParser.g4 | 2 +- .../Examples/StructuredTemplate.lg | 6 ++++++ .../LGFileTest.cs | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/libraries/Microsoft.Bot.Builder.LanguageGeneration/LGFileParser.g4 b/libraries/Microsoft.Bot.Builder.LanguageGeneration/LGFileParser.g4 index 1e9d812cff..1d9a16cfb7 100644 --- a/libraries/Microsoft.Bot.Builder.LanguageGeneration/LGFileParser.g4 +++ b/libraries/Microsoft.Bot.Builder.LanguageGeneration/LGFileParser.g4 @@ -74,7 +74,7 @@ keyValueStructureLine ; keyValueStructureValue - : (TEXT_IN_STRUCTURE_BODY|EXPRESSION_IN_STRUCTURE_BODY|ESCAPE_CHARACTER_IN_STRUCTURE_BODY)+ + : (TEXT_IN_STRUCTURE_BODY|EXPRESSION_IN_STRUCTURE_BODY|ESCAPE_CHARACTER_IN_STRUCTURE_BODY|STRUCTURE_EQUALS)+ ; objectStructureLine diff --git a/tests/Microsoft.Bot.Builder.LanguageGeneration.Tests/Examples/StructuredTemplate.lg b/tests/Microsoft.Bot.Builder.LanguageGeneration.Tests/Examples/StructuredTemplate.lg index a8a78d93ba..ee0426342d 100644 --- a/tests/Microsoft.Bot.Builder.LanguageGeneration.Tests/Examples/StructuredTemplate.lg +++ b/tests/Microsoft.Bot.Builder.LanguageGeneration.Tests/Examples/StructuredTemplate.lg @@ -123,4 +123,10 @@ [MyStruct Speak = @{GetAge()} Text = zoo +] + +> treat everything after the first = as value. +# ValueWithEqualsMark +[Activity + Text = Hello! welcome back. I have your name = @{name} ] \ No newline at end of file diff --git a/tests/Microsoft.Bot.Builder.LanguageGeneration.Tests/LGFileTest.cs b/tests/Microsoft.Bot.Builder.LanguageGeneration.Tests/LGFileTest.cs index 17aa213422..64c5abd149 100644 --- a/tests/Microsoft.Bot.Builder.LanguageGeneration.Tests/LGFileTest.cs +++ b/tests/Microsoft.Bot.Builder.LanguageGeneration.Tests/LGFileTest.cs @@ -713,6 +713,11 @@ public void TestStructuredTemplate() Assert.IsTrue( JToken.DeepEquals(JObject.Parse("{\"lgType\":\"Struct\",\"text\":\"Acme Co\"}"), evaled as JObject)); + + evaled = lgFile.EvaluateTemplate("ValueWithEqualsMark", new { name = "Jack" }); + + Assert.IsTrue( + JToken.DeepEquals(JObject.Parse("{\"lgType\": \"Activity\",\"text\": \"Hello! welcome back. I have your name = Jack\"}"), evaled as JObject)); } [TestMethod] From 685d6a7388c2e518e84ca2f4ebe8c529684992b7 Mon Sep 17 00:00:00 2001 From: Hongyang Date: Wed, 5 Feb 2020 09:04:55 +0800 Subject: [PATCH 2/2] use a more common solution --- .../Microsoft.Bot.Builder.LanguageGeneration/LGFileLexer.g4 | 2 +- .../Microsoft.Bot.Builder.LanguageGeneration/LGFileParser.g4 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/Microsoft.Bot.Builder.LanguageGeneration/LGFileLexer.g4 b/libraries/Microsoft.Bot.Builder.LanguageGeneration/LGFileLexer.g4 index f841f24381..5558d7872a 100644 --- a/libraries/Microsoft.Bot.Builder.LanguageGeneration/LGFileLexer.g4 +++ b/libraries/Microsoft.Bot.Builder.LanguageGeneration/LGFileLexer.g4 @@ -228,7 +228,7 @@ STRUCTURE_IDENTIFIER ; STRUCTURE_EQUALS - : '=' {inStructuredValue = true;} + : '=' {!inStructuredValue}? {inStructuredValue = true;} ; STRUCTURE_OR_MARK diff --git a/libraries/Microsoft.Bot.Builder.LanguageGeneration/LGFileParser.g4 b/libraries/Microsoft.Bot.Builder.LanguageGeneration/LGFileParser.g4 index 1d9a16cfb7..1e9d812cff 100644 --- a/libraries/Microsoft.Bot.Builder.LanguageGeneration/LGFileParser.g4 +++ b/libraries/Microsoft.Bot.Builder.LanguageGeneration/LGFileParser.g4 @@ -74,7 +74,7 @@ keyValueStructureLine ; keyValueStructureValue - : (TEXT_IN_STRUCTURE_BODY|EXPRESSION_IN_STRUCTURE_BODY|ESCAPE_CHARACTER_IN_STRUCTURE_BODY|STRUCTURE_EQUALS)+ + : (TEXT_IN_STRUCTURE_BODY|EXPRESSION_IN_STRUCTURE_BODY|ESCAPE_CHARACTER_IN_STRUCTURE_BODY)+ ; objectStructureLine