-
Notifications
You must be signed in to change notification settings - Fork 0
/
ast.go
116 lines (94 loc) · 1.52 KB
/
ast.go
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package parser
type Node interface {
Pos() int
End() int
}
type SpanType int
const (
SpanMessage SpanType = iota
SpanText
SpanCode
SpanGreentext
SpanSpoiler
SpanMe
)
var spanTypeNames = map[SpanType]string{
SpanMessage: "Message",
SpanText: "Text",
SpanCode: "Code",
SpanGreentext: "Greentext",
SpanSpoiler: "Spoiler",
SpanMe: "Me",
}
func (t SpanType) String() string {
return spanTypeNames[t]
}
type Span struct {
Type SpanType
Nodes []Node
TokPos int
TokEnd int
}
func (s *Span) Insert(n Node) {
if ns, ok := n.(*Span); ok && ns.Type == s.Type {
s.Nodes = append(s.Nodes, ns.Nodes...)
s.TokEnd = ns.TokEnd
} else {
s.Nodes = append(s.Nodes, n)
}
}
func (s *Span) Pos() int {
return s.TokPos
}
func (s *Span) End() int {
return s.TokEnd
}
type Link struct {
URL string
TokPos int
TokEnd int
}
func (l *Link) Pos() int {
return l.TokPos
}
func (l *Link) End() int {
return l.TokEnd
}
type Emote struct {
Name string
Modifiers []string
TokPos int
TokEnd int
}
func (e *Emote) InsertModifier(m string) {
e.Modifiers = append(e.Modifiers, m)
}
func (e *Emote) Pos() int {
return e.TokPos
}
func (e *Emote) End() int {
return e.TokEnd
}
type Tag struct {
Name string
TokPos int
TokEnd int
}
func (t *Tag) Pos() int {
return t.TokPos
}
func (t *Tag) End() int {
return t.TokEnd
}
type Nick struct {
Nick string
TokPos int
TokEnd int
Meta interface{}
}
func (n *Nick) Pos() int {
return n.TokPos
}
func (n *Nick) End() int {
return n.TokEnd
}