-
Notifications
You must be signed in to change notification settings - Fork 15
/
call.go
50 lines (43 loc) · 837 Bytes
/
call.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
package gg
import (
"io"
)
type icall struct {
owner Node
name string
items *group
calls *group
}
// Call is used to generate a function call.
func Call(name string) *icall {
ic := &icall{
name: name,
items: newGroup("(", ")", ","),
calls: newGroup("", "", "."),
}
return ic
}
func (i *icall) render(w io.Writer) {
if i.owner != nil {
i.owner.render(w)
writeString(w, ".")
}
writeString(w, i.name)
i.items.render(w)
if i.calls.length() != 0 {
writeString(w, ".")
i.calls.render(w)
}
}
func (i *icall) WithOwner(name string) *icall {
i.owner = String(name)
return i
}
func (i *icall) AddParameter(value ...interface{}) *icall {
i.items.append(value...)
return i
}
func (i *icall) AddCall(name string, params ...interface{}) *icall {
i.calls.append(Call(name).AddParameter(params...))
return i
}