-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToken.cs
45 lines (33 loc) · 1.04 KB
/
Token.cs
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
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
namespace TokenDiscovery {
/// <summary>
/// A single token completely matching a given pattern
/// </summary>
public class Token {
public Pattern Pattern;
[JsonPropertyName("Pattern")]
public string PatternDescription {
get {
return Pattern.ToString();
}
}
public int StartAt;
public int Length;
public string Text { get; set; }
public List<Token> Children = new List<Token>();
[JsonPropertyName("Children")]
public List<Token> ChildrenForJson {
get {
if (Children.Where(e => e.Pattern.Type >= PatternType.Derived).Any()) {
return Children;
}
return null;
}
}
public override string ToString() {
return Pattern + " >> (" + StartAt + " - " + (StartAt + Length) + ") '" + Text + "'";
}
}
}