mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-15 07:38:14 +00:00
49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
package yqlib
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"container/list"
|
|
|
|
"gopkg.in/op/go-logging.v1"
|
|
)
|
|
|
|
type dataTreeNavigator struct {
|
|
navigationPrefs NavigationPrefs
|
|
}
|
|
|
|
type NavigationPrefs struct {
|
|
FollowAlias bool
|
|
}
|
|
|
|
type DataTreeNavigator interface {
|
|
// given a list of CandidateEntities and a pathNode,
|
|
// this will process the list against the given pathNode and return
|
|
// a new list of matching candidates
|
|
GetMatchingNodes(matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error)
|
|
}
|
|
|
|
func NewDataTreeNavigator(navigationPrefs NavigationPrefs) DataTreeNavigator {
|
|
return &dataTreeNavigator{navigationPrefs}
|
|
}
|
|
|
|
func (d *dataTreeNavigator) GetMatchingNodes(matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) {
|
|
if pathNode == nil {
|
|
log.Debugf("getMatchingNodes - nothing to do")
|
|
return matchingNodes, nil
|
|
}
|
|
log.Debugf("Processing Op: %v", pathNode.Operation.toString())
|
|
if log.IsEnabledFor(logging.DEBUG) {
|
|
for el := matchingNodes.Front(); el != nil; el = el.Next() {
|
|
log.Debug(NodeToString(el.Value.(*CandidateNode)))
|
|
}
|
|
}
|
|
log.Debug(">>")
|
|
handler := pathNode.Operation.OperationType.Handler
|
|
if handler != nil {
|
|
return handler(d, matchingNodes, pathNode)
|
|
}
|
|
return nil, fmt.Errorf("Unknown operator %v", pathNode.Operation.OperationType)
|
|
|
|
}
|