forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpanBuilder.cs
More file actions
85 lines (72 loc) · 2.36 KB
/
Copy pathSpanBuilder.cs
File metadata and controls
85 lines (72 loc) · 2.36 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// 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.Collections.ObjectModel;
using System.Linq;
using System.Web.Razor.Editor;
using System.Web.Razor.Generator;
using System.Web.Razor.Text;
using System.Web.Razor.Tokenizer.Symbols;
namespace System.Web.Razor.Parser.SyntaxTree
{
public class SpanBuilder
{
private IList<ISymbol> _symbols = new List<ISymbol>();
private SourceLocationTracker _tracker = new SourceLocationTracker();
public SpanBuilder(Span original)
{
Kind = original.Kind;
_symbols = new List<ISymbol>(original.Symbols);
EditHandler = original.EditHandler;
CodeGenerator = original.CodeGenerator;
Start = original.Start;
}
public SpanBuilder()
{
Reset();
}
public SourceLocation Start { get; set; }
public SpanKind Kind { get; set; }
public ReadOnlyCollection<ISymbol> Symbols
{
get { return new ReadOnlyCollection<ISymbol>(_symbols); }
}
public SpanEditHandler EditHandler { get; set; }
public ISpanCodeGenerator CodeGenerator { get; set; }
public void Reset()
{
_symbols = new List<ISymbol>();
EditHandler = SpanEditHandler.CreateDefault(s => Enumerable.Empty<ISymbol>());
CodeGenerator = SpanCodeGenerator.Null;
Start = SourceLocation.Zero;
}
public Span Build()
{
return new Span(this);
}
public void ClearSymbols()
{
_symbols.Clear();
}
// Short-cut method for adding a symbol
public void Accept(ISymbol symbol)
{
if (symbol == null)
{
return;
}
if (_symbols.Count == 0)
{
Start = symbol.Start;
symbol.ChangeStart(SourceLocation.Zero);
_tracker.CurrentLocation = SourceLocation.Zero;
}
else
{
symbol.ChangeStart(_tracker.CurrentLocation);
}
_symbols.Add(symbol);
_tracker.UpdateLocation(symbol.Content);
}
}
}