-
Notifications
You must be signed in to change notification settings - Fork 1
/
typedef.go
56 lines (48 loc) · 1.04 KB
/
typedef.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
package thrifter
type TypeDef struct {
NodeCommonField
Type *FieldType // except for identifier
Ident string
Options []*Option
}
func NewTypeDef(start *Token, parent Node) *TypeDef {
return &TypeDef{
NodeCommonField: NodeCommonField{
Parent: parent,
StartToken: start,
},
}
}
func (r *TypeDef) NodeType() string {
return "TypeDef"
}
func (r *TypeDef) NodeValue() interface{} {
return *r
}
func (r *TypeDef) String() string {
return toString(r.StartToken, r.EndToken)
}
func (r *TypeDef) parse(p *Parser) (err error) {
p.peekNonWhitespace()
r.Type = NewFieldType(r)
if err = r.Type.parse(p); err != nil {
return
}
if r.Type.Type == FIELD_TYPE_IDENT {
return p.unexpected(r.Type.Ident, "base type or map or list or set")
}
identTok := p.nextIdent(true)
r.Ident = identTok.Raw
r.EndToken = identTok
// parse options
ru := p.peekNonWhitespace()
if toToken(string(ru)) != T_LEFTPAREN {
return
}
p.next() // consume (
r.Options, r.EndToken, err = parseOptions(p, r)
if err != nil {
return err
}
return
}