terraform/config/lang/ast/call.go

44 lines
691 B
Go
Raw Normal View History

2015-01-11 22:03:37 +01:00
package ast
2015-01-13 17:50:28 +01:00
import (
"fmt"
"strings"
)
2015-01-11 22:03:37 +01:00
// Call represents a function call.
type Call struct {
Func string
Args []Node
2015-01-12 09:28:47 +01:00
Posx Pos
2015-01-11 22:03:37 +01:00
}
2015-01-12 00:26:54 +01:00
func (n *Call) Accept(v Visitor) Node {
for i, a := range n.Args {
n.Args[i] = a.Accept(v)
2015-01-12 00:26:54 +01:00
}
return v(n)
2015-01-12 00:26:54 +01:00
}
2015-01-12 09:28:47 +01:00
func (n *Call) Pos() Pos {
return n.Posx
}
2015-01-13 17:50:28 +01:00
func (n *Call) String() string {
args := make([]string, len(n.Args))
for i, arg := range n.Args {
args[i] = fmt.Sprintf("%s", arg)
}
return fmt.Sprintf("Call(%s, %s)", n.Func, strings.Join(args, ", "))
}
2015-01-15 05:13:35 +01:00
func (n *Call) Type(s Scope) (Type, error) {
f, ok := s.LookupFunc(n.Func)
if !ok {
return TypeInvalid, fmt.Errorf("unknown function: %s", n.Func)
}
return f.ReturnType, nil
}