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)
|
|
|
|
|
2022-02-07 00:55:55 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-02-07 00:55:55 +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
|
|
|
|
}
|
|
|
|
|
2022-02-07 00:55:55 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
}
|