8 // Output represents the root node of all interpolation evaluations. If the
9 // output only has one expression which is either a TypeList or TypeMap, the
10 // Output can be type-asserted to []interface{} or map[string]interface{}
11 // respectively. Otherwise the Output evaluates as a string, and concatenates
12 // the evaluation of each expression.
18 func (n *Output) Accept(v Visitor) Node {
19 for i, expr := range n.Exprs {
20 n.Exprs[i] = expr.Accept(v)
26 func (n *Output) Pos() Pos {
30 func (n *Output) GoString() string {
31 return fmt.Sprintf("*%#v", *n)
34 func (n *Output) String() string {
36 for _, expr := range n.Exprs {
37 b.WriteString(fmt.Sprintf("%s", expr))
43 func (n *Output) Type(s Scope) (Type, error) {
44 // Special case no expressions for backward compatibility
45 if len(n.Exprs) == 0 {
46 return TypeString, nil
49 // Special case a single expression of types list or map
50 if len(n.Exprs) == 1 {
51 exprType, err := n.Exprs[0].Type(s)
53 return TypeInvalid, err
63 // Otherwise ensure all our expressions are strings
64 for index, expr := range n.Exprs {
65 exprType, err := expr.Type(s)
67 return TypeInvalid, err
69 // We only look for things we know we can't coerce with an implicit conversion func
70 if exprType == TypeList || exprType == TypeMap {
71 return TypeInvalid, fmt.Errorf(
72 "multi-expression HIL outputs may only have string inputs: %d is type %s",
77 return TypeString, nil