@@ -9,140 +9,141 @@ type Type interface {
9
9
InstanceOf (Type ) bool
10
10
}
11
11
12
- // ===================== VoidType ===================== //
12
+ // ===================== Void type ===================== //
13
13
14
- // VoidType is void type
15
- type VoidType struct {}
14
+ // VoidType is a void type
15
+ var VoidType = & voidType {}
16
16
17
- func (* VoidType ) String () string {
17
+ type voidType struct {}
18
+
19
+ func (* voidType ) String () string {
18
20
return "Void"
19
21
}
20
22
21
- // InstanceOf returns true if t is VoidType
22
- func (* VoidType ) InstanceOf (t Type ) bool {
23
- if _ , ok := t .(* VoidType ); ok {
23
+ func (* voidType ) InstanceOf (t Type ) bool {
24
+ if _ , ok := t .(* voidType ); ok {
24
25
return true
25
26
}
26
27
return false
27
28
}
28
29
29
- // ===================== NullType ===================== //
30
+ // ===================== Null type ===================== //
31
+
32
+ // NullType is a null type
33
+ var NullType = & nullType {}
30
34
31
- // NullType is JSON null type
32
- type NullType struct {}
35
+ type nullType struct {}
33
36
34
- func (* NullType ) String () string {
37
+ func (* nullType ) String () string {
35
38
return "Null"
36
39
}
37
40
38
- // InstanceOf returns true if t is NullType
39
- func (* NullType ) InstanceOf (t Type ) bool {
40
- if _ , ok := t .(* NullType ); ok {
41
+ func (* nullType ) InstanceOf (t Type ) bool {
42
+ if _ , ok := t .(* nullType ); ok {
41
43
return true
42
44
}
43
45
return false
44
46
}
45
47
46
- // ===================== BoolType ===================== //
48
+ // ===================== Bool type ===================== //
49
+
50
+ // BoolType is a null type
51
+ var BoolType = & boolType {}
47
52
48
- // BoolType is JSON boolean type
49
- type BoolType struct {}
53
+ type boolType struct {}
50
54
51
- func (* BoolType ) String () string {
55
+ func (* boolType ) String () string {
52
56
return "Bool"
53
57
}
54
58
55
- // InstanceOf returns true if t is BoolType
56
- func (* BoolType ) InstanceOf (t Type ) bool {
57
- if _ , ok := t .(* BoolType ); ok {
59
+ func (* boolType ) InstanceOf (t Type ) bool {
60
+ if _ , ok := t .(* boolType ); ok {
58
61
return true
59
62
}
60
63
return false
61
64
}
62
65
63
- // ===================== NumberType ===================== //
66
+ // ===================== Number type ===================== //
64
67
65
- // NumberType is JSON number type
66
- type NumberType struct {}
68
+ // NumberType is a null type
69
+ var NumberType = & numberType {}
67
70
68
- func (* NumberType ) String () string {
71
+ type numberType struct {}
72
+
73
+ func (* numberType ) String () string {
69
74
return "Number"
70
75
}
71
76
72
- // InstanceOf returns true if t is NumberType
73
- func (* NumberType ) InstanceOf (t Type ) bool {
74
- if _ , ok := t .(* NumberType ); ok {
77
+ func (* numberType ) InstanceOf (t Type ) bool {
78
+ if _ , ok := t .(* numberType ); ok {
75
79
return true
76
80
}
77
81
return false
78
82
}
79
83
80
- // ===================== StringType ===================== //
84
+ // ===================== String type ===================== //
85
+
86
+ // StringType is a null type
87
+ var StringType = & stringType {}
81
88
82
- // StringType is JSON string type
83
- type StringType struct {}
89
+ type stringType struct {}
84
90
85
- func (* StringType ) String () string {
91
+ func (* stringType ) String () string {
86
92
return "String"
87
93
}
88
94
89
- // InstanceOf returns true if t is StringType
90
- func (* StringType ) InstanceOf (t Type ) bool {
91
- if _ , ok := t .(* StringType ); ok {
95
+ func (* stringType ) InstanceOf (t Type ) bool {
96
+ if _ , ok := t .(* stringType ); ok {
92
97
return true
93
98
}
94
99
return false
95
100
}
96
101
97
- // ===================== ArrayType ===================== //
102
+ // ===================== Array type ===================== //
98
103
99
- // ArrayType is JSON array type
100
- type ArrayType struct {
101
- arg Type
104
+ // NewArrayType creates array type instance
105
+ func NewArrayType ( arg Type ) Type {
106
+ return & arrayType { arg : arg }
102
107
}
103
108
104
- // NewArrayType creates ArrayType instance
105
- func NewArrayType (arg Type ) * ArrayType {
106
- return & ArrayType {arg : arg }
109
+ type arrayType struct {
110
+ arg Type
107
111
}
108
112
109
- func (t * ArrayType ) String () string {
113
+ func (t * arrayType ) String () string {
110
114
return "Array[" + t .arg .String () + "]"
111
115
}
112
116
113
- // InstanceOf returns true if t is instance of t2
114
- func (t * ArrayType ) InstanceOf (t2 Type ) bool {
115
- if array , ok := t2 .(* ArrayType ); ok {
117
+ func (t * arrayType ) InstanceOf (t2 Type ) bool {
118
+ if array , ok := t2 .(* arrayType ); ok {
116
119
return t .arg .InstanceOf (array .arg )
117
120
}
118
121
return false
119
122
}
120
123
121
- // ===================== ObjectType ===================== //
124
+ // ===================== Object type ===================== //
122
125
123
- // ObjectType is JSON object type
124
- type ObjectType struct {
125
- arg Type
126
+ // NewObjectType creates object type instance
127
+ func NewObjectType ( arg Type ) Type {
128
+ return & objectType { arg : arg }
126
129
}
127
130
128
- // NewObjectType creates ObjectType instance
129
- func NewObjectType (arg Type ) * ObjectType {
130
- return & ObjectType {arg : arg }
131
+ type objectType struct {
132
+ arg Type
131
133
}
132
134
133
- func (t * ObjectType ) String () string {
135
+ func (t * objectType ) String () string {
134
136
return "Object[" + t .arg .String () + "]"
135
137
}
136
138
137
- // InstanceOf returns true if t is instance of t2
138
- func (t * ObjectType ) InstanceOf (t2 Type ) bool {
139
- if array , ok := t2 .(* ObjectType ); ok {
139
+ func (t * objectType ) InstanceOf (t2 Type ) bool {
140
+ if array , ok := t2 .(* objectType ); ok {
140
141
return t .arg .InstanceOf (array .arg )
141
142
}
142
143
return false
143
144
}
144
145
145
- // ===================== AnyType ===================== //
146
+ // ===================== Any type ===================== //
146
147
147
148
// AnyValue allows any type
148
149
var AnyValue = & anyType {}
@@ -153,7 +154,6 @@ func (*anyType) String() string {
153
154
return "Any"
154
155
}
155
156
156
- // InstanceOf always returns true
157
157
func (* anyType ) InstanceOf (_ Type ) bool {
158
158
return true
159
159
}
0 commit comments