diff --git a/.travis.yml b/.travis.yml
index e75fe73221..d56301c453 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -12,7 +12,7 @@ os:
osx_image: xcode8.2
branches:
only:
- - dev
+ - master
- /^release\/.*$/
- /^(.*\/)?ci-.*$/
before_install:
diff --git a/.vsts-pipelines/builds/ci-internal.yml b/.vsts-pipelines/builds/ci-internal.yml
index dc7b8a3cb9..c2c5336fd0 100644
--- a/.vsts-pipelines/builds/ci-internal.yml
+++ b/.vsts-pipelines/builds/ci-internal.yml
@@ -7,7 +7,7 @@ resources:
- repository: buildtools
type: git
name: aspnet-BuildTools
- ref: refs/heads/release/2.2
+ ref: refs/heads/master
phases:
- template: .vsts-pipelines/templates/project-ci.yml@buildtools
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 64ff041d5c..eac4268e4c 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -1,4 +1,4 @@
Contributing
======
-Information on contributing to this repo is in the [Contributing Guide](https://github.com/aspnet/Home/blob/dev/CONTRIBUTING.md) in the Home repo.
+Information on contributing to this repo is in the [Contributing Guide](https://github.com/aspnet/Home/blob/master/CONTRIBUTING.md) in the Home repo.
diff --git a/LICENSE.txt b/LICENSE.txt
index 7b2956ecee..b3b180cd51 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -1,14 +1,201 @@
-Copyright (c) .NET Foundation and Contributors
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
-All rights reserved.
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-Licensed under the Apache License, Version 2.0 (the "License"); you may not use
-this file except in compliance with the License. You may obtain a copy of the
-License at
+ 1. Definitions.
- http://www.apache.org/licenses/LICENSE-2.0
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
-Unless required by applicable law or agreed to in writing, software distributed
-under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-CONDITIONS OF ANY KIND, either express or implied. See the License for the
-specific language governing permissions and limitations under the License.
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright (c) .NET Foundation and Contributors
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/benchmarks/Microsoft.AspNetCore.Razor.Performance/ProjectSystem/ProjectSnapshotManagerBenchmarkBase.cs b/benchmarks/Microsoft.AspNetCore.Razor.Performance/ProjectSystem/ProjectSnapshotManagerBenchmarkBase.cs
index 70590a6a35..580ddd1572 100644
--- a/benchmarks/Microsoft.AspNetCore.Razor.Performance/ProjectSystem/ProjectSnapshotManagerBenchmarkBase.cs
+++ b/benchmarks/Microsoft.AspNetCore.Razor.Performance/ProjectSystem/ProjectSnapshotManagerBenchmarkBase.cs
@@ -132,14 +132,6 @@ namespace Microsoft.AspNetCore.Razor.Performance
private class StaticProjectSnapshotProjectEngineFactory : ProjectSnapshotProjectEngineFactory
{
- public override RazorProjectEngine Create(ProjectSnapshot project, RazorProjectFileSystem fileSystem, Action configure)
- {
- return RazorProjectEngine.Create(project.Configuration, fileSystem, b =>
- {
- RazorExtensions.Register(b);
- });
- }
-
public override IProjectEngineFactory FindFactory(ProjectSnapshot project)
{
throw new NotImplementedException();
@@ -149,6 +141,14 @@ namespace Microsoft.AspNetCore.Razor.Performance
{
throw new NotImplementedException();
}
+
+ public override RazorProjectEngine Create(RazorConfiguration configuration, RazorProjectFileSystem fileSystem, Action configure)
+ {
+ return RazorProjectEngine.Create(configuration, fileSystem, b =>
+ {
+ RazorExtensions.Register(b);
+ });
+ }
}
}
}
diff --git a/build/VSIX.targets b/build/VSIX.targets
index 8027af296d..ae33c87310 100644
--- a/build/VSIX.targets
+++ b/build/VSIX.targets
@@ -105,7 +105,7 @@
/p:Configuration=$(Configuration);
/p:FeatureBranchVersionSuffix=$(FeatureBranchVersionSuffix);
/p:BuildNumber=$(BuildNumber);
- /p:LangVersion=7.1" />
+ /p:LangVersion=7.2" />
diff --git a/build/dependencies.props b/build/dependencies.props
index fc5e7a6682..a79fd5d296 100644
--- a/build/dependencies.props
+++ b/build/dependencies.props
@@ -4,49 +4,52 @@
0.10.13
- 2.2.0-preview2-20181019.2
- 2.2.0-rtm-35519
- 2.2.0-rtm-35519
- 2.2.0-rtm-35519
- 15.6.82
- 15.6.82
- 15.6.82
+ 3.0.0-alpha1-20181017.7
+ 3.0.0-alpha1-10549
+ 3.0.0-alpha1-10549
+ 3.0.0-alpha1-10549
+ 15.8.166
+ 15.8.166
+ 15.8.166
2.8.0
2.8.0
- 2.2.0-rtm-35519
- 2.2.0-rtm-35519
- 2.1.0
- 2.2.0-rtm-35519
- 2.2.0-rtm-35519
- 2.2.0-rtm-35519
+ 3.0.0-alpha1-10549
+ 3.0.0-alpha1-10549
+ 3.0.0-preview1-26907-05
+ 3.0.0-alpha1-10549
+ 3.0.0-alpha1-10549
+ 3.0.0-alpha1-10549
2.0.9
2.1.3
2.2.0-preview3-27014-02
15.6.1
- 15.0.26606
- 15.6.161-preview
- 15.6.161-preview
- 7.10.6070
- 15.3.224
+ 15.8.525
+ 15.8.28010
+ 16.0.142-g25b7188c54
+ 16.0.142-g25b7188c54
+ 16.0.142-g25b7188c54
+ 7.10.6071
+ 15.8.243
2.0.6142705
- 15.3.224
- 15.0.26606
- 10.0.30319
- 11.0.61030
- 12.0.30110
- 8.0.50727
- 9.0.30729
- 7.10.6071
- 15.6.161-preview
+ 15.8.243
+ 15.8.28010
+ 10.0.30320
+ 11.0.61031
+ 12.0.30111
+ 8.0.50728
+ 9.0.30730
+ 7.10.6072
+ 16.0.142-g25b7188c54
+ 15.8.168
1.3.8
1.0.1
4.10.0
2.0.3
11.0.2
- 1.1.92
- 4.5.0
+ 1.3.23
+ 4.6.0-preview1-26907-04
4.3.0
- 4.5.0
+ 4.6.0-preview1-26829-04
9.0.1
2.9.0-beta4-62911-02
2.9.0-beta4-62911-02
diff --git a/build/repo.props b/build/repo.props
index def34f0b6f..fef2fdc0eb 100644
--- a/build/repo.props
+++ b/build/repo.props
@@ -21,7 +21,6 @@
Internal.AspNetCore.Universe.Lineup
- 2.2.0-*
https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json
diff --git a/korebuild-lock.txt b/korebuild-lock.txt
index 9bbcbd3257..bbb101c1a4 100644
--- a/korebuild-lock.txt
+++ b/korebuild-lock.txt
@@ -1,2 +1,2 @@
-version:2.2.0-preview2-20181019.2
-commithash:72ba316025aca165c09cb97b407965d944bad93f
+version:3.0.0-alpha1-20181017.7
+commithash:f4082c290c6c7610e7cb9d787072004453fc175f
diff --git a/korebuild.json b/korebuild.json
index a8b81a48a2..b25cdff3c4 100644
--- a/korebuild.json
+++ b/korebuild.json
@@ -1,6 +1,6 @@
{
- "$schema": "https://raw.githubusercontent.com/aspnet/BuildTools/release/2.2/tools/korebuild.schema.json",
- "channel": "release/2.2",
+ "$schema": "https://raw.githubusercontent.com/aspnet/BuildTools/master/tools/korebuild.schema.json",
+ "channel": "master",
"toolsets": {
"visualstudio": {
"required": false,
diff --git a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorIntermediateNodeLoweringPhase.cs b/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorIntermediateNodeLoweringPhase.cs
index a711567547..762fd61d63 100644
--- a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorIntermediateNodeLoweringPhase.cs
+++ b/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorIntermediateNodeLoweringPhase.cs
@@ -595,9 +595,9 @@ namespace Microsoft.AspNetCore.Razor.Language
{
if (span.Tokens.Count == 1)
{
- var token = span.Tokens[0] as HtmlToken;
+ var token = span.Tokens[0];
if (token != null &&
- token.Type == HtmlTokenType.Unknown &&
+ token.Kind == SyntaxKind.Unknown &&
token.Content.Length == 0)
{
// We don't want to create IR nodes for marker tokens.
diff --git a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorProjectFileSystem.cs b/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorProjectFileSystem.cs
index 2600ce5efe..9283088cd1 100644
--- a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorProjectFileSystem.cs
+++ b/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorProjectFileSystem.cs
@@ -49,6 +49,10 @@ namespace Microsoft.AspNetCore.Razor.Language
var absolutePath = NormalizeAndEnsureValidPath(path);
var file = new FileInfo(absolutePath);
+ if (!absolutePath.StartsWith(absoluteBasePath))
+ {
+ throw new InvalidOperationException($"The file '{file.FullName}' is not a descendent of the base path '{absoluteBasePath}'.");
+ }
var relativePhysicalPath = file.FullName.Substring(absoluteBasePath.Length + 1); // Include leading separator
var filePath = "/" + relativePhysicalPath.Replace(Path.DirectorySeparatorChar, '/');
diff --git a/src/Microsoft.AspNetCore.Razor.Language/DirectiveTokenEditHandler.cs b/src/Microsoft.AspNetCore.Razor.Language/DirectiveTokenEditHandler.cs
index 308c274518..b4edccf638 100644
--- a/src/Microsoft.AspNetCore.Razor.Language/DirectiveTokenEditHandler.cs
+++ b/src/Microsoft.AspNetCore.Razor.Language/DirectiveTokenEditHandler.cs
@@ -4,18 +4,19 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Razor.Language.Legacy;
+using Microsoft.AspNetCore.Razor.Language.Syntax.InternalSyntax;
namespace Microsoft.AspNetCore.Razor.Language
{
internal class DirectiveTokenEditHandler : SpanEditHandler
{
- public DirectiveTokenEditHandler(Func> tokenizer) : base(tokenizer)
+ public DirectiveTokenEditHandler(Func> tokenizer) : base(tokenizer)
{
}
protected override PartialParseResultInternal CanAcceptChange(Span target, SourceChange change)
{
- if (AcceptedCharacters == AcceptedCharactersInternal.NonWhiteSpace)
+ if (AcceptedCharacters == AcceptedCharactersInternal.NonWhitespace)
{
var originalText = change.GetOriginalText(target);
var editedContent = change.GetEditedContent(target);
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Extensions/DesignTimeDirectiveTargetExtension.cs b/src/Microsoft.AspNetCore.Razor.Language/Extensions/DesignTimeDirectiveTargetExtension.cs
index 316c255bfe..29cc438fbb 100644
--- a/src/Microsoft.AspNetCore.Razor.Language/Extensions/DesignTimeDirectiveTargetExtension.cs
+++ b/src/Microsoft.AspNetCore.Razor.Language/Extensions/DesignTimeDirectiveTargetExtension.cs
@@ -65,15 +65,17 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
}
// {node.Content} __typeHelper = default({node.Content});
-
- context.AddSourceMappingFor(node);
- context.CodeWriter
- .Write(node.Content)
- .Write(" ")
- .WriteStartAssignment(TypeHelper)
- .Write("default(")
- .Write(node.Content)
- .WriteLine(");");
+ using (context.CodeWriter.BuildLinePragma(node.Source))
+ {
+ context.AddSourceMappingFor(node);
+ context.CodeWriter
+ .Write(node.Content)
+ .Write(" ")
+ .WriteStartAssignment(TypeHelper)
+ .Write("default(")
+ .Write(node.Content)
+ .WriteLine(");");
+ }
break;
case DirectiveTokenKind.Member:
@@ -86,16 +88,18 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
}
// global::System.Object {node.content} = null;
-
- context.CodeWriter
+ using (context.CodeWriter.BuildLinePragma(node.Source))
+ {
+ context.CodeWriter
.Write("global::")
.Write(typeof(object).FullName)
.Write(" ");
- context.AddSourceMappingFor(node);
- context.CodeWriter
- .Write(node.Content)
- .WriteLine(" = null;");
+ context.AddSourceMappingFor(node);
+ context.CodeWriter
+ .Write(node.Content)
+ .WriteLine(" = null;");
+ }
break;
case DirectiveTokenKind.Namespace:
@@ -108,46 +112,50 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
}
// global::System.Object __typeHelper = nameof({node.Content});
-
- context.CodeWriter
+ using (context.CodeWriter.BuildLinePragma(node.Source))
+ {
+ context.CodeWriter
.Write("global::")
.Write(typeof(object).FullName)
.Write(" ")
.WriteStartAssignment(TypeHelper);
- context.CodeWriter.Write("nameof(");
+ context.CodeWriter.Write("nameof(");
- context.AddSourceMappingFor(node);
- context.CodeWriter
- .Write(node.Content)
- .WriteLine(");");
+ context.AddSourceMappingFor(node);
+ context.CodeWriter
+ .Write(node.Content)
+ .WriteLine(");");
+ }
break;
case DirectiveTokenKind.String:
// global::System.Object __typeHelper = "{node.Content}";
-
- context.CodeWriter
+ using (context.CodeWriter.BuildLinePragma(node.Source))
+ {
+ context.CodeWriter
.Write("global::")
.Write(typeof(object).FullName)
.Write(" ")
.WriteStartAssignment(TypeHelper);
- if (node.Content.StartsWith("\"", StringComparison.Ordinal))
- {
- context.AddSourceMappingFor(node);
- context.CodeWriter.Write(node.Content);
- }
- else
- {
- context.CodeWriter.Write("\"");
- context.AddSourceMappingFor(node);
- context.CodeWriter
- .Write(node.Content)
- .Write("\"");
- }
+ if (node.Content.StartsWith("\"", StringComparison.Ordinal))
+ {
+ context.AddSourceMappingFor(node);
+ context.CodeWriter.Write(node.Content);
+ }
+ else
+ {
+ context.CodeWriter.Write("\"");
+ context.AddSourceMappingFor(node);
+ context.CodeWriter
+ .Write(node.Content)
+ .Write("\"");
+ }
- context.CodeWriter.WriteLine(";");
+ context.CodeWriter.WriteLine(";");
+ }
break;
}
context.CodeWriter.CurrentIndent = originalIndent;
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/AcceptedCharactersInternal.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/AcceptedCharactersInternal.cs
index f6b658f769..9838a182b5 100644
--- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/AcceptedCharactersInternal.cs
+++ b/src/Microsoft.AspNetCore.Razor.Language/Legacy/AcceptedCharactersInternal.cs
@@ -10,13 +10,13 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
None = 0,
NewLine = 1,
- WhiteSpace = 2,
+ Whitespace = 2,
- NonWhiteSpace = 4,
+ NonWhitespace = 4,
- AllWhiteSpace = NewLine | WhiteSpace,
- Any = AllWhiteSpace | NonWhiteSpace,
+ AllWhitespace = NewLine | Whitespace,
+ Any = AllWhitespace | NonWhitespace,
- AnyExceptNewline = NonWhiteSpace | WhiteSpace
+ AnyExceptNewline = NonWhitespace | Whitespace
}
}
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/AutoCompleteEditHandler.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/AutoCompleteEditHandler.cs
index 3aecb29a52..a20dbddfb9 100644
--- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/AutoCompleteEditHandler.cs
+++ b/src/Microsoft.AspNetCore.Razor.Language/Legacy/AutoCompleteEditHandler.cs
@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
+using Microsoft.AspNetCore.Razor.Language.Syntax.InternalSyntax;
using Microsoft.Extensions.Internal;
namespace Microsoft.AspNetCore.Razor.Language.Legacy
@@ -11,18 +12,18 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
private static readonly int TypeHashCode = typeof(AutoCompleteEditHandler).GetHashCode();
- public AutoCompleteEditHandler(Func> tokenizer)
+ public AutoCompleteEditHandler(Func> tokenizer)
: base(tokenizer)
{
}
- public AutoCompleteEditHandler(Func> tokenizer, bool autoCompleteAtEndOfSpan)
+ public AutoCompleteEditHandler(Func> tokenizer, bool autoCompleteAtEndOfSpan)
: this(tokenizer)
{
AutoCompleteAtEndOfSpan = autoCompleteAtEndOfSpan;
}
- public AutoCompleteEditHandler(Func> tokenizer, AcceptedCharactersInternal accepted)
+ public AutoCompleteEditHandler(Func> tokenizer, AcceptedCharactersInternal accepted)
: base(tokenizer, accepted)
{
}
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/CSharpCodeParser.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/CSharpCodeParser.cs
index a75c983fec..1269709459 100644
--- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/CSharpCodeParser.cs
+++ b/src/Microsoft.AspNetCore.Razor.Language/Legacy/CSharpCodeParser.cs
@@ -5,17 +5,18 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
+using Microsoft.AspNetCore.Razor.Language.Syntax.InternalSyntax;
namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
- internal class CSharpCodeParser : TokenizerBackedParser
+ internal class CSharpCodeParser : TokenizerBackedParser
{
private static HashSet InvalidNonWhitespaceNameCharacters = new HashSet(new[]
{
'@', '!', '<', '/', '?', '[', '>', ']', '=', '"', '\'', '*'
});
- private static readonly Func IsValidStatementSpacingToken =
+ private static readonly Func IsValidStatementSpacingToken =
IsSpacingToken(includeNewLines: true, includeComments: true);
internal static readonly DirectiveDescriptor AddTagHelperDirectiveDescriptor = DirectiveDescriptor.CreateDirective(
@@ -102,7 +103,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
public bool IsNested { get; set; }
- protected override bool TokenTypeEquals(CSharpTokenType x, CSharpTokenType y) => x == y;
+ protected override bool TokenKindEquals(SyntaxKind x, SyntaxKind y) => x == y;
protected void MapDirectives(Action handler, params string[] directives)
{
@@ -161,16 +162,18 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
[Conditional("DEBUG")]
internal void Assert(CSharpKeyword expectedKeyword)
{
- Debug.Assert(CurrentToken.Type == CSharpTokenType.Keyword &&
- CurrentToken.Keyword.HasValue &&
- CurrentToken.Keyword.Value == expectedKeyword);
+ var result = CSharpTokenizer.GetTokenKeyword(CurrentToken);
+ Debug.Assert(CurrentToken.Kind == SyntaxKind.Keyword &&
+ result.HasValue &&
+ result.Value == expectedKeyword);
}
protected internal bool At(CSharpKeyword keyword)
{
- return At(CSharpTokenType.Keyword) &&
- CurrentToken.Keyword.HasValue &&
- CurrentToken.Keyword.Value == keyword;
+ var result = CSharpTokenizer.GetTokenKeyword(CurrentToken);
+ return At(SyntaxKind.Keyword) &&
+ result.HasValue &&
+ result.Value == keyword;
}
protected internal bool AcceptIf(CSharpKeyword keyword)
@@ -183,11 +186,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return false;
}
- protected static Func IsSpacingToken(bool includeNewLines, bool includeComments)
+ protected static Func IsSpacingToken(bool includeNewLines, bool includeComments)
{
- return token => token.Type == CSharpTokenType.WhiteSpace ||
- (includeNewLines && token.Type == CSharpTokenType.NewLine) ||
- (includeComments && token.Type == CSharpTokenType.Comment);
+ return token => token.Kind == SyntaxKind.Whitespace ||
+ (includeNewLines && token.Kind == SyntaxKind.NewLine) ||
+ (includeComments && token.Kind == SyntaxKind.CSharpComment);
}
public override void ParseBlock()
@@ -209,24 +212,24 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
AcceptWhile(IsSpacingToken(includeNewLines: true, includeComments: true));
var current = CurrentToken;
- if (At(CSharpTokenType.StringLiteral) &&
+ if (At(SyntaxKind.StringLiteral) &&
CurrentToken.Content.Length > 0 &&
CurrentToken.Content[0] == SyntaxConstants.TransitionCharacter)
{
- var split = Language.SplitToken(CurrentToken, 1, CSharpTokenType.Transition);
+ var split = Language.SplitToken(CurrentToken, 1, SyntaxKind.Transition);
current = split.Item1;
// Back up to the end of the transition
Context.Source.Position -= split.Item2.Content.Length;
NextToken();
}
- else if (At(CSharpTokenType.Transition))
+ else if (At(SyntaxKind.Transition))
{
NextToken();
}
// Accept "@" if we see it, but if we don't, that's OK. We assume we were started for a good reason
- if (current.Type == CSharpTokenType.Transition)
+ if (current.Kind == SyntaxKind.Transition)
{
if (Span.Tokens.Count > 0)
{
@@ -251,9 +254,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
span.ChunkGenerator = new StatementChunkGenerator();
}
- private void AtTransition(CSharpToken current)
+ private void AtTransition(SyntaxToken current)
{
- Debug.Assert(current.Type == CSharpTokenType.Transition);
+ Debug.Assert(current.Kind == SyntaxKind.Transition);
Accept(current);
Span.EditHandler.AcceptedCharacters = AcceptedCharactersInternal.None;
Span.ChunkGenerator = SpanChunkGenerator.Null;
@@ -273,14 +276,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
// What type of block is this?
if (!EndOfFile)
{
- if (CurrentToken.Type == CSharpTokenType.LeftParenthesis)
+ if (CurrentToken.Kind == SyntaxKind.LeftParenthesis)
{
Context.Builder.CurrentBlock.Type = BlockKindInternal.Expression;
Context.Builder.CurrentBlock.ChunkGenerator = new ExpressionChunkGenerator();
ExplicitExpression();
return;
}
- else if (CurrentToken.Type == CSharpTokenType.Identifier)
+ else if (CurrentToken.Kind == SyntaxKind.Identifier)
{
if (TryGetDirectiveHandler(CurrentToken.Content, out var handler))
{
@@ -306,7 +309,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return;
}
}
- else if (CurrentToken.Type == CSharpTokenType.Keyword)
+ else if (CurrentToken.Kind == SyntaxKind.Keyword)
{
if (TryGetDirectiveHandler(CurrentToken.Content, out var handler))
{
@@ -320,7 +323,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return;
}
}
- else if (CurrentToken.Type == CSharpTokenType.LeftBrace)
+ else if (CurrentToken.Kind == SyntaxKind.LeftBrace)
{
VerbatimBlock();
return;
@@ -337,9 +340,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
CurrentKeywords,
acceptTrailingDot: IsNested)
{
- AcceptedCharacters = AcceptedCharactersInternal.NonWhiteSpace
+ AcceptedCharacters = AcceptedCharactersInternal.NonWhitespace
};
- if (At(CSharpTokenType.WhiteSpace) || At(CSharpTokenType.NewLine))
+ if (At(SyntaxKind.Whitespace) || At(SyntaxKind.NewLine))
{
Context.ErrorSink.OnError(
RazorDiagnosticFactory.CreateParsing_UnexpectedWhiteSpaceAtStartOfCodeBlock(
@@ -369,7 +372,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private void VerbatimBlock()
{
- Assert(CSharpTokenType.LeftBrace);
+ Assert(SyntaxKind.LeftBrace);
var block = new Block(Resources.BlockName_Code, CurrentStart);
AcceptAndMoveNext();
@@ -385,13 +388,13 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
Span.ChunkGenerator = new StatementChunkGenerator();
AddMarkerTokenIfNecessary();
- if (!At(CSharpTokenType.RightBrace))
+ if (!At(SyntaxKind.RightBrace))
{
editHandler.AutoCompleteString = "}";
}
Output(SpanKindInternal.Code);
- if (Optional(CSharpTokenType.RightBrace))
+ if (Optional(SyntaxKind.RightBrace))
{
// Set up the "}" span
Span.EditHandler.AcceptedCharacters = AcceptedCharactersInternal.None;
@@ -401,8 +404,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
if (!IsNested)
{
EnsureCurrent();
- if (At(CSharpTokenType.NewLine) ||
- (At(CSharpTokenType.WhiteSpace) && NextIs(CSharpTokenType.NewLine)))
+ if (At(SyntaxKind.NewLine) ||
+ (At(SyntaxKind.Whitespace) && NextIs(SyntaxKind.NewLine)))
{
Context.NullGenerateWhitespaceAndNewLine = true;
}
@@ -413,7 +416,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private void ImplicitExpression()
{
- ImplicitExpression(AcceptedCharactersInternal.NonWhiteSpace);
+ ImplicitExpression(AcceptedCharactersInternal.NonWhitespace);
}
// Async implicit expressions include the "await" keyword and therefore need to allow spaces to
@@ -456,13 +459,13 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
if (!EndOfFile)
{
- if (CurrentToken.Type == CSharpTokenType.LeftParenthesis ||
- CurrentToken.Type == CSharpTokenType.LeftBracket)
+ if (CurrentToken.Kind == SyntaxKind.LeftParenthesis ||
+ CurrentToken.Kind == SyntaxKind.LeftBracket)
{
// If we end within "(", whitespace is fine
Span.EditHandler.AcceptedCharacters = AcceptedCharactersInternal.Any;
- CSharpTokenType right;
+ SyntaxKind right;
bool success;
using (PushSpanConfig((span, prev) =>
@@ -471,13 +474,13 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
span.EditHandler.AcceptedCharacters = AcceptedCharactersInternal.Any;
}))
{
- right = Language.FlipBracket(CurrentToken.Type);
+ right = Language.FlipBracket(CurrentToken.Kind);
success = Balance(BalancingModes.BacktrackOnFailure | BalancingModes.AllowCommentsAndTemplates);
}
if (!success)
{
- AcceptUntil(CSharpTokenType.LessThan);
+ AcceptUntil(SyntaxKind.LessThan);
}
if (At(right))
{
@@ -488,22 +491,22 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
}
return MethodCallOrArrayIndex(acceptedCharacters);
}
- if (At(CSharpTokenType.QuestionMark))
+ if (At(SyntaxKind.QuestionMark))
{
var next = Lookahead(count: 1);
if (next != null)
{
- if (next.Type == CSharpTokenType.Dot)
+ if (next.Kind == SyntaxKind.Dot)
{
// Accept null conditional dot operator (?.).
AcceptAndMoveNext();
AcceptAndMoveNext();
// If the next piece after the ?. is a keyword or identifier then we want to continue.
- return At(CSharpTokenType.Identifier) || At(CSharpTokenType.Keyword);
+ return At(SyntaxKind.Identifier) || At(SyntaxKind.Keyword);
}
- else if (next.Type == CSharpTokenType.LeftBracket)
+ else if (next.Kind == SyntaxKind.LeftBracket)
{
// We're at the ? for a null conditional bracket operator (?[).
AcceptAndMoveNext();
@@ -513,12 +516,12 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
}
}
}
- else if (At(CSharpTokenType.Dot))
+ else if (At(SyntaxKind.Dot))
{
var dot = CurrentToken;
if (NextToken())
{
- if (At(CSharpTokenType.Identifier) || At(CSharpTokenType.Keyword))
+ if (At(SyntaxKind.Identifier) || At(SyntaxKind.Keyword))
{
// Accept the dot and return to the start
Accept(dot);
@@ -540,7 +543,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
Accept(dot);
}
}
- else if (!At(CSharpTokenType.WhiteSpace) && !At(CSharpTokenType.NewLine))
+ else if (!At(SyntaxKind.Whitespace) && !At(SyntaxKind.NewLine))
{
PutCurrentBack();
}
@@ -587,8 +590,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private void CaptureWhitespaceAtEndOfCodeOnlyLine()
{
- var whitespace = ReadWhile(token => token.Type == CSharpTokenType.WhiteSpace);
- if (At(CSharpTokenType.NewLine))
+ var whitespace = ReadWhile(token => token.Kind == SyntaxKind.Whitespace);
+ if (At(SyntaxKind.NewLine))
{
Accept(whitespace);
AcceptAndMoveNext();
@@ -610,7 +613,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private void ExplicitExpression()
{
var block = new Block(Resources.BlockName_ExplicitExpression, CurrentStart);
- Assert(CSharpTokenType.LeftParenthesis);
+ Assert(SyntaxKind.LeftParenthesis);
AcceptAndMoveNext();
Span.EditHandler.AcceptedCharacters = AcceptedCharactersInternal.None;
Span.ChunkGenerator = SpanChunkGenerator.Null;
@@ -621,13 +624,13 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
BalancingModes.BacktrackOnFailure |
BalancingModes.NoErrorOnFailure |
BalancingModes.AllowCommentsAndTemplates,
- CSharpTokenType.LeftParenthesis,
- CSharpTokenType.RightParenthesis,
+ SyntaxKind.LeftParenthesis,
+ SyntaxKind.RightParenthesis,
block.Start);
if (!success)
{
- AcceptUntil(CSharpTokenType.LessThan);
+ AcceptUntil(SyntaxKind.LessThan);
Context.ErrorSink.OnError(
RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
new SourceSpan(block.Start, contentLength: 1 /* ( */), block.Name, ")", "("));
@@ -636,13 +639,13 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
// If necessary, put an empty-content marker token here
if (Span.Tokens.Count == 0)
{
- Accept(new CSharpToken(string.Empty, CSharpTokenType.Unknown));
+ Accept(SyntaxFactory.Token(SyntaxKind.Unknown, string.Empty));
}
// Output the content span and then capture the ")"
Output(SpanKindInternal.Code);
}
- Optional(CSharpTokenType.RightParenthesis);
+ Optional(SyntaxKind.RightParenthesis);
if (!EndOfFile)
{
PutCurrentBack();
@@ -702,7 +705,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
// No embedded transitions in C#, so ignore that param
return allowTemplatesAndComments
&& ((Language.IsTransition(CurrentToken)
- && NextIs(CSharpTokenType.LessThan, CSharpTokenType.Colon, CSharpTokenType.DoubleColon))
+ && NextIs(SyntaxKind.LessThan, SyntaxKind.Colon, SyntaxKind.DoubleColon))
|| Language.IsCommentStart(CurrentToken));
}
@@ -783,12 +786,13 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private void CaseStatement(bool topLevel)
{
- Assert(CSharpTokenType.Keyword);
- Debug.Assert(CurrentToken.Keyword != null &&
- (CurrentToken.Keyword.Value == CSharpKeyword.Case ||
- CurrentToken.Keyword.Value == CSharpKeyword.Default));
- AcceptUntil(CSharpTokenType.Colon);
- Optional(CSharpTokenType.Colon);
+ Assert(SyntaxKind.Keyword);
+ var result = CSharpTokenizer.GetTokenKeyword(CurrentToken);
+ Debug.Assert(result.HasValue &&
+ (result.Value == CSharpKeyword.Case ||
+ result.Value == CSharpKeyword.Default));
+ AcceptUntil(SyntaxKind.Colon);
+ Optional(SyntaxKind.Colon);
}
private void DoStatement(bool topLevel)
@@ -813,7 +817,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
Assert(CSharpKeyword.While);
AcceptAndMoveNext();
AcceptWhile(IsSpacingToken(includeNewLines: true, includeComments: true));
- if (AcceptCondition() && Optional(CSharpTokenType.Semicolon))
+ if (AcceptCondition() && Optional(SyntaxKind.Semicolon))
{
Span.EditHandler.AcceptedCharacters = AcceptedCharactersInternal.None;
}
@@ -832,12 +836,12 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
AcceptAndMoveNext();
AcceptWhile(IsSpacingToken(includeNewLines: false, includeComments: true));
- if (At(CSharpTokenType.LeftParenthesis))
+ if (At(SyntaxKind.LeftParenthesis))
{
// using ( ==> Using Statement
UsingStatement(block);
}
- else if (At(CSharpTokenType.Identifier) || At(CSharpKeyword.Static))
+ else if (At(SyntaxKind.Identifier) || At(CSharpKeyword.Static))
{
// using Identifier ==> Using Declaration
if (!topLevel)
@@ -865,16 +869,16 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
Context.Builder.CurrentBlock.Type = BlockKindInternal.Directive;
var start = CurrentStart;
- if (At(CSharpTokenType.Identifier))
+ if (At(SyntaxKind.Identifier))
{
// non-static using
NamespaceOrTypeName();
var whitespace = ReadWhile(IsSpacingToken(includeNewLines: true, includeComments: true));
- if (At(CSharpTokenType.Assign))
+ if (At(SyntaxKind.Assign))
{
// Alias
Accept(whitespace);
- Assert(CSharpTokenType.Assign);
+ Assert(SyntaxKind.Assign);
AcceptAndMoveNext();
AcceptWhile(IsSpacingToken(includeNewLines: true, includeComments: true));
@@ -904,7 +908,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
// Optional ";"
if (EnsureCurrent())
{
- Optional(CSharpTokenType.Semicolon);
+ Optional(SyntaxKind.Semicolon);
}
}
@@ -919,16 +923,16 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
var expectingDot = false;
var tokens = ReadWhile(token =>
{
- var type = token.Type;
- if ((expectingDot && type == CSharpTokenType.Dot) ||
- (!expectingDot && type == CSharpTokenType.Identifier))
+ var type = token.Kind;
+ if ((expectingDot && type == SyntaxKind.Dot) ||
+ (!expectingDot && type == SyntaxKind.Identifier))
{
expectingDot = !expectingDot;
return true;
}
- if (type != CSharpTokenType.WhiteSpace &&
- type != CSharpTokenType.NewLine)
+ if (type != SyntaxKind.Whitespace &&
+ type != SyntaxKind.NewLine)
{
expectingDot = false;
currentIdentifierLength += token.Content.Length;
@@ -966,69 +970,69 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
protected bool NamespaceOrTypeName()
{
- if (Optional(CSharpTokenType.LeftParenthesis))
+ if (Optional(SyntaxKind.LeftParenthesis))
{
- while (!Optional(CSharpTokenType.RightParenthesis) && !EndOfFile)
+ while (!Optional(SyntaxKind.RightParenthesis) && !EndOfFile)
{
- Optional(CSharpTokenType.WhiteSpace);
+ Optional(SyntaxKind.Whitespace);
if (!NamespaceOrTypeName())
{
return false;
}
- Optional(CSharpTokenType.WhiteSpace);
- Optional(CSharpTokenType.Identifier);
- Optional(CSharpTokenType.WhiteSpace);
- Optional(CSharpTokenType.Comma);
+ Optional(SyntaxKind.Whitespace);
+ Optional(SyntaxKind.Identifier);
+ Optional(SyntaxKind.Whitespace);
+ Optional(SyntaxKind.Comma);
}
- if (At(CSharpTokenType.WhiteSpace) && NextIs(CSharpTokenType.QuestionMark))
+ if (At(SyntaxKind.Whitespace) && NextIs(SyntaxKind.QuestionMark))
{
// Only accept the whitespace if we are going to consume the next token.
AcceptAndMoveNext();
}
- Optional(CSharpTokenType.QuestionMark); // Nullable
+ Optional(SyntaxKind.QuestionMark); // Nullable
return true;
}
- else if (Optional(CSharpTokenType.Identifier) || Optional(CSharpTokenType.Keyword))
+ else if (Optional(SyntaxKind.Identifier) || Optional(SyntaxKind.Keyword))
{
- if (Optional(CSharpTokenType.DoubleColon))
+ if (Optional(SyntaxKind.DoubleColon))
{
- if (!Optional(CSharpTokenType.Identifier))
+ if (!Optional(SyntaxKind.Identifier))
{
- Optional(CSharpTokenType.Keyword);
+ Optional(SyntaxKind.Keyword);
}
}
- if (At(CSharpTokenType.LessThan))
+ if (At(SyntaxKind.LessThan))
{
TypeArgumentList();
}
- if (Optional(CSharpTokenType.Dot))
+ if (Optional(SyntaxKind.Dot))
{
NamespaceOrTypeName();
}
- if (At(CSharpTokenType.WhiteSpace) && NextIs(CSharpTokenType.QuestionMark))
+ if (At(SyntaxKind.Whitespace) && NextIs(SyntaxKind.QuestionMark))
{
// Only accept the whitespace if we are going to consume the next token.
AcceptAndMoveNext();
}
- Optional(CSharpTokenType.QuestionMark); // Nullable
+ Optional(SyntaxKind.QuestionMark); // Nullable
- if (At(CSharpTokenType.WhiteSpace) && NextIs(CSharpTokenType.LeftBracket))
+ if (At(SyntaxKind.Whitespace) && NextIs(SyntaxKind.LeftBracket))
{
// Only accept the whitespace if we are going to consume the next token.
AcceptAndMoveNext();
}
- while (At(CSharpTokenType.LeftBracket))
+ while (At(SyntaxKind.LeftBracket))
{
Balance(BalancingModes.None);
- Optional(CSharpTokenType.RightBracket);
+ Optional(SyntaxKind.RightBracket);
}
return true;
}
@@ -1040,14 +1044,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private void TypeArgumentList()
{
- Assert(CSharpTokenType.LessThan);
+ Assert(SyntaxKind.LessThan);
Balance(BalancingModes.None);
- Optional(CSharpTokenType.GreaterThan);
+ Optional(SyntaxKind.GreaterThan);
}
private void UsingStatement(Block block)
{
- Assert(CSharpTokenType.LeftParenthesis);
+ Assert(SyntaxKind.LeftParenthesis);
// Parse condition
if (AcceptCondition())
@@ -1159,12 +1163,12 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
if (!EndOfFile)
{
// Check for "{" to make sure we're at a block
- if (!At(CSharpTokenType.LeftBrace))
+ if (!At(SyntaxKind.LeftBrace))
{
Context.ErrorSink.OnError(
RazorDiagnosticFactory.CreateParsing_SingleLineControlFlowStatementsNotAllowed(
new SourceSpan(CurrentStart, CurrentToken.Content.Length),
- Language.GetSample(CSharpTokenType.LeftBrace),
+ Language.GetSample(SyntaxKind.LeftBrace),
CurrentToken.Content));
}
@@ -1175,7 +1179,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private void UnconditionalBlock()
{
- Assert(CSharpTokenType.Keyword);
+ Assert(SyntaxKind.Keyword);
var block = new Block(CurrentToken, CurrentStart);
AcceptAndMoveNext();
AcceptWhile(IsSpacingToken(includeNewLines: true, includeComments: true));
@@ -1219,7 +1223,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private void ConditionalBlock(bool topLevel)
{
- Assert(CSharpTokenType.Keyword);
+ Assert(SyntaxKind.Keyword);
var block = new Block(CurrentToken, CurrentStart);
ConditionalBlock(block);
if (topLevel)
@@ -1243,16 +1247,16 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private bool AcceptCondition()
{
- if (At(CSharpTokenType.LeftParenthesis))
+ if (At(SyntaxKind.LeftParenthesis))
{
var complete = Balance(BalancingModes.BacktrackOnFailure | BalancingModes.AllowCommentsAndTemplates);
if (!complete)
{
- AcceptUntil(CSharpTokenType.NewLine);
+ AcceptUntil(SyntaxKind.NewLine);
}
else
{
- Optional(CSharpTokenType.RightParenthesis);
+ Optional(SyntaxKind.RightParenthesis);
}
return complete;
}
@@ -1280,16 +1284,16 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return;
}
- var type = CurrentToken.Type;
+ var type = CurrentToken.Kind;
var loc = CurrentStart;
// Both cases @: and @:: are triggered as markup, second colon in second case will be triggered as a plain text
- var isSingleLineMarkup = type == CSharpTokenType.Transition &&
- (NextIs(CSharpTokenType.Colon, CSharpTokenType.DoubleColon));
+ var isSingleLineMarkup = type == SyntaxKind.Transition &&
+ (NextIs(SyntaxKind.Colon, SyntaxKind.DoubleColon));
var isMarkup = isSingleLineMarkup ||
- type == CSharpTokenType.LessThan ||
- (type == CSharpTokenType.Transition && NextIs(CSharpTokenType.LessThan));
+ type == SyntaxKind.LessThan ||
+ (type == SyntaxKind.Transition && NextIs(SyntaxKind.LessThan));
if (Context.DesignTimeMode || !isMarkup)
{
@@ -1321,7 +1325,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
if (isMarkup)
{
- if (type == CSharpTokenType.Transition && !isSingleLineMarkup)
+ if (type == SyntaxKind.Transition && !isSingleLineMarkup)
{
Context.ErrorSink.OnError(
RazorDiagnosticFactory.CreateParsing_AtInCodeMustBeFollowedByColonParenOrIdentifierStart(
@@ -1331,7 +1335,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
// Markup block
Output(SpanKindInternal.Code);
if (Context.DesignTimeMode && CurrentToken != null &&
- (CurrentToken.Type == CSharpTokenType.LessThan || CurrentToken.Type == CSharpTokenType.Transition))
+ (CurrentToken.Kind == SyntaxKind.LessThan || CurrentToken.Kind == SyntaxKind.Transition))
{
PutCurrentBack();
}
@@ -1344,33 +1348,33 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
}
}
- private void HandleStatement(Block block, CSharpTokenType type)
+ private void HandleStatement(Block block, SyntaxKind type)
{
switch (type)
{
- case CSharpTokenType.RazorCommentTransition:
+ case SyntaxKind.RazorCommentTransition:
Output(SpanKindInternal.Code);
RazorComment();
Statement(block);
break;
- case CSharpTokenType.LeftBrace:
+ case SyntaxKind.LeftBrace:
// Verbatim Block
block = block ?? new Block(Resources.BlockName_Code, CurrentStart);
AcceptAndMoveNext();
CodeBlock(block);
break;
- case CSharpTokenType.Keyword:
+ case SyntaxKind.Keyword:
// Keyword block
HandleKeyword(false, StandardStatement);
break;
- case CSharpTokenType.Transition:
+ case SyntaxKind.Transition:
// Embedded Expression block
EmbeddedExpression();
break;
- case CSharpTokenType.RightBrace:
+ case SyntaxKind.RightBrace:
// Possible end of Code Block, just run the continuation
break;
- case CSharpTokenType.Comment:
+ case SyntaxKind.CSharpComment:
AcceptAndMoveNext();
break;
default:
@@ -1383,11 +1387,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private void EmbeddedExpression()
{
// First, verify the type of the block
- Assert(CSharpTokenType.Transition);
+ Assert(SyntaxKind.Transition);
var transition = CurrentToken;
NextToken();
- if (At(CSharpTokenType.Transition))
+ if (At(SyntaxKind.Transition))
{
// Escaped "@"
Output(SpanKindInternal.Code);
@@ -1397,14 +1401,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
Span.ChunkGenerator = SpanChunkGenerator.Null;
Output(SpanKindInternal.Code);
- Assert(CSharpTokenType.Transition);
+ Assert(SyntaxKind.Transition);
AcceptAndMoveNext();
StandardStatement();
}
else
{
// Throw errors as necessary, but continue parsing
- if (At(CSharpTokenType.LeftBrace))
+ if (At(SyntaxKind.LeftBrace))
{
Context.ErrorSink.OnError(
RazorDiagnosticFactory.CreateParsing_UnexpectedNestedCodeBlock(
@@ -1428,48 +1432,48 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
var bookmark = CurrentStart.AbsoluteIndex;
var read = ReadWhile(token =>
- token.Type != CSharpTokenType.Semicolon &&
- token.Type != CSharpTokenType.RazorCommentTransition &&
- token.Type != CSharpTokenType.Transition &&
- token.Type != CSharpTokenType.LeftBrace &&
- token.Type != CSharpTokenType.LeftParenthesis &&
- token.Type != CSharpTokenType.LeftBracket &&
- token.Type != CSharpTokenType.RightBrace);
+ token.Kind != SyntaxKind.Semicolon &&
+ token.Kind != SyntaxKind.RazorCommentTransition &&
+ token.Kind != SyntaxKind.Transition &&
+ token.Kind != SyntaxKind.LeftBrace &&
+ token.Kind != SyntaxKind.LeftParenthesis &&
+ token.Kind != SyntaxKind.LeftBracket &&
+ token.Kind != SyntaxKind.RightBrace);
- if (At(CSharpTokenType.LeftBrace) ||
- At(CSharpTokenType.LeftParenthesis) ||
- At(CSharpTokenType.LeftBracket))
+ if (At(SyntaxKind.LeftBrace) ||
+ At(SyntaxKind.LeftParenthesis) ||
+ At(SyntaxKind.LeftBracket))
{
Accept(read);
if (Balance(BalancingModes.AllowCommentsAndTemplates | BalancingModes.BacktrackOnFailure))
{
- Optional(CSharpTokenType.RightBrace);
+ Optional(SyntaxKind.RightBrace);
}
else
{
// Recovery
- AcceptUntil(CSharpTokenType.LessThan, CSharpTokenType.RightBrace);
+ AcceptUntil(SyntaxKind.LessThan, SyntaxKind.RightBrace);
return;
}
}
- else if (At(CSharpTokenType.Transition) && (NextIs(CSharpTokenType.LessThan, CSharpTokenType.Colon)))
+ else if (At(SyntaxKind.Transition) && (NextIs(SyntaxKind.LessThan, SyntaxKind.Colon)))
{
Accept(read);
Output(SpanKindInternal.Code);
Template();
}
- else if (At(CSharpTokenType.RazorCommentTransition))
+ else if (At(SyntaxKind.RazorCommentTransition))
{
Accept(read);
RazorComment();
}
- else if (At(CSharpTokenType.Semicolon))
+ else if (At(SyntaxKind.Semicolon))
{
Accept(read);
AcceptAndMoveNext();
return;
}
- else if (At(CSharpTokenType.RightBrace))
+ else if (At(SyntaxKind.RightBrace))
{
Accept(read);
return;
@@ -1478,7 +1482,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
Context.Source.Position = bookmark;
NextToken();
- AcceptUntil(CSharpTokenType.LessThan, CSharpTokenType.LeftBrace, CSharpTokenType.RightBrace);
+ AcceptUntil(SyntaxKind.LessThan, SyntaxKind.LeftBrace, SyntaxKind.RightBrace);
return;
}
}
@@ -1492,7 +1496,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private void CodeBlock(bool acceptTerminatingBrace, Block block)
{
EnsureCurrent();
- while (!EndOfFile && !At(CSharpTokenType.RightBrace))
+ while (!EndOfFile && !At(SyntaxKind.RightBrace))
{
// Parse a statement, then return here
Statement();
@@ -1507,7 +1511,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
}
else if (acceptTerminatingBrace)
{
- Assert(CSharpTokenType.RightBrace);
+ Assert(SyntaxKind.RightBrace);
Span.EditHandler.AcceptedCharacters = AcceptedCharactersInternal.None;
AcceptAndMoveNext();
}
@@ -1515,8 +1519,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private void HandleKeyword(bool topLevel, Action fallback)
{
- Debug.Assert(CurrentToken.Type == CSharpTokenType.Keyword && CurrentToken.Keyword != null);
- if (_keywordParsers.TryGetValue(CurrentToken.Keyword.Value, out var handler))
+ var result = CSharpTokenizer.GetTokenKeyword(CurrentToken);
+ Debug.Assert(CurrentToken.Kind == SyntaxKind.Keyword && result.HasValue);
+ if (_keywordParsers.TryGetValue(result.Value, out var handler))
{
handler(topLevel);
}
@@ -1526,12 +1531,12 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
}
}
- private IEnumerable SkipToNextImportantToken()
+ private IEnumerable SkipToNextImportantToken()
{
while (!EndOfFile)
{
var whitespace = ReadWhile(IsSpacingToken(includeNewLines: true, includeComments: true));
- if (At(CSharpTokenType.RazorCommentTransition))
+ if (At(SyntaxKind.RazorCommentTransition))
{
Accept(whitespace);
Span.EditHandler.AcceptedCharacters = AcceptedCharactersInternal.Any;
@@ -1542,7 +1547,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return whitespace;
}
}
- return Enumerable.Empty();
+ return Enumerable.Empty();
}
// Common code for Parsers, but FxCop REALLY doesn't like it in the base class.. moving it here for now.
@@ -1644,8 +1649,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
for (var i = 0; i < descriptor.Tokens.Count; i++)
{
- if (!At(CSharpTokenType.WhiteSpace) &&
- !At(CSharpTokenType.NewLine) &&
+ if (!At(SyntaxKind.Whitespace) &&
+ !At(SyntaxKind.NewLine) &&
!EndOfFile)
{
Context.ErrorSink.OnError(
@@ -1662,24 +1667,24 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
tokenDescriptor.Kind == DirectiveTokenKind.Type)
{
Span.ChunkGenerator = SpanChunkGenerator.Null;
- Output(SpanKindInternal.Code, AcceptedCharactersInternal.WhiteSpace);
+ Output(SpanKindInternal.Code, AcceptedCharactersInternal.Whitespace);
- if (EndOfFile || At(CSharpTokenType.NewLine))
+ if (EndOfFile || At(SyntaxKind.NewLine))
{
// Add a marker token to provide CSharp intellisense when we start typing the directive token.
AddMarkerTokenIfNecessary();
Span.ChunkGenerator = new DirectiveTokenChunkGenerator(tokenDescriptor);
Span.EditHandler = new DirectiveTokenEditHandler(Language.TokenizeString);
- Output(SpanKindInternal.Code, AcceptedCharactersInternal.NonWhiteSpace);
+ Output(SpanKindInternal.Code, AcceptedCharactersInternal.NonWhitespace);
}
}
else
{
Span.ChunkGenerator = SpanChunkGenerator.Null;
- Output(SpanKindInternal.Markup, AcceptedCharactersInternal.WhiteSpace);
+ Output(SpanKindInternal.Markup, AcceptedCharactersInternal.Whitespace);
}
- if (tokenDescriptor.Optional && (EndOfFile || At(CSharpTokenType.NewLine)))
+ if (tokenDescriptor.Optional && (EndOfFile || At(SyntaxKind.NewLine)))
{
break;
}
@@ -1718,7 +1723,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
break;
case DirectiveTokenKind.Member:
- if (At(CSharpTokenType.Identifier))
+ if (At(SyntaxKind.Identifier))
{
AcceptAndMoveNext();
}
@@ -1732,7 +1737,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
break;
case DirectiveTokenKind.String:
- if (At(CSharpTokenType.StringLiteral) && CurrentToken.Errors.Count == 0)
+ if (At(SyntaxKind.StringLiteral) && !CurrentToken.ContainsDiagnostics)
{
AcceptAndMoveNext();
}
@@ -1748,7 +1753,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
Span.ChunkGenerator = new DirectiveTokenChunkGenerator(tokenDescriptor);
Span.EditHandler = new DirectiveTokenEditHandler(Language.TokenizeString);
- Output(SpanKindInternal.Code, AcceptedCharactersInternal.NonWhiteSpace);
+ Output(SpanKindInternal.Code, AcceptedCharactersInternal.NonWhitespace);
}
AcceptWhile(IsSpacingToken(includeNewLines: false, includeComments: true));
@@ -1757,15 +1762,15 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
switch (descriptor.Kind)
{
case DirectiveKind.SingleLine:
- Output(SpanKindInternal.None, AcceptedCharactersInternal.WhiteSpace);
+ Output(SpanKindInternal.None, AcceptedCharactersInternal.Whitespace);
- Optional(CSharpTokenType.Semicolon);
+ Optional(SyntaxKind.Semicolon);
Span.ChunkGenerator = SpanChunkGenerator.Null;
- Output(SpanKindInternal.MetaCode, AcceptedCharactersInternal.WhiteSpace);
+ Output(SpanKindInternal.MetaCode, AcceptedCharactersInternal.Whitespace);
AcceptWhile(IsSpacingToken(includeNewLines: false, includeComments: true));
- if (At(CSharpTokenType.NewLine))
+ if (At(SyntaxKind.NewLine))
{
AcceptAndMoveNext();
}
@@ -1782,11 +1787,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
// This should contain the optional whitespace after the optional semicolon and the new line.
// Output as Markup as we want intellisense here.
- Output(SpanKindInternal.Markup, AcceptedCharactersInternal.WhiteSpace);
+ Output(SpanKindInternal.Markup, AcceptedCharactersInternal.Whitespace);
break;
case DirectiveKind.RazorBlock:
AcceptWhile(IsSpacingToken(includeNewLines: true, includeComments: true));
- Output(SpanKindInternal.Markup, AcceptedCharactersInternal.AllWhiteSpace);
+ Output(SpanKindInternal.Markup, AcceptedCharactersInternal.AllWhitespace);
ParseDirectiveBlock(descriptor, parseChildren: (startingBraceLocation) =>
{
@@ -1811,12 +1816,12 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
break;
case DirectiveKind.CodeBlock:
AcceptWhile(IsSpacingToken(includeNewLines: true, includeComments: true));
- Output(SpanKindInternal.Markup, AcceptedCharactersInternal.AllWhiteSpace);
+ Output(SpanKindInternal.Markup, AcceptedCharactersInternal.AllWhitespace);
ParseDirectiveBlock(descriptor, parseChildren: (startingBraceLocation) =>
{
NextToken();
- Balance(BalancingModes.NoErrorOnFailure, CSharpTokenType.LeftBrace, CSharpTokenType.RightBrace, startingBraceLocation);
+ Balance(BalancingModes.NoErrorOnFailure, SyntaxKind.LeftBrace, SyntaxKind.RightBrace, startingBraceLocation);
Span.ChunkGenerator = new StatementChunkGenerator();
var existingEditHandler = Span.EditHandler;
Span.EditHandler = new CodeBlockEditHandler(Language.TokenizeString);
@@ -1868,7 +1873,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
RazorDiagnosticFactory.CreateParsing_UnexpectedEOFAfterDirective(
new SourceSpan(CurrentStart, contentLength: 1 /* { */), descriptor.Directive, "{"));
}
- else if (!At(CSharpTokenType.LeftBrace))
+ else if (!At(SyntaxKind.LeftBrace))
{
Context.ErrorSink.OnError(
RazorDiagnosticFactory.CreateParsing_UnexpectedDirectiveLiteral(
@@ -1886,7 +1891,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
parseChildren(startingBraceLocation);
Span.ChunkGenerator = SpanChunkGenerator.Null;
- if (!Optional(CSharpTokenType.RightBrace))
+ if (!Optional(SyntaxKind.RightBrace))
{
editHandler.AutoCompleteString = "}";
Context.ErrorSink.OnError(
@@ -1982,7 +1987,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
// Ex: @addTagHelper "*, Microsoft.AspNetCore.CoolLibrary"
// ^ ^
// Start End
- if (Span.Tokens.Count == 1 && (Span.Tokens[0] as CSharpToken)?.Type == CSharpTokenType.StringLiteral)
+ if (Span.Tokens.Count == 1 && (Span.Tokens[0] as SyntaxToken)?.Kind == SyntaxKind.StringLiteral)
{
offset += Span.Tokens[0].Content.IndexOf(directiveText, StringComparison.Ordinal);
@@ -2081,7 +2086,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
[Conditional("DEBUG")]
protected void AssertDirective(string directive)
{
- Debug.Assert(CurrentToken.Type == CSharpTokenType.Identifier || CurrentToken.Type == CSharpTokenType.Keyword);
+ Debug.Assert(CurrentToken.Kind == SyntaxKind.Identifier || CurrentToken.Kind == SyntaxKind.Keyword);
Debug.Assert(string.Equals(CurrentToken.Content, directive, StringComparison.Ordinal));
}
@@ -2108,18 +2113,18 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
var keywordLength = Span.End.AbsoluteIndex - Span.Start.AbsoluteIndex;
- var foundWhitespace = At(CSharpTokenType.WhiteSpace);
+ var foundWhitespace = At(SyntaxKind.Whitespace);
// If we found whitespace then any content placed within the whitespace MAY cause a destructive change
// to the document. We can't accept it.
var acceptedCharacters = foundWhitespace ? AcceptedCharactersInternal.None : AcceptedCharactersInternal.AnyExceptNewline;
Output(SpanKindInternal.MetaCode, acceptedCharacters);
- AcceptWhile(CSharpTokenType.WhiteSpace);
+ AcceptWhile(SyntaxKind.Whitespace);
Span.ChunkGenerator = SpanChunkGenerator.Null;
Output(SpanKindInternal.Markup, acceptedCharacters);
- if (EndOfFile || At(CSharpTokenType.NewLine))
+ if (EndOfFile || At(SyntaxKind.NewLine))
{
Context.ErrorSink.OnError(
RazorDiagnosticFactory.CreateParsing_DirectiveMustHaveValue(
@@ -2134,7 +2139,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
// Parse to the end of the line. Essentially accepts anything until end of line, comments, invalid code
// etc.
- AcceptUntil(CSharpTokenType.NewLine);
+ AcceptUntil(SyntaxKind.NewLine);
// Pull out the value and remove whitespaces and optional quotes
var rawValue = string.Concat(Span.Tokens.Select(s => s.Content)).Trim();
@@ -2170,7 +2175,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
Start = start;
}
- public Block(CSharpToken token, SourceLocation start)
+ public Block(SyntaxToken token, SourceLocation start)
: this(GetName(token), start)
{
}
@@ -2178,11 +2183,12 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
public string Name { get; set; }
public SourceLocation Start { get; set; }
- private static string GetName(CSharpToken token)
+ private static string GetName(SyntaxToken token)
{
- if (token.Type == CSharpTokenType.Keyword)
+ var result = CSharpTokenizer.GetTokenKeyword(token);
+ if (result.HasValue && token.Kind == SyntaxKind.Keyword)
{
- return CSharpLanguageCharacteristics.GetKeyword(token.Keyword.Value);
+ return CSharpLanguageCharacteristics.GetKeyword(result.Value);
}
return token.Content;
}
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/CSharpLanguageCharacteristics.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/CSharpLanguageCharacteristics.cs
index 70d4bfeda1..e8144cbc0e 100644
--- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/CSharpLanguageCharacteristics.cs
+++ b/src/Microsoft.AspNetCore.Razor.Language/Legacy/CSharpLanguageCharacteristics.cs
@@ -3,64 +3,65 @@
using System.Collections.Generic;
using System.Diagnostics;
+using Microsoft.AspNetCore.Razor.Language.Syntax.InternalSyntax;
namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
- internal class CSharpLanguageCharacteristics : LanguageCharacteristics
+ internal class CSharpLanguageCharacteristics : LanguageCharacteristics
{
private static readonly CSharpLanguageCharacteristics _instance = new CSharpLanguageCharacteristics();
- private static Dictionary _tokenSamples = new Dictionary()
+ private static Dictionary _tokenSamples = new Dictionary()
{
- { CSharpTokenType.Arrow, "->" },
- { CSharpTokenType.Minus, "-" },
- { CSharpTokenType.Decrement, "--" },
- { CSharpTokenType.MinusAssign, "-=" },
- { CSharpTokenType.NotEqual, "!=" },
- { CSharpTokenType.Not, "!" },
- { CSharpTokenType.Modulo, "%" },
- { CSharpTokenType.ModuloAssign, "%=" },
- { CSharpTokenType.AndAssign, "&=" },
- { CSharpTokenType.And, "&" },
- { CSharpTokenType.DoubleAnd, "&&" },
- { CSharpTokenType.LeftParenthesis, "(" },
- { CSharpTokenType.RightParenthesis, ")" },
- { CSharpTokenType.Star, "*" },
- { CSharpTokenType.MultiplyAssign, "*=" },
- { CSharpTokenType.Comma, "," },
- { CSharpTokenType.Dot, "." },
- { CSharpTokenType.Slash, "/" },
- { CSharpTokenType.DivideAssign, "/=" },
- { CSharpTokenType.DoubleColon, "::" },
- { CSharpTokenType.Colon, ":" },
- { CSharpTokenType.Semicolon, ";" },
- { CSharpTokenType.QuestionMark, "?" },
- { CSharpTokenType.NullCoalesce, "??" },
- { CSharpTokenType.RightBracket, "]" },
- { CSharpTokenType.LeftBracket, "[" },
- { CSharpTokenType.XorAssign, "^=" },
- { CSharpTokenType.Xor, "^" },
- { CSharpTokenType.LeftBrace, "{" },
- { CSharpTokenType.OrAssign, "|=" },
- { CSharpTokenType.DoubleOr, "||" },
- { CSharpTokenType.Or, "|" },
- { CSharpTokenType.RightBrace, "}" },
- { CSharpTokenType.Tilde, "~" },
- { CSharpTokenType.Plus, "+" },
- { CSharpTokenType.PlusAssign, "+=" },
- { CSharpTokenType.Increment, "++" },
- { CSharpTokenType.LessThan, "<" },
- { CSharpTokenType.LessThanEqual, "<=" },
- { CSharpTokenType.LeftShift, "<<" },
- { CSharpTokenType.LeftShiftAssign, "<<=" },
- { CSharpTokenType.Assign, "=" },
- { CSharpTokenType.Equals, "==" },
- { CSharpTokenType.GreaterThan, ">" },
- { CSharpTokenType.GreaterThanEqual, ">=" },
- { CSharpTokenType.RightShift, ">>" },
- { CSharpTokenType.RightShiftAssign, ">>=" },
- { CSharpTokenType.Hash, "#" },
- { CSharpTokenType.Transition, "@" },
+ { SyntaxKind.Arrow, "->" },
+ { SyntaxKind.Minus, "-" },
+ { SyntaxKind.Decrement, "--" },
+ { SyntaxKind.MinusAssign, "-=" },
+ { SyntaxKind.NotEqual, "!=" },
+ { SyntaxKind.Not, "!" },
+ { SyntaxKind.Modulo, "%" },
+ { SyntaxKind.ModuloAssign, "%=" },
+ { SyntaxKind.AndAssign, "&=" },
+ { SyntaxKind.And, "&" },
+ { SyntaxKind.DoubleAnd, "&&" },
+ { SyntaxKind.LeftParenthesis, "(" },
+ { SyntaxKind.RightParenthesis, ")" },
+ { SyntaxKind.Star, "*" },
+ { SyntaxKind.MultiplyAssign, "*=" },
+ { SyntaxKind.Comma, "," },
+ { SyntaxKind.Dot, "." },
+ { SyntaxKind.Slash, "/" },
+ { SyntaxKind.DivideAssign, "/=" },
+ { SyntaxKind.DoubleColon, "::" },
+ { SyntaxKind.Colon, ":" },
+ { SyntaxKind.Semicolon, ";" },
+ { SyntaxKind.QuestionMark, "?" },
+ { SyntaxKind.NullCoalesce, "??" },
+ { SyntaxKind.RightBracket, "]" },
+ { SyntaxKind.LeftBracket, "[" },
+ { SyntaxKind.XorAssign, "^=" },
+ { SyntaxKind.Xor, "^" },
+ { SyntaxKind.LeftBrace, "{" },
+ { SyntaxKind.OrAssign, "|=" },
+ { SyntaxKind.DoubleOr, "||" },
+ { SyntaxKind.Or, "|" },
+ { SyntaxKind.RightBrace, "}" },
+ { SyntaxKind.Tilde, "~" },
+ { SyntaxKind.Plus, "+" },
+ { SyntaxKind.PlusAssign, "+=" },
+ { SyntaxKind.Increment, "++" },
+ { SyntaxKind.LessThan, "<" },
+ { SyntaxKind.LessThanEqual, "<=" },
+ { SyntaxKind.LeftShift, "<<" },
+ { SyntaxKind.LeftShiftAssign, "<<=" },
+ { SyntaxKind.Assign, "=" },
+ { SyntaxKind.Equals, "==" },
+ { SyntaxKind.GreaterThan, ">" },
+ { SyntaxKind.GreaterThanEqual, ">=" },
+ { SyntaxKind.RightShift, ">>" },
+ { SyntaxKind.RightShiftAssign, ">>=" },
+ { SyntaxKind.Hash, "#" },
+ { SyntaxKind.Transition, "@" },
};
protected CSharpLanguageCharacteristics()
@@ -74,35 +75,35 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return new CSharpTokenizer(source);
}
- protected override CSharpToken CreateToken(string content, CSharpTokenType type, IReadOnlyList errors)
+ protected override SyntaxToken CreateToken(string content, SyntaxKind kind, IReadOnlyList errors)
{
- return new CSharpToken(content, type, errors);
+ return SyntaxFactory.Token(kind, content, errors);
}
- public override string GetSample(CSharpTokenType type)
+ public override string GetSample(SyntaxKind kind)
{
string sample;
- if (!_tokenSamples.TryGetValue(type, out sample))
+ if (!_tokenSamples.TryGetValue(kind, out sample))
{
- switch (type)
+ switch (kind)
{
- case CSharpTokenType.Identifier:
+ case SyntaxKind.Identifier:
return Resources.CSharpToken_Identifier;
- case CSharpTokenType.Keyword:
+ case SyntaxKind.Keyword:
return Resources.CSharpToken_Keyword;
- case CSharpTokenType.IntegerLiteral:
+ case SyntaxKind.IntegerLiteral:
return Resources.CSharpToken_IntegerLiteral;
- case CSharpTokenType.NewLine:
+ case SyntaxKind.NewLine:
return Resources.CSharpToken_Newline;
- case CSharpTokenType.WhiteSpace:
+ case SyntaxKind.Whitespace:
return Resources.CSharpToken_Whitespace;
- case CSharpTokenType.Comment:
+ case SyntaxKind.CSharpComment:
return Resources.CSharpToken_Comment;
- case CSharpTokenType.RealLiteral:
+ case SyntaxKind.RealLiteral:
return Resources.CSharpToken_RealLiteral;
- case CSharpTokenType.CharacterLiteral:
+ case SyntaxKind.CharacterLiteral:
return Resources.CSharpToken_CharacterLiteral;
- case CSharpTokenType.StringLiteral:
+ case SyntaxKind.StringLiteral:
return Resources.CSharpToken_StringLiteral;
default:
return Resources.Token_Unknown;
@@ -111,59 +112,59 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return sample;
}
- public override CSharpToken CreateMarkerToken()
+ public override SyntaxToken CreateMarkerToken()
{
- return new CSharpToken(string.Empty, CSharpTokenType.Unknown);
+ return SyntaxFactory.Token(SyntaxKind.Unknown, string.Empty);
}
- public override CSharpTokenType GetKnownTokenType(KnownTokenType type)
+ public override SyntaxKind GetKnownTokenType(KnownTokenType type)
{
switch (type)
{
case KnownTokenType.Identifier:
- return CSharpTokenType.Identifier;
+ return SyntaxKind.Identifier;
case KnownTokenType.Keyword:
- return CSharpTokenType.Keyword;
+ return SyntaxKind.Keyword;
case KnownTokenType.NewLine:
- return CSharpTokenType.NewLine;
+ return SyntaxKind.NewLine;
case KnownTokenType.WhiteSpace:
- return CSharpTokenType.WhiteSpace;
+ return SyntaxKind.Whitespace;
case KnownTokenType.Transition:
- return CSharpTokenType.Transition;
+ return SyntaxKind.Transition;
case KnownTokenType.CommentStart:
- return CSharpTokenType.RazorCommentTransition;
+ return SyntaxKind.RazorCommentTransition;
case KnownTokenType.CommentStar:
- return CSharpTokenType.RazorCommentStar;
+ return SyntaxKind.RazorCommentStar;
case KnownTokenType.CommentBody:
- return CSharpTokenType.RazorComment;
+ return SyntaxKind.RazorCommentLiteral;
default:
- return CSharpTokenType.Unknown;
+ return SyntaxKind.Unknown;
}
}
- public override CSharpTokenType FlipBracket(CSharpTokenType bracket)
+ public override SyntaxKind FlipBracket(SyntaxKind bracket)
{
switch (bracket)
{
- case CSharpTokenType.LeftBrace:
- return CSharpTokenType.RightBrace;
- case CSharpTokenType.LeftBracket:
- return CSharpTokenType.RightBracket;
- case CSharpTokenType.LeftParenthesis:
- return CSharpTokenType.RightParenthesis;
- case CSharpTokenType.LessThan:
- return CSharpTokenType.GreaterThan;
- case CSharpTokenType.RightBrace:
- return CSharpTokenType.LeftBrace;
- case CSharpTokenType.RightBracket:
- return CSharpTokenType.LeftBracket;
- case CSharpTokenType.RightParenthesis:
- return CSharpTokenType.LeftParenthesis;
- case CSharpTokenType.GreaterThan:
- return CSharpTokenType.LessThan;
+ case SyntaxKind.LeftBrace:
+ return SyntaxKind.RightBrace;
+ case SyntaxKind.LeftBracket:
+ return SyntaxKind.RightBracket;
+ case SyntaxKind.LeftParenthesis:
+ return SyntaxKind.RightParenthesis;
+ case SyntaxKind.LessThan:
+ return SyntaxKind.GreaterThan;
+ case SyntaxKind.RightBrace:
+ return SyntaxKind.LeftBrace;
+ case SyntaxKind.RightBracket:
+ return SyntaxKind.LeftBracket;
+ case SyntaxKind.RightParenthesis:
+ return SyntaxKind.LeftParenthesis;
+ case SyntaxKind.GreaterThan:
+ return SyntaxKind.LessThan;
default:
Debug.Fail("FlipBracket must be called with a bracket character");
- return CSharpTokenType.Unknown;
+ return SyntaxKind.Unknown;
}
}
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/CSharpToken.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/CSharpToken.cs
deleted file mode 100644
index c928f0880e..0000000000
--- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/CSharpToken.cs
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System;
-using System.Collections.Generic;
-
-namespace Microsoft.AspNetCore.Razor.Language.Legacy
-{
- internal class CSharpToken : TokenBase
- {
- public CSharpToken(
- string content,
- CSharpTokenType type)
- : base(content, type, RazorDiagnostic.EmptyArray)
- {
- if (content == null)
- {
- throw new ArgumentNullException(nameof(content));
- }
- }
-
- public CSharpToken(
- string content,
- CSharpTokenType type,
- IReadOnlyList errors)
- : base(content, type, errors)
- {
- if (content == null)
- {
- throw new ArgumentNullException(nameof(content));
- }
- }
-
- public CSharpKeyword? Keyword { get; set; }
-
- public override bool Equals(object obj)
- {
- var other = obj as CSharpToken;
- return base.Equals(other) &&
- other.Keyword == Keyword;
- }
-
- public override int GetHashCode()
- {
- // Hash code should include only immutable properties.
- return base.GetHashCode();
- }
- }
-}
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/CSharpTokenizer.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/CSharpTokenizer.cs
index f819e98a3a..8d29ab0fea 100644
--- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/CSharpTokenizer.cs
+++ b/src/Microsoft.AspNetCore.Razor.Language/Legacy/CSharpTokenizer.cs
@@ -5,12 +5,13 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
+using Microsoft.AspNetCore.Razor.Language.Syntax.InternalSyntax;
namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
- internal class CSharpTokenizer : Tokenizer
+ internal class CSharpTokenizer : Tokenizer
{
- private Dictionary> _operatorHandlers;
+ private Dictionary> _operatorHandlers;
private static readonly Dictionary _keywords = new Dictionary(StringComparer.Ordinal)
{
@@ -100,31 +101,31 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
base.CurrentState = StartState;
- _operatorHandlers = new Dictionary>()
+ _operatorHandlers = new Dictionary>()
{
{ '-', MinusOperator },
{ '<', LessThanOperator },
{ '>', GreaterThanOperator },
- { '&', CreateTwoCharOperatorHandler(CSharpTokenType.And, '=', CSharpTokenType.AndAssign, '&', CSharpTokenType.DoubleAnd) },
- { '|', CreateTwoCharOperatorHandler(CSharpTokenType.Or, '=', CSharpTokenType.OrAssign, '|', CSharpTokenType.DoubleOr) },
- { '+', CreateTwoCharOperatorHandler(CSharpTokenType.Plus, '=', CSharpTokenType.PlusAssign, '+', CSharpTokenType.Increment) },
- { '=', CreateTwoCharOperatorHandler(CSharpTokenType.Assign, '=', CSharpTokenType.Equals, '>', CSharpTokenType.GreaterThanEqual) },
- { '!', CreateTwoCharOperatorHandler(CSharpTokenType.Not, '=', CSharpTokenType.NotEqual) },
- { '%', CreateTwoCharOperatorHandler(CSharpTokenType.Modulo, '=', CSharpTokenType.ModuloAssign) },
- { '*', CreateTwoCharOperatorHandler(CSharpTokenType.Star, '=', CSharpTokenType.MultiplyAssign) },
- { ':', CreateTwoCharOperatorHandler(CSharpTokenType.Colon, ':', CSharpTokenType.DoubleColon) },
- { '?', CreateTwoCharOperatorHandler(CSharpTokenType.QuestionMark, '?', CSharpTokenType.NullCoalesce) },
- { '^', CreateTwoCharOperatorHandler(CSharpTokenType.Xor, '=', CSharpTokenType.XorAssign) },
- { '(', () => CSharpTokenType.LeftParenthesis },
- { ')', () => CSharpTokenType.RightParenthesis },
- { '{', () => CSharpTokenType.LeftBrace },
- { '}', () => CSharpTokenType.RightBrace },
- { '[', () => CSharpTokenType.LeftBracket },
- { ']', () => CSharpTokenType.RightBracket },
- { ',', () => CSharpTokenType.Comma },
- { ';', () => CSharpTokenType.Semicolon },
- { '~', () => CSharpTokenType.Tilde },
- { '#', () => CSharpTokenType.Hash }
+ { '&', CreateTwoCharOperatorHandler(SyntaxKind.And, '=', SyntaxKind.AndAssign, '&', SyntaxKind.DoubleAnd) },
+ { '|', CreateTwoCharOperatorHandler(SyntaxKind.Or, '=', SyntaxKind.OrAssign, '|', SyntaxKind.DoubleOr) },
+ { '+', CreateTwoCharOperatorHandler(SyntaxKind.Plus, '=', SyntaxKind.PlusAssign, '+', SyntaxKind.Increment) },
+ { '=', CreateTwoCharOperatorHandler(SyntaxKind.Assign, '=', SyntaxKind.Equals, '>', SyntaxKind.GreaterThanEqual) },
+ { '!', CreateTwoCharOperatorHandler(SyntaxKind.Not, '=', SyntaxKind.NotEqual) },
+ { '%', CreateTwoCharOperatorHandler(SyntaxKind.Modulo, '=', SyntaxKind.ModuloAssign) },
+ { '*', CreateTwoCharOperatorHandler(SyntaxKind.Star, '=', SyntaxKind.MultiplyAssign) },
+ { ':', CreateTwoCharOperatorHandler(SyntaxKind.Colon, ':', SyntaxKind.DoubleColon) },
+ { '?', CreateTwoCharOperatorHandler(SyntaxKind.QuestionMark, '?', SyntaxKind.NullCoalesce) },
+ { '^', CreateTwoCharOperatorHandler(SyntaxKind.Xor, '=', SyntaxKind.XorAssign) },
+ { '(', () => SyntaxKind.LeftParenthesis },
+ { ')', () => SyntaxKind.RightParenthesis },
+ { '{', () => SyntaxKind.LeftBrace },
+ { '}', () => SyntaxKind.RightBrace },
+ { '[', () => SyntaxKind.LeftBracket },
+ { ']', () => SyntaxKind.RightBracket },
+ { ',', () => SyntaxKind.Comma },
+ { ';', () => SyntaxKind.Semicolon },
+ { '~', () => SyntaxKind.Tilde },
+ { '#', () => SyntaxKind.Hash }
};
}
@@ -132,11 +133,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private new CSharpTokenizerState? CurrentState => (CSharpTokenizerState?)base.CurrentState;
- public override CSharpTokenType RazorCommentType => CSharpTokenType.RazorComment;
+ public override SyntaxKind RazorCommentKind => SyntaxKind.RazorCommentLiteral;
- public override CSharpTokenType RazorCommentTransitionType => CSharpTokenType.RazorCommentTransition;
+ public override SyntaxKind RazorCommentTransitionKind => SyntaxKind.RazorCommentTransition;
- public override CSharpTokenType RazorCommentStarType => CSharpTokenType.RazorCommentStar;
+ public override SyntaxKind RazorCommentStarKind => SyntaxKind.RazorCommentStar;
protected override StateResult Dispatch()
{
@@ -169,7 +170,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
}
// Optimize memory allocation by returning constants for the most frequent cases
- protected override string GetTokenContent(CSharpTokenType type)
+ protected override string GetTokenContent(SyntaxKind type)
{
var tokenLength = Buffer.Length;
@@ -177,7 +178,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
switch (type)
{
- case CSharpTokenType.IntegerLiteral:
+ case SyntaxKind.IntegerLiteral:
switch (Buffer[0])
{
case '0':
@@ -202,13 +203,13 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return "9";
}
break;
- case CSharpTokenType.NewLine:
+ case SyntaxKind.NewLine:
if (Buffer[0] == '\n')
{
return "\n";
}
break;
- case CSharpTokenType.WhiteSpace:
+ case SyntaxKind.Whitespace:
if (Buffer[0] == ' ')
{
return " ";
@@ -218,57 +219,57 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return "\t";
}
break;
- case CSharpTokenType.Minus:
+ case SyntaxKind.Minus:
return "-";
- case CSharpTokenType.Not:
+ case SyntaxKind.Not:
return "!";
- case CSharpTokenType.Modulo:
+ case SyntaxKind.Modulo:
return "%";
- case CSharpTokenType.And:
+ case SyntaxKind.And:
return "&";
- case CSharpTokenType.LeftParenthesis:
+ case SyntaxKind.LeftParenthesis:
return "(";
- case CSharpTokenType.RightParenthesis:
+ case SyntaxKind.RightParenthesis:
return ")";
- case CSharpTokenType.Star:
+ case SyntaxKind.Star:
return "*";
- case CSharpTokenType.Comma:
+ case SyntaxKind.Comma:
return ",";
- case CSharpTokenType.Dot:
+ case SyntaxKind.Dot:
return ".";
- case CSharpTokenType.Slash:
+ case SyntaxKind.Slash:
return "/";
- case CSharpTokenType.Colon:
+ case SyntaxKind.Colon:
return ":";
- case CSharpTokenType.Semicolon:
+ case SyntaxKind.Semicolon:
return ";";
- case CSharpTokenType.QuestionMark:
+ case SyntaxKind.QuestionMark:
return "?";
- case CSharpTokenType.RightBracket:
+ case SyntaxKind.RightBracket:
return "]";
- case CSharpTokenType.LeftBracket:
+ case SyntaxKind.LeftBracket:
return "[";
- case CSharpTokenType.Xor:
+ case SyntaxKind.Xor:
return "^";
- case CSharpTokenType.LeftBrace:
+ case SyntaxKind.LeftBrace:
return "{";
- case CSharpTokenType.Or:
+ case SyntaxKind.Or:
return "|";
- case CSharpTokenType.RightBrace:
+ case SyntaxKind.RightBrace:
return "}";
- case CSharpTokenType.Tilde:
+ case SyntaxKind.Tilde:
return "~";
- case CSharpTokenType.Plus:
+ case SyntaxKind.Plus:
return "+";
- case CSharpTokenType.LessThan:
+ case SyntaxKind.LessThan:
return "<";
- case CSharpTokenType.Assign:
+ case SyntaxKind.Assign:
return "=";
- case CSharpTokenType.GreaterThan:
+ case SyntaxKind.GreaterThan:
return ">";
- case CSharpTokenType.Hash:
+ case SyntaxKind.Hash:
return "#";
- case CSharpTokenType.Transition:
+ case SyntaxKind.Transition:
return "@";
}
@@ -277,53 +278,53 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
switch (type)
{
- case CSharpTokenType.NewLine:
+ case SyntaxKind.NewLine:
return "\r\n";
- case CSharpTokenType.Arrow:
+ case SyntaxKind.Arrow:
return "->";
- case CSharpTokenType.Decrement:
+ case SyntaxKind.Decrement:
return "--";
- case CSharpTokenType.MinusAssign:
+ case SyntaxKind.MinusAssign:
return "-=";
- case CSharpTokenType.NotEqual:
+ case SyntaxKind.NotEqual:
return "!=";
- case CSharpTokenType.ModuloAssign:
+ case SyntaxKind.ModuloAssign:
return "%=";
- case CSharpTokenType.AndAssign:
+ case SyntaxKind.AndAssign:
return "&=";
- case CSharpTokenType.DoubleAnd:
+ case SyntaxKind.DoubleAnd:
return "&&";
- case CSharpTokenType.MultiplyAssign:
+ case SyntaxKind.MultiplyAssign:
return "*=";
- case CSharpTokenType.DivideAssign:
+ case SyntaxKind.DivideAssign:
return "/=";
- case CSharpTokenType.DoubleColon:
+ case SyntaxKind.DoubleColon:
return "::";
- case CSharpTokenType.NullCoalesce:
+ case SyntaxKind.NullCoalesce:
return "??";
- case CSharpTokenType.XorAssign:
+ case SyntaxKind.XorAssign:
return "^=";
- case CSharpTokenType.OrAssign:
+ case SyntaxKind.OrAssign:
return "|=";
- case CSharpTokenType.DoubleOr:
+ case SyntaxKind.DoubleOr:
return "||";
- case CSharpTokenType.PlusAssign:
+ case SyntaxKind.PlusAssign:
return "+=";
- case CSharpTokenType.Increment:
+ case SyntaxKind.Increment:
return "++";
- case CSharpTokenType.LessThanEqual:
+ case SyntaxKind.LessThanEqual:
return "<=";
- case CSharpTokenType.LeftShift:
+ case SyntaxKind.LeftShift:
return "<<";
- case CSharpTokenType.Equals:
+ case SyntaxKind.Equals:
return "==";
- case CSharpTokenType.GreaterThanEqual:
+ case SyntaxKind.GreaterThanEqual:
if (Buffer[0] == '=')
{
return "=>";
}
return ">=";
- case CSharpTokenType.RightShift:
+ case SyntaxKind.RightShift:
return ">>";
@@ -333,9 +334,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
switch (type)
{
- case CSharpTokenType.LeftShiftAssign:
+ case SyntaxKind.LeftShiftAssign:
return "<<=";
- case CSharpTokenType.RightShiftAssign:
+ case SyntaxKind.RightShiftAssign:
return ">>=";
}
}
@@ -343,9 +344,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return base.GetTokenContent(type);
}
- protected override CSharpToken CreateToken(string content, CSharpTokenType type, IReadOnlyList errors)
+ protected override SyntaxToken CreateToken(string content, SyntaxKind kind, IReadOnlyList errors)
{
- return new CSharpToken(content, type, errors);
+ return SyntaxFactory.Token(kind, content, errors);
}
private StateResult Data()
@@ -359,13 +360,13 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
TakeCurrent();
}
- return Stay(EndToken(CSharpTokenType.NewLine));
+ return Stay(EndToken(SyntaxKind.NewLine));
}
else if (ParserHelpers.IsWhitespace(CurrentCharacter))
{
// CSharp Spec §2.3.3
TakeUntil(c => !ParserHelpers.IsWhitespace(c));
- return Stay(EndToken(CSharpTokenType.WhiteSpace));
+ return Stay(EndToken(SyntaxKind.Whitespace));
}
else if (IsIdentifierStart(CurrentCharacter))
{
@@ -390,7 +391,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
return RealLiteral();
}
- return Stay(Single(CSharpTokenType.Dot));
+ return Stay(Single(SyntaxKind.Dot));
case '/':
TakeCurrent();
if (CurrentCharacter == '/')
@@ -406,11 +407,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
else if (CurrentCharacter == '=')
{
TakeCurrent();
- return Stay(EndToken(CSharpTokenType.DivideAssign));
+ return Stay(EndToken(SyntaxKind.DivideAssign));
}
else
{
- return Stay(EndToken(CSharpTokenType.Slash));
+ return Stay(EndToken(SyntaxKind.Slash));
}
default:
return Stay(EndToken(Operator()));
@@ -429,78 +430,78 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
return Transition(
CSharpTokenizerState.AfterRazorCommentTransition,
- EndToken(CSharpTokenType.RazorCommentTransition));
+ EndToken(SyntaxKind.RazorCommentTransition));
}
else if (CurrentCharacter == '@')
{
// Could be escaped comment transition
return Transition(
CSharpTokenizerState.EscapedRazorCommentTransition,
- EndToken(CSharpTokenType.Transition));
+ EndToken(SyntaxKind.Transition));
}
- return Stay(EndToken(CSharpTokenType.Transition));
+ return Stay(EndToken(SyntaxKind.Transition));
}
private StateResult EscapedRazorCommentTransition()
{
TakeCurrent();
- return Transition(CSharpTokenizerState.Data, EndToken(CSharpTokenType.Transition));
+ return Transition(CSharpTokenizerState.Data, EndToken(SyntaxKind.Transition));
}
- private CSharpTokenType Operator()
+ private SyntaxKind Operator()
{
var first = CurrentCharacter;
TakeCurrent();
- Func handler;
+ Func handler;
if (_operatorHandlers.TryGetValue(first, out handler))
{
return handler();
}
- return CSharpTokenType.Unknown;
+ return SyntaxKind.Unknown;
}
- private CSharpTokenType LessThanOperator()
+ private SyntaxKind LessThanOperator()
{
if (CurrentCharacter == '=')
{
TakeCurrent();
- return CSharpTokenType.LessThanEqual;
+ return SyntaxKind.LessThanEqual;
}
- return CSharpTokenType.LessThan;
+ return SyntaxKind.LessThan;
}
- private CSharpTokenType GreaterThanOperator()
+ private SyntaxKind GreaterThanOperator()
{
if (CurrentCharacter == '=')
{
TakeCurrent();
- return CSharpTokenType.GreaterThanEqual;
+ return SyntaxKind.GreaterThanEqual;
}
- return CSharpTokenType.GreaterThan;
+ return SyntaxKind.GreaterThan;
}
- private CSharpTokenType MinusOperator()
+ private SyntaxKind MinusOperator()
{
if (CurrentCharacter == '>')
{
TakeCurrent();
- return CSharpTokenType.Arrow;
+ return SyntaxKind.Arrow;
}
else if (CurrentCharacter == '-')
{
TakeCurrent();
- return CSharpTokenType.Decrement;
+ return SyntaxKind.Decrement;
}
else if (CurrentCharacter == '=')
{
TakeCurrent();
- return CSharpTokenType.MinusAssign;
+ return SyntaxKind.MinusAssign;
}
- return CSharpTokenType.Minus;
+ return SyntaxKind.Minus;
}
- private Func CreateTwoCharOperatorHandler(CSharpTokenType typeIfOnlyFirst, char second, CSharpTokenType typeIfBoth)
+ private Func CreateTwoCharOperatorHandler(SyntaxKind typeIfOnlyFirst, char second, SyntaxKind typeIfBoth)
{
return () =>
{
@@ -513,7 +514,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
};
}
- private Func CreateTwoCharOperatorHandler(CSharpTokenType typeIfOnlyFirst, char option1, CSharpTokenType typeIfOption1, char option2, CSharpTokenType typeIfOption2)
+ private Func CreateTwoCharOperatorHandler(SyntaxKind typeIfOnlyFirst, char option1, SyntaxKind typeIfOption1, char option2, SyntaxKind typeIfOption2)
{
return () =>
{
@@ -550,14 +551,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
RazorDiagnosticFactory.CreateParsing_UnterminatedStringLiteral(
new SourceSpan(CurrentStart, contentLength: 1 /* end of file */)));
}
- return Transition(CSharpTokenizerState.Data, EndToken(CSharpTokenType.StringLiteral));
+ return Transition(CSharpTokenizerState.Data, EndToken(SyntaxKind.StringLiteral));
}
- private StateResult QuotedCharacterLiteral() => QuotedLiteral('\'', CSharpTokenType.CharacterLiteral);
+ private StateResult QuotedCharacterLiteral() => QuotedLiteral('\'', SyntaxKind.CharacterLiteral);
- private StateResult QuotedStringLiteral() => QuotedLiteral('\"', CSharpTokenType.StringLiteral);
+ private StateResult QuotedStringLiteral() => QuotedLiteral('\"', SyntaxKind.StringLiteral);
- private StateResult QuotedLiteral(char quote, CSharpTokenType literalType)
+ private StateResult QuotedLiteral(char quote, SyntaxKind literalType)
{
TakeUntil(c => c == '\\' || c == quote || ParserHelpers.IsNewLine(c));
if (CurrentCharacter == '\\')
@@ -594,7 +595,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
RazorDiagnosticFactory.CreateParsing_BlockCommentNotTerminated(
new SourceSpan(CurrentStart, contentLength: 1 /* end of file */)));
- return Transition(CSharpTokenizerState.Data, EndToken(CSharpTokenType.Comment));
+ return Transition(CSharpTokenizerState.Data, EndToken(SyntaxKind.CSharpComment));
}
if (CurrentCharacter == '*')
{
@@ -602,7 +603,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
if (CurrentCharacter == '/')
{
TakeCurrent();
- return Transition(CSharpTokenizerState.Data, EndToken(CSharpTokenType.Comment));
+ return Transition(CSharpTokenizerState.Data, EndToken(SyntaxKind.CSharpComment));
}
}
return Stay();
@@ -612,7 +613,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private StateResult SingleLineComment()
{
TakeUntil(c => ParserHelpers.IsNewLine(c));
- return Stay(EndToken(CSharpTokenType.Comment));
+ return Stay(EndToken(SyntaxKind.CSharpComment));
}
// CSharp Spec §2.4.4
@@ -632,7 +633,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
TakeUntil(c => !IsHexDigit(c));
TakeIntegerSuffix();
- return Stay(EndToken(CSharpTokenType.IntegerLiteral));
+ return Stay(EndToken(SyntaxKind.IntegerLiteral));
}
private StateResult DecimalLiteral()
@@ -650,7 +651,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
else
{
TakeIntegerSuffix();
- return Stay(EndToken(CSharpTokenType.IntegerLiteral));
+ return Stay(EndToken(SyntaxKind.IntegerLiteral));
}
}
@@ -669,7 +670,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
TakeCurrent();
}
- return Stay(EndToken(CSharpTokenType.RealLiteral));
+ return Stay(EndToken(SyntaxKind.RealLiteral));
}
// CSharp Spec §2.4.4.3
@@ -708,21 +709,18 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
Debug.Assert(IsIdentifierStart(CurrentCharacter));
TakeCurrent();
TakeUntil(c => !IsIdentifierPart(c));
- CSharpToken token = null;
+ SyntaxToken token = null;
if (HaveContent)
{
CSharpKeyword keyword;
- var type = CSharpTokenType.Identifier;
+ var type = SyntaxKind.Identifier;
var tokenContent = Buffer.ToString();
if (_keywords.TryGetValue(tokenContent, out keyword))
{
- type = CSharpTokenType.Keyword;
+ type = SyntaxKind.Keyword;
}
-
- token = new CSharpToken(tokenContent, type)
- {
- Keyword = type == CSharpTokenType.Keyword ? (CSharpKeyword?)keyword : null,
- };
+
+ token = SyntaxFactory.Token(type, tokenContent);
Buffer.Clear();
CurrentErrors.Clear();
@@ -736,7 +734,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return Transition((int)state, result: null);
}
- private StateResult Transition(CSharpTokenizerState state, CSharpToken result)
+ private StateResult Transition(CSharpTokenizerState state, SyntaxToken result)
{
return Transition((int)state, result);
}
@@ -780,6 +778,16 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return (value >= '0' && value <= '9') || (value >= 'A' && value <= 'F') || (value >= 'a' && value <= 'f');
}
+ internal static CSharpKeyword? GetTokenKeyword(SyntaxToken token)
+ {
+ if (token != null && _keywords.TryGetValue(token.Content, out var keyword))
+ {
+ return keyword;
+ }
+
+ return null;
+ }
+
private enum CSharpTokenizerState
{
Data,
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/CodeBlockEditHandler.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/CodeBlockEditHandler.cs
index d5ce71c43e..89d1f3d6c6 100644
--- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/CodeBlockEditHandler.cs
+++ b/src/Microsoft.AspNetCore.Razor.Language/Legacy/CodeBlockEditHandler.cs
@@ -4,12 +4,13 @@
using System;
using System.Collections.Generic;
using System.Globalization;
+using Microsoft.AspNetCore.Razor.Language.Syntax.InternalSyntax;
namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
internal class CodeBlockEditHandler : SpanEditHandler
{
- public CodeBlockEditHandler(Func> tokenizer) : base(tokenizer)
+ public CodeBlockEditHandler(Func> tokenizer) : base(tokenizer)
{
}
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/DirectiveCSharpTokenizer.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/DirectiveCSharpTokenizer.cs
index a9befaa302..59224e709f 100644
--- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/DirectiveCSharpTokenizer.cs
+++ b/src/Microsoft.AspNetCore.Razor.Language/Legacy/DirectiveCSharpTokenizer.cs
@@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Diagnostics;
+using Microsoft.AspNetCore.Razor.Language.Syntax.InternalSyntax;
namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
@@ -17,11 +18,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
protected override StateResult Dispatch()
{
var result = base.Dispatch();
- if (result.Result != null && !_visitedFirstTokenStart && IsValidTokenType(result.Result.Type))
+ if (result.Result != null && !_visitedFirstTokenStart && IsValidTokenType(result.Result.Kind))
{
_visitedFirstTokenStart = true;
}
- else if (result.Result != null && _visitedFirstTokenStart && result.Result.Type == CSharpTokenType.NewLine)
+ else if (result.Result != null && _visitedFirstTokenStart && result.Result.Kind == SyntaxKind.NewLine)
{
_visitedFirstTokenLineEnd = true;
}
@@ -29,7 +30,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return result;
}
- public override CSharpToken NextToken()
+ public override SyntaxToken NextToken()
{
// Post-Condition: Buffer should be empty at the start of Next()
Debug.Assert(Buffer.Length == 0);
@@ -48,15 +49,15 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return token;
}
- private bool IsValidTokenType(CSharpTokenType type)
+ private bool IsValidTokenType(SyntaxKind kind)
{
- return type != CSharpTokenType.WhiteSpace &&
- type != CSharpTokenType.NewLine &&
- type != CSharpTokenType.Comment &&
- type != CSharpTokenType.RazorComment &&
- type != CSharpTokenType.RazorCommentStar &&
- type != CSharpTokenType.RazorCommentTransition &&
- type != CSharpTokenType.Transition;
+ return kind != SyntaxKind.Whitespace &&
+ kind != SyntaxKind.NewLine &&
+ kind != SyntaxKind.CSharpComment &&
+ kind != SyntaxKind.RazorCommentLiteral &&
+ kind != SyntaxKind.RazorCommentStar &&
+ kind != SyntaxKind.RazorCommentTransition &&
+ kind != SyntaxKind.Transition;
}
}
}
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/DirectiveHtmlTokenizer.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/DirectiveHtmlTokenizer.cs
index 034977c758..4921c8aa1e 100644
--- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/DirectiveHtmlTokenizer.cs
+++ b/src/Microsoft.AspNetCore.Razor.Language/Legacy/DirectiveHtmlTokenizer.cs
@@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Diagnostics;
+using Microsoft.AspNetCore.Razor.Language.Syntax.InternalSyntax;
namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
@@ -16,7 +17,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
protected override StateResult Dispatch()
{
var result = base.Dispatch();
- if (result.Result != null && IsValidTokenType(result.Result.Type))
+ if (result.Result != null && IsValidTokenType(result.Result.Kind))
{
_visitedFirstTokenStart = true;
}
@@ -24,7 +25,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return result;
}
- public override HtmlToken NextToken()
+ public override SyntaxToken NextToken()
{
// Post-Condition: Buffer should be empty at the start of Next()
Debug.Assert(Buffer.Length == 0);
@@ -43,14 +44,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return token;
}
- private bool IsValidTokenType(HtmlTokenType type)
+ private bool IsValidTokenType(SyntaxKind kind)
{
- return type != HtmlTokenType.WhiteSpace &&
- type != HtmlTokenType.NewLine &&
- type != HtmlTokenType.RazorComment &&
- type != HtmlTokenType.RazorCommentStar &&
- type != HtmlTokenType.RazorCommentTransition &&
- type != HtmlTokenType.Transition;
+ return kind != SyntaxKind.Whitespace &&
+ kind != SyntaxKind.NewLine &&
+ kind != SyntaxKind.RazorCommentLiteral &&
+ kind != SyntaxKind.RazorCommentStar &&
+ kind != SyntaxKind.RazorCommentTransition &&
+ kind != SyntaxKind.Transition;
}
}
}
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/HtmlLanguageCharacteristics.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/HtmlLanguageCharacteristics.cs
index 096ae84dc0..c404183ed0 100644
--- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/HtmlLanguageCharacteristics.cs
+++ b/src/Microsoft.AspNetCore.Razor.Language/Legacy/HtmlLanguageCharacteristics.cs
@@ -3,10 +3,11 @@
using System.Collections.Generic;
using System.Diagnostics;
+using Microsoft.AspNetCore.Razor.Language.Syntax.InternalSyntax;
namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
- internal class HtmlLanguageCharacteristics : LanguageCharacteristics
+ internal class HtmlLanguageCharacteristics : LanguageCharacteristics
{
private static readonly HtmlLanguageCharacteristics _instance = new HtmlLanguageCharacteristics();
@@ -19,47 +20,47 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
get { return _instance; }
}
- public override string GetSample(HtmlTokenType type)
+ public override string GetSample(SyntaxKind type)
{
switch (type)
{
- case HtmlTokenType.Text:
+ case SyntaxKind.Text:
return Resources.HtmlToken_Text;
- case HtmlTokenType.WhiteSpace:
+ case SyntaxKind.Whitespace:
return Resources.HtmlToken_WhiteSpace;
- case HtmlTokenType.NewLine:
+ case SyntaxKind.NewLine:
return Resources.HtmlToken_NewLine;
- case HtmlTokenType.OpenAngle:
+ case SyntaxKind.OpenAngle:
return "<";
- case HtmlTokenType.Bang:
+ case SyntaxKind.Bang:
return "!";
- case HtmlTokenType.ForwardSlash:
+ case SyntaxKind.ForwardSlash:
return "/";
- case HtmlTokenType.QuestionMark:
+ case SyntaxKind.QuestionMark:
return "?";
- case HtmlTokenType.DoubleHyphen:
+ case SyntaxKind.DoubleHyphen:
return "--";
- case HtmlTokenType.LeftBracket:
+ case SyntaxKind.LeftBracket:
return "[";
- case HtmlTokenType.CloseAngle:
+ case SyntaxKind.CloseAngle:
return ">";
- case HtmlTokenType.RightBracket:
+ case SyntaxKind.RightBracket:
return "]";
- case HtmlTokenType.Equals:
+ case SyntaxKind.Equals:
return "=";
- case HtmlTokenType.DoubleQuote:
+ case SyntaxKind.DoubleQuote:
return "\"";
- case HtmlTokenType.SingleQuote:
+ case SyntaxKind.SingleQuote:
return "'";
- case HtmlTokenType.Transition:
+ case SyntaxKind.Transition:
return "@";
- case HtmlTokenType.Colon:
+ case SyntaxKind.Colon:
return ":";
- case HtmlTokenType.RazorComment:
+ case SyntaxKind.RazorCommentLiteral:
return Resources.HtmlToken_RazorComment;
- case HtmlTokenType.RazorCommentStar:
+ case SyntaxKind.RazorCommentStar:
return "*";
- case HtmlTokenType.RazorCommentTransition:
+ case SyntaxKind.RazorCommentTransition:
return "@";
default:
return Resources.Token_Unknown;
@@ -71,57 +72,57 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return new HtmlTokenizer(source);
}
- public override HtmlTokenType FlipBracket(HtmlTokenType bracket)
+ public override SyntaxKind FlipBracket(SyntaxKind bracket)
{
switch (bracket)
{
- case HtmlTokenType.LeftBracket:
- return HtmlTokenType.RightBracket;
- case HtmlTokenType.OpenAngle:
- return HtmlTokenType.CloseAngle;
- case HtmlTokenType.RightBracket:
- return HtmlTokenType.LeftBracket;
- case HtmlTokenType.CloseAngle:
- return HtmlTokenType.OpenAngle;
+ case SyntaxKind.LeftBracket:
+ return SyntaxKind.RightBracket;
+ case SyntaxKind.OpenAngle:
+ return SyntaxKind.CloseAngle;
+ case SyntaxKind.RightBracket:
+ return SyntaxKind.LeftBracket;
+ case SyntaxKind.CloseAngle:
+ return SyntaxKind.OpenAngle;
default:
Debug.Fail("FlipBracket must be called with a bracket character");
- return HtmlTokenType.Unknown;
+ return SyntaxKind.Unknown;
}
}
- public override HtmlToken CreateMarkerToken()
+ public override SyntaxToken CreateMarkerToken()
{
- return new HtmlToken(string.Empty, HtmlTokenType.Unknown);
+ return SyntaxFactory.Token(SyntaxKind.Unknown, string.Empty);
}
- public override HtmlTokenType GetKnownTokenType(KnownTokenType type)
+ public override SyntaxKind GetKnownTokenType(KnownTokenType type)
{
switch (type)
{
case KnownTokenType.CommentStart:
- return HtmlTokenType.RazorCommentTransition;
+ return SyntaxKind.RazorCommentTransition;
case KnownTokenType.CommentStar:
- return HtmlTokenType.RazorCommentStar;
+ return SyntaxKind.RazorCommentStar;
case KnownTokenType.CommentBody:
- return HtmlTokenType.RazorComment;
+ return SyntaxKind.RazorCommentLiteral;
case KnownTokenType.Identifier:
- return HtmlTokenType.Text;
+ return SyntaxKind.Text;
case KnownTokenType.Keyword:
- return HtmlTokenType.Text;
+ return SyntaxKind.Text;
case KnownTokenType.NewLine:
- return HtmlTokenType.NewLine;
+ return SyntaxKind.NewLine;
case KnownTokenType.Transition:
- return HtmlTokenType.Transition;
+ return SyntaxKind.Transition;
case KnownTokenType.WhiteSpace:
- return HtmlTokenType.WhiteSpace;
+ return SyntaxKind.Whitespace;
default:
- return HtmlTokenType.Unknown;
+ return SyntaxKind.Unknown;
}
}
- protected override HtmlToken CreateToken(string content, HtmlTokenType type, IReadOnlyList errors)
+ protected override SyntaxToken CreateToken(string content, SyntaxKind kind, IReadOnlyList errors)
{
- return new HtmlToken(content, type, errors);
+ return SyntaxFactory.Token(kind, content, errors);
}
}
}
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/HtmlMarkupParser.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/HtmlMarkupParser.cs
index 2408c552dd..efc0d27598 100644
--- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/HtmlMarkupParser.cs
+++ b/src/Microsoft.AspNetCore.Razor.Language/Legacy/HtmlMarkupParser.cs
@@ -5,22 +5,31 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
+using Microsoft.AspNetCore.Razor.Language.Syntax.InternalSyntax;
namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
- internal class HtmlMarkupParser : TokenizerBackedParser
+ internal class HtmlMarkupParser : TokenizerBackedParser
{
private const string ScriptTagName = "script";
- private static readonly HtmlToken[] nonAllowedHtmlCommentEnding = new[] { HtmlToken.Hyphen, new HtmlToken("!", HtmlTokenType.Bang), new HtmlToken("<", HtmlTokenType.OpenAngle) };
- private static readonly HtmlToken[] singleHyphenArray = new[] { HtmlToken.Hyphen };
+ private static readonly SyntaxToken[] nonAllowedHtmlCommentEnding = new[]
+ {
+ SyntaxFactory.Token(SyntaxKind.Text, "-"),
+ SyntaxFactory.Token(SyntaxKind.Bang, "!"),
+ SyntaxFactory.Token(SyntaxKind.OpenAngle, "<"),
+ };
+ private static readonly SyntaxToken[] singleHyphenArray = new[]
+ {
+ SyntaxFactory.Token(SyntaxKind.Text, "-")
+ };
private static readonly char[] ValidAfterTypeAttributeNameCharacters = { ' ', '\t', '\r', '\n', '\f', '=' };
private SourceLocation _lastTagStart = SourceLocation.Zero;
- private HtmlToken _bufferedOpenAngle;
+ private SyntaxToken _bufferedOpenAngle;
//From http://dev.w3.org/html5/spec/Overview.html#elements-0
- private ISet _voidElements = new HashSet(StringComparer.OrdinalIgnoreCase)
+ private readonly ISet _voidElements = new HashSet(StringComparer.OrdinalIgnoreCase)
{
"area",
"base",
@@ -59,7 +68,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
get { return CaseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase; }
}
- protected override bool TokenTypeEquals(HtmlTokenType x, HtmlTokenType y) => x == y;
+ protected override bool TokenKindEquals(SyntaxKind x, SyntaxKind y) => x == y;
public override void BuildSpan(SpanBuilder span, SourceLocation start, string content)
{
@@ -73,14 +82,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
Output(SpanKindInternal.Markup);
}
- protected void SkipToAndParseCode(HtmlTokenType type)
+ protected void SkipToAndParseCode(SyntaxKind type)
{
- SkipToAndParseCode(token => token.Type == type);
+ SkipToAndParseCode(token => token.Kind == type);
}
- protected void SkipToAndParseCode(Func condition)
+ protected void SkipToAndParseCode(Func condition)
{
- HtmlToken last = null;
+ SyntaxToken last = null;
var startOfLine = false;
while (!EndOfFile && !condition(CurrentToken))
{
@@ -88,15 +97,15 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
Context.NullGenerateWhitespaceAndNewLine = false;
Span.ChunkGenerator = SpanChunkGenerator.Null;
- AcceptWhile(token => token.Type == HtmlTokenType.WhiteSpace);
- if (At(HtmlTokenType.NewLine))
+ AcceptWhile(token => token.Kind == SyntaxKind.Whitespace);
+ if (At(SyntaxKind.NewLine))
{
AcceptAndMoveNext();
}
Output(SpanKindInternal.Markup);
}
- else if (At(HtmlTokenType.NewLine))
+ else if (At(SyntaxKind.NewLine))
{
if (last != null)
{
@@ -108,11 +117,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
last = null;
AcceptAndMoveNext();
}
- else if (At(HtmlTokenType.Transition))
+ else if (At(SyntaxKind.Transition))
{
var transition = CurrentToken;
NextToken();
- if (At(HtmlTokenType.Transition))
+ if (At(SyntaxKind.Transition))
{
if (last != null)
{
@@ -138,7 +147,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
// Handle whitespace rewriting
if (last != null)
{
- if (!Context.DesignTimeMode && last.Type == HtmlTokenType.WhiteSpace && startOfLine)
+ if (!Context.DesignTimeMode && last.Kind == SyntaxKind.Whitespace && startOfLine)
{
// Put the whitespace back too
startOfLine = false;
@@ -155,12 +164,12 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
OtherParserBlock();
}
- else if (At(HtmlTokenType.RazorCommentTransition))
+ else if (At(SyntaxKind.RazorCommentTransition))
{
if (last != null)
{
// Don't render the whitespace between the start of the line and the razor comment.
- if (startOfLine && last.Type == HtmlTokenType.WhiteSpace)
+ if (startOfLine && last.Kind == SyntaxKind.Whitespace)
{
AddMarkerTokenIfNecessary();
// Output the tokens that may have been accepted prior to the whitespace.
@@ -180,8 +189,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
// Handle the whitespace and newline at the end of a razor comment.
if (startOfLine &&
- (At(HtmlTokenType.NewLine) ||
- (At(HtmlTokenType.WhiteSpace) && NextIs(HtmlTokenType.NewLine))))
+ (At(SyntaxKind.NewLine) ||
+ (At(SyntaxKind.Whitespace) && NextIs(SyntaxKind.NewLine))))
{
AcceptWhile(IsSpacingToken(includeNewLines: false));
AcceptAndMoveNext();
@@ -192,7 +201,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
else
{
// As long as we see whitespace, we're still at the "start" of the line
- startOfLine &= At(HtmlTokenType.WhiteSpace);
+ startOfLine &= At(SyntaxKind.Whitespace);
// If there's a last token, accept it
if (last != null)
@@ -213,9 +222,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
}
}
- protected static Func IsSpacingToken(bool includeNewLines)
+ protected static Func IsSpacingToken(bool includeNewLines)
{
- return token => token.Type == HtmlTokenType.WhiteSpace || (includeNewLines && token.Type == HtmlTokenType.NewLine);
+ return token => token.Kind == SyntaxKind.Whitespace || (includeNewLines && token.Kind == SyntaxKind.NewLine);
}
private void OtherParserBlock()
@@ -238,12 +247,12 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
var potentialBang = Lookahead(lookahead);
if (potentialBang != null &&
- potentialBang.Type == HtmlTokenType.Bang)
+ potentialBang.Kind == SyntaxKind.Bang)
{
var afterBang = Lookahead(lookahead + 1);
return afterBang != null &&
- afterBang.Type == HtmlTokenType.Text &&
+ afterBang.Kind == SyntaxKind.Text &&
!string.Equals(afterBang.Content, "DOCTYPE", StringComparison.OrdinalIgnoreCase);
}
@@ -257,7 +266,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
Output(SpanKindInternal.Markup);
// Accept the parser escape character '!'.
- Assert(HtmlTokenType.Bang);
+ Assert(SyntaxKind.Bang);
AcceptAndMoveNext();
// Setup the metacode span that we will be outputing.
@@ -286,23 +295,23 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
AcceptWhile(IsSpacingToken(includeNewLines: true));
- if (CurrentToken.Type == HtmlTokenType.OpenAngle)
+ if (CurrentToken.Kind == SyntaxKind.OpenAngle)
{
// "<" => Implicit Tag Block
- TagBlock(new Stack>());
+ TagBlock(new Stack>());
}
- else if (CurrentToken.Type == HtmlTokenType.Transition)
+ else if (CurrentToken.Kind == SyntaxKind.Transition)
{
// "@" => Explicit Tag/Single Line Block OR Template
Output(SpanKindInternal.Markup);
// Definitely have a transition span
- Assert(HtmlTokenType.Transition);
+ Assert(SyntaxKind.Transition);
AcceptAndMoveNext();
Span.EditHandler.AcceptedCharacters = AcceptedCharactersInternal.None;
Span.ChunkGenerator = SpanChunkGenerator.Null;
Output(SpanKindInternal.Transition);
- if (At(HtmlTokenType.Transition))
+ if (At(SyntaxKind.Transition))
{
Span.ChunkGenerator = SpanChunkGenerator.Null;
AcceptAndMoveNext();
@@ -330,10 +339,10 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private void AfterTransition()
{
// "@:" => Explicit Single Line Block
- if (CurrentToken.Type == HtmlTokenType.Text && CurrentToken.Content.Length > 0 && CurrentToken.Content[0] == ':')
+ if (CurrentToken.Kind == SyntaxKind.Text && CurrentToken.Content.Length > 0 && CurrentToken.Content[0] == ':')
{
// Split the token
- Tuple split = Language.SplitToken(CurrentToken, 1, HtmlTokenType.Colon);
+ var split = Language.SplitToken(CurrentToken, 1, SyntaxKind.Colon);
// The first part (left) is added to this span and we return a MetaCode span
Accept(split.Item1);
@@ -346,9 +355,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
NextToken();
SingleLineMarkup();
}
- else if (CurrentToken.Type == HtmlTokenType.OpenAngle)
+ else if (CurrentToken.Kind == SyntaxKind.OpenAngle)
{
- TagBlock(new Stack>());
+ TagBlock(new Stack>());
}
}
@@ -359,8 +368,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
var old = Context.WhiteSpaceIsSignificantToAncestorBlock;
Context.WhiteSpaceIsSignificantToAncestorBlock = true;
Span.EditHandler = new SpanEditHandler(Language.TokenizeString);
- SkipToAndParseCode(HtmlTokenType.NewLine);
- if (!EndOfFile && CurrentToken.Type == HtmlTokenType.NewLine)
+ SkipToAndParseCode(SyntaxKind.NewLine);
+ if (!EndOfFile && CurrentToken.Kind == SyntaxKind.NewLine)
{
AcceptAndMoveNext();
Span.EditHandler.AcceptedCharacters = AcceptedCharactersInternal.None;
@@ -370,13 +379,13 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
Output(SpanKindInternal.Markup);
}
- private void TagBlock(Stack> tags)
+ private void TagBlock(Stack> tags)
{
// Skip Whitespace and Text
var complete = false;
do
{
- SkipToAndParseCode(HtmlTokenType.OpenAngle);
+ SkipToAndParseCode(SyntaxKind.OpenAngle);
// Output everything prior to the OpenAngle into a markup span
Output(SpanKindInternal.Markup);
@@ -401,7 +410,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
_bufferedOpenAngle = null;
_lastTagStart = CurrentStart;
- Assert(HtmlTokenType.OpenAngle);
+ Assert(SyntaxKind.OpenAngle);
_bufferedOpenAngle = CurrentToken;
var tagStart = CurrentStart;
if (!NextToken())
@@ -440,18 +449,18 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
}
private bool AfterTagStart(SourceLocation tagStart,
- Stack> tags,
+ Stack> tags,
bool atSpecialTag,
IDisposable tagBlockWrapper)
{
if (!EndOfFile)
{
- switch (CurrentToken.Type)
+ switch (CurrentToken.Kind)
{
- case HtmlTokenType.ForwardSlash:
+ case SyntaxKind.ForwardSlash:
// End Tag
return EndTag(tagStart, tags, tagBlockWrapper);
- case HtmlTokenType.Bang:
+ case SyntaxKind.Bang:
// Comment, CDATA, DOCTYPE, or a parser-escaped HTML tag.
if (atSpecialTag)
{
@@ -462,7 +471,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
goto default;
}
- case HtmlTokenType.QuestionMark:
+ case SyntaxKind.QuestionMark:
// XML PI
Accept(_bufferedOpenAngle);
return XmlPI();
@@ -483,15 +492,15 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private bool XmlPI()
{
// Accept "?"
- Assert(HtmlTokenType.QuestionMark);
+ Assert(SyntaxKind.QuestionMark);
AcceptAndMoveNext();
- return AcceptUntilAll(HtmlTokenType.QuestionMark, HtmlTokenType.CloseAngle);
+ return AcceptUntilAll(SyntaxKind.QuestionMark, SyntaxKind.CloseAngle);
}
private bool BangTag()
{
// Accept "!"
- Assert(HtmlTokenType.Bang);
+ Assert(SyntaxKind.Bang);
if (AcceptAndMoveNext())
{
@@ -503,16 +512,16 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
AcceptAndMoveNext();
Output(SpanKindInternal.Markup, AcceptedCharactersInternal.None);
- Span.EditHandler.AcceptedCharacters = AcceptedCharactersInternal.WhiteSpace;
+ Span.EditHandler.AcceptedCharacters = AcceptedCharactersInternal.Whitespace;
while (!EndOfFile)
{
- SkipToAndParseCode(HtmlTokenType.DoubleHyphen);
+ SkipToAndParseCode(SyntaxKind.DoubleHyphen);
var lastDoubleHyphen = AcceptAllButLastDoubleHyphens();
- if (At(HtmlTokenType.CloseAngle))
+ if (At(SyntaxKind.CloseAngle))
{
// Output the content in the comment block as a separate markup
- Output(SpanKindInternal.Markup, AcceptedCharactersInternal.WhiteSpace);
+ Output(SpanKindInternal.Markup, AcceptedCharactersInternal.Whitespace);
// This is the end of a comment block
Accept(lastDoubleHyphen);
@@ -527,7 +536,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
}
}
}
- else if (CurrentToken.Type == HtmlTokenType.LeftBracket)
+ else if (CurrentToken.Kind == SyntaxKind.LeftBracket)
{
if (AcceptAndMoveNext())
{
@@ -537,19 +546,19 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
else
{
AcceptAndMoveNext();
- return AcceptUntilAll(HtmlTokenType.CloseAngle);
+ return AcceptUntilAll(SyntaxKind.CloseAngle);
}
}
return false;
}
- protected HtmlToken AcceptAllButLastDoubleHyphens()
+ protected SyntaxToken AcceptAllButLastDoubleHyphens()
{
var lastDoubleHyphen = CurrentToken;
AcceptWhile(s =>
{
- if (NextIs(HtmlTokenType.DoubleHyphen))
+ if (NextIs(SyntaxKind.DoubleHyphen))
{
lastDoubleHyphen = s;
return true;
@@ -560,10 +569,10 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
NextToken();
- if (At(HtmlTokenType.Text) && IsHyphen(CurrentToken))
+ if (At(SyntaxKind.Text) && IsHyphen(CurrentToken))
{
// Doing this here to maintain the order of tokens
- if (!NextIs(HtmlTokenType.CloseAngle))
+ if (!NextIs(SyntaxKind.CloseAngle))
{
Accept(lastDoubleHyphen);
lastDoubleHyphen = null;
@@ -575,9 +584,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return lastDoubleHyphen;
}
- internal static bool IsHyphen(HtmlToken token)
+ internal static bool IsHyphen(SyntaxToken token)
{
- return token.Equals(HtmlToken.Hyphen);
+ return token.Kind == SyntaxKind.Text && token.Content == "-";
}
protected bool IsHtmlCommentAhead()
@@ -595,13 +604,13 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
// 2.3 nor end with the string ""
- if (CurrentToken.Type != HtmlTokenType.DoubleHyphen)
+ if (CurrentToken.Kind != SyntaxKind.DoubleHyphen)
{
return false;
}
// Check condition 2.1
- if (NextIs(HtmlTokenType.CloseAngle) || NextIs(next => IsHyphen(next) && NextIs(HtmlTokenType.CloseAngle)))
+ if (NextIs(SyntaxKind.CloseAngle) || NextIs(next => IsHyphen(next) && NextIs(SyntaxKind.CloseAngle)))
{
return false;
}
@@ -610,15 +619,15 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
var isValidComment = false;
LookaheadUntil((token, prevTokens) =>
{
- if (token.Type == HtmlTokenType.DoubleHyphen)
+ if (token.Kind == SyntaxKind.DoubleHyphen)
{
- if (NextIs(HtmlTokenType.CloseAngle))
+ if (NextIs(SyntaxKind.CloseAngle))
{
// Check condition 2.3: We're at the end of a comment. Check to make sure the text ending is allowed.
isValidComment = !IsCommentContentEndingInvalid(prevTokens);
return true;
}
- else if (NextIs(ns => IsHyphen(ns) && NextIs(HtmlTokenType.CloseAngle)))
+ else if (NextIs(ns => IsHyphen(ns) && NextIs(SyntaxKind.CloseAngle)))
{
// Check condition 2.3: we're at the end of a comment, which has an extra dash.
// Need to treat the dash as part of the content and check the ending.
@@ -627,17 +636,17 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
isValidComment = true;
return true;
}
- else if (NextIs(ns => ns.Type == HtmlTokenType.Bang && NextIs(HtmlTokenType.CloseAngle)))
+ else if (NextIs(ns => ns.Kind == SyntaxKind.Bang && NextIs(SyntaxKind.CloseAngle)))
{
// This is condition 2.2.3
isValidComment = false;
return true;
}
}
- else if (token.Type == HtmlTokenType.OpenAngle)
+ else if (token.Kind == SyntaxKind.OpenAngle)
{
// Checking condition 2.2.1
- if (NextIs(ns => ns.Type == HtmlTokenType.Bang && NextIs(HtmlTokenType.DoubleHyphen)))
+ if (NextIs(ns => ns.Kind == SyntaxKind.Bang && NextIs(SyntaxKind.DoubleHyphen)))
{
isValidComment = false;
return true;
@@ -653,13 +662,13 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
///
/// Verifies, that the sequence doesn't end with the "<!-" HtmlTokens. Note, the first token is an opening bracket token
///
- internal static bool IsCommentContentEndingInvalid(IEnumerable sequence)
+ internal static bool IsCommentContentEndingInvalid(IEnumerable sequence)
{
var reversedSequence = sequence.Reverse();
var index = 0;
foreach (var item in reversedSequence)
{
- if (!item.Equals(nonAllowedHtmlCommentEnding[index++]))
+ if (!item.IsEquivalentTo(nonAllowedHtmlCommentEnding[index++]))
{
return false;
}
@@ -675,13 +684,13 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private bool CData()
{
- if (CurrentToken.Type == HtmlTokenType.Text && string.Equals(CurrentToken.Content, "cdata", StringComparison.OrdinalIgnoreCase))
+ if (CurrentToken.Kind == SyntaxKind.Text && string.Equals(CurrentToken.Content, "cdata", StringComparison.OrdinalIgnoreCase))
{
if (AcceptAndMoveNext())
{
- if (CurrentToken.Type == HtmlTokenType.LeftBracket)
+ if (CurrentToken.Kind == SyntaxKind.LeftBracket)
{
- return AcceptUntilAll(HtmlTokenType.RightBracket, HtmlTokenType.RightBracket, HtmlTokenType.CloseAngle);
+ return AcceptUntilAll(SyntaxKind.RightBracket, SyntaxKind.RightBracket, SyntaxKind.CloseAngle);
}
}
}
@@ -690,11 +699,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
}
private bool EndTag(SourceLocation tagStart,
- Stack> tags,
+ Stack> tags,
IDisposable tagBlockWrapper)
{
// Accept "/" and move next
- Assert(HtmlTokenType.ForwardSlash);
+ Assert(SyntaxKind.ForwardSlash);
var forwardSlash = CurrentToken;
if (!NextToken())
{
@@ -705,20 +714,20 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
else
{
var tagName = string.Empty;
- HtmlToken bangToken = null;
+ SyntaxToken bangToken = null;
- if (At(HtmlTokenType.Bang))
+ if (At(SyntaxKind.Bang))
{
bangToken = CurrentToken;
var nextToken = Lookahead(count: 1);
- if (nextToken != null && nextToken.Type == HtmlTokenType.Text)
+ if (nextToken != null && nextToken.Kind == SyntaxKind.Text)
{
tagName = "!" + nextToken.Content;
}
}
- else if (At(HtmlTokenType.Text))
+ else if (At(SyntaxKind.Text))
{
tagName = CurrentToken.Content;
}
@@ -738,32 +747,32 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
OptionalBangEscape();
- AcceptUntil(HtmlTokenType.CloseAngle);
+ AcceptUntil(SyntaxKind.CloseAngle);
// Accept the ">"
- return Optional(HtmlTokenType.CloseAngle);
+ return Optional(SyntaxKind.CloseAngle);
}
}
private void RecoverTextTag()
{
// We don't want to skip-to and parse because there shouldn't be anything in the body of text tags.
- AcceptUntil(HtmlTokenType.CloseAngle, HtmlTokenType.NewLine);
+ AcceptUntil(SyntaxKind.CloseAngle, SyntaxKind.NewLine);
// Include the close angle in the text tag block if it's there, otherwise just move on
- Optional(HtmlTokenType.CloseAngle);
+ Optional(SyntaxKind.CloseAngle);
}
- private bool EndTextTag(HtmlToken solidus, IDisposable tagBlockWrapper)
+ private bool EndTextTag(SyntaxToken solidus, IDisposable tagBlockWrapper)
{
Accept(_bufferedOpenAngle);
Accept(solidus);
var textLocation = CurrentStart;
- Assert(HtmlTokenType.Text);
+ Assert(SyntaxKind.Text);
AcceptAndMoveNext();
- var seenCloseAngle = Optional(HtmlTokenType.CloseAngle);
+ var seenCloseAngle = Optional(SyntaxKind.CloseAngle);
if (!seenCloseAngle)
{
@@ -791,32 +800,32 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
get
{
- if (At(HtmlTokenType.OpenAngle))
+ if (At(SyntaxKind.OpenAngle))
{
- if (NextIs(HtmlTokenType.Bang))
+ if (NextIs(SyntaxKind.Bang))
{
return !IsBangEscape(lookahead: 1);
}
- return NextIs(HtmlTokenType.QuestionMark);
+ return NextIs(SyntaxKind.QuestionMark);
}
return false;
}
}
- private bool IsTagRecoveryStopPoint(HtmlToken token)
+ private bool IsTagRecoveryStopPoint(SyntaxToken token)
{
- return token.Type == HtmlTokenType.CloseAngle ||
- token.Type == HtmlTokenType.ForwardSlash ||
- token.Type == HtmlTokenType.OpenAngle ||
- token.Type == HtmlTokenType.SingleQuote ||
- token.Type == HtmlTokenType.DoubleQuote;
+ return token.Kind == SyntaxKind.CloseAngle ||
+ token.Kind == SyntaxKind.ForwardSlash ||
+ token.Kind == SyntaxKind.OpenAngle ||
+ token.Kind == SyntaxKind.SingleQuote ||
+ token.Kind == SyntaxKind.DoubleQuote;
}
private void TagContent()
{
- if (!At(HtmlTokenType.WhiteSpace) && !At(HtmlTokenType.NewLine))
+ if (!At(SyntaxKind.Whitespace) && !At(SyntaxKind.NewLine))
{
// We should be right after the tag name, so if there's no whitespace or new line, something is wrong
RecoverToEndOfTag();
@@ -833,9 +842,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private bool IsEndOfTag()
{
- if (At(HtmlTokenType.ForwardSlash))
+ if (At(SyntaxKind.ForwardSlash))
{
- if (NextIs(HtmlTokenType.CloseAngle))
+ if (NextIs(SyntaxKind.CloseAngle))
{
return true;
}
@@ -844,16 +853,16 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
AcceptAndMoveNext();
}
}
- return At(HtmlTokenType.CloseAngle) || At(HtmlTokenType.OpenAngle);
+ return At(SyntaxKind.CloseAngle) || At(SyntaxKind.OpenAngle);
}
private void BeforeAttribute()
{
// http://dev.w3.org/html5/spec/tokenization.html#before-attribute-name-state
// Capture whitespace
- var whitespace = ReadWhile(token => token.Type == HtmlTokenType.WhiteSpace || token.Type == HtmlTokenType.NewLine);
+ var whitespace = ReadWhile(token => token.Kind == SyntaxKind.Whitespace || token.Kind == SyntaxKind.NewLine);
- if (At(HtmlTokenType.Transition))
+ if (At(SyntaxKind.Transition) || At(SyntaxKind.RazorCommentTransition))
{
// Transition outside of attribute value => Switch to recovery mode
Accept(whitespace);
@@ -863,21 +872,21 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
// http://dev.w3.org/html5/spec/tokenization.html#attribute-name-state
// Read the 'name' (i.e. read until the '=' or whitespace/newline)
- var name = Enumerable.Empty();
- var whitespaceAfterAttributeName = Enumerable.Empty();
+ var name = Enumerable.Empty();
+ var whitespaceAfterAttributeName = Enumerable.Empty();
if (IsValidAttributeNameToken(CurrentToken))
{
name = ReadWhile(token =>
- token.Type != HtmlTokenType.WhiteSpace &&
- token.Type != HtmlTokenType.NewLine &&
- token.Type != HtmlTokenType.Equals &&
- token.Type != HtmlTokenType.CloseAngle &&
- token.Type != HtmlTokenType.OpenAngle &&
- (token.Type != HtmlTokenType.ForwardSlash || !NextIs(HtmlTokenType.CloseAngle)));
+ token.Kind != SyntaxKind.Whitespace &&
+ token.Kind != SyntaxKind.NewLine &&
+ token.Kind != SyntaxKind.Equals &&
+ token.Kind != SyntaxKind.CloseAngle &&
+ token.Kind != SyntaxKind.OpenAngle &&
+ (token.Kind != SyntaxKind.ForwardSlash || !NextIs(SyntaxKind.CloseAngle)));
// capture whitespace after attribute name (if any)
whitespaceAfterAttributeName = ReadWhile(
- token => token.Type == HtmlTokenType.WhiteSpace || token.Type == HtmlTokenType.NewLine);
+ token => token.Kind == SyntaxKind.Whitespace || token.Kind == SyntaxKind.NewLine);
}
else
{
@@ -887,7 +896,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return;
}
- if (!At(HtmlTokenType.Equals))
+ if (!At(SyntaxKind.Equals))
{
// Minimized attribute
@@ -922,13 +931,13 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
}
private void AttributePrefix(
- IEnumerable whitespace,
- IEnumerable nameTokens,
- IEnumerable whitespaceAfterAttributeName)
+ IEnumerable whitespace,
+ IEnumerable nameTokens,
+ IEnumerable whitespaceAfterAttributeName)
{
// First, determine if this is a 'data-' attribute (since those can't use conditional attributes)
var name = string.Concat(nameTokens.Select(s => s.Content));
- var attributeCanBeConditional =
+ var attributeCanBeConditional =
Context.FeatureFlags.EXPERIMENTAL_AllowConditionalDataDashAttributes ||
!name.StartsWith("data-", StringComparison.OrdinalIgnoreCase);
@@ -938,16 +947,16 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
// Since this is not a minimized attribute, the whitespace after attribute name belongs to this attribute.
Accept(whitespaceAfterAttributeName);
- Assert(HtmlTokenType.Equals); // We should be at "="
+ Assert(SyntaxKind.Equals); // We should be at "="
AcceptAndMoveNext();
- var whitespaceAfterEquals = ReadWhile(token => token.Type == HtmlTokenType.WhiteSpace || token.Type == HtmlTokenType.NewLine);
- var quote = HtmlTokenType.Unknown;
- if (At(HtmlTokenType.SingleQuote) || At(HtmlTokenType.DoubleQuote))
+ var whitespaceAfterEquals = ReadWhile(token => token.Kind == SyntaxKind.Whitespace || token.Kind == SyntaxKind.NewLine);
+ var quote = SyntaxKind.Unknown;
+ if (At(SyntaxKind.SingleQuote) || At(SyntaxKind.DoubleQuote))
{
// Found a quote, the whitespace belongs to this attribute.
Accept(whitespaceAfterEquals);
- quote = CurrentToken.Type;
+ quote = CurrentToken.Kind;
AcceptAndMoveNext();
}
else if (whitespaceAfterEquals.Any())
@@ -967,7 +976,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
// Read the attribute value only if the value is quoted
// or if there is no whitespace between '=' and the unquoted value.
- if (quote != HtmlTokenType.Unknown || !whitespaceAfterEquals.Any())
+ if (quote != SyntaxKind.Unknown || !whitespaceAfterEquals.Any())
{
// Read the attribute value.
while (!EndOfFile && !IsEndOfAttributeValue(quote, CurrentToken))
@@ -978,7 +987,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
// Capture the suffix
var suffix = new LocationTagged(string.Empty, CurrentStart);
- if (quote != HtmlTokenType.Unknown && At(quote))
+ if (quote != SyntaxKind.Unknown && At(quote))
{
suffix = new LocationTagged(CurrentToken.Content, CurrentStart);
AcceptAndMoveNext();
@@ -1000,7 +1009,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
// Output the attribute name, the equals and optional quote. Ex: foo="
Output(SpanKindInternal.Markup);
- if (quote == HtmlTokenType.Unknown && whitespaceAfterEquals.Any())
+ if (quote == SyntaxKind.Unknown && whitespaceAfterEquals.Any())
{
return;
}
@@ -1011,7 +1020,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
// Output the attribute value (will include everything in-between the attribute's quotes).
Output(SpanKindInternal.Markup);
- if (quote != HtmlTokenType.Unknown)
+ if (quote != SyntaxKind.Unknown)
{
Optional(quote);
}
@@ -1019,14 +1028,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
}
}
- private void AttributeValue(HtmlTokenType quote)
+ private void AttributeValue(SyntaxKind quote)
{
var prefixStart = CurrentStart;
- var prefix = ReadWhile(token => token.Type == HtmlTokenType.WhiteSpace || token.Type == HtmlTokenType.NewLine);
+ var prefix = ReadWhile(token => token.Kind == SyntaxKind.Whitespace || token.Kind == SyntaxKind.NewLine);
- if (At(HtmlTokenType.Transition))
+ if (At(SyntaxKind.Transition))
{
- if (NextIs(HtmlTokenType.Transition))
+ if (NextIs(SyntaxKind.Transition))
{
// Wrapping this in a block so that the ConditionalAttributeCollapser doesn't rewrite it.
using (Context.Builder.StartBlock(BlockKindInternal.Markup))
@@ -1076,9 +1085,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
var valueStart = CurrentStart;
var value = ReadWhile(token =>
// These three conditions find separators which break the attribute value into portions
- token.Type != HtmlTokenType.WhiteSpace &&
- token.Type != HtmlTokenType.NewLine &&
- token.Type != HtmlTokenType.Transition &&
+ token.Kind != SyntaxKind.Whitespace &&
+ token.Kind != SyntaxKind.NewLine &&
+ token.Kind != SyntaxKind.Transition &&
// This condition checks for the end of the attribute value (it repeats some of the checks above
// but for now that's ok)
!IsEndOfAttributeValue(quote, token));
@@ -1090,27 +1099,27 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
Output(SpanKindInternal.Markup);
}
- private bool IsEndOfAttributeValue(HtmlTokenType quote, HtmlToken token)
+ private bool IsEndOfAttributeValue(SyntaxKind quote, SyntaxToken token)
{
return EndOfFile || token == null ||
- (quote != HtmlTokenType.Unknown
- ? token.Type == quote // If quoted, just wait for the quote
+ (quote != SyntaxKind.Unknown
+ ? token.Kind == quote // If quoted, just wait for the quote
: IsUnquotedEndOfAttributeValue(token));
}
- private bool IsUnquotedEndOfAttributeValue(HtmlToken token)
+ private bool IsUnquotedEndOfAttributeValue(SyntaxToken token)
{
// If unquoted, we have a larger set of terminating characters:
// http://dev.w3.org/html5/spec/tokenization.html#attribute-value-unquoted-state
// Also we need to detect "/" and ">"
- return token.Type == HtmlTokenType.DoubleQuote ||
- token.Type == HtmlTokenType.SingleQuote ||
- token.Type == HtmlTokenType.OpenAngle ||
- token.Type == HtmlTokenType.Equals ||
- (token.Type == HtmlTokenType.ForwardSlash && NextIs(HtmlTokenType.CloseAngle)) ||
- token.Type == HtmlTokenType.CloseAngle ||
- token.Type == HtmlTokenType.WhiteSpace ||
- token.Type == HtmlTokenType.NewLine;
+ return token.Kind == SyntaxKind.DoubleQuote ||
+ token.Kind == SyntaxKind.SingleQuote ||
+ token.Kind == SyntaxKind.OpenAngle ||
+ token.Kind == SyntaxKind.Equals ||
+ (token.Kind == SyntaxKind.ForwardSlash && NextIs(SyntaxKind.CloseAngle)) ||
+ token.Kind == SyntaxKind.CloseAngle ||
+ token.Kind == SyntaxKind.Whitespace ||
+ token.Kind == SyntaxKind.NewLine;
}
private void RecoverToEndOfTag()
@@ -1122,17 +1131,17 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
if (!EndOfFile)
{
EnsureCurrent();
- switch (CurrentToken.Type)
+ switch (CurrentToken.Kind)
{
- case HtmlTokenType.SingleQuote:
- case HtmlTokenType.DoubleQuote:
+ case SyntaxKind.SingleQuote:
+ case SyntaxKind.DoubleQuote:
ParseQuoted();
break;
- case HtmlTokenType.OpenAngle:
+ case SyntaxKind.OpenAngle:
// Another "<" means this tag is invalid.
- case HtmlTokenType.ForwardSlash:
+ case SyntaxKind.ForwardSlash:
// Empty tag
- case HtmlTokenType.CloseAngle:
+ case SyntaxKind.CloseAngle:
// End of tag
return;
default:
@@ -1145,12 +1154,12 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private void ParseQuoted()
{
- var type = CurrentToken.Type;
+ var type = CurrentToken.Kind;
AcceptAndMoveNext();
ParseQuoted(type);
}
- private void ParseQuoted(HtmlTokenType type)
+ private void ParseQuoted(SyntaxKind type)
{
SkipToAndParseCode(type);
if (!EndOfFile)
@@ -1160,12 +1169,12 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
}
}
- private bool StartTag(Stack> tags, IDisposable tagBlockWrapper)
+ private bool StartTag(Stack> tags, IDisposable tagBlockWrapper)
{
- HtmlToken bangToken = null;
- HtmlToken potentialTagNameToken;
+ SyntaxToken bangToken = null;
+ SyntaxToken potentialTagNameToken;
- if (At(HtmlTokenType.Bang))
+ if (At(SyntaxKind.Bang))
{
bangToken = CurrentToken;
@@ -1176,22 +1185,22 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
potentialTagNameToken = CurrentToken;
}
- HtmlToken tagName;
+ SyntaxToken tagName;
- if (potentialTagNameToken == null || potentialTagNameToken.Type != HtmlTokenType.Text)
+ if (potentialTagNameToken == null || potentialTagNameToken.Kind != SyntaxKind.Text)
{
- tagName = new HtmlToken(string.Empty, HtmlTokenType.Unknown);
+ tagName = SyntaxFactory.Token(SyntaxKind.Unknown, string.Empty);
}
else if (bangToken != null)
{
- tagName = new HtmlToken("!" + potentialTagNameToken.Content, HtmlTokenType.Text);
+ tagName = SyntaxFactory.Token(SyntaxKind.Text, "!" + potentialTagNameToken.Content);
}
else
{
tagName = potentialTagNameToken;
}
- Tuple tag = Tuple.Create(tagName, _lastTagStart);
+ var tag = Tuple.Create(tagName, _lastTagStart);
if (tags.Count == 0 &&
// Note tagName may contain a '!' escape character. This ensures doesn't match here.
@@ -1203,23 +1212,23 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
Accept(_bufferedOpenAngle);
var textLocation = CurrentStart;
- Assert(HtmlTokenType.Text);
+ Assert(SyntaxKind.Text);
AcceptAndMoveNext();
var bookmark = CurrentStart.AbsoluteIndex;
- IEnumerable tokens = ReadWhile(IsSpacingToken(includeNewLines: true));
- var empty = At(HtmlTokenType.ForwardSlash);
+ var tokens = ReadWhile(IsSpacingToken(includeNewLines: true));
+ var empty = At(SyntaxKind.ForwardSlash);
if (empty)
{
Accept(tokens);
- Assert(HtmlTokenType.ForwardSlash);
+ Assert(SyntaxKind.ForwardSlash);
AcceptAndMoveNext();
bookmark = CurrentStart.AbsoluteIndex;
tokens = ReadWhile(IsSpacingToken(includeNewLines: true));
}
- if (!Optional(HtmlTokenType.CloseAngle))
+ if (!Optional(SyntaxKind.CloseAngle))
{
Context.Source.Position = bookmark;
NextToken();
@@ -1247,24 +1256,24 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
Accept(_bufferedOpenAngle);
OptionalBangEscape();
- Optional(HtmlTokenType.Text);
+ Optional(SyntaxKind.Text);
return RestOfTag(tag, tags, tagBlockWrapper);
}
- private bool RestOfTag(Tuple tag,
- Stack> tags,
+ private bool RestOfTag(Tuple tag,
+ Stack> tags,
IDisposable tagBlockWrapper)
{
TagContent();
// We are now at a possible end of the tag
// Found '<', so we just abort this tag.
- if (At(HtmlTokenType.OpenAngle))
+ if (At(SyntaxKind.OpenAngle))
{
return false;
}
- var isEmpty = At(HtmlTokenType.ForwardSlash);
+ var isEmpty = At(SyntaxKind.ForwardSlash);
// Found a solidus, so don't accept it but DON'T push the tag to the stack
if (isEmpty)
{
@@ -1272,7 +1281,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
}
// Check for the '>' to determine if the tag is finished
- var seenClose = Optional(HtmlTokenType.CloseAngle);
+ var seenClose = Optional(SyntaxKind.CloseAngle);
if (!seenClose)
{
Context.ErrorSink.OnError(
@@ -1298,17 +1307,17 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
var bookmark = CurrentStart.AbsoluteIndex;
// Skip whitespace
- IEnumerable whiteSpace = ReadWhile(IsSpacingToken(includeNewLines: true));
+ var whiteSpace = ReadWhile(IsSpacingToken(includeNewLines: true));
// Open Angle
- if (At(HtmlTokenType.OpenAngle) && NextIs(HtmlTokenType.ForwardSlash))
+ if (At(SyntaxKind.OpenAngle) && NextIs(SyntaxKind.ForwardSlash))
{
var openAngle = CurrentToken;
NextToken();
- Assert(HtmlTokenType.ForwardSlash);
+ Assert(SyntaxKind.ForwardSlash);
var solidus = CurrentToken;
NextToken();
- if (At(HtmlTokenType.Text) && string.Equals(CurrentToken.Content, tagName, StringComparison.OrdinalIgnoreCase))
+ if (At(SyntaxKind.Text) && string.Equals(CurrentToken.Content, tagName, StringComparison.OrdinalIgnoreCase))
{
// Accept up to here
Accept(whiteSpace);
@@ -1321,9 +1330,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
AcceptAndMoveNext();
// Accept to '>', '<' or EOF
- AcceptUntil(HtmlTokenType.CloseAngle, HtmlTokenType.OpenAngle);
+ AcceptUntil(SyntaxKind.CloseAngle, SyntaxKind.OpenAngle);
// Accept the '>' if we saw it. And if we do see it, we're complete
- var complete = Optional(HtmlTokenType.CloseAngle);
+ var complete = Optional(SyntaxKind.CloseAngle);
if (complete)
{
@@ -1373,17 +1382,17 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
while (!seenEndScript && !EndOfFile)
{
- SkipToAndParseCode(HtmlTokenType.OpenAngle);
+ SkipToAndParseCode(SyntaxKind.OpenAngle);
var tagStart = CurrentStart;
- if (NextIs(HtmlTokenType.ForwardSlash))
+ if (NextIs(SyntaxKind.ForwardSlash))
{
var openAngle = CurrentToken;
NextToken(); // Skip over '<', current is '/'
var solidus = CurrentToken;
NextToken(); // Skip over '/', current should be text
- if (At(HtmlTokenType.Text) &&
+ if (At(SyntaxKind.Text) &&
string.Equals(CurrentToken.Content, ScriptTagName, StringComparison.OrdinalIgnoreCase))
{
seenEndScript = true;
@@ -1409,8 +1418,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
AcceptAndMoveNext(); // '<'
AcceptAndMoveNext(); // '/'
- SkipToAndParseCode(HtmlTokenType.CloseAngle);
- if (!Optional(HtmlTokenType.CloseAngle))
+ SkipToAndParseCode(SyntaxKind.CloseAngle);
+ if (!Optional(SyntaxKind.CloseAngle))
{
Context.ErrorSink.OnError(
RazorDiagnosticFactory.CreateParsing_UnfinishedTag(
@@ -1441,7 +1450,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
tagBlockWrapper.Dispose();
}
- private bool AcceptUntilAll(params HtmlTokenType[] endSequence)
+ private bool AcceptUntilAll(params SyntaxKind[] endSequence)
{
while (!EndOfFile)
{
@@ -1456,9 +1465,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return false;
}
- private bool RemoveTag(Stack> tags, string tagName, SourceLocation tagStart)
+ private bool RemoveTag(Stack> tags, string tagName, SourceLocation tagStart)
{
- Tuple currentTag = null;
+ Tuple currentTag = null;
while (tags.Count > 0)
{
currentTag = tags.Pop();
@@ -1486,7 +1495,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return false;
}
- private void EndTagBlock(Stack> tags, bool complete)
+ private void EndTagBlock(Stack> tags, bool complete)
{
if (tags.Count > 0)
{
@@ -1515,11 +1524,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
if (Context.Builder.LastSpan.Kind == SpanKindInternal.Transition)
{
var tokens = ReadWhile(
- f => (f.Type == HtmlTokenType.WhiteSpace) || (f.Type == HtmlTokenType.NewLine));
+ f => (f.Kind == SyntaxKind.Whitespace) || (f.Kind == SyntaxKind.NewLine));
// Make sure the current token is not markup, which can be html start tag or @:
- if (!(At(HtmlTokenType.OpenAngle) ||
- (At(HtmlTokenType.Transition) && Lookahead(count: 1).Content.StartsWith(":"))))
+ if (!(At(SyntaxKind.OpenAngle) ||
+ (At(SyntaxKind.Transition) && Lookahead(count: 1).Content.StartsWith(":"))))
{
// Don't accept whitespace as markup if the end text tag is followed by csharp.
shouldAcceptWhitespaceAndNewLine = false;
@@ -1533,14 +1542,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
if (shouldAcceptWhitespaceAndNewLine)
{
// Accept whitespace and a single newline if present
- AcceptWhile(HtmlTokenType.WhiteSpace);
- Optional(HtmlTokenType.NewLine);
+ AcceptWhile(SyntaxKind.Whitespace);
+ Optional(SyntaxKind.NewLine);
}
}
else if (Span.EditHandler.AcceptedCharacters == AcceptedCharactersInternal.Any)
{
- AcceptWhile(HtmlTokenType.WhiteSpace);
- Optional(HtmlTokenType.NewLine);
+ AcceptWhile(SyntaxKind.Whitespace);
+ Optional(SyntaxKind.NewLine);
}
PutCurrentBack();
@@ -1551,7 +1560,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
Output(SpanKindInternal.Markup);
}
- internal static bool IsValidAttributeNameToken(HtmlToken token)
+ internal static bool IsValidAttributeNameToken(SyntaxToken token)
{
if (token == null)
{
@@ -1562,16 +1571,16 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
// However, it's not all of it. For instance we don't special case control characters or allow OpenAngle.
// It also doesn't try to exclude Razor specific features such as the @ transition. This is based on the
// expectation that the parser handles such scenarios prior to falling through to name resolution.
- var tokenType = token.Type;
- return tokenType != HtmlTokenType.WhiteSpace &&
- tokenType != HtmlTokenType.NewLine &&
- tokenType != HtmlTokenType.CloseAngle &&
- tokenType != HtmlTokenType.OpenAngle &&
- tokenType != HtmlTokenType.ForwardSlash &&
- tokenType != HtmlTokenType.DoubleQuote &&
- tokenType != HtmlTokenType.SingleQuote &&
- tokenType != HtmlTokenType.Equals &&
- tokenType != HtmlTokenType.Unknown;
+ var tokenType = token.Kind;
+ return tokenType != SyntaxKind.Whitespace &&
+ tokenType != SyntaxKind.NewLine &&
+ tokenType != SyntaxKind.CloseAngle &&
+ tokenType != SyntaxKind.OpenAngle &&
+ tokenType != SyntaxKind.ForwardSlash &&
+ tokenType != SyntaxKind.DoubleQuote &&
+ tokenType != SyntaxKind.SingleQuote &&
+ tokenType != SyntaxKind.Equals &&
+ tokenType != SyntaxKind.Unknown;
}
public void ParseDocument()
@@ -1587,10 +1596,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
Span.Start = CurrentLocation;
+ ParserState = ParserState.Misc;
NextToken();
while (!EndOfFile)
{
- SkipToAndParseCode(HtmlTokenType.OpenAngle);
+ SkipToAndParseCode(SyntaxKind.OpenAngle);
ScanTagInDocumentContext();
}
AddMarkerTokenIfNecessary();
@@ -1605,14 +1615,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
///
private void ScanTagInDocumentContext()
{
- if (At(HtmlTokenType.OpenAngle))
+ if (At(SyntaxKind.OpenAngle))
{
- if (NextIs(HtmlTokenType.Bang))
+ if (NextIs(SyntaxKind.Bang))
{
// Checking to see if we meet the conditions of a special '!' tag: ';" as an HTML tag.
@@ -1667,13 +1687,15 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
// Parsing an end tag
// This section can accept things like: '
' or '' etc.
- Optional(HtmlTokenType.ForwardSlash);
+ ParserState = ParserState.EndTag;
+ Optional(SyntaxKind.ForwardSlash);
// Whitespace here is invalid (according to the spec)
OptionalBangEscape();
- Optional(HtmlTokenType.Text);
- Optional(HtmlTokenType.WhiteSpace);
- Optional(HtmlTokenType.CloseAngle);
+ Optional(SyntaxKind.Text);
+ Optional(SyntaxKind.Whitespace);
+ Optional(SyntaxKind.CloseAngle);
+ ParserState = ParserState.Content;
}
Output(SpanKindInternal.Markup);
@@ -1714,9 +1736,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private static bool IsTypeAttribute(Block block)
{
- var span = block.Children.First() as Span;
- if (span == null)
+ if (!(block.Children.First() is Span span))
{
return false;
}
@@ -1765,7 +1786,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
do
{
- SkipToAndParseCode(token => token.Type == HtmlTokenType.OpenAngle || AtEnd(nestingSequenceComponents));
+ SkipToAndParseCode(token => token.Kind == SyntaxKind.OpenAngle || AtEnd(nestingSequenceComponents));
ScanTagInDocumentContext();
if (!EndOfFile && AtEnd(nestingSequenceComponents))
{
@@ -1783,9 +1804,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
while (nesting > 0 && !EndOfFile)
{
SkipToAndParseCode(token =>
- token.Type == HtmlTokenType.Text ||
- token.Type == HtmlTokenType.OpenAngle);
- if (At(HtmlTokenType.Text))
+ token.Kind == SyntaxKind.Text ||
+ token.Kind == SyntaxKind.OpenAngle);
+ if (At(SyntaxKind.Text))
{
nesting += ProcessTextToken(nestingSequences, nesting);
if (CurrentToken != null)
@@ -1812,7 +1833,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
var bookmark = Context.Source.Position - CurrentToken.Content.Length;
try
{
- foreach (string component in nestingSequenceComponents)
+ foreach (var component in nestingSequenceComponents)
{
if (!EndOfFile && !string.Equals(CurrentToken.Content, component, Comparison))
{
@@ -1837,7 +1858,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private int ProcessTextToken(Tuple nestingSequences, int currentNesting)
{
- for (int i = 0; i < CurrentToken.Content.Length; i++)
+ for (var i = 0; i < CurrentToken.Content.Length; i++)
{
var nestingDelta = HandleNestingSequence(nestingSequences.Item1, i, currentNesting, 1);
if (nestingDelta == 0)
@@ -1868,10 +1889,10 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
PutCurrentBack();
// Carve up the token
- Tuple pair = Language.SplitToken(token, position, HtmlTokenType.Text);
+ var pair = Language.SplitToken(token, position, SyntaxKind.Text);
var preSequence = pair.Item1;
Debug.Assert(pair.Item2 != null);
- pair = Language.SplitToken(pair.Item2, sequence.Length, HtmlTokenType.Text);
+ pair = Language.SplitToken(pair.Item2, sequence.Length, SyntaxKind.Text);
var sequenceToken = pair.Item1;
var postSequence = pair.Item2;
var postSequenceBookmark = bookmark.AbsoluteIndex + preSequence.Content.Length + pair.Item1.Content.Length;
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/HtmlToken.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/HtmlToken.cs
deleted file mode 100644
index 2d52ed14e2..0000000000
--- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/HtmlToken.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System;
-using System.Collections.Generic;
-
-namespace Microsoft.AspNetCore.Razor.Language.Legacy
-{
- internal class HtmlToken : TokenBase
- {
- internal static readonly HtmlToken Hyphen = new HtmlToken("-", HtmlTokenType.Text);
-
- public HtmlToken(string content, HtmlTokenType type)
- : base(content, type, RazorDiagnostic.EmptyArray)
- {
- if (content == null)
- {
- throw new ArgumentNullException(nameof(content));
- }
- }
-
- public HtmlToken(
- string content,
- HtmlTokenType type,
- IReadOnlyList errors)
- : base(content, type, errors)
- {
- if (content == null)
- {
- throw new ArgumentNullException(nameof(content));
- }
- }
- }
-}
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/HtmlTokenType.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/HtmlTokenType.cs
deleted file mode 100644
index 82d96d7ebc..0000000000
--- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/HtmlTokenType.cs
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System;
-
-namespace Microsoft.AspNetCore.Razor.Language.Legacy
-{
- [Flags]
- internal enum HtmlTokenType
- {
- Unknown,
- Text, // Text which isn't one of the below
- WhiteSpace, // Non-newline Whitespace
- NewLine, // Newline
- OpenAngle, // <
- Bang, // !
- ForwardSlash, // /
- QuestionMark, // ?
- DoubleHyphen, // --
- LeftBracket, // [
- CloseAngle, // >
- RightBracket, // ]
- Equals, // =
- DoubleQuote, // "
- SingleQuote, // '
- Transition, // @
- Colon,
- RazorComment,
- RazorCommentStar,
- RazorCommentTransition
- }
-}
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/HtmlTokenizer.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/HtmlTokenizer.cs
index 99a7152447..bc55f991a1 100644
--- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/HtmlTokenizer.cs
+++ b/src/Microsoft.AspNetCore.Razor.Language/Legacy/HtmlTokenizer.cs
@@ -3,11 +3,12 @@
using System.Collections.Generic;
using System.Diagnostics;
+using Microsoft.AspNetCore.Razor.Language.Syntax.InternalSyntax;
namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
// Tokenizer _loosely_ based on http://dev.w3.org/html5/spec/Overview.html#tokenization
- internal class HtmlTokenizer : Tokenizer
+ internal class HtmlTokenizer : Tokenizer
{
private const char TransitionChar = '@';
@@ -21,24 +22,24 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private new HtmlTokenizerState? CurrentState => (HtmlTokenizerState?)base.CurrentState;
- public override HtmlTokenType RazorCommentType
+ public override SyntaxKind RazorCommentKind
{
- get { return HtmlTokenType.RazorComment; }
+ get { return SyntaxKind.RazorCommentLiteral; }
}
- public override HtmlTokenType RazorCommentTransitionType
+ public override SyntaxKind RazorCommentTransitionKind
{
- get { return HtmlTokenType.RazorCommentTransition; }
+ get { return SyntaxKind.RazorCommentTransition; }
}
- public override HtmlTokenType RazorCommentStarType
+ public override SyntaxKind RazorCommentStarKind
{
- get { return HtmlTokenType.RazorCommentStar; }
+ get { return SyntaxKind.RazorCommentStar; }
}
- protected override HtmlToken CreateToken(string content, HtmlTokenType type, IReadOnlyList errors)
+ protected override SyntaxToken CreateToken(string content, SyntaxKind type, IReadOnlyList errors)
{
- return new HtmlToken(content, type, errors);
+ return SyntaxFactory.Token(type, content, errors);
}
protected override StateResult Dispatch()
@@ -66,7 +67,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
}
// Optimize memory allocation by returning constants for the most frequent cases
- protected override string GetTokenContent(HtmlTokenType type)
+ protected override string GetTokenContent(SyntaxKind type)
{
var tokenLength = Buffer.Length;
@@ -74,27 +75,27 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
switch (type)
{
- case HtmlTokenType.OpenAngle:
+ case SyntaxKind.OpenAngle:
return "<";
- case HtmlTokenType.Bang:
+ case SyntaxKind.Bang:
return "!";
- case HtmlTokenType.ForwardSlash:
+ case SyntaxKind.ForwardSlash:
return "/";
- case HtmlTokenType.QuestionMark:
+ case SyntaxKind.QuestionMark:
return "?";
- case HtmlTokenType.LeftBracket:
+ case SyntaxKind.LeftBracket:
return "[";
- case HtmlTokenType.CloseAngle:
+ case SyntaxKind.CloseAngle:
return ">";
- case HtmlTokenType.RightBracket:
+ case SyntaxKind.RightBracket:
return "]";
- case HtmlTokenType.Equals:
+ case SyntaxKind.Equals:
return "=";
- case HtmlTokenType.DoubleQuote:
+ case SyntaxKind.DoubleQuote:
return "\"";
- case HtmlTokenType.SingleQuote:
+ case SyntaxKind.SingleQuote:
return "'";
- case HtmlTokenType.WhiteSpace:
+ case SyntaxKind.Whitespace:
if (Buffer[0] == ' ')
{
return " ";
@@ -104,7 +105,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return "\t";
}
break;
- case HtmlTokenType.NewLine:
+ case SyntaxKind.NewLine:
if (Buffer[0] == '\n')
{
return "\n";
@@ -113,7 +114,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
}
}
- if (tokenLength == 2 && type == HtmlTokenType.NewLine)
+ if (tokenLength == 2 && type == SyntaxKind.NewLine)
{
return "\r\n";
}
@@ -139,17 +140,17 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
return Transition(
HtmlTokenizerState.AfterRazorCommentTransition,
- EndToken(HtmlTokenType.RazorCommentTransition));
+ EndToken(SyntaxKind.RazorCommentTransition));
}
else if (CurrentCharacter == '@')
{
// Could be escaped comment transition
return Transition(
HtmlTokenizerState.EscapedRazorCommentTransition,
- EndToken(HtmlTokenType.Transition));
+ EndToken(SyntaxKind.Transition));
}
- return Stay(EndToken(HtmlTokenType.Transition));
+ return Stay(EndToken(SyntaxKind.Transition));
}
else if (AtToken())
{
@@ -164,7 +165,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private StateResult EscapedRazorCommentTransition()
{
TakeCurrent();
- return Transition(HtmlTokenizerState.Data, EndToken(HtmlTokenType.Transition));
+ return Transition(HtmlTokenizerState.Data, EndToken(SyntaxKind.Transition));
}
private StateResult Text()
@@ -190,10 +191,10 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
}
// Output the Text token and return to the Data state to tokenize the next character (if there is one)
- return Transition(HtmlTokenizerState.Data, EndToken(HtmlTokenType.Text));
+ return Transition(HtmlTokenizerState.Data, EndToken(SyntaxKind.Text));
}
- private HtmlToken Token()
+ private SyntaxToken Token()
{
Debug.Assert(AtToken());
var sym = CurrentCharacter;
@@ -201,45 +202,45 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
switch (sym)
{
case '<':
- return EndToken(HtmlTokenType.OpenAngle);
+ return EndToken(SyntaxKind.OpenAngle);
case '!':
- return EndToken(HtmlTokenType.Bang);
+ return EndToken(SyntaxKind.Bang);
case '/':
- return EndToken(HtmlTokenType.ForwardSlash);
+ return EndToken(SyntaxKind.ForwardSlash);
case '?':
- return EndToken(HtmlTokenType.QuestionMark);
+ return EndToken(SyntaxKind.QuestionMark);
case '[':
- return EndToken(HtmlTokenType.LeftBracket);
+ return EndToken(SyntaxKind.LeftBracket);
case '>':
- return EndToken(HtmlTokenType.CloseAngle);
+ return EndToken(SyntaxKind.CloseAngle);
case ']':
- return EndToken(HtmlTokenType.RightBracket);
+ return EndToken(SyntaxKind.RightBracket);
case '=':
- return EndToken(HtmlTokenType.Equals);
+ return EndToken(SyntaxKind.Equals);
case '"':
- return EndToken(HtmlTokenType.DoubleQuote);
+ return EndToken(SyntaxKind.DoubleQuote);
case '\'':
- return EndToken(HtmlTokenType.SingleQuote);
+ return EndToken(SyntaxKind.SingleQuote);
case '-':
Debug.Assert(CurrentCharacter == '-');
TakeCurrent();
- return EndToken(HtmlTokenType.DoubleHyphen);
+ return EndToken(SyntaxKind.DoubleHyphen);
default:
Debug.Fail("Unexpected token!");
- return EndToken(HtmlTokenType.Unknown);
+ return EndToken(SyntaxKind.Unknown);
}
}
- private HtmlToken Whitespace()
+ private SyntaxToken Whitespace()
{
while (ParserHelpers.IsWhitespace(CurrentCharacter))
{
TakeCurrent();
}
- return EndToken(HtmlTokenType.WhiteSpace);
+ return EndToken(SyntaxKind.Whitespace);
}
- private HtmlToken Newline()
+ private SyntaxToken Newline()
{
Debug.Assert(ParserHelpers.IsNewLine(CurrentCharacter));
// CSharp Spec §2.3.1
@@ -249,7 +250,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
TakeCurrent();
}
- return EndToken(HtmlTokenType.NewLine);
+ return EndToken(SyntaxKind.NewLine);
}
private bool AtToken()
@@ -274,7 +275,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return Transition((int)state, result: null);
}
- private StateResult Transition(HtmlTokenizerState state, HtmlToken result)
+ private StateResult Transition(HtmlTokenizerState state, SyntaxToken result)
{
return Transition((int)state, result);
}
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/IToken.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/IToken.cs
deleted file mode 100644
index 2f8eb1214d..0000000000
--- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/IToken.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-namespace Microsoft.AspNetCore.Razor.Language.Legacy
-{
- internal interface IToken
- {
- Span Parent { get; set; }
-
- string Content { get; }
-
- SourceLocation Start { get; }
- }
-}
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/ITokenizer.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/ITokenizer.cs
index 530df75dbc..0dac9f1b4f 100644
--- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/ITokenizer.cs
+++ b/src/Microsoft.AspNetCore.Razor.Language/Legacy/ITokenizer.cs
@@ -1,10 +1,12 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+using Microsoft.AspNetCore.Razor.Language.Syntax.InternalSyntax;
+
namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
internal interface ITokenizer
{
- IToken NextToken();
+ SyntaxToken NextToken();
}
}
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/ImplicitExpressionEditHandler.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/ImplicitExpressionEditHandler.cs
index b3869f00d0..fb9efdc751 100644
--- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/ImplicitExpressionEditHandler.cs
+++ b/src/Microsoft.AspNetCore.Razor.Language/Legacy/ImplicitExpressionEditHandler.cs
@@ -7,6 +7,7 @@ using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
+using Microsoft.AspNetCore.Razor.Language.Syntax;
using Microsoft.Extensions.Internal;
namespace Microsoft.AspNetCore.Razor.Language.Legacy
@@ -16,7 +17,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private readonly ISet _keywords;
private readonly IReadOnlyCollection _readOnlyKeywords;
- public ImplicitExpressionEditHandler(Func> tokenizer, ISet keywords, bool acceptTrailingDot)
+ public ImplicitExpressionEditHandler(Func> tokenizer, ISet keywords, bool acceptTrailingDot)
: base(tokenizer)
{
_keywords = keywords ?? new HashSet();
@@ -172,20 +173,20 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
for (var i = 0; i < target.Tokens.Count; i++)
{
- var token = target.Tokens[i] as CSharpToken;
+ var token = target.Tokens[i];
if (token == null)
{
break;
}
- var tokenStartIndex = token.Start.AbsoluteIndex;
- var tokenEndIndex = tokenStartIndex + token.Content.Length;
+ var tokenStartIndex = token.Position;
+ var tokenEndIndex = token.EndPosition;
// We're looking for the first token that contains the SourceChange.
if (tokenEndIndex > change.Span.AbsoluteIndex)
{
- if (tokenEndIndex >= change.Span.AbsoluteIndex + change.Span.Length && token.Type == CSharpTokenType.Identifier)
+ if (tokenEndIndex >= change.Span.AbsoluteIndex + change.Span.Length && token.Kind == SyntaxKind.Identifier)
{
// The token we're changing happens to be an identifier. Need to check if its transformed state is also one.
// We do this transformation logic to capture the case that the new text change happens to not be an identifier;
@@ -200,8 +201,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
break;
}
- var newToken = (CSharpToken)newTokens.First();
- if (newToken.Type == CSharpTokenType.Identifier)
+ var newToken = newTokens.First();
+ if (newToken.Kind == SyntaxKind.Identifier)
{
return true;
}
@@ -241,8 +242,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
var changeStart = change.Span.AbsoluteIndex;
var changeLength = change.Span.Length;
var changeEnd = changeStart + changeLength;
- var tokens = target.Tokens.Cast().ToArray();
- if (!IsInsideParenthesis(changeStart, tokens) || !IsInsideParenthesis(changeEnd, tokens))
+ if (!IsInsideParenthesis(changeStart, target.Tokens) || !IsInsideParenthesis(changeEnd, target.Tokens))
{
// Either the start or end of the delete does not fall inside of parenthesis, unacceptable inner deletion.
return false;
@@ -274,8 +274,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return false;
}
- var tokens = target.Tokens.Cast().ToArray();
- if (IsInsideParenthesis(change.Span.AbsoluteIndex, tokens))
+ if (IsInsideParenthesis(change.Span.AbsoluteIndex, target.Tokens))
{
return true;
}
@@ -284,7 +283,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
}
// Internal for testing
- internal static bool IsInsideParenthesis(int position, IReadOnlyList tokens)
+ internal static bool IsInsideParenthesis(int position, IReadOnlyList tokens)
{
var balanceCount = 0;
var foundInsertionPoint = false;
@@ -322,9 +321,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
}
// Internal for testing
- internal static bool ContainsPosition(int position, CSharpToken currentToken)
+ internal static bool ContainsPosition(int position, SyntaxToken currentToken)
{
- var tokenStart = currentToken.Start.AbsoluteIndex;
+ var tokenStart = currentToken.Position;
if (tokenStart == position)
{
// Token is exactly at the insertion point.
@@ -342,14 +341,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
}
// Internal for testing
- internal static bool TryUpdateBalanceCount(CSharpToken token, ref int count)
+ internal static bool TryUpdateBalanceCount(SyntaxToken token, ref int count)
{
var updatedCount = count;
- if (token.Type == CSharpTokenType.LeftParenthesis)
+ if (token.Kind == SyntaxKind.LeftParenthesis)
{
updatedCount++;
}
- else if (token.Type == CSharpTokenType.RightParenthesis)
+ else if (token.Kind == SyntaxKind.RightParenthesis)
{
if (updatedCount == 0)
{
@@ -358,7 +357,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
updatedCount--;
}
- else if (token.Type == CSharpTokenType.StringLiteral)
+ else if (token.Kind == SyntaxKind.StringLiteral)
{
var content = token.Content;
if (content.Length > 0 && content[content.Length - 1] != '"')
@@ -370,7 +369,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
}
}
}
- else if (token.Type == CSharpTokenType.CharacterLiteral)
+ else if (token.Kind == SyntaxKind.CharacterLiteral)
{
var content = token.Content;
if (content.Length > 0 && content[content.Length - 1] != '\'')
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/LanguageCharacteristics.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/LanguageCharacteristics.cs
index b12bf612b9..b08bbb0fe1 100644
--- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/LanguageCharacteristics.cs
+++ b/src/Microsoft.AspNetCore.Razor.Language/Legacy/LanguageCharacteristics.cs
@@ -3,30 +3,29 @@
using System;
using System.Collections.Generic;
+using Microsoft.AspNetCore.Razor.Language.Syntax.InternalSyntax;
namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
- internal abstract class LanguageCharacteristics
- where TTokenType : struct
- where TTokenizer : Tokenizer
- where TToken : TokenBase
+ internal abstract class LanguageCharacteristics
+ where TTokenizer : Tokenizer
{
- public abstract string GetSample(TTokenType type);
+ public abstract string GetSample(SyntaxKind type);
public abstract TTokenizer CreateTokenizer(ITextDocument source);
- public abstract TTokenType FlipBracket(TTokenType bracket);
- public abstract TToken CreateMarkerToken();
+ public abstract SyntaxKind FlipBracket(SyntaxKind bracket);
+ public abstract SyntaxToken CreateMarkerToken();
- public virtual IEnumerable TokenizeString(string content)
+ public virtual IEnumerable TokenizeString(string content)
{
return TokenizeString(SourceLocation.Zero, content);
}
- public virtual IEnumerable TokenizeString(SourceLocation start, string input)
+ public virtual IEnumerable TokenizeString(SourceLocation start, string input)
{
using (var reader = new SeekableTextReader(input, start.FilePath))
{
var tok = CreateTokenizer(reader);
- TToken token;
+ SyntaxToken token;
while ((token = tok.NextToken()) != null)
{
yield return token;
@@ -34,76 +33,76 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
}
}
- public virtual bool IsWhiteSpace(TToken token)
+ public virtual bool IsWhiteSpace(SyntaxToken token)
{
return IsKnownTokenType(token, KnownTokenType.WhiteSpace);
}
- public virtual bool IsNewLine(TToken token)
+ public virtual bool IsNewLine(SyntaxToken token)
{
return IsKnownTokenType(token, KnownTokenType.NewLine);
}
- public virtual bool IsIdentifier(TToken token)
+ public virtual bool IsIdentifier(SyntaxToken token)
{
return IsKnownTokenType(token, KnownTokenType.Identifier);
}
- public virtual bool IsKeyword(TToken token)
+ public virtual bool IsKeyword(SyntaxToken token)
{
return IsKnownTokenType(token, KnownTokenType.Keyword);
}
- public virtual bool IsTransition(TToken token)
+ public virtual bool IsTransition(SyntaxToken token)
{
return IsKnownTokenType(token, KnownTokenType.Transition);
}
- public virtual bool IsCommentStart(TToken token)
+ public virtual bool IsCommentStart(SyntaxToken token)
{
return IsKnownTokenType(token, KnownTokenType.CommentStart);
}
- public virtual bool IsCommentStar(TToken token)
+ public virtual bool IsCommentStar(SyntaxToken token)
{
return IsKnownTokenType(token, KnownTokenType.CommentStar);
}
- public virtual bool IsCommentBody(TToken token)
+ public virtual bool IsCommentBody(SyntaxToken token)
{
return IsKnownTokenType(token, KnownTokenType.CommentBody);
}
- public virtual bool IsUnknown(TToken token)
+ public virtual bool IsUnknown(SyntaxToken token)
{
return IsKnownTokenType(token, KnownTokenType.Unknown);
}
- public virtual bool IsKnownTokenType(TToken token, KnownTokenType type)
+ public virtual bool IsKnownTokenType(SyntaxToken token, KnownTokenType type)
{
- return token != null && Equals(token.Type, GetKnownTokenType(type));
+ return token != null && Equals(token.Kind, GetKnownTokenType(type));
}
- public virtual Tuple SplitToken(TToken token, int splitAt, TTokenType leftType)
+ public virtual Tuple SplitToken(SyntaxToken token, int splitAt, SyntaxKind leftType)
{
var left = CreateToken(token.Content.Substring(0, splitAt), leftType, RazorDiagnostic.EmptyArray);
- TToken right = null;
+ SyntaxToken right = null;
if (splitAt < token.Content.Length)
{
- right = CreateToken(token.Content.Substring(splitAt), token.Type, token.Errors);
+ right = CreateToken(token.Content.Substring(splitAt), token.Kind, token.GetDiagnostics());
}
return Tuple.Create(left, right);
}
- public abstract TTokenType GetKnownTokenType(KnownTokenType type);
+ public abstract SyntaxKind GetKnownTokenType(KnownTokenType type);
public virtual bool KnowsTokenType(KnownTokenType type)
{
return type == KnownTokenType.Unknown || !Equals(GetKnownTokenType(type), GetKnownTokenType(KnownTokenType.Unknown));
}
- protected abstract TToken CreateToken(string content, TTokenType type, IReadOnlyList errors);
+ protected abstract SyntaxToken CreateToken(string content, SyntaxKind type, IReadOnlyList errors);
}
}
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/MarkupRewriter.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/MarkupRewriter.cs
index 42074050ff..95908fb736 100644
--- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/MarkupRewriter.cs
+++ b/src/Microsoft.AspNetCore.Razor.Language/Legacy/MarkupRewriter.cs
@@ -67,9 +67,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
builder.Kind = SpanKindInternal.Markup;
builder.ChunkGenerator = new MarkupChunkGenerator();
- foreach (IToken sym in HtmlLanguageCharacteristics.Instance.TokenizeString(start, content))
+ foreach (var token in HtmlLanguageCharacteristics.Instance.TokenizeString(start, content))
{
- builder.Accept(sym);
+ builder.Accept(token);
}
}
}
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/Span.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/Span.cs
index fbf9f9f2c2..b9147e8dac 100644
--- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/Span.cs
+++ b/src/Microsoft.AspNetCore.Razor.Language/Legacy/Span.cs
@@ -5,12 +5,16 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
+using Microsoft.AspNetCore.Razor.Language.Syntax;
+using Microsoft.Extensions.Internal;
namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
internal class Span : SyntaxTreeNode
{
+ private static readonly List EmptyTokenList = new List(0);
private static readonly int TypeHashCode = typeof(Span).GetHashCode();
+ private IReadOnlyList _greenTokens;
private string _content;
private int? _length;
private SourceLocation _start;
@@ -23,7 +27,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
public ISpanChunkGenerator ChunkGenerator { get; private set; }
public SpanKindInternal Kind { get; private set; }
- public IReadOnlyList Tokens { get; private set; }
+
+ public IReadOnlyList Tokens { get; private set; }
// Allow test code to re-link spans
public Span Previous { get; internal set; }
@@ -31,6 +36,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
public SpanEditHandler EditHandler { get; private set; }
+ public SyntaxNode SyntaxNode { get; private set; }
+
public override bool IsBlock => false;
public override int Length
@@ -93,19 +100,29 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
public void ReplaceWith(SpanBuilder builder)
{
Kind = builder.Kind;
- Tokens = builder.Tokens;
-
- for (var i = 0; i 0)
+ {
+ tokens = new List();
+ var currentStart = _start.AbsoluteIndex;
+ for (var i = 0; i < _greenTokens.Count; i++)
+ {
+ var token = new SyntaxToken(_greenTokens[i], parent: SyntaxNode, parentSpan: this, position: currentStart);
+ tokens.Add(token);
+ currentStart += token.FullWidth;
+ }
+ }
+
+ Tokens = tokens;
+
Parent?.ChildChanged();
// Since we took references to the values in SpanBuilder, clear its references out
@@ -145,8 +162,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
///
public override bool EquivalentTo(SyntaxTreeNode node)
{
- var other = node as Span;
- return other != null &&
+ return node is Span other &&
Kind.Equals(other.Kind) &&
Start.Equals(other.Start) &&
EditHandler.Equals(other.EditHandler) &&
@@ -161,12 +177,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
public override bool Equals(object obj)
{
- var other = obj as Span;
- return other != null &&
+ return obj is Span other &&
Kind.Equals(other.Kind) &&
EditHandler.Equals(other.EditHandler) &&
ChunkGenerator.Equals(other.ChunkGenerator) &&
- Tokens.SequenceEqual(other.Tokens);
+ Tokens.SequenceEqual(other.Tokens, SyntaxTokenComparer.Default);
}
public override int GetHashCode()
@@ -185,5 +200,28 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
var spanBuilder = new SpanBuilder(this);
return spanBuilder.Build();
}
+
+ private class SyntaxTokenComparer : IEqualityComparer
+ {
+ public static readonly SyntaxTokenComparer Default = new SyntaxTokenComparer();
+
+ private SyntaxTokenComparer()
+ {
+ }
+
+ public bool Equals(SyntaxToken x, SyntaxToken y)
+ {
+ return x.IsEquivalentTo(y);
+ }
+
+ public int GetHashCode(SyntaxToken obj)
+ {
+ var hash = HashCodeCombiner.Start();
+ hash.Add(obj.Content, StringComparer.Ordinal);
+ hash.Add(obj.Kind);
+
+ return hash;
+ }
+ }
}
}
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/SpanBuilder.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/SpanBuilder.cs
index 6d2e647b91..ad2b08b61c 100644
--- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/SpanBuilder.cs
+++ b/src/Microsoft.AspNetCore.Razor.Language/Legacy/SpanBuilder.cs
@@ -3,14 +3,16 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Linq;
+using Microsoft.AspNetCore.Razor.Language.Syntax.InternalSyntax;
namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
internal class SpanBuilder
{
private SourceLocation _start;
- private List _tokens;
+ private List _tokens;
private SourceLocationTracker _tracker;
public SpanBuilder(Span original)
@@ -20,7 +22,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
_start = original.Start;
ChunkGenerator = original.ChunkGenerator;
- _tokens = new List(original.Tokens);
+ _tokens = new List(original.Tokens.Select(t =>t.Green));
_tracker = new SourceLocationTracker(original.Start);
}
@@ -33,6 +35,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
Start = location;
}
+ public Syntax.GreenNode SyntaxNode { get; private set; }
+
public ISpanChunkGenerator ChunkGenerator { get; set; }
public SourceLocation Start
@@ -49,13 +53,13 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
public SpanKindInternal Kind { get; set; }
- public IReadOnlyList Tokens
+ public IReadOnlyList Tokens
{
get
{
if (_tokens == null)
{
- _tokens = new List();
+ _tokens = new List();
}
return _tokens;
@@ -69,22 +73,18 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
// Need to potentially allocate a new list because Span.ReplaceWith takes ownership
// of the original list.
_tokens = null;
- _tokens = new List();
+ _tokens = new List();
- EditHandler = SpanEditHandler.CreateDefault((content) => Enumerable.Empty());
+ EditHandler = SpanEditHandler.CreateDefault((content) => Enumerable.Empty());
ChunkGenerator = SpanChunkGenerator.Null;
Start = SourceLocation.Undefined;
}
- public Span Build()
+ public Span Build(SyntaxKind syntaxKind = SyntaxKind.Unknown)
{
+ SyntaxNode = GetSyntaxNode(syntaxKind);
+
var span = new Span(this);
-
- for (var i = 0; i < span.Tokens.Count; i++)
- {
- var token = span.Tokens[i];
- token.Parent = span;
- }
return span;
}
@@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
_tokens?.Clear();
}
- public void Accept(IToken token)
+ public void Accept(SyntaxToken token)
{
if (token == null)
{
@@ -109,5 +109,27 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
_tokens.Add(token);
_tracker.UpdateLocation(token.Content);
}
+
+ private Syntax.GreenNode GetSyntaxNode(SyntaxKind syntaxKind)
+ {
+ if (syntaxKind == SyntaxKind.HtmlTextLiteral)
+ {
+ var textTokens = new SyntaxListBuilder(SyntaxListBuilder.Create());
+ foreach (var token in Tokens)
+ {
+ if (token.Kind == SyntaxKind.Unknown)
+ {
+ Debug.Assert(false, $"Unexpected token {token.Kind}");
+ continue;
+ }
+
+ textTokens.Add(token);
+ }
+ var textResult = textTokens.ToList();
+ return SyntaxFactory.HtmlTextLiteral(new SyntaxList(textResult.Node));
+ }
+
+ return null;
+ }
}
}
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/SpanEditHandler.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/SpanEditHandler.cs
index d5407f34dd..321b4d37ce 100644
--- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/SpanEditHandler.cs
+++ b/src/Microsoft.AspNetCore.Razor.Language/Legacy/SpanEditHandler.cs
@@ -3,7 +3,7 @@
using System;
using System.Collections.Generic;
-using System.Diagnostics;
+using Microsoft.AspNetCore.Razor.Language.Syntax.InternalSyntax;
namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
@@ -11,12 +11,12 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
private static readonly int TypeHashCode = typeof(SpanEditHandler).GetHashCode();
- public SpanEditHandler(Func> tokenizer)
+ public SpanEditHandler(Func> tokenizer)
: this(tokenizer, AcceptedCharactersInternal.Any)
{
}
- public SpanEditHandler(Func> tokenizer, AcceptedCharactersInternal accepted)
+ public SpanEditHandler(Func> tokenizer, AcceptedCharactersInternal accepted)
{
AcceptedCharacters = accepted;
Tokenizer = tokenizer;
@@ -24,9 +24,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
public AcceptedCharactersInternal AcceptedCharacters { get; set; }
- public Func> Tokenizer { get; set; }
+ public Func> Tokenizer { get; set; }
- public static SpanEditHandler CreateDefault(Func> tokenizer)
+ public static SpanEditHandler CreateDefault(Func> tokenizer)
{
return new SpanEditHandler(tokenizer);
}
@@ -116,8 +116,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
public override bool Equals(object obj)
{
- var other = obj as SpanEditHandler;
- return other != null &&
+ return obj is SpanEditHandler other &&
GetType() == other.GetType() &&
AcceptedCharacters == other.AcceptedCharacters;
}
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/TagHelperBlockRewriter.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/TagHelperBlockRewriter.cs
index f08d0579e5..1aea40a746 100644
--- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/TagHelperBlockRewriter.cs
+++ b/src/Microsoft.AspNetCore.Razor.Language/Legacy/TagHelperBlockRewriter.cs
@@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
+using Microsoft.AspNetCore.Razor.Language.Syntax;
namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
@@ -150,7 +151,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
};
// Will contain tokens that represent a single attribute value:
- var htmlTokens = span.Tokens.OfType().ToArray();
+ var tokens = span.Tokens;
var capturedAttributeValueStart = false;
var attributeValueStartLocation = span.Start;
@@ -165,9 +166,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
// Iterate down through the tokens to find the name and the start of the value.
// We subtract the tokenOffset so we don't accept an ending quote of a span.
- for (var i = 0; i < htmlTokens.Length - tokenOffset; i++)
+ for (var i = 0; i < tokens.Count - tokenOffset; i++)
{
- var token = htmlTokens[i];
+ var token = tokens[i];
if (afterEquals)
{
@@ -186,9 +187,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
attributeValueStartLocation = token.Start;
}
- builder.Accept(token);
+ builder.Accept(token.Green);
}
- else if (name == null && HtmlMarkupParser.IsValidAttributeNameToken(token))
+ else if (name == null && HtmlMarkupParser.IsValidAttributeNameToken(token.Green))
{
// We've captured all leading whitespace prior to the attribute name.
// We're now at: " |asp-for='...'" or " |asp-for=..."
@@ -196,10 +197,10 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
var nameBuilder = new StringBuilder();
// Move the indexer past the attribute name tokens.
- for (var j = i; j < htmlTokens.Length; j++)
+ for (var j = i; j < tokens.Count; j++)
{
- var nameToken = htmlTokens[j];
- if (!HtmlMarkupParser.IsValidAttributeNameToken(nameToken))
+ var nameToken = tokens[j];
+ if (!HtmlMarkupParser.IsValidAttributeNameToken(nameToken.Green))
{
break;
}
@@ -213,7 +214,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
name = nameBuilder.ToString();
attributeValueStartLocation = SourceLocationTracker.Advance(attributeValueStartLocation, name);
}
- else if (token.Type == HtmlTokenType.Equals)
+ else if (token.Kind == SyntaxKind.Equals)
{
// We've captured all leading whitespace and the attribute name.
// We're now at: " asp-for|='...'" or " asp-for|=..."
@@ -227,19 +228,19 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
do
{
i++; // Start from the token after '='.
- } while (i < htmlTokens.Length &&
- (htmlTokens[i].Type == HtmlTokenType.WhiteSpace ||
- htmlTokens[i].Type == HtmlTokenType.NewLine));
+ } while (i < tokens.Count &&
+ (tokens[i].Kind == SyntaxKind.Whitespace ||
+ tokens[i].Kind == SyntaxKind.NewLine));
// Check for attribute start values, aka single or double quote
- if (i < htmlTokens.Length && IsQuote(htmlTokens[i]))
+ if (i < tokens.Count && IsQuote(tokens[i]))
{
- if (htmlTokens[i].Type == HtmlTokenType.SingleQuote)
+ if (tokens[i].Kind == SyntaxKind.SingleQuote)
{
attributeValueStyle = AttributeStructure.SingleQuotes;
}
- tokenStartLocation = htmlTokens[i].Start;
+ tokenStartLocation = tokens[i].Start;
// If there's a start quote then there must be an end quote to be valid, skip it.
tokenOffset = 1;
@@ -260,7 +261,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
afterEquals = true;
}
- else if (token.Type == HtmlTokenType.WhiteSpace)
+ else if (token.Kind == SyntaxKind.Whitespace)
{
// We're at the start of the attribute, this branch may be hit on the first iterations of
// the loop since the parser separates attributes with their spaces included as tokens.
@@ -343,9 +344,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
var nameTokens = childSpan
.Tokens
- .OfType()
- .SkipWhile(token => !HtmlMarkupParser.IsValidAttributeNameToken(token)) // Skip prefix
- .TakeWhile(nameToken => HtmlMarkupParser.IsValidAttributeNameToken(nameToken))
+ .SkipWhile(token => !HtmlMarkupParser.IsValidAttributeNameToken(token.Green)) // Skip prefix
+ .TakeWhile(nameToken => HtmlMarkupParser.IsValidAttributeNameToken(nameToken.Green))
.Select(nameToken => nameToken.Content);
var name = string.Concat(nameTokens);
@@ -362,12 +362,12 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
var result = CreateTryParseResult(name, descriptors, processedBoundAttributeNames);
var firstChild = builder.Children[0] as Span;
- if (firstChild != null && firstChild.Tokens[0] is HtmlToken)
+ if (firstChild != null)
{
- var htmlToken = firstChild.Tokens[firstChild.Tokens.Count - 1] as HtmlToken;
- switch (htmlToken.Type)
+ var token = firstChild.Tokens[firstChild.Tokens.Count - 1];
+ switch (token.Kind)
{
- case HtmlTokenType.Equals:
+ case SyntaxKind.Equals:
if (builder.Children.Count == 2 &&
builder.Children[1] is Span value &&
value.Kind == SpanKindInternal.Markup)
@@ -385,10 +385,10 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
result.AttributeStructure = AttributeStructure.DoubleQuotes;
}
break;
- case HtmlTokenType.DoubleQuote:
+ case SyntaxKind.DoubleQuote:
result.AttributeStructure = AttributeStructure.DoubleQuotes;
break;
- case HtmlTokenType.SingleQuote:
+ case SyntaxKind.SingleQuote:
result.AttributeStructure = AttributeStructure.SingleQuotes;
break;
default:
@@ -408,8 +408,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
// In some malformed cases e.g. : ITokenizer
- where TTokenType : struct
- where TToken : TokenBase
+ internal abstract class Tokenizer : ITokenizer
{
protected Tokenizer(ITextDocument source)
{
@@ -31,7 +30,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
protected int? CurrentState { get; set; }
- protected TToken CurrentToken { get; private set; }
+ protected SyntaxToken CurrenSyntaxToken { get; private set; }
public ITextDocument Source { get; private set; }
@@ -42,9 +41,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
get { return Source.Peek() == -1; }
}
- public abstract TTokenType RazorCommentStarType { get; }
- public abstract TTokenType RazorCommentType { get; }
- public abstract TTokenType RazorCommentTransitionType { get; }
+ public abstract SyntaxKind RazorCommentStarKind { get; }
+ public abstract SyntaxKind RazorCommentKind { get; }
+ public abstract SyntaxKind RazorCommentTransitionKind { get; }
protected bool HaveContent
{
@@ -64,16 +63,16 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
public SourceLocation CurrentStart { get; private set; }
- protected abstract TToken CreateToken(string content, TTokenType type, IReadOnlyList errors);
+ protected abstract SyntaxToken CreateToken(string content, SyntaxKind type, IReadOnlyList errors);
protected abstract StateResult Dispatch();
- IToken ITokenizer.NextToken()
+ SyntaxToken ITokenizer.NextToken()
{
return NextToken();
}
- public virtual TToken NextToken()
+ public virtual SyntaxToken NextToken()
{
// Post-Condition: Buffer should be empty at the start of Next()
Debug.Assert(Buffer.Length == 0);
@@ -95,7 +94,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return token;
}
- protected virtual TToken Turn()
+ protected virtual SyntaxToken Turn()
{
if (CurrentState != null)
{
@@ -105,19 +104,19 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
var next = Dispatch();
CurrentState = next.State;
- CurrentToken = next.Result;
+ CurrenSyntaxToken = next.Result;
}
- while (CurrentState != null && CurrentToken == null);
+ while (CurrentState != null && CurrenSyntaxToken == null);
if (CurrentState == null)
{
- return default(TToken); // Terminated
+ return default(SyntaxToken); // Terminated
}
- return CurrentToken;
+ return CurrenSyntaxToken;
}
- return default(TToken);
+ return default(SyntaxToken);
}
public void Reset()
@@ -149,7 +148,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
/// Returns a result containing the specified output and indicating that the next call to
/// should invoke the provided state.
///
- protected StateResult Transition(int state, TToken result)
+ protected StateResult Transition(int state, SyntaxToken result)
{
return new StateResult(state, result);
}
@@ -159,7 +158,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return new StateResult((int)state, result: null);
}
- protected StateResult Transition(RazorCommentTokenizerState state, TToken result)
+ protected StateResult Transition(RazorCommentTokenizerState state, SyntaxToken result)
{
return new StateResult((int)state, result);
}
@@ -180,12 +179,12 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
/// Returns a result containing the specified output and indicating that the next call to
/// should re-invoke the current state.
///
- protected StateResult Stay(TToken result)
+ protected StateResult Stay(SyntaxToken result)
{
return new StateResult(CurrentState, result);
}
- protected TToken Single(TTokenType type)
+ protected SyntaxToken Single(SyntaxKind type)
{
TakeCurrent();
return EndToken(type);
@@ -199,9 +198,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
CurrentStart = CurrentLocation;
}
- protected TToken EndToken(TTokenType type)
+ protected SyntaxToken EndToken(SyntaxKind type)
{
- TToken token = null;
+ SyntaxToken token = null;
if (HaveContent)
{
// Perf: Don't allocate a new errors array unless necessary.
@@ -222,7 +221,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return token;
}
- protected virtual string GetTokenContent(TTokenType type)
+ protected virtual string GetTokenContent(SyntaxKind type)
{
return Buffer.ToString();
}
@@ -278,7 +277,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
AssertCurrent('*');
TakeCurrent();
- return Transition(1002, EndToken(RazorCommentStarType));
+ return Transition(1002, EndToken(RazorCommentStarKind));
}
protected StateResult RazorCommentBody()
@@ -292,7 +291,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
return Transition(
RazorCommentTokenizerState.StarAfterRazorCommentBody,
- EndToken(RazorCommentType));
+ EndToken(RazorCommentKind));
}
else
{
@@ -306,7 +305,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
}
}
- return Transition(StartState, EndToken(RazorCommentType));
+ return Transition(StartState, EndToken(RazorCommentKind));
}
protected StateResult StarAfterRazorCommentBody()
@@ -315,14 +314,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
TakeCurrent();
return Transition(
RazorCommentTokenizerState.AtTokenAfterRazorCommentBody,
- EndToken(RazorCommentStarType));
+ EndToken(RazorCommentStarKind));
}
protected StateResult AtTokenAfterRazorCommentBody()
{
AssertCurrent('@');
TakeCurrent();
- return Transition(StartState, EndToken(RazorCommentTransitionType));
+ return Transition(StartState, EndToken(RazorCommentTransitionKind));
}
///
@@ -397,7 +396,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
protected struct StateResult
{
- public StateResult(int? state, TToken result)
+ public StateResult(int? state, SyntaxToken result)
{
State = state;
Result = result;
@@ -405,7 +404,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
public int? State { get; }
- public TToken Result { get; }
+ public SyntaxToken Result { get; }
}
private static LookaheadToken BeginLookahead(ITextBuffer buffer)
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/TokenizerBackedParser.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/TokenizerBackedParser.cs
index af5a08831f..5168dbe79c 100644
--- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/TokenizerBackedParser.cs
+++ b/src/Microsoft.AspNetCore.Razor.Language/Legacy/TokenizerBackedParser.cs
@@ -5,36 +5,37 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
+using Microsoft.AspNetCore.Razor.Language.Syntax.InternalSyntax;
namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
- internal abstract partial class TokenizerBackedParser : ParserBase
- where TTokenType : struct
- where TTokenizer : Tokenizer
- where TToken : TokenBase
+ internal abstract class TokenizerBackedParser : ParserBase
+ where TTokenizer : Tokenizer
{
- private readonly TokenizerView _tokenizer;
+ private readonly TokenizerView _tokenizer;
- protected TokenizerBackedParser(LanguageCharacteristics language, ParserContext context)
+ protected TokenizerBackedParser(LanguageCharacteristics language, ParserContext context)
: base(context)
{
Language = language;
var languageTokenizer = Language.CreateTokenizer(Context.Source);
- _tokenizer = new TokenizerView(languageTokenizer);
+ _tokenizer = new TokenizerView(languageTokenizer);
Span = new SpanBuilder(CurrentLocation);
}
+ protected ParserState ParserState { get; set; }
+
protected SpanBuilder Span { get; private set; }
protected Action SpanConfig { get; set; }
- protected TToken CurrentToken
+ protected SyntaxToken CurrentToken
{
get { return _tokenizer.Current; }
}
- protected TToken PreviousToken { get; private set; }
+ protected SyntaxToken PreviousToken { get; private set; }
protected SourceLocation CurrentLocation => _tokenizer.Tokenizer.CurrentLocation;
@@ -45,7 +46,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
get { return _tokenizer.EndOfFile; }
}
- protected LanguageCharacteristics Language { get; }
+ protected LanguageCharacteristics Language { get; }
protected virtual void HandleEmbeddedTransition()
{
@@ -58,21 +59,18 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
public override void BuildSpan(SpanBuilder span, SourceLocation start, string content)
{
- foreach (IToken sym in Language.TokenizeString(start, content))
+ foreach (var token in Language.TokenizeString(start, content))
{
- span.Accept(sym);
+ span.Accept(token);
}
}
protected void Initialize(SpanBuilder span)
{
- if (SpanConfig != null)
- {
- SpanConfig(span);
- }
+ SpanConfig?.Invoke(span);
}
- protected TToken Lookahead(int count)
+ protected SyntaxToken Lookahead(int count)
{
if (count < 0)
{
@@ -84,7 +82,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
}
// We add 1 in order to store the current token.
- var tokens = new TToken[count + 1];
+ var tokens = new SyntaxToken[count + 1];
var currentToken = CurrentToken;
tokens[0] = currentToken;
@@ -115,7 +113,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
/// A predicate accepting the token being evaluated and the list of tokens which have been looped through.
/// true, if the condition was met. false - if the condition wasn't met and the last token has already been processed.
/// The list of previous tokens is passed in the reverse order. So the last processed element will be the first one in the list.
- protected bool LookaheadUntil(Func, bool> condition)
+ protected bool LookaheadUntil(Func, bool> condition)
{
if (condition == null)
{
@@ -124,7 +122,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
var matchFound = false;
- var tokens = new List();
+ var tokens = new List();
tokens.Add(CurrentToken);
while (true)
@@ -163,14 +161,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
// Helpers
[Conditional("DEBUG")]
- internal void Assert(TTokenType expectedType)
+ internal void Assert(SyntaxKind expectedType)
{
- Debug.Assert(!EndOfFile && TokenTypeEquals(CurrentToken.Type, expectedType));
+ Debug.Assert(!EndOfFile && TokenKindEquals(CurrentToken.Kind, expectedType));
}
- abstract protected bool TokenTypeEquals(TTokenType x, TTokenType y);
+ protected abstract bool TokenKindEquals(SyntaxKind x, SyntaxKind y);
- protected internal void PutBack(TToken token)
+ protected internal void PutBack(SyntaxToken token)
{
if (token != null)
{
@@ -180,7 +178,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
///
/// Put the specified tokens back in the input stream. The provided list MUST be in the ORDER THE TOKENS WERE READ. The
- /// list WILL be reversed and the Putback(TToken) will be called on each item.
+ /// list WILL be reversed and the Putback(SyntaxToken) will be called on each item.
///
///
/// If a document contains tokens: a, b, c, d, e, f
@@ -189,9 +187,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
/// that is the correct format for providing to this method. The caller of this method would,
/// in that case, want to put c, b and a back into the stream, so "a, b, c" is the CORRECT order
///
- protected internal void PutBack(IEnumerable tokens)
+ protected internal void PutBack(IEnumerable tokens)
{
- foreach (TToken token in tokens.Reverse())
+ foreach (var token in tokens.Reverse())
{
PutBack(token);
}
@@ -207,7 +205,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
protected internal bool Balance(BalancingModes mode)
{
- var left = CurrentToken.Type;
+ var left = CurrentToken.Kind;
var right = Language.FlipBracket(left);
var start = CurrentStart;
AcceptAndMoveNext();
@@ -223,21 +221,21 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return Balance(mode, left, right, start);
}
- protected internal bool Balance(BalancingModes mode, TTokenType left, TTokenType right, SourceLocation start)
+ protected internal bool Balance(BalancingModes mode, SyntaxKind left, SyntaxKind right, SourceLocation start)
{
var startPosition = CurrentStart.AbsoluteIndex;
var nesting = 1;
if (!EndOfFile)
{
- var syms = new List();
+ var tokens = new List();
do
{
if (IsAtEmbeddedTransition(
(mode & BalancingModes.AllowCommentsAndTemplates) == BalancingModes.AllowCommentsAndTemplates,
(mode & BalancingModes.AllowEmbeddedTransitions) == BalancingModes.AllowEmbeddedTransitions))
{
- Accept(syms);
- syms.Clear();
+ Accept(tokens);
+ tokens.Clear();
HandleEmbeddedTransition();
// Reset backtracking since we've already outputted some spans.
@@ -253,7 +251,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
}
if (nesting > 0)
{
- syms.Add(CurrentToken);
+ tokens.Add(CurrentToken);
}
}
while (nesting > 0 && NextToken());
@@ -275,29 +273,29 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
}
else
{
- Accept(syms);
+ Accept(tokens);
}
}
else
{
// Accept all the tokens we saw
- Accept(syms);
+ Accept(tokens);
}
}
return nesting == 0;
}
- protected internal bool NextIs(TTokenType type)
+ protected internal bool NextIs(SyntaxKind type)
{
- return NextIs(sym => sym != null && TokenTypeEquals(type, sym.Type));
+ return NextIs(token => token != null && TokenKindEquals(type, token.Kind));
}
- protected internal bool NextIs(params TTokenType[] types)
+ protected internal bool NextIs(params SyntaxKind[] types)
{
- return NextIs(sym => sym != null && types.Any(t => TokenTypeEquals(t, sym.Type)));
+ return NextIs(token => token != null && types.Any(t => TokenKindEquals(t, token.Kind)));
}
- protected internal bool NextIs(Func condition)
+ protected internal bool NextIs(Func condition)
{
var cur = CurrentToken;
if (NextToken())
@@ -317,14 +315,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return false;
}
- protected internal bool Was(TTokenType type)
+ protected internal bool Was(SyntaxKind type)
{
- return PreviousToken != null && TokenTypeEquals(PreviousToken.Type, type);
+ return PreviousToken != null && TokenKindEquals(PreviousToken.Kind, type);
}
- protected internal bool At(TTokenType type)
+ protected internal bool At(SyntaxKind type)
{
- return !EndOfFile && CurrentToken != null && TokenTypeEquals(CurrentToken.Type, type);
+ return !EndOfFile && CurrentToken != null && TokenKindEquals(CurrentToken.Kind, type);
}
protected internal bool AcceptAndMoveNext()
@@ -333,11 +331,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return NextToken();
}
- protected TToken AcceptSingleWhiteSpaceCharacter()
+ protected SyntaxToken AcceptSingleWhiteSpaceCharacter()
{
if (Language.IsWhiteSpace(CurrentToken))
{
- Tuple pair = Language.SplitToken(CurrentToken, 1, Language.GetKnownTokenType(KnownTokenType.WhiteSpace));
+ var pair = Language.SplitToken(CurrentToken, 1, Language.GetKnownTokenType(KnownTokenType.WhiteSpace));
Accept(pair.Item1);
Span.EditHandler.AcceptedCharacters = AcceptedCharactersInternal.None;
NextToken();
@@ -346,19 +344,19 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return null;
}
- protected internal void Accept(IEnumerable tokens)
+ protected internal void Accept(IEnumerable tokens)
{
- foreach (TToken token in tokens)
+ foreach (var token in tokens)
{
Accept(token);
}
}
- protected internal void Accept(TToken token)
+ protected internal void Accept(SyntaxToken token)
{
if (token != null)
{
- foreach (var error in token.Errors)
+ foreach (var error in token.GetDiagnostics())
{
Context.ErrorSink.OnError(error);
}
@@ -367,11 +365,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
}
}
- protected internal bool AcceptAll(params TTokenType[] types)
+ protected internal bool AcceptAll(params SyntaxKind[] kinds)
{
- foreach (TTokenType type in types)
+ foreach (var kind in kinds)
{
- if (CurrentToken == null || !TokenTypeEquals(CurrentToken.Type, type))
+ if (CurrentToken == null || !TokenKindEquals(CurrentToken.Kind, kind))
{
return false;
}
@@ -388,31 +386,31 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
}
}
- protected internal void Output(SpanKindInternal kind)
+ protected internal void Output(SpanKindInternal kind, SyntaxKind syntaxKind = SyntaxKind.Unknown)
{
Configure(kind, null);
- Output();
+ Output(syntaxKind);
}
- protected internal void Output(SpanKindInternal kind, AcceptedCharactersInternal accepts)
+ protected internal void Output(SpanKindInternal kind, AcceptedCharactersInternal accepts, SyntaxKind syntaxKind = SyntaxKind.Unknown)
{
Configure(kind, accepts);
- Output();
+ Output(syntaxKind);
}
- protected internal void Output(AcceptedCharactersInternal accepts)
+ protected internal void Output(AcceptedCharactersInternal accepts, SyntaxKind syntaxKind = SyntaxKind.Unknown)
{
Configure(null, accepts);
- Output();
+ Output(syntaxKind);
}
- private void Output()
+ private void Output(SyntaxKind syntaxKind)
{
if (Span.Tokens.Count > 0)
{
var nextStart = Span.End;
- var builtSpan = Span.Build();
+ var builtSpan = Span.Build(syntaxKind);
Context.Builder.Add(builtSpan);
Initialize(Span);
@@ -437,7 +435,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
protected IDisposable PushSpanConfig(Action> newConfig)
{
- Action old = SpanConfig;
+ var old = SpanConfig;
ConfigureSpan(newConfig);
return new DisposableAction(() => SpanConfig = old);
}
@@ -450,7 +448,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
protected void ConfigureSpan(Action> config)
{
- Action prev = SpanConfig;
+ var prev = SpanConfig;
if (config == null)
{
SpanConfig = null;
@@ -467,9 +465,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
Expected(Language.GetKnownTokenType(type));
}
- protected internal void Expected(params TTokenType[] types)
+ protected internal void Expected(params SyntaxKind[] types)
{
- Debug.Assert(!EndOfFile && CurrentToken != null && types.Contains(CurrentToken.Type));
+ Debug.Assert(!EndOfFile && CurrentToken != null && types.Contains(CurrentToken.Kind));
AcceptAndMoveNext();
}
@@ -478,7 +476,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return Optional(Language.GetKnownTokenType(type));
}
- protected internal bool Optional(TTokenType type)
+ protected internal bool Optional(SyntaxKind type)
{
if (At(type))
{
@@ -498,61 +496,61 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return true;
}
- protected internal void AcceptWhile(TTokenType type)
+ protected internal void AcceptWhile(SyntaxKind type)
{
- AcceptWhile(sym => TokenTypeEquals(type, sym.Type));
+ AcceptWhile(token => TokenKindEquals(type, token.Kind));
}
// We want to avoid array allocations and enumeration where possible, so we use the same technique as string.Format
- protected internal void AcceptWhile(TTokenType type1, TTokenType type2)
+ protected internal void AcceptWhile(SyntaxKind type1, SyntaxKind type2)
{
- AcceptWhile(sym => TokenTypeEquals(type1, sym.Type) || TokenTypeEquals(type2, sym.Type));
+ AcceptWhile(token => TokenKindEquals(type1, token.Kind) || TokenKindEquals(type2, token.Kind));
}
- protected internal void AcceptWhile(TTokenType type1, TTokenType type2, TTokenType type3)
+ protected internal void AcceptWhile(SyntaxKind type1, SyntaxKind type2, SyntaxKind type3)
{
- AcceptWhile(sym => TokenTypeEquals(type1, sym.Type) || TokenTypeEquals(type2, sym.Type) || TokenTypeEquals(type3, sym.Type));
+ AcceptWhile(token => TokenKindEquals(type1, token.Kind) || TokenKindEquals(type2, token.Kind) || TokenKindEquals(type3, token.Kind));
}
- protected internal void AcceptWhile(params TTokenType[] types)
+ protected internal void AcceptWhile(params SyntaxKind[] types)
{
- AcceptWhile(sym => types.Any(expected => TokenTypeEquals(expected, sym.Type)));
+ AcceptWhile(token => types.Any(expected => TokenKindEquals(expected, token.Kind)));
}
- protected internal void AcceptUntil(TTokenType type)
+ protected internal void AcceptUntil(SyntaxKind type)
{
- AcceptWhile(sym => !TokenTypeEquals(type, sym.Type));
+ AcceptWhile(token => !TokenKindEquals(type, token.Kind));
}
// We want to avoid array allocations and enumeration where possible, so we use the same technique as string.Format
- protected internal void AcceptUntil(TTokenType type1, TTokenType type2)
+ protected internal void AcceptUntil(SyntaxKind type1, SyntaxKind type2)
{
- AcceptWhile(sym => !TokenTypeEquals(type1, sym.Type) && !TokenTypeEquals(type2, sym.Type));
+ AcceptWhile(token => !TokenKindEquals(type1, token.Kind) && !TokenKindEquals(type2, token.Kind));
}
- protected internal void AcceptUntil(TTokenType type1, TTokenType type2, TTokenType type3)
+ protected internal void AcceptUntil(SyntaxKind type1, SyntaxKind type2, SyntaxKind type3)
{
- AcceptWhile(sym => !TokenTypeEquals(type1, sym.Type) && !TokenTypeEquals(type2, sym.Type) && !TokenTypeEquals(type3, sym.Type));
+ AcceptWhile(token => !TokenKindEquals(type1, token.Kind) && !TokenKindEquals(type2, token.Kind) && !TokenKindEquals(type3, token.Kind));
}
- protected internal void AcceptUntil(params TTokenType[] types)
+ protected internal void AcceptUntil(params SyntaxKind[] types)
{
- AcceptWhile(sym => types.All(expected => !TokenTypeEquals(expected, sym.Type)));
+ AcceptWhile(token => types.All(expected => !TokenKindEquals(expected, token.Kind)));
}
- protected internal void AcceptWhile(Func condition)
+ protected internal void AcceptWhile(Func condition)
{
Accept(ReadWhileLazy(condition));
}
- protected internal IEnumerable ReadWhile(Func condition)
+ protected internal IEnumerable ReadWhile(Func condition)
{
return ReadWhileLazy(condition).ToList();
}
- protected TToken AcceptWhiteSpaceInLines()
+ protected SyntaxToken AcceptWhiteSpaceInLines()
{
- TToken lastWs = null;
+ SyntaxToken lastWs = null;
while (Language.IsWhiteSpace(CurrentToken) || Language.IsNewLine(CurrentToken))
{
// Capture the previous whitespace node
@@ -586,7 +584,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
// Don't open this to sub classes because it's lazy but it looks eager.
// You have to advance the Enumerable to read the next characters.
- internal IEnumerable ReadWhileLazy(Func condition)
+ internal IEnumerable ReadWhileLazy(Func condition)
{
while (EnsureCurrent() && condition(CurrentToken))
{
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/TokenizerView.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/TokenizerView.cs
index 2b290bda5c..ef481af1ac 100644
--- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/TokenizerView.cs
+++ b/src/Microsoft.AspNetCore.Razor.Language/Legacy/TokenizerView.cs
@@ -1,12 +1,12 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+using Microsoft.AspNetCore.Razor.Language.Syntax.InternalSyntax;
+
namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
- internal class TokenizerView
- where TTokenType : struct
- where TTokenizer : Tokenizer
- where TToken : TokenBase
+ internal class TokenizerView
+ where TTokenizer : Tokenizer
{
public TokenizerView(TTokenizer tokenizer)
{
@@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
public TTokenizer Tokenizer { get; private set; }
public bool EndOfFile { get; private set; }
- public TToken Current { get; private set; }
+ public SyntaxToken Current { get; private set; }
public ITextDocument Source
{
@@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return !EndOfFile;
}
- public void PutBack(TToken token)
+ public void PutBack(SyntaxToken token)
{
Source.Position -= token.Content.Length;
Current = null;
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Properties/AssemblyInfo.cs b/src/Microsoft.AspNetCore.Razor.Language/Properties/AssemblyInfo.cs
index 7214d8baca..310bbca195 100644
--- a/src/Microsoft.AspNetCore.Razor.Language/Properties/AssemblyInfo.cs
+++ b/src/Microsoft.AspNetCore.Razor.Language/Properties/AssemblyInfo.cs
@@ -2,6 +2,8 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Runtime.CompilerServices;
+[assembly: InternalsVisibleTo("rzls, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
+[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Razor.LanguageServer.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Razor.Performance, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Mvc.Razor.Extensions.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Syntax/ArrayElement.cs b/src/Microsoft.AspNetCore.Razor.Language/Syntax/ArrayElement.cs
new file mode 100644
index 0000000000..85345e657b
--- /dev/null
+++ b/src/Microsoft.AspNetCore.Razor.Language/Syntax/ArrayElement.cs
@@ -0,0 +1,58 @@
+// Copyright (c) .NET Foundation. All rights reserved.
+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+
+namespace Microsoft.AspNetCore.Razor.Language.Syntax
+{
+ internal struct ArrayElement
+ {
+ public T Value;
+
+ public static implicit operator T(ArrayElement element)
+ {
+ return element.Value;
+ }
+
+ //NOTE: there is no opposite conversion operator T -> ArrayElement
+ //
+ // that is because it is preferred to update array elements in-place
+ // "elements[i].Value = v" results in much better code than "elements[i] = (ArrayElement)v"
+ //
+ // The reason is that x86 ABI requires that structs must be returned in
+ // a return buffer even if they can fit in a register like this one.
+ // Also since struct contains a reference, the write to the buffer is done with a checked GC barrier
+ // as JIT does not know if the write goes to a stack or a heap location.
+ // Assigning to Value directly easily avoids all this redundancy.
+
+ public static ArrayElement[] MakeElementArray(T[] items)
+ {
+ if (items == null)
+ {
+ return null;
+ }
+
+ var array = new ArrayElement[items.Length];
+ for (var i = 0; i < items.Length; i++)
+ {
+ array[i].Value = items[i];
+ }
+
+ return array;
+ }
+
+ public static T[] MakeArray(ArrayElement[] items)
+ {
+ if (items == null)
+ {
+ return null;
+ }
+
+ var array = new T[items.Length];
+ for (var i = 0; i < items.Length; i++)
+ {
+ array[i] = items[i].Value;
+ }
+
+ return array;
+ }
+ }
+}
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Syntax/Generated/Syntax.xml.Internal.Generated.cs b/src/Microsoft.AspNetCore.Razor.Language/Syntax/Generated/Syntax.xml.Internal.Generated.cs
new file mode 100644
index 0000000000..aee8330582
--- /dev/null
+++ b/src/Microsoft.AspNetCore.Razor.Language/Syntax/Generated/Syntax.xml.Internal.Generated.cs
@@ -0,0 +1,1406 @@
+//
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading;
+
+namespace Microsoft.AspNetCore.Razor.Language.Syntax.InternalSyntax
+{
+ internal abstract partial class RazorSyntaxNode : GreenNode
+ {
+ internal RazorSyntaxNode(SyntaxKind kind, RazorDiagnostic[] diagnostics, SyntaxAnnotation[] annotations)
+ : base(kind, diagnostics, annotations)
+ {
+ }
+ internal RazorSyntaxNode(SyntaxKind kind)
+ : base(kind)
+ {
+ }
+ }
+
+ internal sealed partial class RazorCommentBlockSyntax : RazorSyntaxNode
+ {
+ private readonly SyntaxToken _startCommentTransition;
+ private readonly SyntaxToken _startCommentStar;
+ private readonly SyntaxToken _comment;
+ private readonly SyntaxToken _endCommentStar;
+ private readonly SyntaxToken _endCommentTransition;
+
+ internal RazorCommentBlockSyntax(SyntaxKind kind, SyntaxToken startCommentTransition, SyntaxToken startCommentStar, SyntaxToken comment, SyntaxToken endCommentStar, SyntaxToken endCommentTransition, RazorDiagnostic[] diagnostics, SyntaxAnnotation[] annotations)
+ : base(kind, diagnostics, annotations)
+ {
+ SlotCount = 5;
+ AdjustFlagsAndWidth(startCommentTransition);
+ _startCommentTransition = startCommentTransition;
+ AdjustFlagsAndWidth(startCommentStar);
+ _startCommentStar = startCommentStar;
+ if (comment != null)
+ {
+ AdjustFlagsAndWidth(comment);
+ _comment = comment;
+ }
+ AdjustFlagsAndWidth(endCommentStar);
+ _endCommentStar = endCommentStar;
+ AdjustFlagsAndWidth(endCommentTransition);
+ _endCommentTransition = endCommentTransition;
+ }
+
+
+ internal RazorCommentBlockSyntax(SyntaxKind kind, SyntaxToken startCommentTransition, SyntaxToken startCommentStar, SyntaxToken comment, SyntaxToken endCommentStar, SyntaxToken endCommentTransition)
+ : base(kind)
+ {
+ SlotCount = 5;
+ AdjustFlagsAndWidth(startCommentTransition);
+ _startCommentTransition = startCommentTransition;
+ AdjustFlagsAndWidth(startCommentStar);
+ _startCommentStar = startCommentStar;
+ if (comment != null)
+ {
+ AdjustFlagsAndWidth(comment);
+ _comment = comment;
+ }
+ AdjustFlagsAndWidth(endCommentStar);
+ _endCommentStar = endCommentStar;
+ AdjustFlagsAndWidth(endCommentTransition);
+ _endCommentTransition = endCommentTransition;
+ }
+
+ public SyntaxToken StartCommentTransition { get { return _startCommentTransition; } }
+ public SyntaxToken StartCommentStar { get { return _startCommentStar; } }
+ public SyntaxToken Comment { get { return _comment; } }
+ public SyntaxToken EndCommentStar { get { return _endCommentStar; } }
+ public SyntaxToken EndCommentTransition { get { return _endCommentTransition; } }
+
+ internal override GreenNode GetSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return _startCommentTransition;
+ case 1: return _startCommentStar;
+ case 2: return _comment;
+ case 3: return _endCommentStar;
+ case 4: return _endCommentTransition;
+ default: return null;
+ }
+ }
+
+ internal override SyntaxNode CreateRed(SyntaxNode parent, int position)
+ {
+ return new Syntax.RazorCommentBlockSyntax(this, parent, position);
+ }
+
+ public override TResult Accept(SyntaxVisitor visitor)
+ {
+ return visitor.VisitRazorCommentBlock(this);
+ }
+
+ public override void Accept(SyntaxVisitor visitor)
+ {
+ visitor.VisitRazorCommentBlock(this);
+ }
+
+ public RazorCommentBlockSyntax Update(SyntaxToken startCommentTransition, SyntaxToken startCommentStar, SyntaxToken comment, SyntaxToken endCommentStar, SyntaxToken endCommentTransition)
+ {
+ if (startCommentTransition != StartCommentTransition || startCommentStar != StartCommentStar || comment != Comment || endCommentStar != EndCommentStar || endCommentTransition != EndCommentTransition)
+ {
+ var newNode = SyntaxFactory.RazorCommentBlock(startCommentTransition, startCommentStar, comment, endCommentStar, endCommentTransition);
+ var diags = GetDiagnostics();
+ if (diags != null && diags.Length > 0)
+ newNode = newNode.WithDiagnosticsGreen(diags);
+ var annotations = GetAnnotations();
+ if (annotations != null && annotations.Length > 0)
+ newNode = newNode.WithAnnotationsGreen(annotations);
+ return newNode;
+ }
+
+ return this;
+ }
+
+ internal override GreenNode SetDiagnostics(RazorDiagnostic[] diagnostics)
+ {
+ return new RazorCommentBlockSyntax(Kind, _startCommentTransition, _startCommentStar, _comment, _endCommentStar, _endCommentTransition, diagnostics, GetAnnotations());
+ }
+
+ internal override GreenNode SetAnnotations(SyntaxAnnotation[] annotations)
+ {
+ return new RazorCommentBlockSyntax(Kind, _startCommentTransition, _startCommentStar, _comment, _endCommentStar, _endCommentTransition, GetDiagnostics(), annotations);
+ }
+ }
+
+ internal abstract partial class HtmlSyntaxNode : RazorSyntaxNode
+ {
+ internal HtmlSyntaxNode(SyntaxKind kind, RazorDiagnostic[] diagnostics, SyntaxAnnotation[] annotations)
+ : base(kind, diagnostics, annotations)
+ {
+ }
+ internal HtmlSyntaxNode(SyntaxKind kind)
+ : base(kind)
+ {
+ }
+ }
+
+ internal sealed partial class HtmlTextLiteralSyntax : HtmlSyntaxNode
+ {
+ private readonly GreenNode _textTokens;
+
+ internal HtmlTextLiteralSyntax(SyntaxKind kind, GreenNode textTokens, RazorDiagnostic[] diagnostics, SyntaxAnnotation[] annotations)
+ : base(kind, diagnostics, annotations)
+ {
+ SlotCount = 1;
+ if (textTokens != null)
+ {
+ AdjustFlagsAndWidth(textTokens);
+ _textTokens = textTokens;
+ }
+ }
+
+
+ internal HtmlTextLiteralSyntax(SyntaxKind kind, GreenNode textTokens)
+ : base(kind)
+ {
+ SlotCount = 1;
+ if (textTokens != null)
+ {
+ AdjustFlagsAndWidth(textTokens);
+ _textTokens = textTokens;
+ }
+ }
+
+ public SyntaxList TextTokens { get { return new SyntaxList(_textTokens); } }
+
+ internal override GreenNode GetSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return _textTokens;
+ default: return null;
+ }
+ }
+
+ internal override SyntaxNode CreateRed(SyntaxNode parent, int position)
+ {
+ return new Syntax.HtmlTextLiteralSyntax(this, parent, position);
+ }
+
+ public override TResult Accept(SyntaxVisitor visitor)
+ {
+ return visitor.VisitHtmlTextLiteral(this);
+ }
+
+ public override void Accept(SyntaxVisitor visitor)
+ {
+ visitor.VisitHtmlTextLiteral(this);
+ }
+
+ public HtmlTextLiteralSyntax Update(Microsoft.AspNetCore.Razor.Language.Syntax.InternalSyntax.SyntaxList textTokens)
+ {
+ if (textTokens != TextTokens)
+ {
+ var newNode = SyntaxFactory.HtmlTextLiteral(textTokens);
+ var diags = GetDiagnostics();
+ if (diags != null && diags.Length > 0)
+ newNode = newNode.WithDiagnosticsGreen(diags);
+ var annotations = GetAnnotations();
+ if (annotations != null && annotations.Length > 0)
+ newNode = newNode.WithAnnotationsGreen(annotations);
+ return newNode;
+ }
+
+ return this;
+ }
+
+ internal override GreenNode SetDiagnostics(RazorDiagnostic[] diagnostics)
+ {
+ return new HtmlTextLiteralSyntax(Kind, _textTokens, diagnostics, GetAnnotations());
+ }
+
+ internal override GreenNode SetAnnotations(SyntaxAnnotation[] annotations)
+ {
+ return new HtmlTextLiteralSyntax(Kind, _textTokens, GetDiagnostics(), annotations);
+ }
+ }
+
+ internal abstract partial class CSharpSyntaxNode : RazorSyntaxNode
+ {
+ internal CSharpSyntaxNode(SyntaxKind kind, RazorDiagnostic[] diagnostics, SyntaxAnnotation[] annotations)
+ : base(kind, diagnostics, annotations)
+ {
+ }
+ internal CSharpSyntaxNode(SyntaxKind kind)
+ : base(kind)
+ {
+ }
+ }
+
+ internal sealed partial class CSharpTransitionSyntax : CSharpSyntaxNode
+ {
+ private readonly SyntaxToken _transition;
+
+ internal CSharpTransitionSyntax(SyntaxKind kind, SyntaxToken transition, RazorDiagnostic[] diagnostics, SyntaxAnnotation[] annotations)
+ : base(kind, diagnostics, annotations)
+ {
+ SlotCount = 1;
+ AdjustFlagsAndWidth(transition);
+ _transition = transition;
+ }
+
+
+ internal CSharpTransitionSyntax(SyntaxKind kind, SyntaxToken transition)
+ : base(kind)
+ {
+ SlotCount = 1;
+ AdjustFlagsAndWidth(transition);
+ _transition = transition;
+ }
+
+ public SyntaxToken Transition { get { return _transition; } }
+
+ internal override GreenNode GetSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return _transition;
+ default: return null;
+ }
+ }
+
+ internal override SyntaxNode CreateRed(SyntaxNode parent, int position)
+ {
+ return new Syntax.CSharpTransitionSyntax(this, parent, position);
+ }
+
+ public override TResult Accept(SyntaxVisitor visitor)
+ {
+ return visitor.VisitCSharpTransition(this);
+ }
+
+ public override void Accept(SyntaxVisitor visitor)
+ {
+ visitor.VisitCSharpTransition(this);
+ }
+
+ public CSharpTransitionSyntax Update(SyntaxToken transition)
+ {
+ if (transition != Transition)
+ {
+ var newNode = SyntaxFactory.CSharpTransition(transition);
+ var diags = GetDiagnostics();
+ if (diags != null && diags.Length > 0)
+ newNode = newNode.WithDiagnosticsGreen(diags);
+ var annotations = GetAnnotations();
+ if (annotations != null && annotations.Length > 0)
+ newNode = newNode.WithAnnotationsGreen(annotations);
+ return newNode;
+ }
+
+ return this;
+ }
+
+ internal override GreenNode SetDiagnostics(RazorDiagnostic[] diagnostics)
+ {
+ return new CSharpTransitionSyntax(Kind, _transition, diagnostics, GetAnnotations());
+ }
+
+ internal override GreenNode SetAnnotations(SyntaxAnnotation[] annotations)
+ {
+ return new CSharpTransitionSyntax(Kind, _transition, GetDiagnostics(), annotations);
+ }
+ }
+
+ internal sealed partial class CSharpMetaCodeSyntax : CSharpSyntaxNode
+ {
+ private readonly GreenNode _metaCode;
+
+ internal CSharpMetaCodeSyntax(SyntaxKind kind, GreenNode metaCode, RazorDiagnostic[] diagnostics, SyntaxAnnotation[] annotations)
+ : base(kind, diagnostics, annotations)
+ {
+ SlotCount = 1;
+ if (metaCode != null)
+ {
+ AdjustFlagsAndWidth(metaCode);
+ _metaCode = metaCode;
+ }
+ }
+
+
+ internal CSharpMetaCodeSyntax(SyntaxKind kind, GreenNode metaCode)
+ : base(kind)
+ {
+ SlotCount = 1;
+ if (metaCode != null)
+ {
+ AdjustFlagsAndWidth(metaCode);
+ _metaCode = metaCode;
+ }
+ }
+
+ public SyntaxList MetaCode { get { return new SyntaxList(_metaCode); } }
+
+ internal override GreenNode GetSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return _metaCode;
+ default: return null;
+ }
+ }
+
+ internal override SyntaxNode CreateRed(SyntaxNode parent, int position)
+ {
+ return new Syntax.CSharpMetaCodeSyntax(this, parent, position);
+ }
+
+ public override TResult Accept(SyntaxVisitor visitor)
+ {
+ return visitor.VisitCSharpMetaCode(this);
+ }
+
+ public override void Accept(SyntaxVisitor visitor)
+ {
+ visitor.VisitCSharpMetaCode(this);
+ }
+
+ public CSharpMetaCodeSyntax Update(Microsoft.AspNetCore.Razor.Language.Syntax.InternalSyntax.SyntaxList metaCode)
+ {
+ if (metaCode != MetaCode)
+ {
+ var newNode = SyntaxFactory.CSharpMetaCode(metaCode);
+ var diags = GetDiagnostics();
+ if (diags != null && diags.Length > 0)
+ newNode = newNode.WithDiagnosticsGreen(diags);
+ var annotations = GetAnnotations();
+ if (annotations != null && annotations.Length > 0)
+ newNode = newNode.WithAnnotationsGreen(annotations);
+ return newNode;
+ }
+
+ return this;
+ }
+
+ internal override GreenNode SetDiagnostics(RazorDiagnostic[] diagnostics)
+ {
+ return new CSharpMetaCodeSyntax(Kind, _metaCode, diagnostics, GetAnnotations());
+ }
+
+ internal override GreenNode SetAnnotations(SyntaxAnnotation[] annotations)
+ {
+ return new CSharpMetaCodeSyntax(Kind, _metaCode, GetDiagnostics(), annotations);
+ }
+ }
+
+ internal sealed partial class CSharpCodeLiteralSyntax : CSharpSyntaxNode
+ {
+ private readonly GreenNode _cSharpTokens;
+
+ internal CSharpCodeLiteralSyntax(SyntaxKind kind, GreenNode cSharpTokens, RazorDiagnostic[] diagnostics, SyntaxAnnotation[] annotations)
+ : base(kind, diagnostics, annotations)
+ {
+ SlotCount = 1;
+ if (cSharpTokens != null)
+ {
+ AdjustFlagsAndWidth(cSharpTokens);
+ _cSharpTokens = cSharpTokens;
+ }
+ }
+
+
+ internal CSharpCodeLiteralSyntax(SyntaxKind kind, GreenNode cSharpTokens)
+ : base(kind)
+ {
+ SlotCount = 1;
+ if (cSharpTokens != null)
+ {
+ AdjustFlagsAndWidth(cSharpTokens);
+ _cSharpTokens = cSharpTokens;
+ }
+ }
+
+ public SyntaxList CSharpTokens { get { return new SyntaxList(_cSharpTokens); } }
+
+ internal override GreenNode GetSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return _cSharpTokens;
+ default: return null;
+ }
+ }
+
+ internal override SyntaxNode CreateRed(SyntaxNode parent, int position)
+ {
+ return new Syntax.CSharpCodeLiteralSyntax(this, parent, position);
+ }
+
+ public override TResult Accept(SyntaxVisitor visitor)
+ {
+ return visitor.VisitCSharpCodeLiteral(this);
+ }
+
+ public override void Accept(SyntaxVisitor visitor)
+ {
+ visitor.VisitCSharpCodeLiteral(this);
+ }
+
+ public CSharpCodeLiteralSyntax Update(Microsoft.AspNetCore.Razor.Language.Syntax.InternalSyntax.SyntaxList cSharpTokens)
+ {
+ if (cSharpTokens != CSharpTokens)
+ {
+ var newNode = SyntaxFactory.CSharpCodeLiteral(cSharpTokens);
+ var diags = GetDiagnostics();
+ if (diags != null && diags.Length > 0)
+ newNode = newNode.WithDiagnosticsGreen(diags);
+ var annotations = GetAnnotations();
+ if (annotations != null && annotations.Length > 0)
+ newNode = newNode.WithAnnotationsGreen(annotations);
+ return newNode;
+ }
+
+ return this;
+ }
+
+ internal override GreenNode SetDiagnostics(RazorDiagnostic[] diagnostics)
+ {
+ return new CSharpCodeLiteralSyntax(Kind, _cSharpTokens, diagnostics, GetAnnotations());
+ }
+
+ internal override GreenNode SetAnnotations(SyntaxAnnotation[] annotations)
+ {
+ return new CSharpCodeLiteralSyntax(Kind, _cSharpTokens, GetDiagnostics(), annotations);
+ }
+ }
+
+ internal sealed partial class CSharpCodeBlockSyntax : CSharpSyntaxNode
+ {
+ private readonly GreenNode _children;
+
+ internal CSharpCodeBlockSyntax(SyntaxKind kind, GreenNode children, RazorDiagnostic[] diagnostics, SyntaxAnnotation[] annotations)
+ : base(kind, diagnostics, annotations)
+ {
+ SlotCount = 1;
+ if (children != null)
+ {
+ AdjustFlagsAndWidth(children);
+ _children = children;
+ }
+ }
+
+
+ internal CSharpCodeBlockSyntax(SyntaxKind kind, GreenNode children)
+ : base(kind)
+ {
+ SlotCount = 1;
+ if (children != null)
+ {
+ AdjustFlagsAndWidth(children);
+ _children = children;
+ }
+ }
+
+ public SyntaxList Children { get { return new SyntaxList(_children); } }
+
+ internal override GreenNode GetSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return _children;
+ default: return null;
+ }
+ }
+
+ internal override SyntaxNode CreateRed(SyntaxNode parent, int position)
+ {
+ return new Syntax.CSharpCodeBlockSyntax(this, parent, position);
+ }
+
+ public override TResult Accept(SyntaxVisitor visitor)
+ {
+ return visitor.VisitCSharpCodeBlock(this);
+ }
+
+ public override void Accept(SyntaxVisitor visitor)
+ {
+ visitor.VisitCSharpCodeBlock(this);
+ }
+
+ public CSharpCodeBlockSyntax Update(Microsoft.AspNetCore.Razor.Language.Syntax.InternalSyntax.SyntaxList children)
+ {
+ if (children != Children)
+ {
+ var newNode = SyntaxFactory.CSharpCodeBlock(children);
+ var diags = GetDiagnostics();
+ if (diags != null && diags.Length > 0)
+ newNode = newNode.WithDiagnosticsGreen(diags);
+ var annotations = GetAnnotations();
+ if (annotations != null && annotations.Length > 0)
+ newNode = newNode.WithAnnotationsGreen(annotations);
+ return newNode;
+ }
+
+ return this;
+ }
+
+ internal override GreenNode SetDiagnostics(RazorDiagnostic[] diagnostics)
+ {
+ return new CSharpCodeBlockSyntax(Kind, _children, diagnostics, GetAnnotations());
+ }
+
+ internal override GreenNode SetAnnotations(SyntaxAnnotation[] annotations)
+ {
+ return new CSharpCodeBlockSyntax(Kind, _children, GetDiagnostics(), annotations);
+ }
+ }
+
+ internal abstract partial class CSharpBlockSyntax : CSharpSyntaxNode
+ {
+ internal CSharpBlockSyntax(SyntaxKind kind, RazorDiagnostic[] diagnostics, SyntaxAnnotation[] annotations)
+ : base(kind, diagnostics, annotations)
+ {
+ }
+ internal CSharpBlockSyntax(SyntaxKind kind)
+ : base(kind)
+ {
+ }
+
+ public abstract CSharpTransitionSyntax Transition { get; }
+
+ public abstract CSharpSyntaxNode Body { get; }
+ }
+
+ internal sealed partial class CSharpStatement : CSharpBlockSyntax
+ {
+ private readonly CSharpTransitionSyntax _transition;
+ private readonly CSharpSyntaxNode _body;
+
+ internal CSharpStatement(SyntaxKind kind, CSharpTransitionSyntax transition, CSharpSyntaxNode body, RazorDiagnostic[] diagnostics, SyntaxAnnotation[] annotations)
+ : base(kind, diagnostics, annotations)
+ {
+ SlotCount = 2;
+ AdjustFlagsAndWidth(transition);
+ _transition = transition;
+ AdjustFlagsAndWidth(body);
+ _body = body;
+ }
+
+
+ internal CSharpStatement(SyntaxKind kind, CSharpTransitionSyntax transition, CSharpSyntaxNode body)
+ : base(kind)
+ {
+ SlotCount = 2;
+ AdjustFlagsAndWidth(transition);
+ _transition = transition;
+ AdjustFlagsAndWidth(body);
+ _body = body;
+ }
+
+ public override CSharpTransitionSyntax Transition { get { return _transition; } }
+ public override CSharpSyntaxNode Body { get { return _body; } }
+
+ internal override GreenNode GetSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return _transition;
+ case 1: return _body;
+ default: return null;
+ }
+ }
+
+ internal override SyntaxNode CreateRed(SyntaxNode parent, int position)
+ {
+ return new Syntax.CSharpStatement(this, parent, position);
+ }
+
+ public override TResult Accept(SyntaxVisitor visitor)
+ {
+ return visitor.VisitCSharpStatement(this);
+ }
+
+ public override void Accept(SyntaxVisitor visitor)
+ {
+ visitor.VisitCSharpStatement(this);
+ }
+
+ public CSharpStatement Update(CSharpTransitionSyntax transition, CSharpSyntaxNode body)
+ {
+ if (transition != Transition || body != Body)
+ {
+ var newNode = SyntaxFactory.CSharpStatement(transition, body);
+ var diags = GetDiagnostics();
+ if (diags != null && diags.Length > 0)
+ newNode = newNode.WithDiagnosticsGreen(diags);
+ var annotations = GetAnnotations();
+ if (annotations != null && annotations.Length > 0)
+ newNode = newNode.WithAnnotationsGreen(annotations);
+ return newNode;
+ }
+
+ return this;
+ }
+
+ internal override GreenNode SetDiagnostics(RazorDiagnostic[] diagnostics)
+ {
+ return new CSharpStatement(Kind, _transition, _body, diagnostics, GetAnnotations());
+ }
+
+ internal override GreenNode SetAnnotations(SyntaxAnnotation[] annotations)
+ {
+ return new CSharpStatement(Kind, _transition, _body, GetDiagnostics(), annotations);
+ }
+ }
+
+ internal sealed partial class CSharpStatementBodySyntax : CSharpSyntaxNode
+ {
+ private readonly CSharpMetaCodeSyntax _openBrace;
+ private readonly CSharpCodeBlockSyntax _cSharpCode;
+ private readonly CSharpMetaCodeSyntax _closeBrace;
+
+ internal CSharpStatementBodySyntax(SyntaxKind kind, CSharpMetaCodeSyntax openBrace, CSharpCodeBlockSyntax cSharpCode, CSharpMetaCodeSyntax closeBrace, RazorDiagnostic[] diagnostics, SyntaxAnnotation[] annotations)
+ : base(kind, diagnostics, annotations)
+ {
+ SlotCount = 3;
+ AdjustFlagsAndWidth(openBrace);
+ _openBrace = openBrace;
+ AdjustFlagsAndWidth(cSharpCode);
+ _cSharpCode = cSharpCode;
+ AdjustFlagsAndWidth(closeBrace);
+ _closeBrace = closeBrace;
+ }
+
+
+ internal CSharpStatementBodySyntax(SyntaxKind kind, CSharpMetaCodeSyntax openBrace, CSharpCodeBlockSyntax cSharpCode, CSharpMetaCodeSyntax closeBrace)
+ : base(kind)
+ {
+ SlotCount = 3;
+ AdjustFlagsAndWidth(openBrace);
+ _openBrace = openBrace;
+ AdjustFlagsAndWidth(cSharpCode);
+ _cSharpCode = cSharpCode;
+ AdjustFlagsAndWidth(closeBrace);
+ _closeBrace = closeBrace;
+ }
+
+ public CSharpMetaCodeSyntax OpenBrace { get { return _openBrace; } }
+ public CSharpCodeBlockSyntax CSharpCode { get { return _cSharpCode; } }
+ public CSharpMetaCodeSyntax CloseBrace { get { return _closeBrace; } }
+
+ internal override GreenNode GetSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return _openBrace;
+ case 1: return _cSharpCode;
+ case 2: return _closeBrace;
+ default: return null;
+ }
+ }
+
+ internal override SyntaxNode CreateRed(SyntaxNode parent, int position)
+ {
+ return new Syntax.CSharpStatementBodySyntax(this, parent, position);
+ }
+
+ public override TResult Accept(SyntaxVisitor visitor)
+ {
+ return visitor.VisitCSharpStatementBody(this);
+ }
+
+ public override void Accept(SyntaxVisitor visitor)
+ {
+ visitor.VisitCSharpStatementBody(this);
+ }
+
+ public CSharpStatementBodySyntax Update(CSharpMetaCodeSyntax openBrace, CSharpCodeBlockSyntax cSharpCode, CSharpMetaCodeSyntax closeBrace)
+ {
+ if (openBrace != OpenBrace || cSharpCode != CSharpCode || closeBrace != CloseBrace)
+ {
+ var newNode = SyntaxFactory.CSharpStatementBody(openBrace, cSharpCode, closeBrace);
+ var diags = GetDiagnostics();
+ if (diags != null && diags.Length > 0)
+ newNode = newNode.WithDiagnosticsGreen(diags);
+ var annotations = GetAnnotations();
+ if (annotations != null && annotations.Length > 0)
+ newNode = newNode.WithAnnotationsGreen(annotations);
+ return newNode;
+ }
+
+ return this;
+ }
+
+ internal override GreenNode SetDiagnostics(RazorDiagnostic[] diagnostics)
+ {
+ return new CSharpStatementBodySyntax(Kind, _openBrace, _cSharpCode, _closeBrace, diagnostics, GetAnnotations());
+ }
+
+ internal override GreenNode SetAnnotations(SyntaxAnnotation[] annotations)
+ {
+ return new CSharpStatementBodySyntax(Kind, _openBrace, _cSharpCode, _closeBrace, GetDiagnostics(), annotations);
+ }
+ }
+
+ internal sealed partial class CSharpExpression : CSharpBlockSyntax
+ {
+ private readonly CSharpTransitionSyntax _transition;
+ private readonly CSharpSyntaxNode _body;
+
+ internal CSharpExpression(SyntaxKind kind, CSharpTransitionSyntax transition, CSharpSyntaxNode body, RazorDiagnostic[] diagnostics, SyntaxAnnotation[] annotations)
+ : base(kind, diagnostics, annotations)
+ {
+ SlotCount = 2;
+ AdjustFlagsAndWidth(transition);
+ _transition = transition;
+ AdjustFlagsAndWidth(body);
+ _body = body;
+ }
+
+
+ internal CSharpExpression(SyntaxKind kind, CSharpTransitionSyntax transition, CSharpSyntaxNode body)
+ : base(kind)
+ {
+ SlotCount = 2;
+ AdjustFlagsAndWidth(transition);
+ _transition = transition;
+ AdjustFlagsAndWidth(body);
+ _body = body;
+ }
+
+ public override CSharpTransitionSyntax Transition { get { return _transition; } }
+ public override CSharpSyntaxNode Body { get { return _body; } }
+
+ internal override GreenNode GetSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return _transition;
+ case 1: return _body;
+ default: return null;
+ }
+ }
+
+ internal override SyntaxNode CreateRed(SyntaxNode parent, int position)
+ {
+ return new Syntax.CSharpExpression(this, parent, position);
+ }
+
+ public override TResult Accept(SyntaxVisitor visitor)
+ {
+ return visitor.VisitCSharpExpression(this);
+ }
+
+ public override void Accept(SyntaxVisitor visitor)
+ {
+ visitor.VisitCSharpExpression(this);
+ }
+
+ public CSharpExpression Update(CSharpTransitionSyntax transition, CSharpSyntaxNode body)
+ {
+ if (transition != Transition || body != Body)
+ {
+ var newNode = SyntaxFactory.CSharpExpression(transition, body);
+ var diags = GetDiagnostics();
+ if (diags != null && diags.Length > 0)
+ newNode = newNode.WithDiagnosticsGreen(diags);
+ var annotations = GetAnnotations();
+ if (annotations != null && annotations.Length > 0)
+ newNode = newNode.WithAnnotationsGreen(annotations);
+ return newNode;
+ }
+
+ return this;
+ }
+
+ internal override GreenNode SetDiagnostics(RazorDiagnostic[] diagnostics)
+ {
+ return new CSharpExpression(Kind, _transition, _body, diagnostics, GetAnnotations());
+ }
+
+ internal override GreenNode SetAnnotations(SyntaxAnnotation[] annotations)
+ {
+ return new CSharpExpression(Kind, _transition, _body, GetDiagnostics(), annotations);
+ }
+ }
+
+ internal sealed partial class CSharpExpressionBodySyntax : CSharpSyntaxNode
+ {
+ private readonly CSharpMetaCodeSyntax _openParen;
+ private readonly CSharpCodeBlockSyntax _cSharpCode;
+ private readonly CSharpMetaCodeSyntax _closeParen;
+
+ internal CSharpExpressionBodySyntax(SyntaxKind kind, CSharpMetaCodeSyntax openParen, CSharpCodeBlockSyntax cSharpCode, CSharpMetaCodeSyntax closeParen, RazorDiagnostic[] diagnostics, SyntaxAnnotation[] annotations)
+ : base(kind, diagnostics, annotations)
+ {
+ SlotCount = 3;
+ if (openParen != null)
+ {
+ AdjustFlagsAndWidth(openParen);
+ _openParen = openParen;
+ }
+ AdjustFlagsAndWidth(cSharpCode);
+ _cSharpCode = cSharpCode;
+ if (closeParen != null)
+ {
+ AdjustFlagsAndWidth(closeParen);
+ _closeParen = closeParen;
+ }
+ }
+
+
+ internal CSharpExpressionBodySyntax(SyntaxKind kind, CSharpMetaCodeSyntax openParen, CSharpCodeBlockSyntax cSharpCode, CSharpMetaCodeSyntax closeParen)
+ : base(kind)
+ {
+ SlotCount = 3;
+ if (openParen != null)
+ {
+ AdjustFlagsAndWidth(openParen);
+ _openParen = openParen;
+ }
+ AdjustFlagsAndWidth(cSharpCode);
+ _cSharpCode = cSharpCode;
+ if (closeParen != null)
+ {
+ AdjustFlagsAndWidth(closeParen);
+ _closeParen = closeParen;
+ }
+ }
+
+ public CSharpMetaCodeSyntax OpenParen { get { return _openParen; } }
+ public CSharpCodeBlockSyntax CSharpCode { get { return _cSharpCode; } }
+ public CSharpMetaCodeSyntax CloseParen { get { return _closeParen; } }
+
+ internal override GreenNode GetSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return _openParen;
+ case 1: return _cSharpCode;
+ case 2: return _closeParen;
+ default: return null;
+ }
+ }
+
+ internal override SyntaxNode CreateRed(SyntaxNode parent, int position)
+ {
+ return new Syntax.CSharpExpressionBodySyntax(this, parent, position);
+ }
+
+ public override TResult Accept(SyntaxVisitor visitor)
+ {
+ return visitor.VisitCSharpExpressionBody(this);
+ }
+
+ public override void Accept(SyntaxVisitor visitor)
+ {
+ visitor.VisitCSharpExpressionBody(this);
+ }
+
+ public CSharpExpressionBodySyntax Update(CSharpMetaCodeSyntax openParen, CSharpCodeBlockSyntax cSharpCode, CSharpMetaCodeSyntax closeParen)
+ {
+ if (openParen != OpenParen || cSharpCode != CSharpCode || closeParen != CloseParen)
+ {
+ var newNode = SyntaxFactory.CSharpExpressionBody(openParen, cSharpCode, closeParen);
+ var diags = GetDiagnostics();
+ if (diags != null && diags.Length > 0)
+ newNode = newNode.WithDiagnosticsGreen(diags);
+ var annotations = GetAnnotations();
+ if (annotations != null && annotations.Length > 0)
+ newNode = newNode.WithAnnotationsGreen(annotations);
+ return newNode;
+ }
+
+ return this;
+ }
+
+ internal override GreenNode SetDiagnostics(RazorDiagnostic[] diagnostics)
+ {
+ return new CSharpExpressionBodySyntax(Kind, _openParen, _cSharpCode, _closeParen, diagnostics, GetAnnotations());
+ }
+
+ internal override GreenNode SetAnnotations(SyntaxAnnotation[] annotations)
+ {
+ return new CSharpExpressionBodySyntax(Kind, _openParen, _cSharpCode, _closeParen, GetDiagnostics(), annotations);
+ }
+ }
+
+ internal sealed partial class CSharpDirectiveSyntax : CSharpBlockSyntax
+ {
+ private readonly CSharpTransitionSyntax _transition;
+ private readonly CSharpSyntaxNode _body;
+
+ internal CSharpDirectiveSyntax(SyntaxKind kind, CSharpTransitionSyntax transition, CSharpSyntaxNode body, RazorDiagnostic[] diagnostics, SyntaxAnnotation[] annotations)
+ : base(kind, diagnostics, annotations)
+ {
+ SlotCount = 2;
+ AdjustFlagsAndWidth(transition);
+ _transition = transition;
+ AdjustFlagsAndWidth(body);
+ _body = body;
+ }
+
+
+ internal CSharpDirectiveSyntax(SyntaxKind kind, CSharpTransitionSyntax transition, CSharpSyntaxNode body)
+ : base(kind)
+ {
+ SlotCount = 2;
+ AdjustFlagsAndWidth(transition);
+ _transition = transition;
+ AdjustFlagsAndWidth(body);
+ _body = body;
+ }
+
+ public override CSharpTransitionSyntax Transition { get { return _transition; } }
+ public override CSharpSyntaxNode Body { get { return _body; } }
+
+ internal override GreenNode GetSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return _transition;
+ case 1: return _body;
+ default: return null;
+ }
+ }
+
+ internal override SyntaxNode CreateRed(SyntaxNode parent, int position)
+ {
+ return new Syntax.CSharpDirectiveSyntax(this, parent, position);
+ }
+
+ public override TResult Accept(SyntaxVisitor visitor)
+ {
+ return visitor.VisitCSharpDirective(this);
+ }
+
+ public override void Accept(SyntaxVisitor visitor)
+ {
+ visitor.VisitCSharpDirective(this);
+ }
+
+ public CSharpDirectiveSyntax Update(CSharpTransitionSyntax transition, CSharpSyntaxNode body)
+ {
+ if (transition != Transition || body != Body)
+ {
+ var newNode = SyntaxFactory.CSharpDirective(transition, body);
+ var diags = GetDiagnostics();
+ if (diags != null && diags.Length > 0)
+ newNode = newNode.WithDiagnosticsGreen(diags);
+ var annotations = GetAnnotations();
+ if (annotations != null && annotations.Length > 0)
+ newNode = newNode.WithAnnotationsGreen(annotations);
+ return newNode;
+ }
+
+ return this;
+ }
+
+ internal override GreenNode SetDiagnostics(RazorDiagnostic[] diagnostics)
+ {
+ return new CSharpDirectiveSyntax(Kind, _transition, _body, diagnostics, GetAnnotations());
+ }
+
+ internal override GreenNode SetAnnotations(SyntaxAnnotation[] annotations)
+ {
+ return new CSharpDirectiveSyntax(Kind, _transition, _body, GetDiagnostics(), annotations);
+ }
+ }
+
+ internal sealed partial class CSharpDirectiveBodySyntax : CSharpSyntaxNode
+ {
+ private readonly CSharpMetaCodeSyntax _keyword;
+ private readonly CSharpCodeBlockSyntax _cSharpCode;
+
+ internal CSharpDirectiveBodySyntax(SyntaxKind kind, CSharpMetaCodeSyntax keyword, CSharpCodeBlockSyntax cSharpCode, RazorDiagnostic[] diagnostics, SyntaxAnnotation[] annotations)
+ : base(kind, diagnostics, annotations)
+ {
+ SlotCount = 2;
+ AdjustFlagsAndWidth(keyword);
+ _keyword = keyword;
+ AdjustFlagsAndWidth(cSharpCode);
+ _cSharpCode = cSharpCode;
+ }
+
+
+ internal CSharpDirectiveBodySyntax(SyntaxKind kind, CSharpMetaCodeSyntax keyword, CSharpCodeBlockSyntax cSharpCode)
+ : base(kind)
+ {
+ SlotCount = 2;
+ AdjustFlagsAndWidth(keyword);
+ _keyword = keyword;
+ AdjustFlagsAndWidth(cSharpCode);
+ _cSharpCode = cSharpCode;
+ }
+
+ public CSharpMetaCodeSyntax Keyword { get { return _keyword; } }
+ public CSharpCodeBlockSyntax CSharpCode { get { return _cSharpCode; } }
+
+ internal override GreenNode GetSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return _keyword;
+ case 1: return _cSharpCode;
+ default: return null;
+ }
+ }
+
+ internal override SyntaxNode CreateRed(SyntaxNode parent, int position)
+ {
+ return new Syntax.CSharpDirectiveBodySyntax(this, parent, position);
+ }
+
+ public override TResult Accept(SyntaxVisitor visitor)
+ {
+ return visitor.VisitCSharpDirectiveBody(this);
+ }
+
+ public override void Accept(SyntaxVisitor visitor)
+ {
+ visitor.VisitCSharpDirectiveBody(this);
+ }
+
+ public CSharpDirectiveBodySyntax Update(CSharpMetaCodeSyntax keyword, CSharpCodeBlockSyntax cSharpCode)
+ {
+ if (keyword != Keyword || cSharpCode != CSharpCode)
+ {
+ var newNode = SyntaxFactory.CSharpDirectiveBody(keyword, cSharpCode);
+ var diags = GetDiagnostics();
+ if (diags != null && diags.Length > 0)
+ newNode = newNode.WithDiagnosticsGreen(diags);
+ var annotations = GetAnnotations();
+ if (annotations != null && annotations.Length > 0)
+ newNode = newNode.WithAnnotationsGreen(annotations);
+ return newNode;
+ }
+
+ return this;
+ }
+
+ internal override GreenNode SetDiagnostics(RazorDiagnostic[] diagnostics)
+ {
+ return new CSharpDirectiveBodySyntax(Kind, _keyword, _cSharpCode, diagnostics, GetAnnotations());
+ }
+
+ internal override GreenNode SetAnnotations(SyntaxAnnotation[] annotations)
+ {
+ return new CSharpDirectiveBodySyntax(Kind, _keyword, _cSharpCode, GetDiagnostics(), annotations);
+ }
+ }
+
+ internal partial class SyntaxVisitor
+ {
+ public virtual TResult VisitRazorCommentBlock(RazorCommentBlockSyntax node)
+ {
+ return DefaultVisit(node);
+ }
+
+ public virtual TResult VisitHtmlTextLiteral(HtmlTextLiteralSyntax node)
+ {
+ return DefaultVisit(node);
+ }
+
+ public virtual TResult VisitCSharpTransition(CSharpTransitionSyntax node)
+ {
+ return DefaultVisit(node);
+ }
+
+ public virtual TResult VisitCSharpMetaCode(CSharpMetaCodeSyntax node)
+ {
+ return DefaultVisit(node);
+ }
+
+ public virtual TResult VisitCSharpCodeLiteral(CSharpCodeLiteralSyntax node)
+ {
+ return DefaultVisit(node);
+ }
+
+ public virtual TResult VisitCSharpCodeBlock(CSharpCodeBlockSyntax node)
+ {
+ return DefaultVisit(node);
+ }
+
+ public virtual TResult VisitCSharpStatement(CSharpStatement node)
+ {
+ return DefaultVisit(node);
+ }
+
+ public virtual TResult VisitCSharpStatementBody(CSharpStatementBodySyntax node)
+ {
+ return DefaultVisit(node);
+ }
+
+ public virtual TResult VisitCSharpExpression(CSharpExpression node)
+ {
+ return DefaultVisit(node);
+ }
+
+ public virtual TResult VisitCSharpExpressionBody(CSharpExpressionBodySyntax node)
+ {
+ return DefaultVisit(node);
+ }
+
+ public virtual TResult VisitCSharpDirective(CSharpDirectiveSyntax node)
+ {
+ return DefaultVisit(node);
+ }
+
+ public virtual TResult VisitCSharpDirectiveBody(CSharpDirectiveBodySyntax node)
+ {
+ return DefaultVisit(node);
+ }
+ }
+
+
+ internal partial class SyntaxVisitor
+ {
+ public virtual void VisitRazorCommentBlock(RazorCommentBlockSyntax node)
+ {
+ DefaultVisit(node);
+ }
+
+ public virtual void VisitHtmlTextLiteral(HtmlTextLiteralSyntax node)
+ {
+ DefaultVisit(node);
+ }
+
+ public virtual void VisitCSharpTransition(CSharpTransitionSyntax node)
+ {
+ DefaultVisit(node);
+ }
+
+ public virtual void VisitCSharpMetaCode(CSharpMetaCodeSyntax node)
+ {
+ DefaultVisit(node);
+ }
+
+ public virtual void VisitCSharpCodeLiteral(CSharpCodeLiteralSyntax node)
+ {
+ DefaultVisit(node);
+ }
+
+ public virtual void VisitCSharpCodeBlock(CSharpCodeBlockSyntax node)
+ {
+ DefaultVisit(node);
+ }
+
+ public virtual void VisitCSharpStatement(CSharpStatement node)
+ {
+ DefaultVisit(node);
+ }
+
+ public virtual void VisitCSharpStatementBody(CSharpStatementBodySyntax node)
+ {
+ DefaultVisit(node);
+ }
+
+ public virtual void VisitCSharpExpression(CSharpExpression node)
+ {
+ DefaultVisit(node);
+ }
+
+ public virtual void VisitCSharpExpressionBody(CSharpExpressionBodySyntax node)
+ {
+ DefaultVisit(node);
+ }
+
+ public virtual void VisitCSharpDirective(CSharpDirectiveSyntax node)
+ {
+ DefaultVisit(node);
+ }
+
+ public virtual void VisitCSharpDirectiveBody(CSharpDirectiveBodySyntax node)
+ {
+ DefaultVisit(node);
+ }
+ }
+
+ internal static partial class SyntaxFactory
+ {
+ public static RazorCommentBlockSyntax RazorCommentBlock(SyntaxToken startCommentTransition, SyntaxToken startCommentStar, SyntaxToken comment, SyntaxToken endCommentStar, SyntaxToken endCommentTransition)
+ {
+ if (startCommentTransition == null)
+ throw new ArgumentNullException(nameof(startCommentTransition));
+ switch (startCommentTransition.Kind)
+ {
+ case SyntaxKind.RazorCommentTransition:
+ break;
+ default:
+ throw new ArgumentException("startCommentTransition");
+ }
+ if (startCommentStar == null)
+ throw new ArgumentNullException(nameof(startCommentStar));
+ switch (startCommentStar.Kind)
+ {
+ case SyntaxKind.RazorCommentStar:
+ break;
+ default:
+ throw new ArgumentException("startCommentStar");
+ }
+ if (comment != null)
+ {
+ switch (comment.Kind)
+ {
+ case SyntaxKind.RazorComment:
+ case SyntaxKind.Unknown:
+ break;
+ default:
+ throw new ArgumentException("comment");
+ }
+ }
+ if (endCommentStar == null)
+ throw new ArgumentNullException(nameof(endCommentStar));
+ switch (endCommentStar.Kind)
+ {
+ case SyntaxKind.RazorCommentStar:
+ break;
+ default:
+ throw new ArgumentException("endCommentStar");
+ }
+ if (endCommentTransition == null)
+ throw new ArgumentNullException(nameof(endCommentTransition));
+ switch (endCommentTransition.Kind)
+ {
+ case SyntaxKind.RazorCommentTransition:
+ break;
+ default:
+ throw new ArgumentException("endCommentTransition");
+ }
+
+ return new RazorCommentBlockSyntax(SyntaxKind.RazorComment, startCommentTransition, startCommentStar, comment, endCommentStar, endCommentTransition);
+ }
+
+ public static HtmlTextLiteralSyntax HtmlTextLiteral(Microsoft.AspNetCore.Razor.Language.Syntax.InternalSyntax.SyntaxList textTokens)
+ {
+ var result = new HtmlTextLiteralSyntax(SyntaxKind.HtmlTextLiteral, textTokens.Node);
+
+ return result;
+ }
+
+ public static CSharpTransitionSyntax CSharpTransition(SyntaxToken transition)
+ {
+ if (transition == null)
+ throw new ArgumentNullException(nameof(transition));
+ switch (transition.Kind)
+ {
+ case SyntaxKind.Transition:
+ break;
+ default:
+ throw new ArgumentException("transition");
+ }
+
+ var result = new CSharpTransitionSyntax(SyntaxKind.CSharpTransition, transition);
+
+ return result;
+ }
+
+ public static CSharpMetaCodeSyntax CSharpMetaCode(Microsoft.AspNetCore.Razor.Language.Syntax.InternalSyntax.SyntaxList metaCode)
+ {
+ var result = new CSharpMetaCodeSyntax(SyntaxKind.CSharpMetaCode, metaCode.Node);
+
+ return result;
+ }
+
+ public static CSharpCodeLiteralSyntax CSharpCodeLiteral(Microsoft.AspNetCore.Razor.Language.Syntax.InternalSyntax.SyntaxList cSharpTokens)
+ {
+ var result = new CSharpCodeLiteralSyntax(SyntaxKind.CSharpCodeLiteral, cSharpTokens.Node);
+
+ return result;
+ }
+
+ public static CSharpCodeBlockSyntax CSharpCodeBlock(Microsoft.AspNetCore.Razor.Language.Syntax.InternalSyntax.SyntaxList children)
+ {
+ var result = new CSharpCodeBlockSyntax(SyntaxKind.CSharpCodeBlock, children.Node);
+
+ return result;
+ }
+
+ public static CSharpStatement CSharpStatement(CSharpTransitionSyntax transition, CSharpSyntaxNode body)
+ {
+ if (transition == null)
+ throw new ArgumentNullException(nameof(transition));
+ if (body == null)
+ throw new ArgumentNullException(nameof(body));
+
+ var result = new CSharpStatement(SyntaxKind.CSharpStatement, transition, body);
+
+ return result;
+ }
+
+ public static CSharpStatementBodySyntax CSharpStatementBody(CSharpMetaCodeSyntax openBrace, CSharpCodeBlockSyntax cSharpCode, CSharpMetaCodeSyntax closeBrace)
+ {
+ if (openBrace == null)
+ throw new ArgumentNullException(nameof(openBrace));
+ if (cSharpCode == null)
+ throw new ArgumentNullException(nameof(cSharpCode));
+ if (closeBrace == null)
+ throw new ArgumentNullException(nameof(closeBrace));
+
+ var result = new CSharpStatementBodySyntax(SyntaxKind.CSharpStatementBody, openBrace, cSharpCode, closeBrace);
+
+ return result;
+ }
+
+ public static CSharpExpression CSharpExpression(CSharpTransitionSyntax transition, CSharpSyntaxNode body)
+ {
+ if (transition == null)
+ throw new ArgumentNullException(nameof(transition));
+ if (body == null)
+ throw new ArgumentNullException(nameof(body));
+
+ var result = new CSharpExpression(SyntaxKind.CSharpExpression, transition, body);
+
+ return result;
+ }
+
+ public static CSharpExpressionBodySyntax CSharpExpressionBody(CSharpMetaCodeSyntax openParen, CSharpCodeBlockSyntax cSharpCode, CSharpMetaCodeSyntax closeParen)
+ {
+ if (cSharpCode == null)
+ throw new ArgumentNullException(nameof(cSharpCode));
+
+ var result = new CSharpExpressionBodySyntax(SyntaxKind.CSharpExpressionBody, openParen, cSharpCode, closeParen);
+
+ return result;
+ }
+
+ public static CSharpDirectiveSyntax CSharpDirective(CSharpTransitionSyntax transition, CSharpSyntaxNode body)
+ {
+ if (transition == null)
+ throw new ArgumentNullException(nameof(transition));
+ if (body == null)
+ throw new ArgumentNullException(nameof(body));
+
+ var result = new CSharpDirectiveSyntax(SyntaxKind.CSharpDirective, transition, body);
+
+ return result;
+ }
+
+ public static CSharpDirectiveBodySyntax CSharpDirectiveBody(CSharpMetaCodeSyntax keyword, CSharpCodeBlockSyntax cSharpCode)
+ {
+ if (keyword == null)
+ throw new ArgumentNullException(nameof(keyword));
+ if (cSharpCode == null)
+ throw new ArgumentNullException(nameof(cSharpCode));
+
+ var result = new CSharpDirectiveBodySyntax(SyntaxKind.CSharpDirectiveBody, keyword, cSharpCode);
+
+ return result;
+ }
+
+ internal static IEnumerable GetNodeTypes()
+ {
+ return new Type[] {
+ typeof(RazorCommentBlockSyntax),
+ typeof(HtmlTextLiteralSyntax),
+ typeof(CSharpTransitionSyntax),
+ typeof(CSharpMetaCodeSyntax),
+ typeof(CSharpCodeLiteralSyntax),
+ typeof(CSharpCodeBlockSyntax),
+ typeof(CSharpStatement),
+ typeof(CSharpStatementBodySyntax),
+ typeof(CSharpExpression),
+ typeof(CSharpExpressionBodySyntax),
+ typeof(CSharpDirectiveSyntax),
+ typeof(CSharpDirectiveBodySyntax)
+ };
+ }
+ }
+}
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Syntax/Generated/Syntax.xml.Main.Generated.cs b/src/Microsoft.AspNetCore.Razor.Language/Syntax/Generated/Syntax.xml.Main.Generated.cs
new file mode 100644
index 0000000000..d22da664db
--- /dev/null
+++ b/src/Microsoft.AspNetCore.Razor.Language/Syntax/Generated/Syntax.xml.Main.Generated.cs
@@ -0,0 +1,375 @@
+//
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading;
+
+
+namespace Microsoft.AspNetCore.Razor.Language.Syntax
+{
+ internal partial class SyntaxVisitor
+ {
+ /// Called when the visitor visits a RazorCommentBlockSyntax node.
+ public virtual TResult VisitRazorCommentBlock(RazorCommentBlockSyntax node)
+ {
+ return DefaultVisit(node);
+ }
+
+ /// Called when the visitor visits a HtmlTextLiteralSyntax node.
+ public virtual TResult VisitHtmlTextLiteral(HtmlTextLiteralSyntax node)
+ {
+ return DefaultVisit(node);
+ }
+
+ /// Called when the visitor visits a CSharpTransitionSyntax node.
+ public virtual TResult VisitCSharpTransition(CSharpTransitionSyntax node)
+ {
+ return DefaultVisit(node);
+ }
+
+ /// Called when the visitor visits a CSharpMetaCodeSyntax node.
+ public virtual TResult VisitCSharpMetaCode(CSharpMetaCodeSyntax node)
+ {
+ return DefaultVisit(node);
+ }
+
+ /// Called when the visitor visits a CSharpCodeLiteralSyntax node.
+ public virtual TResult VisitCSharpCodeLiteral(CSharpCodeLiteralSyntax node)
+ {
+ return DefaultVisit(node);
+ }
+
+ /// Called when the visitor visits a CSharpCodeBlockSyntax node.
+ public virtual TResult VisitCSharpCodeBlock(CSharpCodeBlockSyntax node)
+ {
+ return DefaultVisit(node);
+ }
+
+ /// Called when the visitor visits a CSharpStatement node.
+ public virtual TResult VisitCSharpStatement(CSharpStatement node)
+ {
+ return DefaultVisit(node);
+ }
+
+ /// Called when the visitor visits a CSharpStatementBodySyntax node.
+ public virtual TResult VisitCSharpStatementBody(CSharpStatementBodySyntax node)
+ {
+ return DefaultVisit(node);
+ }
+
+ /// Called when the visitor visits a CSharpExpression node.
+ public virtual TResult VisitCSharpExpression(CSharpExpression node)
+ {
+ return DefaultVisit(node);
+ }
+
+ /// Called when the visitor visits a CSharpExpressionBodySyntax node.
+ public virtual TResult VisitCSharpExpressionBody(CSharpExpressionBodySyntax node)
+ {
+ return DefaultVisit(node);
+ }
+
+ /// Called when the visitor visits a CSharpDirectiveSyntax node.
+ public virtual TResult VisitCSharpDirective(CSharpDirectiveSyntax node)
+ {
+ return DefaultVisit(node);
+ }
+
+ /// Called when the visitor visits a CSharpDirectiveBodySyntax node.
+ public virtual TResult VisitCSharpDirectiveBody(CSharpDirectiveBodySyntax node)
+ {
+ return DefaultVisit(node);
+ }
+ }
+
+ internal partial class SyntaxVisitor
+ {
+ /// Called when the visitor visits a RazorCommentBlockSyntax node.
+ public virtual void VisitRazorCommentBlock(RazorCommentBlockSyntax node)
+ {
+ DefaultVisit(node);
+ }
+
+ /// Called when the visitor visits a HtmlTextLiteralSyntax node.
+ public virtual void VisitHtmlTextLiteral(HtmlTextLiteralSyntax node)
+ {
+ DefaultVisit(node);
+ }
+
+ /// Called when the visitor visits a CSharpTransitionSyntax node.
+ public virtual void VisitCSharpTransition(CSharpTransitionSyntax node)
+ {
+ DefaultVisit(node);
+ }
+
+ /// Called when the visitor visits a CSharpMetaCodeSyntax node.
+ public virtual void VisitCSharpMetaCode(CSharpMetaCodeSyntax node)
+ {
+ DefaultVisit(node);
+ }
+
+ /// Called when the visitor visits a CSharpCodeLiteralSyntax node.
+ public virtual void VisitCSharpCodeLiteral(CSharpCodeLiteralSyntax node)
+ {
+ DefaultVisit(node);
+ }
+
+ /// Called when the visitor visits a CSharpCodeBlockSyntax node.
+ public virtual void VisitCSharpCodeBlock(CSharpCodeBlockSyntax node)
+ {
+ DefaultVisit(node);
+ }
+
+ /// Called when the visitor visits a CSharpStatement node.
+ public virtual void VisitCSharpStatement(CSharpStatement node)
+ {
+ DefaultVisit(node);
+ }
+
+ /// Called when the visitor visits a CSharpStatementBodySyntax node.
+ public virtual void VisitCSharpStatementBody(CSharpStatementBodySyntax node)
+ {
+ DefaultVisit(node);
+ }
+
+ /// Called when the visitor visits a CSharpExpression node.
+ public virtual void VisitCSharpExpression(CSharpExpression node)
+ {
+ DefaultVisit(node);
+ }
+
+ /// Called when the visitor visits a CSharpExpressionBodySyntax node.
+ public virtual void VisitCSharpExpressionBody(CSharpExpressionBodySyntax node)
+ {
+ DefaultVisit(node);
+ }
+
+ /// Called when the visitor visits a CSharpDirectiveSyntax node.
+ public virtual void VisitCSharpDirective(CSharpDirectiveSyntax node)
+ {
+ DefaultVisit(node);
+ }
+
+ /// Called when the visitor visits a CSharpDirectiveBodySyntax node.
+ public virtual void VisitCSharpDirectiveBody(CSharpDirectiveBodySyntax node)
+ {
+ DefaultVisit(node);
+ }
+ }
+
+ internal static partial class SyntaxFactory
+ {
+ /// Creates a new RazorCommentBlockSyntax instance.
+ public static RazorCommentBlockSyntax RazorCommentBlock(SyntaxToken startCommentTransition, SyntaxToken startCommentStar, SyntaxToken comment, SyntaxToken endCommentStar, SyntaxToken endCommentTransition)
+ {
+ switch (startCommentTransition.Kind)
+ {
+ case SyntaxKind.RazorCommentTransition:
+ break;
+ default:
+ throw new ArgumentException("startCommentTransition");
+ }
+ switch (startCommentStar.Kind)
+ {
+ case SyntaxKind.RazorCommentStar:
+ break;
+ default:
+ throw new ArgumentException("startCommentStar");
+ }
+ switch (comment.Kind)
+ {
+ case SyntaxKind.RazorComment:
+ case SyntaxKind.Unknown:
+ break;
+ default:
+ throw new ArgumentException("comment");
+ }
+ switch (endCommentStar.Kind)
+ {
+ case SyntaxKind.RazorCommentStar:
+ break;
+ default:
+ throw new ArgumentException("endCommentStar");
+ }
+ switch (endCommentTransition.Kind)
+ {
+ case SyntaxKind.RazorCommentTransition:
+ break;
+ default:
+ throw new ArgumentException("endCommentTransition");
+ }
+ return (RazorCommentBlockSyntax)InternalSyntax.SyntaxFactory.RazorCommentBlock((Syntax.InternalSyntax.SyntaxToken)startCommentTransition.Green, (Syntax.InternalSyntax.SyntaxToken)startCommentStar.Green, (Syntax.InternalSyntax.SyntaxToken)comment.Green, (Syntax.InternalSyntax.SyntaxToken)endCommentStar.Green, (Syntax.InternalSyntax.SyntaxToken)endCommentTransition.Green).CreateRed();
+ }
+
+ /// Creates a new RazorCommentBlockSyntax instance.
+ public static RazorCommentBlockSyntax RazorCommentBlock()
+ {
+ return SyntaxFactory.RazorCommentBlock(SyntaxFactory.Token(SyntaxKind.RazorCommentTransition), SyntaxFactory.Token(SyntaxKind.RazorCommentStar), default(SyntaxToken), SyntaxFactory.Token(SyntaxKind.RazorCommentStar), SyntaxFactory.Token(SyntaxKind.RazorCommentTransition));
+ }
+
+ /// Creates a new HtmlTextLiteralSyntax instance.
+ public static HtmlTextLiteralSyntax HtmlTextLiteral(SyntaxList textTokens)
+ {
+ return (HtmlTextLiteralSyntax)InternalSyntax.SyntaxFactory.HtmlTextLiteral(textTokens.Node.ToGreenList()).CreateRed();
+ }
+
+ /// Creates a new HtmlTextLiteralSyntax instance.
+ public static HtmlTextLiteralSyntax HtmlTextLiteral()
+ {
+ return SyntaxFactory.HtmlTextLiteral(default(SyntaxList));
+ }
+
+ /// Creates a new CSharpTransitionSyntax instance.
+ public static CSharpTransitionSyntax CSharpTransition(SyntaxToken transition)
+ {
+ switch (transition.Kind)
+ {
+ case SyntaxKind.Transition:
+ break;
+ default:
+ throw new ArgumentException("transition");
+ }
+ return (CSharpTransitionSyntax)InternalSyntax.SyntaxFactory.CSharpTransition((Syntax.InternalSyntax.SyntaxToken)transition.Green).CreateRed();
+ }
+
+ /// Creates a new CSharpTransitionSyntax instance.
+ public static CSharpTransitionSyntax CSharpTransition()
+ {
+ return SyntaxFactory.CSharpTransition(SyntaxFactory.Token(SyntaxKind.Transition));
+ }
+
+ /// Creates a new CSharpMetaCodeSyntax instance.
+ public static CSharpMetaCodeSyntax CSharpMetaCode(SyntaxList metaCode)
+ {
+ return (CSharpMetaCodeSyntax)InternalSyntax.SyntaxFactory.CSharpMetaCode(metaCode.Node.ToGreenList()).CreateRed();
+ }
+
+ /// Creates a new CSharpMetaCodeSyntax instance.
+ public static CSharpMetaCodeSyntax CSharpMetaCode()
+ {
+ return SyntaxFactory.CSharpMetaCode(default(SyntaxList));
+ }
+
+ /// Creates a new CSharpCodeLiteralSyntax instance.
+ public static CSharpCodeLiteralSyntax CSharpCodeLiteral(SyntaxList cSharpTokens)
+ {
+ return (CSharpCodeLiteralSyntax)InternalSyntax.SyntaxFactory.CSharpCodeLiteral(cSharpTokens.Node.ToGreenList()).CreateRed();
+ }
+
+ /// Creates a new CSharpCodeLiteralSyntax instance.
+ public static CSharpCodeLiteralSyntax CSharpCodeLiteral()
+ {
+ return SyntaxFactory.CSharpCodeLiteral(default(SyntaxList));
+ }
+
+ /// Creates a new CSharpCodeBlockSyntax instance.
+ public static CSharpCodeBlockSyntax CSharpCodeBlock(SyntaxList children)
+ {
+ return (CSharpCodeBlockSyntax)InternalSyntax.SyntaxFactory.CSharpCodeBlock(children.Node.ToGreenList()).CreateRed();
+ }
+
+ /// Creates a new CSharpCodeBlockSyntax instance.
+ public static CSharpCodeBlockSyntax CSharpCodeBlock()
+ {
+ return SyntaxFactory.CSharpCodeBlock(default(SyntaxList));
+ }
+
+ /// Creates a new CSharpStatement instance.
+ public static CSharpStatement CSharpStatement(CSharpTransitionSyntax transition, CSharpSyntaxNode body)
+ {
+ if (transition == null)
+ throw new ArgumentNullException(nameof(transition));
+ if (body == null)
+ throw new ArgumentNullException(nameof(body));
+ return (CSharpStatement)InternalSyntax.SyntaxFactory.CSharpStatement(transition == null ? null : (InternalSyntax.CSharpTransitionSyntax)transition.Green, body == null ? null : (InternalSyntax.CSharpSyntaxNode)body.Green).CreateRed();
+ }
+
+ /// Creates a new CSharpStatement instance.
+ public static CSharpStatement CSharpStatement(CSharpSyntaxNode body)
+ {
+ return SyntaxFactory.CSharpStatement(SyntaxFactory.CSharpTransition(), body);
+ }
+
+ /// Creates a new CSharpStatementBodySyntax instance.
+ public static CSharpStatementBodySyntax CSharpStatementBody(CSharpMetaCodeSyntax openBrace, CSharpCodeBlockSyntax cSharpCode, CSharpMetaCodeSyntax closeBrace)
+ {
+ if (openBrace == null)
+ throw new ArgumentNullException(nameof(openBrace));
+ if (cSharpCode == null)
+ throw new ArgumentNullException(nameof(cSharpCode));
+ if (closeBrace == null)
+ throw new ArgumentNullException(nameof(closeBrace));
+ return (CSharpStatementBodySyntax)InternalSyntax.SyntaxFactory.CSharpStatementBody(openBrace == null ? null : (InternalSyntax.CSharpMetaCodeSyntax)openBrace.Green, cSharpCode == null ? null : (InternalSyntax.CSharpCodeBlockSyntax)cSharpCode.Green, closeBrace == null ? null : (InternalSyntax.CSharpMetaCodeSyntax)closeBrace.Green).CreateRed();
+ }
+
+ /// Creates a new CSharpStatementBodySyntax instance.
+ public static CSharpStatementBodySyntax CSharpStatementBody()
+ {
+ return SyntaxFactory.CSharpStatementBody(SyntaxFactory.CSharpMetaCode(), SyntaxFactory.CSharpCodeBlock(), SyntaxFactory.CSharpMetaCode());
+ }
+
+ /// Creates a new CSharpExpression instance.
+ public static CSharpExpression CSharpExpression(CSharpTransitionSyntax transition, CSharpSyntaxNode body)
+ {
+ if (transition == null)
+ throw new ArgumentNullException(nameof(transition));
+ if (body == null)
+ throw new ArgumentNullException(nameof(body));
+ return (CSharpExpression)InternalSyntax.SyntaxFactory.CSharpExpression(transition == null ? null : (InternalSyntax.CSharpTransitionSyntax)transition.Green, body == null ? null : (InternalSyntax.CSharpSyntaxNode)body.Green).CreateRed();
+ }
+
+ /// Creates a new CSharpExpression instance.
+ public static CSharpExpression CSharpExpression(CSharpSyntaxNode body)
+ {
+ return SyntaxFactory.CSharpExpression(SyntaxFactory.CSharpTransition(), body);
+ }
+
+ /// Creates a new CSharpExpressionBodySyntax instance.
+ public static CSharpExpressionBodySyntax CSharpExpressionBody(CSharpMetaCodeSyntax openParen, CSharpCodeBlockSyntax cSharpCode, CSharpMetaCodeSyntax closeParen)
+ {
+ if (cSharpCode == null)
+ throw new ArgumentNullException(nameof(cSharpCode));
+ return (CSharpExpressionBodySyntax)InternalSyntax.SyntaxFactory.CSharpExpressionBody(openParen == null ? null : (InternalSyntax.CSharpMetaCodeSyntax)openParen.Green, cSharpCode == null ? null : (InternalSyntax.CSharpCodeBlockSyntax)cSharpCode.Green, closeParen == null ? null : (InternalSyntax.CSharpMetaCodeSyntax)closeParen.Green).CreateRed();
+ }
+
+ /// Creates a new CSharpExpressionBodySyntax instance.
+ public static CSharpExpressionBodySyntax CSharpExpressionBody()
+ {
+ return SyntaxFactory.CSharpExpressionBody(default(CSharpMetaCodeSyntax), SyntaxFactory.CSharpCodeBlock(), default(CSharpMetaCodeSyntax));
+ }
+
+ /// Creates a new CSharpDirectiveSyntax instance.
+ public static CSharpDirectiveSyntax CSharpDirective(CSharpTransitionSyntax transition, CSharpSyntaxNode body)
+ {
+ if (transition == null)
+ throw new ArgumentNullException(nameof(transition));
+ if (body == null)
+ throw new ArgumentNullException(nameof(body));
+ return (CSharpDirectiveSyntax)InternalSyntax.SyntaxFactory.CSharpDirective(transition == null ? null : (InternalSyntax.CSharpTransitionSyntax)transition.Green, body == null ? null : (InternalSyntax.CSharpSyntaxNode)body.Green).CreateRed();
+ }
+
+ /// Creates a new CSharpDirectiveSyntax instance.
+ public static CSharpDirectiveSyntax CSharpDirective(CSharpSyntaxNode body)
+ {
+ return SyntaxFactory.CSharpDirective(SyntaxFactory.CSharpTransition(), body);
+ }
+
+ /// Creates a new CSharpDirectiveBodySyntax instance.
+ public static CSharpDirectiveBodySyntax CSharpDirectiveBody(CSharpMetaCodeSyntax keyword, CSharpCodeBlockSyntax cSharpCode)
+ {
+ if (keyword == null)
+ throw new ArgumentNullException(nameof(keyword));
+ if (cSharpCode == null)
+ throw new ArgumentNullException(nameof(cSharpCode));
+ return (CSharpDirectiveBodySyntax)InternalSyntax.SyntaxFactory.CSharpDirectiveBody(keyword == null ? null : (InternalSyntax.CSharpMetaCodeSyntax)keyword.Green, cSharpCode == null ? null : (InternalSyntax.CSharpCodeBlockSyntax)cSharpCode.Green).CreateRed();
+ }
+
+ /// Creates a new CSharpDirectiveBodySyntax instance.
+ public static CSharpDirectiveBodySyntax CSharpDirectiveBody()
+ {
+ return SyntaxFactory.CSharpDirectiveBody(SyntaxFactory.CSharpMetaCode(), SyntaxFactory.CSharpCodeBlock());
+ }
+ }
+}
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Syntax/Generated/Syntax.xml.Syntax.Generated.cs b/src/Microsoft.AspNetCore.Razor.Language/Syntax/Generated/Syntax.xml.Syntax.Generated.cs
new file mode 100644
index 0000000000..a11e4071eb
--- /dev/null
+++ b/src/Microsoft.AspNetCore.Razor.Language/Syntax/Generated/Syntax.xml.Syntax.Generated.cs
@@ -0,0 +1,1079 @@
+//
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading;
+
+
+namespace Microsoft.AspNetCore.Razor.Language.Syntax
+{
+ internal abstract partial class RazorSyntaxNode : SyntaxNode
+ {
+ internal RazorSyntaxNode(GreenNode green, SyntaxNode parent, int position)
+ : base(green, parent, position)
+ {
+ }
+ }
+
+ internal sealed partial class RazorCommentBlockSyntax : RazorSyntaxNode
+ {
+ private SyntaxToken _startCommentTransition;
+ private SyntaxToken _startCommentStar;
+ private SyntaxToken _comment;
+ private SyntaxToken _endCommentStar;
+ private SyntaxToken _endCommentTransition;
+
+ internal RazorCommentBlockSyntax(GreenNode green, SyntaxNode parent, int position)
+ : base(green, parent, position)
+ {
+ }
+
+ public SyntaxToken StartCommentTransition
+ {
+ get
+ {
+ return GetRedAtZero(ref _startCommentTransition);
+ }
+ }
+
+ public SyntaxToken StartCommentStar
+ {
+ get
+ {
+ return GetRed(ref _startCommentStar, 1);
+ }
+ }
+
+ public SyntaxToken Comment
+ {
+ get
+ {
+ return GetRed(ref _comment, 2);
+ }
+ }
+
+ public SyntaxToken EndCommentStar
+ {
+ get
+ {
+ return GetRed(ref _endCommentStar, 3);
+ }
+ }
+
+ public SyntaxToken EndCommentTransition
+ {
+ get
+ {
+ return GetRed(ref _endCommentTransition, 4);
+ }
+ }
+
+ internal override SyntaxNode GetNodeSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return GetRedAtZero(ref _startCommentTransition);
+ case 1: return GetRed(ref _startCommentStar, 1);
+ case 2: return GetRed(ref _comment, 2);
+ case 3: return GetRed(ref _endCommentStar, 3);
+ case 4: return GetRed(ref _endCommentTransition, 4);
+ default: return null;
+ }
+ }
+ internal override SyntaxNode GetCachedSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return _startCommentTransition;
+ case 1: return _startCommentStar;
+ case 2: return _comment;
+ case 3: return _endCommentStar;
+ case 4: return _endCommentTransition;
+ default: return null;
+ }
+ }
+
+ public override TResult Accept(SyntaxVisitor visitor)
+ {
+ return visitor.VisitRazorCommentBlock(this);
+ }
+
+ public override void Accept(SyntaxVisitor visitor)
+ {
+ visitor.VisitRazorCommentBlock(this);
+ }
+
+ public RazorCommentBlockSyntax Update(SyntaxToken startCommentTransition, SyntaxToken startCommentStar, SyntaxToken comment, SyntaxToken endCommentStar, SyntaxToken endCommentTransition)
+ {
+ if (startCommentTransition != StartCommentTransition || startCommentStar != StartCommentStar || comment != Comment || endCommentStar != EndCommentStar || endCommentTransition != EndCommentTransition)
+ {
+ var newNode = SyntaxFactory.RazorCommentBlock(startCommentTransition, startCommentStar, comment, endCommentStar, endCommentTransition);
+ var annotations = GetAnnotations();
+ if (annotations != null && annotations.Length > 0)
+ return newNode.WithAnnotations(annotations);
+ return newNode;
+ }
+
+ return this;
+ }
+
+ public RazorCommentBlockSyntax WithStartCommentTransition(SyntaxToken startCommentTransition)
+ {
+ return Update(startCommentTransition, _startCommentStar, _comment, _endCommentStar, _endCommentTransition);
+ }
+
+ public RazorCommentBlockSyntax WithStartCommentStar(SyntaxToken startCommentStar)
+ {
+ return Update(_startCommentTransition, startCommentStar, _comment, _endCommentStar, _endCommentTransition);
+ }
+
+ public RazorCommentBlockSyntax WithComment(SyntaxToken comment)
+ {
+ return Update(_startCommentTransition, _startCommentStar, comment, _endCommentStar, _endCommentTransition);
+ }
+
+ public RazorCommentBlockSyntax WithEndCommentStar(SyntaxToken endCommentStar)
+ {
+ return Update(_startCommentTransition, _startCommentStar, _comment, endCommentStar, _endCommentTransition);
+ }
+
+ public RazorCommentBlockSyntax WithEndCommentTransition(SyntaxToken endCommentTransition)
+ {
+ return Update(_startCommentTransition, _startCommentStar, _comment, _endCommentStar, endCommentTransition);
+ }
+ }
+
+ internal abstract partial class HtmlSyntaxNode : RazorSyntaxNode
+ {
+ internal HtmlSyntaxNode(GreenNode green, SyntaxNode parent, int position)
+ : base(green, parent, position)
+ {
+ }
+ }
+
+ internal sealed partial class HtmlTextLiteralSyntax : HtmlSyntaxNode
+ {
+ private SyntaxNode _textTokens;
+
+ internal HtmlTextLiteralSyntax(GreenNode green, SyntaxNode parent, int position)
+ : base(green, parent, position)
+ {
+ }
+
+ public SyntaxList TextTokens
+ {
+ get
+ {
+ return new SyntaxList(GetRed(ref _textTokens, 0));
+ }
+ }
+
+ internal override SyntaxNode GetNodeSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return GetRedAtZero(ref _textTokens);
+ default: return null;
+ }
+ }
+ internal override SyntaxNode GetCachedSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return _textTokens;
+ default: return null;
+ }
+ }
+
+ public override TResult Accept(SyntaxVisitor visitor)
+ {
+ return visitor.VisitHtmlTextLiteral(this);
+ }
+
+ public override void Accept(SyntaxVisitor visitor)
+ {
+ visitor.VisitHtmlTextLiteral(this);
+ }
+
+ public HtmlTextLiteralSyntax Update(SyntaxList textTokens)
+ {
+ if (textTokens != TextTokens)
+ {
+ var newNode = SyntaxFactory.HtmlTextLiteral(textTokens);
+ var annotations = GetAnnotations();
+ if (annotations != null && annotations.Length > 0)
+ return newNode.WithAnnotations(annotations);
+ return newNode;
+ }
+
+ return this;
+ }
+
+ public HtmlTextLiteralSyntax WithTextTokens(SyntaxList textTokens)
+ {
+ return Update(textTokens);
+ }
+
+ public HtmlTextLiteralSyntax AddTextTokens(params SyntaxToken[] items)
+ {
+ return WithTextTokens(this.TextTokens.AddRange(items));
+ }
+ }
+
+ internal abstract partial class CSharpSyntaxNode : RazorSyntaxNode
+ {
+ internal CSharpSyntaxNode(GreenNode green, SyntaxNode parent, int position)
+ : base(green, parent, position)
+ {
+ }
+ }
+
+ internal sealed partial class CSharpTransitionSyntax : CSharpSyntaxNode
+ {
+ private SyntaxToken _transition;
+
+ internal CSharpTransitionSyntax(GreenNode green, SyntaxNode parent, int position)
+ : base(green, parent, position)
+ {
+ }
+
+ public SyntaxToken Transition
+ {
+ get
+ {
+ return GetRedAtZero(ref _transition);
+ }
+ }
+
+ internal override SyntaxNode GetNodeSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return GetRedAtZero(ref _transition);
+ default: return null;
+ }
+ }
+ internal override SyntaxNode GetCachedSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return _transition;
+ default: return null;
+ }
+ }
+
+ public override TResult Accept(SyntaxVisitor visitor)
+ {
+ return visitor.VisitCSharpTransition(this);
+ }
+
+ public override void Accept(SyntaxVisitor visitor)
+ {
+ visitor.VisitCSharpTransition(this);
+ }
+
+ public CSharpTransitionSyntax Update(SyntaxToken transition)
+ {
+ if (transition != Transition)
+ {
+ var newNode = SyntaxFactory.CSharpTransition(transition);
+ var annotations = GetAnnotations();
+ if (annotations != null && annotations.Length > 0)
+ return newNode.WithAnnotations(annotations);
+ return newNode;
+ }
+
+ return this;
+ }
+
+ public CSharpTransitionSyntax WithTransition(SyntaxToken transition)
+ {
+ return Update(transition);
+ }
+ }
+
+ internal sealed partial class CSharpMetaCodeSyntax : CSharpSyntaxNode
+ {
+ private SyntaxNode _metaCode;
+
+ internal CSharpMetaCodeSyntax(GreenNode green, SyntaxNode parent, int position)
+ : base(green, parent, position)
+ {
+ }
+
+ public SyntaxList MetaCode
+ {
+ get
+ {
+ return new SyntaxList(GetRed(ref _metaCode, 0));
+ }
+ }
+
+ internal override SyntaxNode GetNodeSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return GetRedAtZero(ref _metaCode);
+ default: return null;
+ }
+ }
+ internal override SyntaxNode GetCachedSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return _metaCode;
+ default: return null;
+ }
+ }
+
+ public override TResult Accept(SyntaxVisitor visitor)
+ {
+ return visitor.VisitCSharpMetaCode(this);
+ }
+
+ public override void Accept(SyntaxVisitor visitor)
+ {
+ visitor.VisitCSharpMetaCode(this);
+ }
+
+ public CSharpMetaCodeSyntax Update(SyntaxList metaCode)
+ {
+ if (metaCode != MetaCode)
+ {
+ var newNode = SyntaxFactory.CSharpMetaCode(metaCode);
+ var annotations = GetAnnotations();
+ if (annotations != null && annotations.Length > 0)
+ return newNode.WithAnnotations(annotations);
+ return newNode;
+ }
+
+ return this;
+ }
+
+ public CSharpMetaCodeSyntax WithMetaCode(SyntaxList metaCode)
+ {
+ return Update(metaCode);
+ }
+
+ public CSharpMetaCodeSyntax AddMetaCode(params SyntaxToken[] items)
+ {
+ return WithMetaCode(this.MetaCode.AddRange(items));
+ }
+ }
+
+ internal sealed partial class CSharpCodeLiteralSyntax : CSharpSyntaxNode
+ {
+ private SyntaxNode _cSharpTokens;
+
+ internal CSharpCodeLiteralSyntax(GreenNode green, SyntaxNode parent, int position)
+ : base(green, parent, position)
+ {
+ }
+
+ public SyntaxList CSharpTokens
+ {
+ get
+ {
+ return new SyntaxList(GetRed(ref _cSharpTokens, 0));
+ }
+ }
+
+ internal override SyntaxNode GetNodeSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return GetRedAtZero(ref _cSharpTokens);
+ default: return null;
+ }
+ }
+ internal override SyntaxNode GetCachedSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return _cSharpTokens;
+ default: return null;
+ }
+ }
+
+ public override TResult Accept(SyntaxVisitor visitor)
+ {
+ return visitor.VisitCSharpCodeLiteral(this);
+ }
+
+ public override void Accept(SyntaxVisitor visitor)
+ {
+ visitor.VisitCSharpCodeLiteral(this);
+ }
+
+ public CSharpCodeLiteralSyntax Update(SyntaxList cSharpTokens)
+ {
+ if (cSharpTokens != CSharpTokens)
+ {
+ var newNode = SyntaxFactory.CSharpCodeLiteral(cSharpTokens);
+ var annotations = GetAnnotations();
+ if (annotations != null && annotations.Length > 0)
+ return newNode.WithAnnotations(annotations);
+ return newNode;
+ }
+
+ return this;
+ }
+
+ public CSharpCodeLiteralSyntax WithCSharpTokens(SyntaxList cSharpTokens)
+ {
+ return Update(cSharpTokens);
+ }
+
+ public CSharpCodeLiteralSyntax AddCSharpTokens(params SyntaxToken[] items)
+ {
+ return WithCSharpTokens(this.CSharpTokens.AddRange(items));
+ }
+ }
+
+ internal sealed partial class CSharpCodeBlockSyntax : CSharpSyntaxNode
+ {
+ private SyntaxNode _children;
+
+ internal CSharpCodeBlockSyntax(GreenNode green, SyntaxNode parent, int position)
+ : base(green, parent, position)
+ {
+ }
+
+ public SyntaxList Children
+ {
+ get
+ {
+ return new SyntaxList(GetRed(ref _children, 0));
+ }
+ }
+
+ internal override SyntaxNode GetNodeSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return GetRedAtZero(ref _children);
+ default: return null;
+ }
+ }
+ internal override SyntaxNode GetCachedSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return _children;
+ default: return null;
+ }
+ }
+
+ public override TResult Accept(SyntaxVisitor visitor)
+ {
+ return visitor.VisitCSharpCodeBlock(this);
+ }
+
+ public override void Accept(SyntaxVisitor visitor)
+ {
+ visitor.VisitCSharpCodeBlock(this);
+ }
+
+ public CSharpCodeBlockSyntax Update(SyntaxList children)
+ {
+ if (children != Children)
+ {
+ var newNode = SyntaxFactory.CSharpCodeBlock(children);
+ var annotations = GetAnnotations();
+ if (annotations != null && annotations.Length > 0)
+ return newNode.WithAnnotations(annotations);
+ return newNode;
+ }
+
+ return this;
+ }
+
+ public CSharpCodeBlockSyntax WithChildren(SyntaxList children)
+ {
+ return Update(children);
+ }
+
+ public CSharpCodeBlockSyntax AddChildren(params RazorSyntaxNode[] items)
+ {
+ return WithChildren(this.Children.AddRange(items));
+ }
+ }
+
+ internal abstract partial class CSharpBlockSyntax : CSharpSyntaxNode
+ {
+ internal CSharpBlockSyntax(GreenNode green, SyntaxNode parent, int position)
+ : base(green, parent, position)
+ {
+ }
+
+ public abstract CSharpTransitionSyntax Transition { get; }
+ public CSharpBlockSyntax WithTransition(CSharpTransitionSyntax _transition) => WithTransitionCore(_transition);
+ internal abstract CSharpBlockSyntax WithTransitionCore(CSharpTransitionSyntax _transition);
+
+ public abstract CSharpSyntaxNode Body { get; }
+ public CSharpBlockSyntax WithBody(CSharpSyntaxNode _body) => WithBodyCore(_body);
+ internal abstract CSharpBlockSyntax WithBodyCore(CSharpSyntaxNode _body);
+ }
+
+ internal sealed partial class CSharpStatement : CSharpBlockSyntax
+ {
+ private CSharpTransitionSyntax _transition;
+ private CSharpSyntaxNode _body;
+
+ internal CSharpStatement(GreenNode green, SyntaxNode parent, int position)
+ : base(green, parent, position)
+ {
+ }
+
+ public override CSharpTransitionSyntax Transition
+ {
+ get
+ {
+ return GetRedAtZero(ref _transition);
+ }
+ }
+
+ public override CSharpSyntaxNode Body
+ {
+ get
+ {
+ return GetRed(ref _body, 1);
+ }
+ }
+
+ internal override SyntaxNode GetNodeSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return GetRedAtZero(ref _transition);
+ case 1: return GetRed(ref _body, 1);
+ default: return null;
+ }
+ }
+ internal override SyntaxNode GetCachedSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return _transition;
+ case 1: return _body;
+ default: return null;
+ }
+ }
+
+ public override TResult Accept(SyntaxVisitor visitor)
+ {
+ return visitor.VisitCSharpStatement(this);
+ }
+
+ public override void Accept(SyntaxVisitor visitor)
+ {
+ visitor.VisitCSharpStatement(this);
+ }
+
+ public CSharpStatement Update(CSharpTransitionSyntax transition, CSharpSyntaxNode body)
+ {
+ if (transition != Transition || body != Body)
+ {
+ var newNode = SyntaxFactory.CSharpStatement(transition, body);
+ var annotations = GetAnnotations();
+ if (annotations != null && annotations.Length > 0)
+ return newNode.WithAnnotations(annotations);
+ return newNode;
+ }
+
+ return this;
+ }
+
+ internal override CSharpBlockSyntax WithTransitionCore(CSharpTransitionSyntax transition) => WithTransition(transition);
+ public new CSharpStatement WithTransition(CSharpTransitionSyntax transition)
+ {
+ return Update(transition, _body);
+ }
+
+ internal override CSharpBlockSyntax WithBodyCore(CSharpSyntaxNode body) => WithBody(body);
+ public new CSharpStatement WithBody(CSharpSyntaxNode body)
+ {
+ return Update(_transition, body);
+ }
+ }
+
+ internal sealed partial class CSharpStatementBodySyntax : CSharpSyntaxNode
+ {
+ private CSharpMetaCodeSyntax _openBrace;
+ private CSharpCodeBlockSyntax _cSharpCode;
+ private CSharpMetaCodeSyntax _closeBrace;
+
+ internal CSharpStatementBodySyntax(GreenNode green, SyntaxNode parent, int position)
+ : base(green, parent, position)
+ {
+ }
+
+ public CSharpMetaCodeSyntax OpenBrace
+ {
+ get
+ {
+ return GetRedAtZero(ref _openBrace);
+ }
+ }
+
+ public CSharpCodeBlockSyntax CSharpCode
+ {
+ get
+ {
+ return GetRed(ref _cSharpCode, 1);
+ }
+ }
+
+ public CSharpMetaCodeSyntax CloseBrace
+ {
+ get
+ {
+ return GetRed(ref _closeBrace, 2);
+ }
+ }
+
+ internal override SyntaxNode GetNodeSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return GetRedAtZero(ref _openBrace);
+ case 1: return GetRed(ref _cSharpCode, 1);
+ case 2: return GetRed(ref _closeBrace, 2);
+ default: return null;
+ }
+ }
+ internal override SyntaxNode GetCachedSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return _openBrace;
+ case 1: return _cSharpCode;
+ case 2: return _closeBrace;
+ default: return null;
+ }
+ }
+
+ public override TResult Accept(SyntaxVisitor visitor)
+ {
+ return visitor.VisitCSharpStatementBody(this);
+ }
+
+ public override void Accept(SyntaxVisitor visitor)
+ {
+ visitor.VisitCSharpStatementBody(this);
+ }
+
+ public CSharpStatementBodySyntax Update(CSharpMetaCodeSyntax openBrace, CSharpCodeBlockSyntax cSharpCode, CSharpMetaCodeSyntax closeBrace)
+ {
+ if (openBrace != OpenBrace || cSharpCode != CSharpCode || closeBrace != CloseBrace)
+ {
+ var newNode = SyntaxFactory.CSharpStatementBody(openBrace, cSharpCode, closeBrace);
+ var annotations = GetAnnotations();
+ if (annotations != null && annotations.Length > 0)
+ return newNode.WithAnnotations(annotations);
+ return newNode;
+ }
+
+ return this;
+ }
+
+ public CSharpStatementBodySyntax WithOpenBrace(CSharpMetaCodeSyntax openBrace)
+ {
+ return Update(openBrace, _cSharpCode, _closeBrace);
+ }
+
+ public CSharpStatementBodySyntax WithCSharpCode(CSharpCodeBlockSyntax cSharpCode)
+ {
+ return Update(_openBrace, cSharpCode, _closeBrace);
+ }
+
+ public CSharpStatementBodySyntax WithCloseBrace(CSharpMetaCodeSyntax closeBrace)
+ {
+ return Update(_openBrace, _cSharpCode, closeBrace);
+ }
+
+ public CSharpStatementBodySyntax AddOpenBraceMetaCode(params SyntaxToken[] items)
+ {
+ return this.WithOpenBrace(this.OpenBrace.WithMetaCode(this.OpenBrace.MetaCode.AddRange(items)));
+ }
+
+ public CSharpStatementBodySyntax AddCSharpCodeChildren(params RazorSyntaxNode[] items)
+ {
+ return this.WithCSharpCode(this.CSharpCode.WithChildren(this.CSharpCode.Children.AddRange(items)));
+ }
+
+ public CSharpStatementBodySyntax AddCloseBraceMetaCode(params SyntaxToken[] items)
+ {
+ return this.WithCloseBrace(this.CloseBrace.WithMetaCode(this.CloseBrace.MetaCode.AddRange(items)));
+ }
+ }
+
+ internal sealed partial class CSharpExpression : CSharpBlockSyntax
+ {
+ private CSharpTransitionSyntax _transition;
+ private CSharpSyntaxNode _body;
+
+ internal CSharpExpression(GreenNode green, SyntaxNode parent, int position)
+ : base(green, parent, position)
+ {
+ }
+
+ public override CSharpTransitionSyntax Transition
+ {
+ get
+ {
+ return GetRedAtZero(ref _transition);
+ }
+ }
+
+ public override CSharpSyntaxNode Body
+ {
+ get
+ {
+ return GetRed(ref _body, 1);
+ }
+ }
+
+ internal override SyntaxNode GetNodeSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return GetRedAtZero(ref _transition);
+ case 1: return GetRed(ref _body, 1);
+ default: return null;
+ }
+ }
+ internal override SyntaxNode GetCachedSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return _transition;
+ case 1: return _body;
+ default: return null;
+ }
+ }
+
+ public override TResult Accept(SyntaxVisitor visitor)
+ {
+ return visitor.VisitCSharpExpression(this);
+ }
+
+ public override void Accept(SyntaxVisitor visitor)
+ {
+ visitor.VisitCSharpExpression(this);
+ }
+
+ public CSharpExpression Update(CSharpTransitionSyntax transition, CSharpSyntaxNode body)
+ {
+ if (transition != Transition || body != Body)
+ {
+ var newNode = SyntaxFactory.CSharpExpression(transition, body);
+ var annotations = GetAnnotations();
+ if (annotations != null && annotations.Length > 0)
+ return newNode.WithAnnotations(annotations);
+ return newNode;
+ }
+
+ return this;
+ }
+
+ internal override CSharpBlockSyntax WithTransitionCore(CSharpTransitionSyntax transition) => WithTransition(transition);
+ public new CSharpExpression WithTransition(CSharpTransitionSyntax transition)
+ {
+ return Update(transition, _body);
+ }
+
+ internal override CSharpBlockSyntax WithBodyCore(CSharpSyntaxNode body) => WithBody(body);
+ public new CSharpExpression WithBody(CSharpSyntaxNode body)
+ {
+ return Update(_transition, body);
+ }
+ }
+
+ internal sealed partial class CSharpExpressionBodySyntax : CSharpSyntaxNode
+ {
+ private CSharpMetaCodeSyntax _openParen;
+ private CSharpCodeBlockSyntax _cSharpCode;
+ private CSharpMetaCodeSyntax _closeParen;
+
+ internal CSharpExpressionBodySyntax(GreenNode green, SyntaxNode parent, int position)
+ : base(green, parent, position)
+ {
+ }
+
+ public CSharpMetaCodeSyntax OpenParen
+ {
+ get
+ {
+ return GetRedAtZero(ref _openParen);
+ }
+ }
+
+ public CSharpCodeBlockSyntax CSharpCode
+ {
+ get
+ {
+ return GetRed(ref _cSharpCode, 1);
+ }
+ }
+
+ public CSharpMetaCodeSyntax CloseParen
+ {
+ get
+ {
+ return GetRed(ref _closeParen, 2);
+ }
+ }
+
+ internal override SyntaxNode GetNodeSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return GetRedAtZero(ref _openParen);
+ case 1: return GetRed(ref _cSharpCode, 1);
+ case 2: return GetRed(ref _closeParen, 2);
+ default: return null;
+ }
+ }
+ internal override SyntaxNode GetCachedSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return _openParen;
+ case 1: return _cSharpCode;
+ case 2: return _closeParen;
+ default: return null;
+ }
+ }
+
+ public override TResult Accept(SyntaxVisitor visitor)
+ {
+ return visitor.VisitCSharpExpressionBody(this);
+ }
+
+ public override void Accept(SyntaxVisitor visitor)
+ {
+ visitor.VisitCSharpExpressionBody(this);
+ }
+
+ public CSharpExpressionBodySyntax Update(CSharpMetaCodeSyntax openParen, CSharpCodeBlockSyntax cSharpCode, CSharpMetaCodeSyntax closeParen)
+ {
+ if (openParen != OpenParen || cSharpCode != CSharpCode || closeParen != CloseParen)
+ {
+ var newNode = SyntaxFactory.CSharpExpressionBody(openParen, cSharpCode, closeParen);
+ var annotations = GetAnnotations();
+ if (annotations != null && annotations.Length > 0)
+ return newNode.WithAnnotations(annotations);
+ return newNode;
+ }
+
+ return this;
+ }
+
+ public CSharpExpressionBodySyntax WithOpenParen(CSharpMetaCodeSyntax openParen)
+ {
+ return Update(openParen, _cSharpCode, _closeParen);
+ }
+
+ public CSharpExpressionBodySyntax WithCSharpCode(CSharpCodeBlockSyntax cSharpCode)
+ {
+ return Update(_openParen, cSharpCode, _closeParen);
+ }
+
+ public CSharpExpressionBodySyntax WithCloseParen(CSharpMetaCodeSyntax closeParen)
+ {
+ return Update(_openParen, _cSharpCode, closeParen);
+ }
+
+ public CSharpExpressionBodySyntax AddOpenParenMetaCode(params SyntaxToken[] items)
+ {
+ var _openParen = this.OpenParen ?? SyntaxFactory.CSharpMetaCode();
+ return this.WithOpenParen(_openParen.WithMetaCode(_openParen.MetaCode.AddRange(items)));
+ }
+
+ public CSharpExpressionBodySyntax AddCSharpCodeChildren(params RazorSyntaxNode[] items)
+ {
+ return this.WithCSharpCode(this.CSharpCode.WithChildren(this.CSharpCode.Children.AddRange(items)));
+ }
+
+ public CSharpExpressionBodySyntax AddCloseParenMetaCode(params SyntaxToken[] items)
+ {
+ var _closeParen = this.CloseParen ?? SyntaxFactory.CSharpMetaCode();
+ return this.WithCloseParen(_closeParen.WithMetaCode(_closeParen.MetaCode.AddRange(items)));
+ }
+ }
+
+ internal sealed partial class CSharpDirectiveSyntax : CSharpBlockSyntax
+ {
+ private CSharpTransitionSyntax _transition;
+ private CSharpSyntaxNode _body;
+
+ internal CSharpDirectiveSyntax(GreenNode green, SyntaxNode parent, int position)
+ : base(green, parent, position)
+ {
+ }
+
+ public override CSharpTransitionSyntax Transition
+ {
+ get
+ {
+ return GetRedAtZero(ref _transition);
+ }
+ }
+
+ public override CSharpSyntaxNode Body
+ {
+ get
+ {
+ return GetRed(ref _body, 1);
+ }
+ }
+
+ internal override SyntaxNode GetNodeSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return GetRedAtZero(ref _transition);
+ case 1: return GetRed(ref _body, 1);
+ default: return null;
+ }
+ }
+ internal override SyntaxNode GetCachedSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return _transition;
+ case 1: return _body;
+ default: return null;
+ }
+ }
+
+ public override TResult Accept(SyntaxVisitor visitor)
+ {
+ return visitor.VisitCSharpDirective(this);
+ }
+
+ public override void Accept(SyntaxVisitor visitor)
+ {
+ visitor.VisitCSharpDirective(this);
+ }
+
+ public CSharpDirectiveSyntax Update(CSharpTransitionSyntax transition, CSharpSyntaxNode body)
+ {
+ if (transition != Transition || body != Body)
+ {
+ var newNode = SyntaxFactory.CSharpDirective(transition, body);
+ var annotations = GetAnnotations();
+ if (annotations != null && annotations.Length > 0)
+ return newNode.WithAnnotations(annotations);
+ return newNode;
+ }
+
+ return this;
+ }
+
+ internal override CSharpBlockSyntax WithTransitionCore(CSharpTransitionSyntax transition) => WithTransition(transition);
+ public new CSharpDirectiveSyntax WithTransition(CSharpTransitionSyntax transition)
+ {
+ return Update(transition, _body);
+ }
+
+ internal override CSharpBlockSyntax WithBodyCore(CSharpSyntaxNode body) => WithBody(body);
+ public new CSharpDirectiveSyntax WithBody(CSharpSyntaxNode body)
+ {
+ return Update(_transition, body);
+ }
+ }
+
+ internal sealed partial class CSharpDirectiveBodySyntax : CSharpSyntaxNode
+ {
+ private CSharpMetaCodeSyntax _keyword;
+ private CSharpCodeBlockSyntax _cSharpCode;
+
+ internal CSharpDirectiveBodySyntax(GreenNode green, SyntaxNode parent, int position)
+ : base(green, parent, position)
+ {
+ }
+
+ public CSharpMetaCodeSyntax Keyword
+ {
+ get
+ {
+ return GetRedAtZero(ref _keyword);
+ }
+ }
+
+ public CSharpCodeBlockSyntax CSharpCode
+ {
+ get
+ {
+ return GetRed(ref _cSharpCode, 1);
+ }
+ }
+
+ internal override SyntaxNode GetNodeSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return GetRedAtZero(ref _keyword);
+ case 1: return GetRed(ref _cSharpCode, 1);
+ default: return null;
+ }
+ }
+ internal override SyntaxNode GetCachedSlot(int index)
+ {
+ switch (index)
+ {
+ case 0: return _keyword;
+ case 1: return _cSharpCode;
+ default: return null;
+ }
+ }
+
+ public override TResult Accept(SyntaxVisitor visitor)
+ {
+ return visitor.VisitCSharpDirectiveBody(this);
+ }
+
+ public override void Accept(SyntaxVisitor visitor)
+ {
+ visitor.VisitCSharpDirectiveBody(this);
+ }
+
+ public CSharpDirectiveBodySyntax Update(CSharpMetaCodeSyntax keyword, CSharpCodeBlockSyntax cSharpCode)
+ {
+ if (keyword != Keyword || cSharpCode != CSharpCode)
+ {
+ var newNode = SyntaxFactory.CSharpDirectiveBody(keyword, cSharpCode);
+ var annotations = GetAnnotations();
+ if (annotations != null && annotations.Length > 0)
+ return newNode.WithAnnotations(annotations);
+ return newNode;
+ }
+
+ return this;
+ }
+
+ public CSharpDirectiveBodySyntax WithKeyword(CSharpMetaCodeSyntax keyword)
+ {
+ return Update(keyword, _cSharpCode);
+ }
+
+ public CSharpDirectiveBodySyntax WithCSharpCode(CSharpCodeBlockSyntax cSharpCode)
+ {
+ return Update(_keyword, cSharpCode);
+ }
+
+ public CSharpDirectiveBodySyntax AddKeywordMetaCode(params SyntaxToken[] items)
+ {
+ return this.WithKeyword(this.Keyword.WithMetaCode(this.Keyword.MetaCode.AddRange(items)));
+ }
+
+ public CSharpDirectiveBodySyntax AddCSharpCodeChildren(params RazorSyntaxNode[] items)
+ {
+ return this.WithCSharpCode(this.CSharpCode.WithChildren(this.CSharpCode.Children.AddRange(items)));
+ }
+ }
+}
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Syntax/GreenNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Syntax/GreenNode.cs
new file mode 100644
index 0000000000..7e05d7ab39
--- /dev/null
+++ b/src/Microsoft.AspNetCore.Razor.Language/Syntax/GreenNode.cs
@@ -0,0 +1,577 @@
+// Copyright (c) .NET Foundation. All rights reserved.
+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Text;
+
+namespace Microsoft.AspNetCore.Razor.Language.Syntax
+{
+ internal abstract class GreenNode
+ {
+ private static readonly RazorDiagnostic[] EmptyDiagnostics = Array.Empty();
+ private static readonly SyntaxAnnotation[] EmptyAnnotations = Array.Empty();
+ private static readonly ConditionalWeakTable DiagnosticsTable =
+ new ConditionalWeakTable();
+ private static readonly ConditionalWeakTable AnnotationsTable =
+ new ConditionalWeakTable();
+
+ private NodeFlags _flags;
+ private byte _slotCount;
+
+ protected GreenNode(SyntaxKind kind)
+ {
+ Kind = kind;
+ }
+
+ protected GreenNode(SyntaxKind kind, int fullWidth)
+ : this(kind)
+ {
+ FullWidth = fullWidth;
+ }
+
+ protected GreenNode(SyntaxKind kind, RazorDiagnostic[] diagnostics, SyntaxAnnotation[] annotations)
+ : this(kind, 0, diagnostics, annotations)
+ {
+ }
+
+ protected GreenNode(SyntaxKind kind, int fullWidth, RazorDiagnostic[] diagnostics, SyntaxAnnotation[] annotations)
+ : this(kind, fullWidth)
+ {
+ if (diagnostics?.Length > 0)
+ {
+ _flags |= NodeFlags.ContainsDiagnostics;
+ DiagnosticsTable.Add(this, diagnostics);
+ }
+
+ if (annotations?.Length > 0)
+ {
+ foreach (var annotation in annotations)
+ {
+ if (annotation == null)
+ {
+ throw new ArgumentException(nameof(annotations), "Annotation cannot be null");
+ }
+ }
+
+ _flags |= NodeFlags.ContainsAnnotations;
+ AnnotationsTable.Add(this, annotations);
+ }
+ }
+
+ protected void AdjustFlagsAndWidth(GreenNode node)
+ {
+ if (node == null)
+ {
+ return;
+ }
+
+ _flags |= (node.Flags & NodeFlags.InheritMask);
+ FullWidth += node.FullWidth;
+ }
+
+ #region Kind
+ internal SyntaxKind Kind { get; }
+
+ internal virtual bool IsList => false;
+
+ internal virtual bool IsToken => false;
+
+ internal virtual bool IsTrivia => false;
+ #endregion
+
+ #region Slots
+ public int SlotCount
+ {
+ get
+ {
+ int count = _slotCount;
+ if (count == byte.MaxValue)
+ {
+ count = GetSlotCount();
+ }
+
+ return count;
+ }
+
+ protected set
+ {
+ _slotCount = (byte)value;
+ }
+ }
+
+ internal abstract GreenNode GetSlot(int index);
+
+ // for slot counts >= byte.MaxValue
+ protected virtual int GetSlotCount()
+ {
+ return _slotCount;
+ }
+
+ public virtual int GetSlotOffset(int index)
+ {
+ var offset = 0;
+ for (var i = 0; i < index; i++)
+ {
+ var child = GetSlot(i);
+ if (child != null)
+ offset += child.FullWidth;
+ }
+
+ return offset;
+ }
+
+ public virtual int FindSlotIndexContainingOffset(int offset)
+ {
+ Debug.Assert(0 <= offset && offset < FullWidth);
+
+ int i;
+ var accumulatedWidth = 0;
+ for (i = 0; ; i++)
+ {
+ Debug.Assert(i < SlotCount);
+ var child = GetSlot(i);
+ if (child != null)
+ {
+ accumulatedWidth += child.FullWidth;
+ if (offset < accumulatedWidth)
+ {
+ break;
+ }
+ }
+ }
+
+ return i;
+ }
+ #endregion
+
+ #region Flags
+ internal NodeFlags Flags => _flags;
+
+ internal void SetFlags(NodeFlags flags)
+ {
+ _flags |= flags;
+ }
+
+ internal void ClearFlags(NodeFlags flags)
+ {
+ _flags &= ~flags;
+ }
+
+ internal virtual bool IsMissing => (_flags & NodeFlags.IsMissing) != 0;
+
+ public bool ContainsDiagnostics
+ {
+ get
+ {
+ return (_flags & NodeFlags.ContainsDiagnostics) != 0;
+ }
+ }
+
+ public bool ContainsAnnotations
+ {
+ get
+ {
+ return (_flags & NodeFlags.ContainsAnnotations) != 0;
+ }
+ }
+ #endregion
+
+ #region Spans
+ internal int FullWidth { get; private set; }
+
+ public virtual int Width
+ {
+ get
+ {
+ return FullWidth - GetLeadingTriviaWidth() - GetTrailingTriviaWidth();
+ }
+ }
+
+ public virtual int GetLeadingTriviaWidth()
+ {
+ return FullWidth != 0 ? GetFirstTerminal().GetLeadingTriviaWidth() : 0;
+ }
+
+ public virtual int GetTrailingTriviaWidth()
+ {
+ return FullWidth != 0 ? GetLastTerminal().GetTrailingTriviaWidth() : 0;
+ }
+
+ public bool HasLeadingTrivia
+ {
+ get
+ {
+ return GetLeadingTriviaWidth() != 0;
+ }
+ }
+
+ public bool HasTrailingTrivia
+ {
+ get
+ {
+ return GetTrailingTriviaWidth() != 0;
+ }
+ }
+ #endregion
+
+ #region Diagnostics
+ internal abstract GreenNode SetDiagnostics(RazorDiagnostic[] diagnostics);
+
+ internal RazorDiagnostic[] GetDiagnostics()
+ {
+ if (ContainsDiagnostics)
+ {
+ if (DiagnosticsTable.TryGetValue(this, out var diagnostics))
+ {
+ return diagnostics;
+ }
+ }
+
+ return EmptyDiagnostics;
+ }
+ #endregion
+
+ #region Annotations
+ internal abstract GreenNode SetAnnotations(SyntaxAnnotation[] annotations);
+
+ internal SyntaxAnnotation[] GetAnnotations()
+ {
+ if (ContainsAnnotations)
+ {
+ if (AnnotationsTable.TryGetValue(this, out var annotations))
+ {
+ Debug.Assert(annotations.Length != 0, "There cannot be an empty annotation entry.");
+ return annotations;
+ }
+ }
+
+ return EmptyAnnotations;
+ }
+ #endregion
+
+ #region Text
+ public virtual string ToFullString()
+ {
+ var builder = new StringBuilder();
+ var writer = new StringWriter(builder, System.Globalization.CultureInfo.InvariantCulture);
+ WriteTo(writer);
+ return builder.ToString();
+ }
+
+ public virtual void WriteTo(TextWriter writer)
+ {
+ WriteTo(writer, leading: true, trailing: true);
+ }
+
+ protected internal void WriteTo(TextWriter writer, bool leading, bool trailing)
+ {
+ // Use an actual Stack so we can write out deeply recursive structures without overflowing.
+ var stack = new Stack();
+ stack.Push(new StackEntry(this, leading, trailing));
+
+ // Separated out stack processing logic so that it does not unintentionally refer to
+ // "this", "leading" or "trailing.
+ ProcessStack(writer, stack);
+ }
+
+ protected virtual void WriteTriviaTo(TextWriter writer)
+ {
+ throw new NotImplementedException();
+ }
+
+ protected virtual void WriteTokenTo(TextWriter writer, bool leading, bool trailing)
+ {
+ throw new NotImplementedException();
+ }
+ #endregion
+
+ #region Tokens
+
+ public virtual object GetValue()
+ {
+ return null;
+ }
+
+ public virtual string GetValueText()
+ {
+ return string.Empty;
+ }
+
+ public virtual GreenNode GetLeadingTrivia()
+ {
+ return null;
+ }
+
+ public virtual GreenNode GetTrailingTrivia()
+ {
+ return null;
+ }
+
+ public virtual GreenNode WithLeadingTrivia(GreenNode trivia)
+ {
+ return this;
+ }
+
+ public virtual GreenNode WithTrailingTrivia(GreenNode trivia)
+ {
+ return this;
+ }
+
+ public InternalSyntax.SyntaxToken GetFirstToken()
+ {
+ return (InternalSyntax.SyntaxToken)GetFirstTerminal();
+ }
+
+ public InternalSyntax.SyntaxToken GetLastToken()
+ {
+ return (InternalSyntax.SyntaxToken)GetLastTerminal();
+ }
+
+ internal GreenNode GetFirstTerminal()
+ {
+ var node = this;
+
+ do
+ {
+ GreenNode firstChild = null;
+ for (int i = 0, n = node.SlotCount; i < n; i++)
+ {
+ var child = node.GetSlot(i);
+ if (child != null)
+ {
+ firstChild = child;
+ break;
+ }
+ }
+ node = firstChild;
+ } while (node?._slotCount > 0);
+
+ return node;
+ }
+
+ internal GreenNode GetLastTerminal()
+ {
+ var node = this;
+
+ do
+ {
+ GreenNode lastChild = null;
+ for (var i = node.SlotCount - 1; i >= 0; i--)
+ {
+ var child = node.GetSlot(i);
+ if (child != null)
+ {
+ lastChild = child;
+ break;
+ }
+ }
+ node = lastChild;
+ } while (node?._slotCount > 0);
+
+ return node;
+ }
+ #endregion
+
+ #region Equivalence
+ public virtual bool IsEquivalentTo(GreenNode other)
+ {
+ if (this == other)
+ {
+ return true;
+ }
+
+ if (other == null)
+ {
+ return false;
+ }
+
+ return EquivalentToInternal(this, other);
+ }
+
+ private static bool EquivalentToInternal(GreenNode node1, GreenNode node2)
+ {
+ if (node1.Kind != node2.Kind)
+ {
+ // A single-element list is usually represented as just a single node,
+ // but can be represented as a List node with one child. Move to that
+ // child if necessary.
+ if (node1.IsList && node1.SlotCount == 1)
+ {
+ node1 = node1.GetSlot(0);
+ }
+
+ if (node2.IsList && node2.SlotCount == 1)
+ {
+ node2 = node2.GetSlot(0);
+ }
+
+ if (node1.Kind != node2.Kind)
+ {
+ return false;
+ }
+ }
+
+ if (node1.FullWidth != node2.FullWidth)
+ {
+ return false;
+ }
+
+ var n = node1.SlotCount;
+ if (n != node2.SlotCount)
+ {
+ return false;
+ }
+
+ for (var i = 0; i < n; i++)
+ {
+ var node1Child = node1.GetSlot(i);
+ var node2Child = node2.GetSlot(i);
+ if (node1Child != null && node2Child != null && !node1Child.IsEquivalentTo(node2Child))
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+ #endregion
+
+ #region Factories
+ public virtual GreenNode CreateList(IEnumerable nodes, bool alwaysCreateListNode = false)
+ {
+ if (nodes == null)
+ {
+ return null;
+ }
+
+ var list = nodes.ToArray();
+
+ switch (list.Length)
+ {
+ case 0:
+ return null;
+ case 1:
+ if (alwaysCreateListNode)
+ {
+ goto default;
+ }
+ else
+ {
+ return list[0];
+ }
+ case 2:
+ return InternalSyntax.SyntaxList.List(list[0], list[1]);
+ case 3:
+ return InternalSyntax.SyntaxList.List(list[0], list[1], list[2]);
+ default:
+ return InternalSyntax.SyntaxList.List(list);
+ }
+ }
+
+ public SyntaxNode CreateRed()
+ {
+ return CreateRed(null, 0);
+ }
+
+ internal abstract SyntaxNode CreateRed(SyntaxNode parent, int position);
+ #endregion
+
+ public abstract TResult Accept(InternalSyntax.SyntaxVisitor visitor);
+
+ public abstract void Accept(InternalSyntax.SyntaxVisitor visitor);
+
+ #region StaticMethods
+
+ private static void ProcessStack(TextWriter writer,
+ Stack stack)
+ {
+ while (stack.Count > 0)
+ {
+ var current = stack.Pop();
+ var currentNode = current.Node;
+ var currentLeading = current.Leading;
+ var currentTrailing = current.Trailing;
+
+ if (currentNode.IsToken)
+ {
+ currentNode.WriteTokenTo(writer, currentLeading, currentTrailing);
+ continue;
+ }
+
+ if (currentNode.IsTrivia)
+ {
+ currentNode.WriteTriviaTo(writer);
+ continue;
+ }
+
+ var firstIndex = GetFirstNonNullChildIndex(currentNode);
+ var lastIndex = GetLastNonNullChildIndex(currentNode);
+
+ for (var i = lastIndex; i >= firstIndex; i--)
+ {
+ var child = currentNode.GetSlot(i);
+ if (child != null)
+ {
+ var first = i == firstIndex;
+ var last = i == lastIndex;
+ stack.Push(new StackEntry(child, currentLeading | !first, currentTrailing | !last));
+ }
+ }
+ }
+ }
+
+ private static int GetFirstNonNullChildIndex(GreenNode node)
+ {
+ int n = node.SlotCount;
+ int firstIndex = 0;
+ for (; firstIndex < n; firstIndex++)
+ {
+ var child = node.GetSlot(firstIndex);
+ if (child != null)
+ {
+ break;
+ }
+ }
+
+ return firstIndex;
+ }
+
+ private static int GetLastNonNullChildIndex(GreenNode node)
+ {
+ int n = node.SlotCount;
+ int lastIndex = n - 1;
+ for (; lastIndex >= 0; lastIndex--)
+ {
+ var child = node.GetSlot(lastIndex);
+ if (child != null)
+ {
+ break;
+ }
+ }
+
+ return lastIndex;
+ }
+
+ private struct StackEntry
+ {
+ public StackEntry(GreenNode node, bool leading, bool trailing)
+ {
+ Node = node;
+ Leading = leading;
+ Trailing = trailing;
+ }
+
+ public GreenNode Node { get; }
+
+ public bool Leading { get; }
+
+ public bool Trailing { get; }
+ }
+ #endregion
+ }
+}
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Syntax/GreenNodeExtensions.cs b/src/Microsoft.AspNetCore.Razor.Language/Syntax/GreenNodeExtensions.cs
new file mode 100644
index 0000000000..6895dfdd02
--- /dev/null
+++ b/src/Microsoft.AspNetCore.Razor.Language/Syntax/GreenNodeExtensions.cs
@@ -0,0 +1,56 @@
+// Copyright (c) .NET Foundation. All rights reserved.
+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+
+using System.Collections.Generic;
+
+namespace Microsoft.AspNetCore.Razor.Language.Syntax
+{
+ internal static class GreenNodeExtensions
+ {
+ internal static InternalSyntax.SyntaxList ToGreenList(this SyntaxNode node) where T : GreenNode
+ {
+ return node != null ?
+ ToGreenList(node.Green) :
+ default(InternalSyntax.SyntaxList);
+ }
+
+ internal static InternalSyntax.SyntaxList ToGreenList(this GreenNode node) where T : GreenNode
+ {
+ return new InternalSyntax.SyntaxList(node);
+ }
+
+ public static TNode WithAnnotationsGreen(this TNode node, IEnumerable annotations) where TNode : GreenNode
+ {
+ var newAnnotations = new List();
+ foreach (var candidate in annotations)
+ {
+ if (!newAnnotations.Contains(candidate))
+ {
+ newAnnotations.Add(candidate);
+ }
+ }
+
+ if (newAnnotations.Count == 0)
+ {
+ var existingAnnotations = node.GetAnnotations();
+ if (existingAnnotations == null || existingAnnotations.Length == 0)
+ {
+ return node;
+ }
+ else
+ {
+ return (TNode)node.SetAnnotations(null);
+ }
+ }
+ else
+ {
+ return (TNode)node.SetAnnotations(newAnnotations.ToArray());
+ }
+ }
+
+ public static TNode WithDiagnosticsGreen(this TNode node, RazorDiagnostic[] diagnostics) where TNode : GreenNode
+ {
+ return (TNode)node.SetDiagnostics(diagnostics);
+ }
+ }
+}
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Syntax/InternalSyntax/SyntaxFactory.cs b/src/Microsoft.AspNetCore.Razor.Language/Syntax/InternalSyntax/SyntaxFactory.cs
new file mode 100644
index 0000000000..79562ded0d
--- /dev/null
+++ b/src/Microsoft.AspNetCore.Razor.Language/Syntax/InternalSyntax/SyntaxFactory.cs
@@ -0,0 +1,21 @@
+// Copyright (c) .NET Foundation. All rights reserved.
+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+
+using System.Collections.Generic;
+using System.Linq;
+
+namespace Microsoft.AspNetCore.Razor.Language.Syntax.InternalSyntax
+{
+ internal static partial class SyntaxFactory
+ {
+ internal static SyntaxToken Token(SyntaxKind kind, string content, IEnumerable diagnostics)
+ {
+ return Token(kind, content, diagnostics.ToArray());
+ }
+
+ internal static SyntaxToken Token(SyntaxKind kind, string content, params RazorDiagnostic[] diagnostics)
+ {
+ return new SyntaxToken(kind, content, diagnostics);
+ }
+ }
+}
diff --git a/src/Microsoft.AspNetCore.Razor.Language/Syntax/InternalSyntax/SyntaxList.cs b/src/Microsoft.AspNetCore.Razor.Language/Syntax/InternalSyntax/SyntaxList.cs
new file mode 100644
index 0000000000..ff466af513
--- /dev/null
+++ b/src/Microsoft.AspNetCore.Razor.Language/Syntax/InternalSyntax/SyntaxList.cs
@@ -0,0 +1,428 @@
+// Copyright (c) .NET Foundation. All rights reserved.
+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+
+using System;
+using System.Diagnostics;
+
+namespace Microsoft.AspNetCore.Razor.Language.Syntax.InternalSyntax
+{
+ internal abstract class SyntaxList : GreenNode
+ {
+ internal SyntaxList()
+ : base(SyntaxKind.List)
+ {
+ }
+
+ internal SyntaxList(RazorDiagnostic[] diagnostics, SyntaxAnnotation[] annotations)
+ : base(SyntaxKind.List, diagnostics, annotations)
+ {
+ }
+
+ internal override bool IsList => true;
+
+ internal static GreenNode List(GreenNode child)
+ {
+ return child;
+ }
+
+ internal static WithTwoChildren List(GreenNode child0, GreenNode child1)
+ {
+ Debug.Assert(child0 != null);
+ Debug.Assert(child1 != null);
+
+ var result = new WithTwoChildren(child0, child1);
+ return result;
+ }
+
+ internal static WithThreeChildren List(GreenNode child0, GreenNode child1, GreenNode child2)
+ {
+ Debug.Assert(child0 != null);
+ Debug.Assert(child1 != null);
+ Debug.Assert(child2 != null);
+
+ var result = new WithThreeChildren(child0, child1, child2);
+ return result;
+ }
+
+ internal static GreenNode List(GreenNode[] nodes)
+ {
+ return List(nodes, nodes.Length);
+ }
+
+ internal static GreenNode List(GreenNode[] nodes, int count)
+ {
+ var array = new ArrayElement[count];
+ for (int i = 0; i < count; i++)
+ {
+ Debug.Assert(nodes[i] != null);
+ array[i].Value = nodes[i];
+ }
+
+ return List(array);
+ }
+
+ internal static SyntaxList List(ArrayElement[] children)
+ {
+ // "WithLotsOfChildren" list will allocate a separate array to hold
+ // precomputed node offsets. It may not be worth it for smallish lists.
+ if (children.Length < 10)
+ {
+ return new WithManyChildren(children);
+ }
+ else
+ {
+ return new WithLotsOfChildren(children);
+ }
+ }
+
+ internal abstract void CopyTo(ArrayElement[] array, int offset);
+
+ internal static GreenNode Concat(GreenNode left, GreenNode right)
+ {
+ if (left == null)
+ {
+ return right;
+ }
+
+ if (right == null)
+ {
+ return left;
+ }
+
+ var leftList = left as SyntaxList;
+ var rightList = right as SyntaxList;
+ if (leftList != null)
+ {
+ if (rightList != null)
+ {
+ var tmp = new ArrayElement[left.SlotCount + right.SlotCount];
+ leftList.CopyTo(tmp, 0);
+ rightList.CopyTo(tmp, left.SlotCount);
+ return List(tmp);
+ }
+ else
+ {
+ var tmp = new ArrayElement[left.SlotCount + 1];
+ leftList.CopyTo(tmp, 0);
+ tmp[left.SlotCount].Value = right;
+ return List(tmp);
+ }
+ }
+ else if (rightList != null)
+ {
+ var tmp = new ArrayElement[rightList.SlotCount + 1];
+ tmp[0].Value = left;
+ rightList.CopyTo(tmp, 1);
+ return List(tmp);
+ }
+ else
+ {
+ return List(left, right);
+ }
+ }
+
+ public override TResult Accept(SyntaxVisitor visitor)
+ {
+ return visitor.Visit(this);
+ }
+
+ public override void Accept(SyntaxVisitor visitor)
+ {
+ visitor.Visit(this);
+ }
+
+ internal class WithTwoChildren : SyntaxList
+ {
+ private readonly GreenNode _child0;
+ private readonly GreenNode _child1;
+
+ internal WithTwoChildren(GreenNode child0, GreenNode child1)
+ {
+ SlotCount = 2;
+ AdjustFlagsAndWidth(child0);
+ _child0 = child0;
+ AdjustFlagsAndWidth(child1);
+ _child1 = child1;
+ }
+
+ internal WithTwoChildren(RazorDiagnostic[] diagnostics, SyntaxAnnotation[] annotations, GreenNode child0, GreenNode child1)
+ {
+ SlotCount = 2;
+ AdjustFlagsAndWidth(child0);
+ _child0 = child0;
+ AdjustFlagsAndWidth(child1);
+ _child1 = child1;
+ }
+
+ internal override GreenNode GetSlot(int index)
+ {
+ switch (index)
+ {
+ case 0:
+ return _child0;
+ case 1:
+ return _child1;
+ default:
+ return null;
+ }
+ }
+
+ internal override void CopyTo(ArrayElement[] array, int offset)
+ {
+ array[offset].Value = _child0;
+ array[offset + 1].Value = _child1;
+ }
+
+ internal override SyntaxNode CreateRed(SyntaxNode parent, int position)
+ {
+ return new Syntax.SyntaxList.WithTwoChildren(this, parent, position);
+ }
+
+ internal override GreenNode SetDiagnostics(RazorDiagnostic[] errors)
+ {
+ return new WithTwoChildren(errors, this.GetAnnotations(), _child0, _child1);
+ }
+
+ internal override GreenNode SetAnnotations(SyntaxAnnotation[] annotations)
+ {
+ return new WithTwoChildren(GetDiagnostics(), annotations, _child0, _child1);
+ }
+ }
+
+ internal class WithThreeChildren : SyntaxList
+ {
+ private readonly GreenNode _child0;
+ private readonly GreenNode _child1;
+ private readonly GreenNode _child2;
+
+ internal WithThreeChildren(GreenNode child0, GreenNode child1, GreenNode child2)
+ {
+ SlotCount = 3;
+ AdjustFlagsAndWidth(child0);
+ _child0 = child0;
+ AdjustFlagsAndWidth(child1);
+ _child1 = child1;
+ AdjustFlagsAndWidth(child2);
+ _child2 = child2;
+ }
+
+ internal WithThreeChildren(RazorDiagnostic[] diagnostics, SyntaxAnnotation[] annotations, GreenNode child0, GreenNode child1, GreenNode child2)
+ : base(diagnostics, annotations)
+ {
+ SlotCount = 3;
+ AdjustFlagsAndWidth(child0);
+ _child0 = child0;
+ AdjustFlagsAndWidth(child1);
+ _child1 = child1;
+ AdjustFlagsAndWidth(child2);
+ _child2 = child2;
+ }
+
+ internal override GreenNode GetSlot(int index)
+ {
+ switch (index)
+ {
+ case 0:
+ return _child0;
+ case 1:
+ return _child1;
+ case 2:
+ return _child2;
+ default:
+ return null;
+ }
+ }
+
+ internal override void CopyTo(ArrayElement[] array, int offset)
+ {
+ array[offset].Value = _child0;
+ array[offset + 1].Value = _child1;
+ array[offset + 2].Value = _child2;
+ }
+
+ internal override SyntaxNode CreateRed(SyntaxNode parent, int position)
+ {
+ return new Syntax.SyntaxList.WithThreeChildren(this, parent, position);
+ }
+
+ internal override GreenNode SetDiagnostics(RazorDiagnostic[] errors)
+ {
+ return new WithThreeChildren(errors, GetAnnotations(), _child0, _child1, _child2);
+ }
+
+ internal override GreenNode SetAnnotations(SyntaxAnnotation[] annotations)
+ {
+ return new WithThreeChildren(GetDiagnostics(), annotations, _child0, _child1, _child2);
+ }
+ }
+
+ internal abstract class WithManyChildrenBase : SyntaxList
+ {
+ internal readonly ArrayElement[] children;
+
+ internal WithManyChildrenBase(ArrayElement[] children)
+ {
+ this.children = children;
+ this.InitializeChildren();
+ }
+
+ internal WithManyChildrenBase(RazorDiagnostic[] diagnostics, SyntaxAnnotation[] annotations, ArrayElement[] children)
+ : base(diagnostics, annotations)
+ {
+ this.children = children;
+ this.InitializeChildren();
+ }
+
+ private void InitializeChildren()
+ {
+ var n = children.Length;
+ if (n < byte.MaxValue)
+ {
+ SlotCount = (byte)n;
+ }
+ else
+ {
+ SlotCount = byte.MaxValue;
+ }
+
+ for (var i = 0; i < children.Length; i++)
+ {
+ AdjustFlagsAndWidth(children[i]);
+ }
+ }
+
+ protected override int GetSlotCount()
+ {
+ return children.Length;
+ }
+
+ internal override GreenNode GetSlot(int index)
+ {
+ return children[index];
+ }
+
+ internal override void CopyTo(ArrayElement[] array, int offset)
+ {
+ Array.Copy(children, 0, array, offset, children.Length);
+ }
+
+ internal override SyntaxNode CreateRed(SyntaxNode parent, int position)
+ {
+ return new Syntax.SyntaxList.WithManyChildren(this, parent, position);
+ }
+ }
+
+ internal sealed class WithManyChildren : WithManyChildrenBase
+ {
+ internal WithManyChildren(ArrayElement[] children)
+ : base(children)
+ {
+ }
+
+ internal WithManyChildren(RazorDiagnostic[] diagnostics, SyntaxAnnotation[] annotations, ArrayElement[] children)
+ : base(diagnostics, annotations, children)
+ {
+ }
+
+ internal override GreenNode SetDiagnostics(RazorDiagnostic[] errors)
+ {
+ return new WithManyChildren(errors, GetAnnotations(), children);
+ }
+
+ internal override GreenNode SetAnnotations(SyntaxAnnotation[] annotations)
+ {
+ return new WithManyChildren(GetDiagnostics(), annotations, children);
+ }
+ }
+
+ internal sealed class WithLotsOfChildren : WithManyChildrenBase
+ {
+ private readonly int[] _childOffsets;
+
+ internal WithLotsOfChildren(ArrayElement[] children)
+ : base(children)
+ {
+ _childOffsets = CalculateOffsets(children);
+ }
+
+ internal WithLotsOfChildren(RazorDiagnostic[] diagnostics, SyntaxAnnotation[] annotations, ArrayElement