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