refactored

This commit is contained in:
Mike Farah
2020-11-04 10:48:43 +11:00
parent 0cb2ff5b2e
commit b1f139c965
53 changed files with 452 additions and 349 deletions
+43
View File
@@ -0,0 +1,43 @@
package yqlib
import (
"container/list"
"gopkg.in/yaml.v3"
)
func RecursiveDescentOperator(d *dataTreeNavigator, matchMap *list.List, pathNode *PathTreeNode) (*list.List, error) {
var results = list.New()
err := recursiveDecent(d, results, matchMap)
if err != nil {
return nil, err
}
return results, nil
}
func recursiveDecent(d *dataTreeNavigator, results *list.List, matchMap *list.List) error {
for el := matchMap.Front(); el != nil; el = el.Next() {
candidate := el.Value.(*CandidateNode)
candidate.Node = UnwrapDoc(candidate.Node)
log.Debugf("Recursive Decent, added %v", NodeToString(candidate))
results.PushBack(candidate)
if candidate.Node.Kind != yaml.AliasNode {
children, err := Splat(d, nodeToMap(candidate))
if err != nil {
return err
}
err = recursiveDecent(d, results, children)
if err != nil {
return err
}
}
}
return nil
}