@@ -17,7 +17,7 @@ internal class CSharpCodeParser : TokenizerBackedParser<CSharpTokenizer>
17
17
} ) ;
18
18
19
19
private static readonly Func < SyntaxToken , bool > IsValidStatementSpacingToken =
20
- IsSpacingToken ( includeNewLines : true , includeComments : true ) ;
20
+ IsSpacingTokenIncludingNewLinesAndComments ;
21
21
22
22
internal static readonly DirectiveDescriptor AddTagHelperDirectiveDescriptor = DirectiveDescriptor . CreateDirective (
23
23
SyntaxConstants . CSharp . AddTagHelperKeyword ,
@@ -124,7 +124,7 @@ public CSharpCodeBlockSyntax ParseBlock()
124
124
{
125
125
NextToken ( ) ;
126
126
127
- var precedingWhitespace = ReadWhile ( IsSpacingToken ( includeNewLines : true , includeComments : true ) ) ;
127
+ var precedingWhitespace = ReadWhile ( IsSpacingTokenIncludingNewLinesAndComments ) ;
128
128
129
129
// We are usually called when the other parser sees a transition '@'. Look for it.
130
130
SyntaxToken transitionToken = null ;
@@ -1317,7 +1317,7 @@ private void ParseExtensibleDirective(in SyntaxListBuilder<RazorSyntaxNode> buil
1317
1317
1318
1318
if ( At ( SyntaxKind . Whitespace ) )
1319
1319
{
1320
- AcceptWhile ( IsSpacingToken ( includeNewLines : false , includeComments : true ) ) ;
1320
+ AcceptWhile ( IsSpacingTokenIncludingComments ) ;
1321
1321
1322
1322
if ( tokenDescriptor . Kind == DirectiveTokenKind . Member ||
1323
1323
tokenDescriptor . Kind == DirectiveTokenKind . Namespace ||
@@ -1443,7 +1443,7 @@ private void ParseExtensibleDirective(in SyntaxListBuilder<RazorSyntaxNode> buil
1443
1443
directiveBuilder . Add ( OutputTokensAsStatementLiteral ( ) ) ;
1444
1444
}
1445
1445
1446
- AcceptWhile ( IsSpacingToken ( includeNewLines : false , includeComments : true ) ) ;
1446
+ AcceptWhile ( IsSpacingTokenIncludingComments ) ;
1447
1447
SpanContext . ChunkGenerator = SpanChunkGenerator . Null ;
1448
1448
1449
1449
switch ( descriptor . Kind )
@@ -1455,7 +1455,7 @@ private void ParseExtensibleDirective(in SyntaxListBuilder<RazorSyntaxNode> buil
1455
1455
TryAccept ( SyntaxKind . Semicolon ) ;
1456
1456
directiveBuilder . Add ( OutputAsMetaCode ( Output ( ) , AcceptedCharactersInternal . Whitespace ) ) ;
1457
1457
1458
- AcceptWhile ( IsSpacingToken ( includeNewLines : false , includeComments : true ) ) ;
1458
+ AcceptWhile ( IsSpacingTokenIncludingComments ) ;
1459
1459
1460
1460
if ( At ( SyntaxKind . NewLine ) )
1461
1461
{
@@ -1478,7 +1478,7 @@ private void ParseExtensibleDirective(in SyntaxListBuilder<RazorSyntaxNode> buil
1478
1478
directiveBuilder . Add ( OutputAsMarkupEphemeralLiteral ( ) ) ;
1479
1479
break ;
1480
1480
case DirectiveKind . RazorBlock :
1481
- AcceptWhile ( IsSpacingToken ( includeNewLines : true , includeComments : true ) ) ;
1481
+ AcceptWhile ( IsSpacingTokenIncludingNewLinesAndComments ) ;
1482
1482
SpanContext . EditHandler . AcceptedCharacters = AcceptedCharactersInternal . AllWhitespace ;
1483
1483
directiveBuilder . Add ( OutputTokensAsUnclassifiedLiteral ( ) ) ;
1484
1484
@@ -1502,7 +1502,7 @@ private void ParseExtensibleDirective(in SyntaxListBuilder<RazorSyntaxNode> buil
1502
1502
} ) ;
1503
1503
break ;
1504
1504
case DirectiveKind . CodeBlock :
1505
- AcceptWhile ( IsSpacingToken ( includeNewLines : true , includeComments : true ) ) ;
1505
+ AcceptWhile ( IsSpacingTokenIncludingNewLinesAndComments ) ;
1506
1506
SpanContext . EditHandler . AcceptedCharacters = AcceptedCharactersInternal . AllWhitespace ;
1507
1507
directiveBuilder . Add ( OutputTokensAsUnclassifiedLiteral ( ) ) ;
1508
1508
@@ -1753,7 +1753,7 @@ private void ParseAwaitExpression(SyntaxListBuilder<RazorSyntaxNode> builder, CS
1753
1753
AcceptAndMoveNext ( ) ;
1754
1754
1755
1755
// Accept 1 or more spaces between the await and the following code.
1756
- AcceptWhile ( IsSpacingToken ( includeNewLines : false , includeComments : true ) ) ;
1756
+ AcceptWhile ( IsSpacingTokenIncludingComments ) ;
1757
1757
1758
1758
// Top level basically indicates if we're within an expression or statement.
1759
1759
// Ex: topLevel true = @await Foo() | topLevel false = @{ await Foo(); }
@@ -1806,12 +1806,12 @@ private void ParseConditionalBlock(in SyntaxListBuilder<RazorSyntaxNode> builder
1806
1806
private void ParseConditionalBlock ( in SyntaxListBuilder < RazorSyntaxNode > builder , Block block )
1807
1807
{
1808
1808
AcceptAndMoveNext ( ) ;
1809
- AcceptWhile ( IsSpacingToken ( includeNewLines : true , includeComments : true ) ) ;
1809
+ AcceptWhile ( IsSpacingTokenIncludingNewLinesAndComments ) ;
1810
1810
1811
1811
// Parse the condition, if present (if not present, we'll let the C# compiler complain)
1812
1812
if ( TryParseCondition ( builder ) )
1813
1813
{
1814
- AcceptWhile ( IsSpacingToken ( includeNewLines : true , includeComments : true ) ) ;
1814
+ AcceptWhile ( IsSpacingTokenIncludingNewLinesAndComments ) ;
1815
1815
1816
1816
ParseExpectedCodeBlock ( builder , block ) ;
1817
1817
}
@@ -1874,7 +1874,7 @@ private void ParseUnconditionalBlock(in SyntaxListBuilder<RazorSyntaxNode> build
1874
1874
Assert ( SyntaxKind . Keyword ) ;
1875
1875
var block = new Block ( CurrentToken , CurrentStart ) ;
1876
1876
AcceptAndMoveNext ( ) ;
1877
- AcceptWhile ( IsSpacingToken ( includeNewLines : true , includeComments : true ) ) ;
1877
+ AcceptWhile ( IsSpacingTokenIncludingNewLinesAndComments ) ;
1878
1878
ParseExpectedCodeBlock ( builder , block ) ;
1879
1879
}
1880
1880
@@ -1937,7 +1937,7 @@ private void ParseElseClause(in SyntaxListBuilder<RazorSyntaxNode> builder)
1937
1937
var block = new Block ( CurrentToken , CurrentStart ) ;
1938
1938
1939
1939
AcceptAndMoveNext ( ) ;
1940
- AcceptWhile ( IsSpacingToken ( includeNewLines : true , includeComments : true ) ) ;
1940
+ AcceptWhile ( IsSpacingTokenIncludingNewLinesAndComments ) ;
1941
1941
if ( At ( CSharpKeyword . If ) )
1942
1942
{
1943
1943
// ElseIf
@@ -2059,7 +2059,7 @@ private void ParseWhileClause(in SyntaxListBuilder<RazorSyntaxNode> builder)
2059
2059
Accept ( whitespace ) ;
2060
2060
Assert ( CSharpKeyword . While ) ;
2061
2061
AcceptAndMoveNext ( ) ;
2062
- AcceptWhile ( IsSpacingToken ( includeNewLines : true , includeComments : true ) ) ;
2062
+ AcceptWhile ( IsSpacingTokenIncludingNewLinesAndComments ) ;
2063
2063
if ( TryParseCondition ( builder ) && TryAccept ( SyntaxKind . Semicolon ) )
2064
2064
{
2065
2065
SpanContext . EditHandler . AcceptedCharacters = AcceptedCharactersInternal . None ;
@@ -2078,7 +2078,7 @@ private void ParseUsingKeyword(SyntaxListBuilder<RazorSyntaxNode> builder, CShar
2078
2078
var topLevel = transition != null ;
2079
2079
var block = new Block ( CurrentToken , CurrentStart ) ;
2080
2080
var usingToken = EatCurrentToken ( ) ;
2081
- var whitespaceOrComments = ReadWhile ( IsSpacingToken ( includeNewLines : false , includeComments : true ) ) ;
2081
+ var whitespaceOrComments = ReadWhile ( IsSpacingTokenIncludingComments ) ;
2082
2082
var atLeftParen = At ( SyntaxKind . LeftParenthesis ) ;
2083
2083
var atIdentifier = At ( SyntaxKind . Identifier ) ;
2084
2084
var atStatic = At ( CSharpKeyword . Static ) ;
@@ -2115,7 +2115,7 @@ private void ParseUsingKeyword(SyntaxListBuilder<RazorSyntaxNode> builder, CShar
2115
2115
builder . Add ( transition ) ;
2116
2116
}
2117
2117
AcceptAndMoveNext ( ) ;
2118
- AcceptWhile ( IsSpacingToken ( includeNewLines : false , includeComments : true ) ) ;
2118
+ AcceptWhile ( IsSpacingTokenIncludingComments ) ;
2119
2119
ParseStandardStatement ( builder ) ;
2120
2120
}
2121
2121
else
@@ -2132,7 +2132,7 @@ private void ParseUsingKeyword(SyntaxListBuilder<RazorSyntaxNode> builder, CShar
2132
2132
}
2133
2133
2134
2134
AcceptAndMoveNext ( ) ;
2135
- AcceptWhile ( IsSpacingToken ( includeNewLines : false , includeComments : true ) ) ;
2135
+ AcceptWhile ( IsSpacingTokenIncludingComments ) ;
2136
2136
}
2137
2137
2138
2138
if ( topLevel )
@@ -2145,7 +2145,7 @@ private void ParseUsingStatement(in SyntaxListBuilder<RazorSyntaxNode> builder,
2145
2145
{
2146
2146
Assert ( CSharpKeyword . Using ) ;
2147
2147
AcceptAndMoveNext ( ) ;
2148
- AcceptWhile ( IsSpacingToken ( includeNewLines : false , includeComments : true ) ) ;
2148
+ AcceptWhile ( IsSpacingTokenIncludingComments ) ;
2149
2149
2150
2150
Assert ( SyntaxKind . LeftParenthesis ) ;
2151
2151
if ( transition != null )
@@ -2156,7 +2156,7 @@ private void ParseUsingStatement(in SyntaxListBuilder<RazorSyntaxNode> builder,
2156
2156
// Parse condition
2157
2157
if ( TryParseCondition ( builder ) )
2158
2158
{
2159
- AcceptWhile ( IsSpacingToken ( includeNewLines : true , includeComments : true ) ) ;
2159
+ AcceptWhile ( IsSpacingTokenIncludingNewLinesAndComments ) ;
2160
2160
2161
2161
// Parse code block
2162
2162
ParseExpectedCodeBlock ( builder , block ) ;
@@ -2174,22 +2174,22 @@ private void ParseUsingDeclaration(in SyntaxListBuilder<RazorSyntaxNode> builder
2174
2174
AcceptAndMoveNext ( ) ;
2175
2175
var isStatic = false ;
2176
2176
var nonNamespaceTokenCount = TokenBuilder . Count ;
2177
- AcceptWhile ( IsSpacingToken ( includeNewLines : false , includeComments : true ) ) ;
2177
+ AcceptWhile ( IsSpacingTokenIncludingComments ) ;
2178
2178
var start = CurrentStart ;
2179
2179
if ( At ( SyntaxKind . Identifier ) )
2180
2180
{
2181
2181
// non-static using
2182
2182
nonNamespaceTokenCount = TokenBuilder . Count ;
2183
2183
TryParseNamespaceOrTypeName ( directiveBuilder ) ;
2184
- var whitespace = ReadWhile ( IsSpacingToken ( includeNewLines : true , includeComments : true ) ) ;
2184
+ var whitespace = ReadWhile ( IsSpacingTokenIncludingNewLinesAndComments ) ;
2185
2185
if ( At ( SyntaxKind . Assign ) )
2186
2186
{
2187
2187
// Alias
2188
2188
Accept ( whitespace ) ;
2189
2189
Assert ( SyntaxKind . Assign ) ;
2190
2190
AcceptAndMoveNext ( ) ;
2191
2191
2192
- AcceptWhile ( IsSpacingToken ( includeNewLines : true , includeComments : true ) ) ;
2192
+ AcceptWhile ( IsSpacingTokenIncludingNewLinesAndComments ) ;
2193
2193
2194
2194
// One more namespace or type name
2195
2195
TryParseNamespaceOrTypeName ( directiveBuilder ) ;
@@ -2205,7 +2205,7 @@ private void ParseUsingDeclaration(in SyntaxListBuilder<RazorSyntaxNode> builder
2205
2205
// static using
2206
2206
isStatic = true ;
2207
2207
AcceptAndMoveNext ( ) ;
2208
- AcceptWhile ( IsSpacingToken ( includeNewLines : false , includeComments : true ) ) ;
2208
+ AcceptWhile ( IsSpacingTokenIncludingComments ) ;
2209
2209
nonNamespaceTokenCount = TokenBuilder . Count ;
2210
2210
TryParseNamespaceOrTypeName ( directiveBuilder ) ;
2211
2211
}
@@ -2391,7 +2391,7 @@ private IEnumerable<SyntaxToken> SkipToNextImportantToken(in SyntaxListBuilder<R
2391
2391
{
2392
2392
while ( ! EndOfFile )
2393
2393
{
2394
- var whitespace = ReadWhile ( IsSpacingToken ( includeNewLines : true , includeComments : true ) ) ;
2394
+ var whitespace = ReadWhile ( IsSpacingTokenIncludingNewLinesAndComments ) ;
2395
2395
if ( At ( SyntaxKind . RazorCommentTransition ) )
2396
2396
{
2397
2397
Accept ( whitespace ) ;
@@ -2622,11 +2622,24 @@ protected internal bool At(CSharpKeyword keyword)
2622
2622
result . Value == keyword ;
2623
2623
}
2624
2624
2625
- protected static Func < SyntaxToken , bool > IsSpacingToken ( bool includeNewLines , bool includeComments )
2626
- {
2627
- return token => token . Kind == SyntaxKind . Whitespace ||
2628
- ( includeNewLines && token . Kind == SyntaxKind . NewLine ) ||
2629
- ( includeComments && token . Kind == SyntaxKind . CSharpComment ) ;
2625
+ protected static bool IsSpacingToken ( SyntaxToken token )
2626
+ {
2627
+ return token . Kind == SyntaxKind . Whitespace ;
2628
+ }
2629
+
2630
+ protected static bool IsSpacingTokenIncludingNewLines ( SyntaxToken token )
2631
+ {
2632
+ return IsSpacingToken ( token ) || token . Kind == SyntaxKind . NewLine ;
2633
+ }
2634
+
2635
+ protected static bool IsSpacingTokenIncludingComments ( SyntaxToken token )
2636
+ {
2637
+ return IsSpacingToken ( token ) || token . Kind == SyntaxKind . CSharpComment ;
2638
+ }
2639
+
2640
+ protected static bool IsSpacingTokenIncludingNewLinesAndComments ( SyntaxToken token )
2641
+ {
2642
+ return IsSpacingTokenIncludingNewLines ( token ) || token . Kind == SyntaxKind . CSharpComment ;
2630
2643
}
2631
2644
2632
2645
protected class Block
0 commit comments