Skip to content

Commit 31f53d4

Browse files
committed
Refactored Html parser - part 1
1 parent 46242b3 commit 31f53d4

File tree

10 files changed

+2436
-1718
lines changed

10 files changed

+2436
-1718
lines changed

src/Razor/src/Microsoft.AspNetCore.Razor.Language/Legacy/DirectiveHtmlTokenizer.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,20 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
99
internal class DirectiveHtmlTokenizer : HtmlTokenizer
1010
{
1111
private bool _visitedFirstTokenStart = false;
12+
private SourceLocation _firstTokenVisitLocation = SourceLocation.Undefined;
1213

1314
public DirectiveHtmlTokenizer(ITextDocument source) : base(source)
1415
{
1516
}
1617

1718
protected override StateResult Dispatch()
1819
{
20+
var location = CurrentLocation;
1921
var result = base.Dispatch();
2022
if (result.Result != null && IsValidTokenType(result.Result.Kind))
2123
{
2224
_visitedFirstTokenStart = true;
25+
_firstTokenVisitLocation = location;
2326
}
2427

2528
return result;
@@ -31,8 +34,10 @@ public override SyntaxToken NextToken()
3134
Debug.Assert(Buffer.Length == 0);
3235
StartToken();
3336

34-
if (EndOfFile || _visitedFirstTokenStart)
37+
if (EndOfFile || (_visitedFirstTokenStart && _firstTokenVisitLocation != CurrentLocation))
3538
{
39+
// We also need to make sure we are currently past the position where we found the first token.
40+
// If the position is equal, that means the parser put the token back for later parsing.
3641
return null;
3742
}
3843

0 commit comments

Comments
 (0)