yq/pkg/yqlib/operator_with.go

35 lines
843 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) {
2024-02-15 22:41:33 +00:00
log.Debugf("withOperator")
2021-09-12 11:52:02 +00:00
// with(path, exp)
if expressionNode.RHS.Operation.OperationType != blockOpType {
2022-10-05 03:12:08 +00:00
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
}