-
Notifications
You must be signed in to change notification settings - Fork 14
/
reg_array_fn.go
80 lines (63 loc) · 1.53 KB
/
reg_array_fn.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
80
package goql
import "github.com/fzerorubigd/goql/astdata"
type isArrayFn int
func (isArrayFn) Execute(args ...Getter) (Getter, error) {
def, err := getSingleDef(args...)
if err != nil {
return nil, err
}
if def == nil {
return Bool{Null: true}, nil
}
_, ok1 := def.(*astdata.ArrayType)
_, ok2 := def.(*astdata.EllipsisType)
return Bool{Bool: ok1 || ok2}, nil
}
type arrayItemFn int
func (arrayItemFn) Execute(args ...Getter) (Getter, error) {
def, err := getSingleDef(args...)
if err != nil {
return nil, err
}
if def == nil {
return Definition{}, nil
}
a, ok := def.(*astdata.ArrayType)
if ok {
return Definition{Definition: a.ValueDefinition()}, nil
}
e, ok := def.(*astdata.EllipsisType)
if ok {
return Definition{Definition: e.ValueDefinition()}, nil
}
return Definition{}, nil
}
type arrayTypeFn int
func (arrayTypeFn) Execute(args ...Getter) (Getter, error) {
def, err := getSingleDef(args...)
if err != nil {
return nil, err
}
if def == nil {
return String{Null: true}, nil
}
if arr, ok := def.(*astdata.ArrayType); ok {
if arr.Slice() {
return String{String: "slice"}, nil // enum?
}
return String{String: "array"}, nil // enum?
}
if _, ok := def.(*astdata.EllipsisType); ok {
return String{String: "ellipsis"}, nil // enum?
}
return String{Null: true}, nil
}
func registerArrayFunc() {
// Map functions
RegisterFunction("is_array", isArrayFn(0))
RegisterFunction("array_type", arrayTypeFn(0))
RegisterFunction("array_def", arrayItemFn(0))
}
func init() {
registerArrayFunc()
}