From 1f7dc16b018bc505be4e1a31b24ad516b6eecc29 Mon Sep 17 00:00:00 2001 From: Hongyang Date: Fri, 20 Mar 2020 18:00:08 +0800 Subject: [PATCH 1/2] fix ! flag issue --- .../AdaptiveExpressions/parser/ExpressionAntlrParser.g4 | 2 +- libraries/AdaptiveExpressions/parser/ExpressionParser.cs | 5 +++++ tests/AdaptiveExpressions.Tests/ExpressionParserTests.cs | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/libraries/AdaptiveExpressions/parser/ExpressionAntlrParser.g4 b/libraries/AdaptiveExpressions/parser/ExpressionAntlrParser.g4 index c0e17d62b9..a1c13d719e 100644 --- a/libraries/AdaptiveExpressions/parser/ExpressionAntlrParser.g4 +++ b/libraries/AdaptiveExpressions/parser/ExpressionAntlrParser.g4 @@ -25,7 +25,7 @@ primaryExpression | IDENTIFIER #idAtom | stringInterpolation #stringInterpolationAtom | primaryExpression DOT IDENTIFIER #memberAccessExp - | primaryExpression OPEN_BRACKET argsList? CLOSE_BRACKET #funcInvokeExp + | primaryExpression NON? OPEN_BRACKET argsList? CLOSE_BRACKET #funcInvokeExp | primaryExpression OPEN_SQUARE_BRACKET expression CLOSE_SQUARE_BRACKET #indexAccessExp ; diff --git a/libraries/AdaptiveExpressions/parser/ExpressionParser.cs b/libraries/AdaptiveExpressions/parser/ExpressionParser.cs index 2b740a10c0..98ecd5062a 100644 --- a/libraries/AdaptiveExpressions/parser/ExpressionParser.cs +++ b/libraries/AdaptiveExpressions/parser/ExpressionParser.cs @@ -105,6 +105,11 @@ public override Expression VisitFuncInvokeExp([NotNull] ExpressionAntlrParser.Fu // Remove the check to check primaryExpression is just an IDENTIFIER to support "." in template name var functionName = context.primaryExpression().GetText(); + if (context.NON() != null) + { + functionName += context.NON().GetText(); + } + return MakeExpression(functionName, parameters.ToArray()); } diff --git a/tests/AdaptiveExpressions.Tests/ExpressionParserTests.cs b/tests/AdaptiveExpressions.Tests/ExpressionParserTests.cs index 5475737672..966c9a3822 100644 --- a/tests/AdaptiveExpressions.Tests/ExpressionParserTests.cs +++ b/tests/AdaptiveExpressions.Tests/ExpressionParserTests.cs @@ -347,8 +347,8 @@ public class ExpressionParserTests Test("(1 + 2) != (4 - 1)", false), Test("!!exists(one) != !!exists(one)", false), Test("!!exists(one) !=\r\n !!exists(one)", false), - Test("hello != 'hello'", false), - Test("hello != 'world'", true), + Test("hello!= 'hello'", false), + Test("hello!= 'world'", true), Test("hello != \"hello\"", false), Test("hello != \"world\"", true), Test("(1 + 2) >= (4 - 1)", true), From 07c77b53bf47970267d0c0d4241ace624f04196c Mon Sep 17 00:00:00 2001 From: Hongyang Date: Fri, 20 Mar 2020 18:03:43 +0800 Subject: [PATCH 2/2] remove original stype --- libraries/AdaptiveExpressions/parser/ExpressionAntlrLexer.g4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/AdaptiveExpressions/parser/ExpressionAntlrLexer.g4 b/libraries/AdaptiveExpressions/parser/ExpressionAntlrLexer.g4 index fea42d3cbd..22722fea0a 100644 --- a/libraries/AdaptiveExpressions/parser/ExpressionAntlrLexer.g4 +++ b/libraries/AdaptiveExpressions/parser/ExpressionAntlrLexer.g4 @@ -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;