-
Notifications
You must be signed in to change notification settings - Fork 16
/
list.go
40 lines (31 loc) · 773 Bytes
/
list.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
package dynaml
import (
"fmt"
"strings"
"github.com/mandelsoft/spiff/yaml"
)
type ListExpr struct {
Contents []Expression
}
func (e ListExpr) Evaluate(binding Binding, locally bool) (interface{}, EvaluationInfo, bool) {
resolved := true
values, info, ok := ResolveExpressionListOrPushEvaluation(&e.Contents, &resolved, nil, binding, false)
if !ok {
return nil, info, false
}
if !resolved {
return e, info, true
}
nodes := []yaml.Node{}
for i, _ := range values {
nodes = append(nodes, NewNode(values[i], binding))
}
return nodes, info, true
}
func (e ListExpr) String() string {
vals := make([]string, len(e.Contents))
for i, e := range e.Contents {
vals[i] = fmt.Sprintf("%s", e)
}
return fmt.Sprintf("[%s]", strings.Join(vals, ", "))
}