@@ -32,6 +32,22 @@ type Type struct {
32
32
Return * Type `json:"return,omitempty"`
33
33
}
34
34
35
+ var (
36
+ Operators = []string {"matches" , "contains" , "startsWith" , "endsWith" }
37
+ Builtins = map [Identifier ]* Type {
38
+ "true" : {Kind : "bool" },
39
+ "false" : {Kind : "bool" },
40
+ "len" : {Kind : "func" , Arguments : []* Type {{Kind : "array" , Type : & Type {Kind : "any" }}}, Return : & Type {Kind : "int" }},
41
+ "all" : {Kind : "func" , Arguments : []* Type {{Kind : "array" , Type : & Type {Kind : "any" }}, {Kind : "func" }}, Return : & Type {Kind : "bool" }},
42
+ "none" : {Kind : "func" , Arguments : []* Type {{Kind : "array" , Type : & Type {Kind : "any" }}, {Kind : "func" }}, Return : & Type {Kind : "bool" }},
43
+ "any" : {Kind : "func" , Arguments : []* Type {{Kind : "array" , Type : & Type {Kind : "any" }}, {Kind : "func" }}, Return : & Type {Kind : "bool" }},
44
+ "one" : {Kind : "func" , Arguments : []* Type {{Kind : "array" , Type : & Type {Kind : "any" }}, {Kind : "func" }}, Return : & Type {Kind : "bool" }},
45
+ "filter" : {Kind : "func" , Arguments : []* Type {{Kind : "array" , Type : & Type {Kind : "any" }}, {Kind : "func" }}, Return : & Type {Kind : "array" , Type : & Type {Kind : "any" }}},
46
+ "map" : {Kind : "func" , Arguments : []* Type {{Kind : "array" , Type : & Type {Kind : "any" }}, {Kind : "func" }}, Return : & Type {Kind : "array" , Type : & Type {Kind : "any" }}},
47
+ "count" : {Kind : "func" , Arguments : []* Type {{Kind : "array" , Type : & Type {Kind : "any" }}, {Kind : "func" }}, Return : & Type {Kind : "int" }},
48
+ }
49
+ )
50
+
35
51
func CreateDoc (i interface {}) * Context {
36
52
c := & Context {
37
53
Variables : make (map [Identifier ]* Type ),
@@ -42,6 +58,16 @@ func CreateDoc(i interface{}) *Context {
42
58
c .Variables [Identifier (name )] = c .use (t .Type , fromMethod (t .Method ))
43
59
}
44
60
61
+ for _ , op := range Operators {
62
+ c .Variables [Identifier (op )] = & Type {
63
+ Kind : "operator" ,
64
+ }
65
+ }
66
+
67
+ for builtin , t := range Builtins {
68
+ c .Variables [builtin ] = t
69
+ }
70
+
45
71
return c
46
72
}
47
73
0 commit comments