2020-11-03 23:48:43 +00:00
|
|
|
package yqlib
|
2020-10-17 11:39:01 +00:00
|
|
|
|
2020-10-21 01:54:58 +00:00
|
|
|
import "container/list"
|
2020-10-17 11:39:01 +00:00
|
|
|
|
2021-01-12 23:18:53 +00:00
|
|
|
func assignUpdateOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) {
|
|
|
|
lhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Lhs)
|
2020-10-17 11:39:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-11-19 06:08:13 +00:00
|
|
|
var rhs *list.List
|
2021-01-12 23:18:53 +00:00
|
|
|
if !expressionNode.Operation.UpdateAssign {
|
|
|
|
rhs, err = d.GetMatchingNodes(matchingNodes, expressionNode.Rhs)
|
2020-11-19 06:08:13 +00:00
|
|
|
}
|
|
|
|
|
2020-10-17 11:39:01 +00:00
|
|
|
for el := lhs.Front(); el != nil; el = el.Next() {
|
|
|
|
candidate := el.Value.(*CandidateNode)
|
|
|
|
|
2021-01-12 23:18:53 +00:00
|
|
|
if expressionNode.Operation.UpdateAssign {
|
|
|
|
rhs, err = d.GetMatchingNodes(nodeToMap(candidate), expressionNode.Rhs)
|
2020-11-19 06:08:13 +00:00
|
|
|
}
|
2020-10-17 11:39:01 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// grab the first value
|
|
|
|
first := rhs.Front()
|
|
|
|
|
|
|
|
if first != nil {
|
2021-01-01 23:27:32 +00:00
|
|
|
rhsCandidate := first.Value.(*CandidateNode)
|
2021-01-12 23:00:51 +00:00
|
|
|
rhsCandidate.Node = unwrapDoc(rhsCandidate.Node)
|
2021-01-01 23:27:32 +00:00
|
|
|
candidate.UpdateFrom(rhsCandidate)
|
2020-10-17 11:39:01 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-11 22:40:37 +00:00
|
|
|
|
2020-10-17 11:39:01 +00:00
|
|
|
return matchingNodes, nil
|
|
|
|
}
|
2020-10-19 05:14:29 +00:00
|
|
|
|
|
|
|
// does not update content or values
|
2021-01-12 23:18:53 +00:00
|
|
|
func assignAttributesOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) {
|
|
|
|
lhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Lhs)
|
2020-10-19 05:14:29 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
for el := lhs.Front(); el != nil; el = el.Next() {
|
|
|
|
candidate := el.Value.(*CandidateNode)
|
|
|
|
|
2021-01-12 23:18:53 +00:00
|
|
|
rhs, err := d.GetMatchingNodes(nodeToMap(candidate), expressionNode.Rhs)
|
2020-10-19 05:14:29 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// grab the first value
|
|
|
|
first := rhs.Front()
|
|
|
|
|
|
|
|
if first != nil {
|
|
|
|
candidate.UpdateAttributesFrom(first.Value.(*CandidateNode))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return matchingNodes, nil
|
|
|
|
}
|