-
Notifications
You must be signed in to change notification settings - Fork 1
/
set.go
70 lines (63 loc) · 1.27 KB
/
set.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
package thrifter
type SetType struct {
NodeCommonField
Elem *FieldType
CppType string
}
func NewSetType(start *Token, parent Node) *SetType {
return &SetType{
NodeCommonField: NodeCommonField{
Parent: parent,
StartToken: start,
},
}
}
func (r *SetType) NodeType() string {
return "SetType"
}
func (r *SetType) NodeValue() interface{} {
return *r
}
func (r *SetType) String() string {
return toString(r.StartToken, r.EndToken)
}
func (r *SetType) parse(p *Parser) (err error) {
p.peekNonWhitespace()
tok := p.next()
if tok.Type == T_LESS {
if err = r.parseElem(p); err != nil {
return
}
} else if tok.Type == T_IDENT && tok.Value == "cpp_type" {
p.peekNonWhitespace()
strTok, err := p.nextString()
if err != nil {
return err
}
r.CppType = strTok.Value
p.peekNonWhitespace()
tok := p.next()
if tok.Type != T_LESS {
return p.unexpected(tok.Value, "<")
}
if err = r.parseElem(p); err != nil {
return err
}
} else {
err = p.unexpected(tok.Value, "< or cpp_type")
}
return
}
func (r *SetType) parseElem(p *Parser) (err error) {
r.Elem = NewFieldType(r)
if err = r.Elem.parse(p); err != nil {
return
}
tok := p.next()
if tok.Type != T_GREATER {
err = p.unexpected(tok.Value, ">")
return
}
r.EndToken = tok
return
}