From d0541ad5b2ef07d016e2fbe6076029d02236f0fa Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Mon, 12 May 2014 15:03:38 -0700 Subject: [PATCH] Modify await keyword to accept dots. When doing Html.Foo we used to not accept the "." and then group the rest of the line together at the end. #45 --- .../Parser/CSharpCodeParser.Expressions.cs | 7 +------ src/Microsoft.AspNet.Razor/Parser/CSharpCodeParser.cs | 8 +++++++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNet.Razor/Parser/CSharpCodeParser.Expressions.cs b/src/Microsoft.AspNet.Razor/Parser/CSharpCodeParser.Expressions.cs index 07d56c3a8a..b677dd15ad 100644 --- a/src/Microsoft.AspNet.Razor/Parser/CSharpCodeParser.Expressions.cs +++ b/src/Microsoft.AspNet.Razor/Parser/CSharpCodeParser.Expressions.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNet.Razor.Parser { private void SetUpExpressions() { - MapKeywords(AwaitExpression, CSharpKeyword.Await); + MapExpressionKeyword(AwaitExpression, CSharpKeyword.Await); } private void AwaitExpression(bool topLevel) @@ -23,11 +23,6 @@ namespace Microsoft.AspNet.Razor.Parser // Accept 1 or more spaces between the await and the following code. AcceptWhile(IsSpacingToken(includeNewLines: false, includeComments: true)); - // Accept a single code piece to await. This will accept up until a method "call" signature. - // Ex: "@await |Foo|()" Inbetween the pipes is what is accepted. The Statement/ImplicitExpression - // handling capture method calls and the parameters passed in. - AcceptWhile(CSharpSymbolType.Identifier); - // Top level basically indicates if we're within an expression or statement. // Ex: topLevel true = @await Foo() | topLevel false = @{ await Foo(); } // Note that in this case @{ @await Foo() } top level is true for await. diff --git a/src/Microsoft.AspNet.Razor/Parser/CSharpCodeParser.cs b/src/Microsoft.AspNet.Razor/Parser/CSharpCodeParser.cs index d17d0ffb93..c1684adfb5 100644 --- a/src/Microsoft.AspNet.Razor/Parser/CSharpCodeParser.cs +++ b/src/Microsoft.AspNet.Razor/Parser/CSharpCodeParser.cs @@ -19,7 +19,6 @@ namespace Microsoft.AspNet.Razor.Parser internal static ISet DefaultKeywords = new HashSet() { - "await", "if", "do", "try", @@ -78,6 +77,13 @@ namespace Microsoft.AspNet.Razor.Parser return _directiveParsers.TryGetValue(directive, out handler); } + private void MapExpressionKeyword(Action handler, CSharpKeyword keyword) + { + _keywordParsers.Add(keyword, handler); + + // Expression keywords don't belong in the regular keyword list + } + private void MapKeywords(Action handler, params CSharpKeyword[] keywords) { MapKeywords(handler, topLevel: true, keywords: keywords);