-
-
Notifications
You must be signed in to change notification settings - Fork 550
/
operator_with.go
34 lines (23 loc) · 843 Bytes
/
operator_with.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
package yqlib
import "fmt"
func withOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debugf("withOperator")
// with(path, exp)
if expressionNode.RHS.Operation.OperationType != blockOpType {
return Context{}, fmt.Errorf("with must be given a block (;), got %v instead", expressionNode.RHS.Operation.OperationType.Type)
}
pathExp := expressionNode.RHS.LHS
updateContext, err := d.GetMatchingNodes(context, pathExp)
if err != nil {
return Context{}, err
}
updateExp := expressionNode.RHS.RHS
for el := updateContext.MatchingNodes.Front(); el != nil; el = el.Next() {
candidate := el.Value.(*CandidateNode)
_, err = d.GetMatchingNodes(updateContext.SingleChildContext(candidate), updateExp)
if err != nil {
return Context{}, err
}
}
return context, nil
}