2021-11-30 23:32:36 +00:00
|
|
|
package yqlib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"container/list"
|
|
|
|
)
|
|
|
|
|
|
|
|
func mapValuesOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
|
|
|
|
|
|
|
|
for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {
|
|
|
|
candidate := el.Value.(*CandidateNode)
|
|
|
|
//run expression against entries
|
|
|
|
// splat toEntries and pipe it into Rhs
|
2021-12-20 22:30:08 +00:00
|
|
|
splatted, err := splat(context.SingleChildContext(candidate), traversePreferences{})
|
2021-11-30 23:32:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return Context{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
assignUpdateExp := &ExpressionNode{
|
|
|
|
Operation: &Operation{OperationType: assignOpType, UpdateAssign: true},
|
2022-02-07 00:55:55 +00:00
|
|
|
RHS: expressionNode.RHS,
|
2021-11-30 23:32:36 +00:00
|
|
|
}
|
|
|
|
_, err = assignUpdateOperator(d, splatted, assignUpdateExp)
|
|
|
|
if err != nil {
|
|
|
|
return Context{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return context, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func mapOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
|
|
|
|
|
|
|
|
var results = list.New()
|
|
|
|
|
|
|
|
for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {
|
|
|
|
candidate := el.Value.(*CandidateNode)
|
|
|
|
//run expression against entries
|
|
|
|
// splat toEntries and pipe it into Rhs
|
2021-12-20 22:30:08 +00:00
|
|
|
splatted, err := splat(context.SingleChildContext(candidate), traversePreferences{})
|
2021-11-30 23:32:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return Context{}, err
|
|
|
|
}
|
|
|
|
|
2022-02-07 00:55:55 +00:00
|
|
|
result, err := d.GetMatchingNodes(splatted, expressionNode.RHS)
|
|
|
|
log.Debug("expressionNode.Rhs %v", expressionNode.RHS.Operation.OperationType)
|
2021-11-30 23:32:36 +00:00
|
|
|
log.Debug("result %v", result)
|
|
|
|
if err != nil {
|
|
|
|
return Context{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
selfExpression := &ExpressionNode{Operation: &Operation{OperationType: selfReferenceOpType}}
|
|
|
|
collected, err := collectTogether(d, result, selfExpression)
|
|
|
|
if err != nil {
|
|
|
|
return Context{}, err
|
|
|
|
}
|
2023-10-18 01:11:53 +00:00
|
|
|
collected.Style = candidate.Style
|
2021-11-30 23:32:36 +00:00
|
|
|
|
|
|
|
results.PushBack(collected)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return context.ChildContext(results), nil
|
|
|
|
}
|