Skip to content

Commit 10df616

Browse files
committed
Add info about builtins and operators to docgen tool
1 parent 79ed70d commit 10df616

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

docgen/docgen.go

+26
Original file line numberDiff line numberDiff line change
@@ -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+
3551
func 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

docgen/docgen_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ func (*Env) Duration(s string) Duration {
3333
}
3434

3535
func TestCreateDoc(t *testing.T) {
36+
Operators = nil
37+
Builtins = nil
3638
doc := CreateDoc(&Env{})
3739
expected := &Context{
3840
Variables: map[Identifier]*Type{
@@ -96,6 +98,8 @@ func TestCreateDoc_FromMap(t *testing.T) {
9698
}{},
9799
"Max": math.Max,
98100
}
101+
Operators = nil
102+
Builtins = nil
99103
doc := CreateDoc(env)
100104
expected := &Context{
101105
Variables: map[Identifier]*Type{

0 commit comments

Comments
 (0)