yq/pkg/yqlib/operator_with.go

35 lines
842 B
Go
Raw Normal View History

2021-09-12 11:52:02 +00:00
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)
2021-09-12 11:52:02 +00:00
}
pathExp := expressionNode.RHS.LHS
2021-09-12 11:52:02 +00:00
updateContext, err := d.GetMatchingNodes(context, pathExp)
if err != nil {
return Context{}, err
}
updateExp := expressionNode.RHS.RHS
2021-09-12 11:52:02 +00:00
2022-04-14 02:03:18 +00:00
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
}
2021-09-12 11:52:02 +00:00
}
return context, nil
}