-
Notifications
You must be signed in to change notification settings - Fork 0
/
c_types_list.go
79 lines (60 loc) · 1.85 KB
/
c_types_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
70
71
72
73
74
75
76
77
78
79
package constraint
import (
"strings"
schema "github.com/jsightapi/jsight-schema-core"
"github.com/jsightapi/jsight-schema-core/json"
)
type TypesList struct {
innerTypeNames []string
// typeNames collection of real type names, used only for building AST nodes.
typeNames []string
// elementASTNodes contains an AST node for all items in this constraint
// This property was added only for build AST node, so it won't affect current
// logic at all.
elementASTNodes []schema.RuleASTNode
source schema.RuleASTNodeSource
hasUserTypes bool
}
var (
_ Constraint = TypesList{}
_ Constraint = (*TypesList)(nil)
)
func NewTypesList(s schema.RuleASTNodeSource) *TypesList {
return &TypesList{
innerTypeNames: make([]string, 0, 5),
source: s,
}
}
func (c TypesList) HasUserTypes() bool {
return c.hasUserTypes
}
func (TypesList) IsJsonTypeCompatible(json.Type) bool {
return true
}
func (TypesList) Type() Type {
return TypesListConstraintType
}
func (c TypesList) String() string {
return TypesListConstraintType.String() + ": " + strings.Join(c.innerTypeNames, ", ")
}
func (c *TypesList) AddName(name, typ string, s schema.RuleASTNodeSource) {
c.AddNameWithASTNode(name, typ, newRuleASTNode(schema.TokenTypeString, typ, s))
}
func (c *TypesList) AddNameWithASTNode(name, typ string, an schema.RuleASTNode) {
c.innerTypeNames = append(c.innerTypeNames, name)
c.typeNames = append(c.typeNames, typ)
c.elementASTNodes = append(c.elementASTNodes, an)
c.hasUserTypes = c.hasUserTypes || name[0] == '@'
}
func (c TypesList) Names() []string {
return c.innerTypeNames
}
func (c TypesList) Len() int {
return len(c.innerTypeNames)
}
func (c TypesList) ASTNode() schema.RuleASTNode {
n := newRuleASTNode(schema.TokenTypeArray, "", c.source)
n.Items = c.elementASTNodes
return n
}
func (c TypesList) Source() schema.RuleASTNodeSource { return c.source }