Commit 54c21d0
authored
Compiler: Rationalize nodes, tokens, visitors, walkers, and rewriters, oh my! (#11853)
Razor's syntax model doesn't provide as much separation between syntax
nodes and tokens as Roslyn's. This is due in part to the fact that
Roslyn's model is designed to support two languages, not just one. When
Razor's syntax model was adapted from Roslyn's, some mistakes were made
when modifying it fit a single language. Currently, the base hierarchy
of Razor's syntax model like so:
```mermaid
---
config:
class:
hideEmptyMembersBox: true
---
classDiagram
SyntaxNode <|-- SyntaxList
SyntaxNode <|-- RazorSyntaxNode
RazorSyntaxNode <|-- SyntaxToken
RazorSyntaxNode <|-- RazorBlockSyntax
RazorSyntaxNode <|-- `...Add Other RazorSyntaxNodes`
```
A glaring mistake in the class hierarchy above is that `SyntaxToken`
inherits from `RazorSyntaxNode`, which is reserved for Razor
non-terminal syntax nodes. This PR changes `SyntaxToken` to inherit from
`SyntaxNode` and moves several methods intended for non-terminals to
`RazorSyntaxNode. This creates a much more sensible hierarchy:
```mermaid
---
config:
class:
hideEmptyMembersBox: true
---
classDiagram
SyntaxNode <|-- SyntaxList
SyntaxNode <|-- SyntaxToken
SyntaxNode <|-- RazorSyntaxNode
RazorSyntaxNode <|-- RazorBlockSyntax
RazorSyntaxNode <|-- `...And Other RazorSyntaxNodes`
```
This PR adds much cleaner separation between `SyntaxNode`, `SyntaxList`
and `SyntaxToken`, and updates the `SyntaxVisitor`, `SyntaxWalker`, and
`SyntaxRewriter` APIs to better match Roslyn's. This removes a lot of
baggage from `SyntaxToken`, making it easier to convert to a struct in
the near future.
----
CI Build:
https://dev.azure.com/dnceng/internal/_build/results?buildId=2706052&view=results
Test Insertion:
https://dev.azure.com/devdiv/DevDiv/_git/VS/pullrequest/635607
Toolset Test Run:
https://dev.azure.com/dnceng/internal/_build/results?buildId=2706053&view=resultsFile tree
28 files changed
+836
-829
lines changed- src
- Compiler
- Microsoft.AspNetCore.Razor.Language
- legacyTest/Legacy
- test
- IntegrationTests
- Legacy
- Syntax
- Microsoft.CodeAnalysis.Razor.Compiler/src/Language
- Legacy
- Syntax
- Razor
- src/Microsoft.CodeAnalysis.Razor.Workspaces
- Completion
- Extensions
- Formatting/Passes/New
- SemanticTokens
- test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Language/Legacy
28 files changed
+836
-829
lines changedLines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/FindTokenIntegrationTest.cs
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
51 | | - | |
| 52 | + | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
0 commit comments