-
Notifications
You must be signed in to change notification settings - Fork 0
/
token.go
137 lines (104 loc) · 3.14 KB
/
token.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package gqlparser
import "strconv"
// privateSealed is just a private type. it's used to limit patterns like sealed class.
type privateSealed struct{}
type Token interface {
isToken() privateSealed
GetContent() string
GetPosition() int
}
type StringToken struct {
Quote byte
Content string
RawContent string
Position int
}
func (*StringToken) isToken() privateSealed { return privateSealed{} }
func (t *StringToken) GetContent() string { return t.RawContent }
func (t *StringToken) GetPosition() int { return t.Position }
type OperatorToken struct {
Type string
RawContent string
Position int
}
func (*OperatorToken) isToken() privateSealed { return privateSealed{} }
func (t *OperatorToken) GetContent() string {
if t.RawContent != "" {
return t.RawContent
}
return t.Type
}
func (t *OperatorToken) GetPosition() int { return t.Position }
type WildcardToken struct {
Position int
}
func (*WildcardToken) isToken() privateSealed { return privateSealed{} }
func (t *WildcardToken) GetContent() string { return "*" }
func (t *WildcardToken) GetPosition() int { return t.Position }
type BooleanToken struct {
Value bool
RawContent string
Position int
}
func (*BooleanToken) isToken() privateSealed { return privateSealed{} }
func (t *BooleanToken) GetContent() string {
return t.RawContent
}
func (t *BooleanToken) GetPosition() int { return t.Position }
type OrderToken struct {
Descending bool
RawContent string
Position int
}
func (*OrderToken) isToken() privateSealed { return privateSealed{} }
func (t *OrderToken) GetContent() string {
return t.RawContent
}
func (t *OrderToken) GetPosition() int { return t.Position }
type SymbolToken struct {
Content string
Position int
}
func (*SymbolToken) isToken() privateSealed { return privateSealed{} }
func (t *SymbolToken) GetContent() string { return t.Content }
func (t *SymbolToken) GetPosition() int { return t.Position }
type KeywordToken struct {
Name string
RawContent string
Position int
}
func (*KeywordToken) isToken() privateSealed { return privateSealed{} }
func (t *KeywordToken) GetContent() string { return t.RawContent }
func (t *KeywordToken) GetPosition() int { return t.Position }
type NumericToken struct {
Int64 int64
Float64 float64
Floating bool
RawContent string
Position int
}
func (*NumericToken) isToken() privateSealed { return privateSealed{} }
func (t *NumericToken) GetContent() string {
return t.RawContent
}
func (t *NumericToken) GetPosition() int { return t.Position }
type BindingToken struct {
Index int64
Name string
Position int
}
func (*BindingToken) isToken() privateSealed { return privateSealed{} }
func (t *BindingToken) GetContent() string {
if t.Index != 0 {
return "@" + strconv.FormatInt(t.Index, 10)
}
return "@" + t.Name
}
func (t *BindingToken) GetPosition() int { return t.Position }
type WhitespaceToken struct {
Content string
Position int
}
func (*WhitespaceToken) isToken() privateSealed { return privateSealed{} }
func (t *WhitespaceToken) GetContent() string { return t.Content }
func (t *WhitespaceToken) GetPosition() int { return t.Position }