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