yq/pkg/yqlib/treeops/operator_recursive_descent.go
2020-10-18 11:31:36 +11:00

35 lines
863 B
Go

package treeops
import (
"github.com/elliotchance/orderedmap"
)
func RecursiveDescentOperator(d *dataTreeNavigator, matchMap *orderedmap.OrderedMap, pathNode *PathTreeNode) (*orderedmap.OrderedMap, error) {
var results = orderedmap.NewOrderedMap()
err := recursiveDecent(d, results, matchMap)
if err != nil {
return nil, err
}
return results, nil
}
func recursiveDecent(d *dataTreeNavigator, results *orderedmap.OrderedMap, matchMap *orderedmap.OrderedMap) error {
for el := matchMap.Front(); el != nil; el = el.Next() {
candidate := el.Value.(*CandidateNode)
results.Set(candidate.GetKey(), candidate)
children, err := d.traverse(nodeToMap(candidate), &PathElement{PathElementType: PathKey, Value: "[]"})
if err != nil {
return err
}
err = recursiveDecent(d, results, children)
if err != nil {
return err
}
}
return nil
}