Skip to content

Commit

Permalink
${} instead of @{} as bounding syntax. (#3381)
Browse files Browse the repository at this point in the history
* migrate expression namespace from Microsoft.Bot.Expressions to AdaptiveExpressions

* change expression mark from '@' to '$'

* fix error

* merge master
  • Loading branch information
Danieladu authored Feb 16, 2020
1 parent dc67247 commit ea87e8c
Show file tree
Hide file tree
Showing 362 changed files with 1,251 additions and 1,251 deletions.
2 changes: 1 addition & 1 deletion doc/BUILD 2019 BOM/commonExpressionLanguage.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
- - [ ] New pre-built functions ask
- - [X] [4/11] forEach(collection, iterator, expression)
- - [ ] [Post //BUILD] match(regExp)
- - [X] [4/11] lgTemplate(templateName, arg1, arg2,...) - drop support for @{[]}
- - [X] [4/11] lgTemplate(templateName, arg1, arg2,...) - drop support for ${[]}
- - [ ] property(scope, expression) evaluates to scope.<expressionResult>
- - [ ] [4/11] Drop support for object manipulation functions (json, addProperty, setProperty, removeProperty) from expression library - from doc. Vishwac.
- - [ ] [4/11] Document exists function - Vishwac.
Expand Down
2 changes: 1 addition & 1 deletion doc/CommonExpressionLanguage/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ See [here](./api-reference.md) for API reference.
|{} |Used to denote a variable in template expansion. E.g. {myVariable} |N/A |
|() |Enforces precedence order and groups sub expressions into larger expressions. E.g. (A+B)*C |N/A |
|. |Property selector. E.g. myObject.Property1 |N/A |
|@{} |Used to denote parts of a multi-line value that requires evaluation |N/A |
|${} |Used to denote parts of a multi-line value that requires evaluation |N/A |
|\ |Escape character for templates, expressions. |N/A |
|@entityName|Short hand notation that expands to turn.entities.entityName |N/A |
|$propertyName|Short hand notation that expands to dialog.result.property |N/A |
Expand Down
16 changes: 8 additions & 8 deletions doc/LanguageGeneration/lg-file-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,16 @@ Here is an example -
```
```

Multi-line variation can request template expansion and entity substitution by enclosing the requested operation in @{}.
Multi-line variation can request template expansion and entity substitution by enclosing the requested operation in ${}.

Here is an example -
```markdown
# MultiLineExample
- ```
Here is what I have for the order
- Title: @{reservation.title}
- Location: @{reservation.location}
- Date/ time: @{reservation.dateTimeReadBack}
- Title: ${reservation.title}
- Location: ${reservation.location}
- Date/ time: ${reservation.dateTimeReadBack}
```
```

Expand Down Expand Up @@ -173,16 +173,16 @@ Here is an example of complex object that your bot's code will parse out and ren
# ImageGalleryTemplate
- ```
{
"titleText": "@{[TitleText]}",
"subTitle": "@{[SubText]}",
"titleText": "${[TitleText]}",
"subTitle": "${[SubText]}",
"images": [
{
"type": "Image",
"url": "@{[CardImages]}"
"url": "${[CardImages]}"
},
{
"type": "Image",
"url": "@{[CardImages]}"
"url": "${[CardImages]}"
}
]
}
Expand Down
10 changes: 5 additions & 5 deletions doc/LanguageGeneration/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ Here is an example of a card definition.
# HeroCardTemplate(buttonsCollection)
- ```
[Herocard
title=@{[TitleText]}
subtitle=@{[SubText]}
text=@{[DescriptionText]}
images=@{[CardImages]}
buttons=@{join(buttonsCollection, '|')]
title=${[TitleText]}
subtitle=${[SubText]}
text=${[DescriptionText]}
images=${[CardImages]}
buttons=${join(buttonsCollection, '|')]
```

# TitleText
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace AdaptiveExpressions.Properties
/// * a string without '=' then value is treated as string with string interpolation.
/// * You can escape the '=' prefix by putting a backslash.
/// Examples:
/// prop = "Hello @{user.name}" => "Hello Joe"
/// prop = "Hello ${user.name}" => "Hello Joe"
/// prop = "=length(user.name)" => "3"
/// prop = "=user.name" => "Joe"
/// prop = "\=user" => "=user".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace AdaptiveExpressions.Properties
/// You can escape the '=' prefix by putting a backslash.
/// Examples:
/// prop = true ==> true
/// prop = "Hello @{user.name}" => "Hello Joe"
/// prop = "Hello ${user.name}" => "Hello Joe"
/// prop = "=length(user.name)" => 3
/// prop = "=user.age" => 45.
/// prop = "\=user.age" => "=user.age".
Expand Down
2 changes: 1 addition & 1 deletion libraries/AdaptiveExpressions/parser/ExpressionEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ private string EvalEscape(string exp)

private string TrimExpression(string expression)
{
var result = expression.Trim().TrimStart('@').Trim();
var result = expression.Trim().TrimStart('$').Trim();

if (result.StartsWith("{") && result.EndsWith("}"))
{
Expand Down
2 changes: 1 addition & 1 deletion libraries/AdaptiveExpressions/parser/ExpressionLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ mode STRING_INTERPOLATION_MODE;

STRING_INTERPOLATION_END : '`' {ignoreWS = true;} -> type(STRING_INTERPOLATION_START), popMode;

TEMPLATE : '@' '{' (STRING | ~[\r\n{}'"])*? '}';
TEMPLATE : '$' '{' (STRING | ~[\r\n{}'"])*? '}';
ESCAPE_CHARACTER : '\\' ~[\r\n]?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"description": "Expression to format the output.",
"examples": [
"=toUpper(this.value)",
"@{toUpper(this.value)}"
"${toUpper(this.value)}"
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Microsoft.Bot.Builder.LanguageGeneration
public class Evaluator : LGFileParserBaseVisitor<object>
{
public const string LGType = "lgType";
public static readonly Regex ExpressionRecognizeRegex = new Regex(@"(?<!\\)@{((\'[^\r\n\']*\')|(\""[^\""\r\n]*\"")|(\`(\\\`|[^\`])*\`)|([^\r\n{}'""`]))+}?", RegexOptions.Compiled);
public static readonly Regex ExpressionRecognizeRegex = new Regex(@"(?<!\\)\${((\'[^\r\n\']*\')|(\""[^\""\r\n]*\"")|(\`(\\\`|[^\`])*\`)|([^\r\n{}'""`]))+}?", RegexOptions.Compiled);
private const string ReExecuteSuffix = "!";
private readonly Stack<EvaluationTarget> evaluationTargetStack = new Stack<EvaluationTarget>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ public static string Escape(this string text)
}

/// <summary>
/// trim expression. @{abc} => abc, @{a == {}} => a == {}.
/// trim expression. ${abc} => abc, ${a == {}} => a == {}.
/// </summary>
/// <param name="expression">input expression string.</param>
/// <returns>pure expression string.</returns>
public static string TrimExpression(this string expression)
{
var result = expression.Trim().TrimStart('@').Trim();
var result = expression.Trim().TrimStart('$').Trim();

if (result.StartsWith("{") && result.EndsWith("}"))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ fragment STRING_LITERAL : ('\'' (~['\r\n])* '\'') | ('"' (~["\r\n])* '"');
fragment STRING_INTERPOLATION : '`' ('\\`' | ~'`')* '`';
fragment EXPRESSION_FRAGMENT : '@' '{' (STRING_LITERAL | STRING_INTERPOLATION | EMPTY_OBJECT | ~[\r\n{}'"`] )+ '}'?;
fragment EXPRESSION_FRAGMENT : '$' '{' (STRING_LITERAL | STRING_INTERPOLATION | EMPTY_OBJECT | ~[\r\n{}'"`] )+ '}'?;
fragment ESCAPE_CHARACTER_FRAGMENT : '\\' ~[\r\n]?;
// top level elements
COMMENTS
: ('>'|'$') ~('\r'|'\n')+ -> skip
: '>' ~('\r'|'\n')+ -> skip
;
WS
Expand Down Expand Up @@ -210,7 +210,7 @@ TEXT_IN_STRUCTURE_NAME
mode STRUCTURE_BODY_MODE;
STRUCTURED_COMMENTS
: ('>'|'$') ~[\r\n]* '\r'?'\n' { !inStructuredValue && beginOfStructureProperty}? -> skip
: '>' ~[\r\n]* '\r'?'\n' { !inStructuredValue && beginOfStructureProperty}? -> skip
;
WS_IN_STRUCTURE_BODY
Expand Down
2 changes: 1 addition & 1 deletion schemas/sdk.schema
Original file line number Diff line number Diff line change
Expand Up @@ -11648,7 +11648,7 @@
"description": "Expression to format the output.",
"examples": [
"=toUpper(this.value)",
"@{toUpper(this.value)}"
"${toUpper(this.value)}"
]
}
},
Expand Down
18 changes: 9 additions & 9 deletions tests/AdaptiveExpressions.Tests/ExpressionEngineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,15 @@ public class ExpressionEngineTests
#region string interpolation test
Test("`hi`", "hi"),
Test(@"`hi\``", "hi`"),
Test("`@{world}`", "world"),
Test(@"`hi @{string('jack\`')}`", "hi jack`"),
Test(@"`\@{world}`", "@{world}"), // use escape character
Test("length(`hello @{world}`)", "hello world".Length),
Test("json(`{'foo': '@{hello}','item': '@{world}'}`).foo", "hello"),
Test("`hello @{world}` == 'hello world'", true),
Test("`hello @{world}` != 'hello hello'", true),
Test("`hello @{user.nickname}` == 'hello John'", true),
Test("`hello @{user.nickname}` != 'hello Dong'", true),
Test("`${world}`", "world"),
Test(@"`hi ${string('jack\`')}`", "hi jack`"),
Test(@"`\${world}`", "${world}"), // use escape character
Test("length(`hello ${world}`)", "hello world".Length),
Test("json(`{'foo': '${hello}','item': '${world}'}`).foo", "hello"),
Test("`hello ${world}` == 'hello world'", true),
Test("`hello ${world}` != 'hello hello'", true),
Test("`hello ${user.nickname}` == 'hello John'", true),
Test("`hello ${user.nickname}` != 'hello Dong'", true),
#endregion

#region SetPathToProperty test
Expand Down
8 changes: 4 additions & 4 deletions tests/AdaptiveExpressions.Tests/ExpressionPropertyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ public void ExpressionPropertyTests_StringExpression()
Assert.AreEqual("joe", result);
Assert.IsNull(error);

str = new StringExpression("Hello @{test}");
Assert.AreEqual("=`Hello @{test}`", str.ExpressionText);
str = new StringExpression("Hello ${test}");
Assert.AreEqual("=`Hello ${test}`", str.ExpressionText);
Assert.IsNull(str.Value);
Assert.AreEqual(str.ToString(), JsonConvert.DeserializeObject<StringExpression>(JsonConvert.SerializeObject(str, settings: settings), settings: settings).ToString());
(result, error) = str.TryGetValue(data);
Expand Down Expand Up @@ -325,8 +325,8 @@ public void ExpressionPropertyTests_ValueExpression()
Assert.AreEqual(JsonConvert.SerializeObject(data.test), JsonConvert.SerializeObject(result));
Assert.IsNull(error);

val = new ValueExpression("Hello @{test.x}");
Assert.AreEqual("=`Hello @{test.x}`", val.ExpressionText);
val = new ValueExpression("Hello ${test.x}");
Assert.AreEqual("=`Hello ${test.x}`", val.ExpressionText);
Assert.IsNull(val.Value);
Assert.AreEqual(val.ToString(), JsonConvert.DeserializeObject<ValueExpression>(JsonConvert.SerializeObject(val, settings: settings), settings: settings).ToString());
(result, error) = val.TryGetValue(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private AdaptiveDialog CreateQnAMakerActionDialog(MockHttpMessageHandler mockHtt
{
new SendActivity()
{
Activity = new ActivityTemplate("@{@answer}")
Activity = new ActivityTemplate("${@answer}")
},
new AssertCondition()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,21 @@ public async Task CheckStructuredLGDiagnostics()
var context = await GetTurnContext("DignosticStructuredLG.lg");
var languageGenerator = context.TurnState.Get<ILanguageGenerator>();

var lgStringResult = await languageGenerator.Generate(context, "@{ErrorStructuredType()}", null);
var lgStringResult = await languageGenerator.Generate(context, "${ErrorStructuredType()}", null);
var diagnostics = ActivityChecker.Check(lgStringResult);
Assert.AreEqual(diagnostics.Count, 1);
Assert.IsTrue(diagnostics[0].Severity == DiagnosticSeverity.Error);
Assert.AreEqual("Type 'mystruct' is not supported currently.", diagnostics[0].Message);

lgStringResult = await languageGenerator.Generate(context, "@{ErrorActivityType()}", null);
lgStringResult = await languageGenerator.Generate(context, "${ErrorActivityType()}", null);
diagnostics = ActivityChecker.Check(lgStringResult);
Assert.AreEqual(diagnostics.Count, 2);
Assert.IsTrue(diagnostics[0].Severity == DiagnosticSeverity.Error);
Assert.AreEqual(diagnostics[0].Message, "'xxx' is not a valid activity type.");
Assert.IsTrue(diagnostics[1].Severity == DiagnosticSeverity.Warning);
Assert.AreEqual(diagnostics[1].Message, "'invalidproperty' not support in Activity.");

lgStringResult = await languageGenerator.Generate(context, "@{ErrorMessage()}", null);
lgStringResult = await languageGenerator.Generate(context, "${ErrorMessage()}", null);
diagnostics = ActivityChecker.Check(lgStringResult);
Assert.AreEqual(diagnostics.Count, 5);
Assert.IsTrue(diagnostics[0].Severity == DiagnosticSeverity.Warning);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"actions": [
{
"$kind": "Microsoft.SendActivity",
"activity": "@{test()}"
"activity": "${test()}"
},
{
"$kind": "Microsoft.AdaptiveDialog",
Expand All @@ -18,7 +18,7 @@
"actions": [
{
"$kind": "Microsoft.SendActivity",
"activity": "@{test()}"
"activity": "${test()}"
}
]
}
Expand Down
Loading

0 comments on commit ea87e8c

Please sign in to comment.