@@ -32,6 +32,22 @@ type Type struct {
3232 Return * Type `json:"return,omitempty"`
3333}
3434
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+
3551func CreateDoc (i interface {}) * Context {
3652 c := & Context {
3753 Variables : make (map [Identifier ]* Type ),
@@ -42,6 +58,16 @@ func CreateDoc(i interface{}) *Context {
4258 c .Variables [Identifier (name )] = c .use (t .Type , fromMethod (t .Method ))
4359 }
4460
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+
4571 return c
4672}
4773
0 commit comments