-
Notifications
You must be signed in to change notification settings - Fork 0
/
ast_utils.go
60 lines (49 loc) · 1.12 KB
/
ast_utils.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
package astjson
func IsBool(value *Value) bool {
return value.NodeType == Bool
}
func IsNull(value *Value) bool {
return value.NodeType == Null
}
func IsNumber(value *Value) bool {
return value.NodeType == Number
}
func IsString(value *Value) bool {
return value.NodeType == String
}
func IsArray(value *Value) bool {
return value.NodeType == Array
}
func IsObject(value *Value) bool {
return value.NodeType == Object
}
func GetArrayValues(value *Value) []Value {
if !IsArray(value) {
panic("value is not an object")
}
return value.AstValue.(*ArrayAst).Values
}
func GetObjectKvMap(value *Value) map[string]Value {
if !IsObject(value) {
panic("value is not an object")
}
return value.AstValue.(*ObjectAst).KvMap
}
func GetString(value *Value) string {
if !IsString(value) {
panic("value is not a string")
}
return string(value.AstValue.(StringAst))
}
func GetBool(value *Value) bool {
if !IsBool(value) {
panic("value is not a bool")
}
return bool(value.AstValue.(BoolAst))
}
func GetNumber(value *Value) NumberAst {
if !IsNumber(value) {
panic("value is not a number")
}
return value.AstValue.(NumberAst)
}