-
Notifications
You must be signed in to change notification settings - Fork 1
/
thrift.go
119 lines (111 loc) · 2.46 KB
/
thrift.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
package thrifter
type Thrift struct {
NodeCommonField
// thrift file name, if it exists
FileName string
// since Thrift is the root node, we need a property to access its children
Nodes []Node
}
func NewThrift(parent Node, FileName string) *Thrift {
return &Thrift{
NodeCommonField: NodeCommonField{
Parent: parent,
},
FileName: FileName,
}
}
func (r *Thrift) NodeType() string {
return "Thrift"
}
func (r *Thrift) NodeValue() interface{} {
return *r
}
func (r *Thrift) String() string {
return toString(r.StartToken, r.EndToken)
}
func (r *Thrift) parse(p *Parser) (err error) {
tok := p.next()
if r.StartToken == nil {
r.StartToken = tok
}
switch {
case tok.Type == T_COMMENT ||
tok.Type == T_SPACE ||
tok.Type == T_LINEBREAK ||
tok.Type == T_RETURN ||
tok.Type == T_TAB:
if err = r.parse(p); err != nil {
return
}
case tok.Type == T_NAMESPACE:
node := NewNamespace(tok, r)
if err = node.parse(p); err != nil {
return
}
r.Nodes = append(r.Nodes, node)
if err = r.parse(p); err != nil {
return
}
case tok.Type == T_SENUM:
case tok.Type == T_ENUM:
node := NewEnum(tok, r)
if err = node.parse(p); err != nil {
return
}
r.Nodes = append(r.Nodes, node)
if err = r.parse(p); err != nil {
return
}
case tok.Type == T_CONST:
node := NewConst(tok, r)
if err = node.parse(p); err != nil {
return
}
r.Nodes = append(r.Nodes, node)
if err = r.parse(p); err != nil {
return
}
case tok.Type == T_SERVICE:
node := NewService(tok, r)
if err = node.parse(p); err != nil {
return
}
r.Nodes = append(r.Nodes, node)
if err = r.parse(p); err != nil {
return
}
case tok.Type == T_STRUCT, tok.Type == T_EXCEPTION, tok.Type == T_UNION:
node := NewStruct(tok, r)
if err = node.parse(p); err != nil {
return
}
r.Nodes = append(r.Nodes, node)
if err = r.parse(p); err != nil {
return
}
case tok.Type == T_INCLUDE, tok.Type == T_CPP_INCLUDE:
node := NewInclude(tok, r)
if err = node.parse(p); err != nil {
return
}
r.Nodes = append(r.Nodes, node)
if err = r.parse(p); err != nil {
return
}
case tok.Type == T_TYPEDEF:
node := NewTypeDef(tok, r)
if err = node.parse(p); err != nil {
return
}
r.Nodes = append(r.Nodes, node)
if err = r.parse(p); err != nil {
return
}
case tok.Type == T_EOF:
r.EndToken = tok
return
default:
return p.unexpected(tok.Raw, ".thrift element {namespace|enum|const|service|struct|include|typedef|union|exception}")
}
return
}