Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SyntaxTreeVerifier.cs « Language « Microsoft.AspNetCore.Razor.Test.Common « test « Razor « src - github.com/dotnet/aspnetcore.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2e5f86d1cc03542befc8cb11e82f30b48724c8ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// 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 Microsoft.AspNetCore.Razor.Language.Legacy;

namespace Microsoft.AspNetCore.Razor.Language
{
    // Verifies recursively that a syntax tree has no gaps in terms of position/location.
    internal class SyntaxTreeVerifier : ParserVisitor
    {
        private readonly SourceLocationTracker _tracker = new SourceLocationTracker(SourceLocation.Zero);

        private SyntaxTreeVerifier()
        {
        }

        public static void Verify(RazorSyntaxTree syntaxTree)
        {
            Verify(syntaxTree.Root);
        }

        public static void Verify(Block block)
        {
            new SyntaxTreeVerifier().VisitBlock(block);
        }

        public override void VisitSpan(Span span)
        {
            var start = span.Start;
            if (!start.Equals(_tracker.CurrentLocation))
            {
                throw new InvalidOperationException($"Span starting at {span.Start} should start at {_tracker.CurrentLocation} - {span} ");
            }

            for (var i = 0; i < span.Symbols.Count; i++)
            {
                _tracker.UpdateLocation(span.Symbols[i].Content);
            }
        }
    }
}