2020-11-03 23:48:43 +00:00
|
|
|
package yqlib
|
2020-10-08 23:59:03 +00:00
|
|
|
|
2020-10-09 01:04:19 +00:00
|
|
|
import (
|
2020-10-10 04:00:39 +00:00
|
|
|
"fmt"
|
|
|
|
|
2020-10-21 01:54:58 +00:00
|
|
|
"container/list"
|
|
|
|
|
2020-11-22 00:56:28 +00:00
|
|
|
logging "gopkg.in/op/go-logging.v1"
|
2020-10-09 01:04:19 +00:00
|
|
|
)
|
|
|
|
|
2020-10-08 23:59:03 +00:00
|
|
|
type DataTreeNavigator interface {
|
2021-01-12 23:18:53 +00:00
|
|
|
// given a list of CandidateEntities and a expressionNode,
|
|
|
|
// this will process the list against the given expressionNode and return
|
2020-10-27 05:45:16 +00:00
|
|
|
// a new list of matching candidates
|
2021-01-12 23:18:53 +00:00
|
|
|
GetMatchingNodes(matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error)
|
2020-10-08 23:59:03 +00:00
|
|
|
}
|
|
|
|
|
2020-11-22 00:56:28 +00:00
|
|
|
type dataTreeNavigator struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewDataTreeNavigator() DataTreeNavigator {
|
|
|
|
return &dataTreeNavigator{}
|
2020-10-08 23:59:03 +00:00
|
|
|
}
|
|
|
|
|
2021-01-12 23:18:53 +00:00
|
|
|
func (d *dataTreeNavigator) GetMatchingNodes(matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) {
|
|
|
|
if expressionNode == nil {
|
2020-10-13 01:51:37 +00:00
|
|
|
log.Debugf("getMatchingNodes - nothing to do")
|
|
|
|
return matchingNodes, nil
|
|
|
|
}
|
2021-01-12 23:18:53 +00:00
|
|
|
log.Debugf("Processing Op: %v", expressionNode.Operation.toString())
|
2020-10-17 11:10:47 +00:00
|
|
|
if log.IsEnabledFor(logging.DEBUG) {
|
|
|
|
for el := matchingNodes.Front(); el != nil; el = el.Next() {
|
|
|
|
log.Debug(NodeToString(el.Value.(*CandidateNode)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Debug(">>")
|
2021-01-12 23:18:53 +00:00
|
|
|
handler := expressionNode.Operation.OperationType.Handler
|
2020-10-20 02:53:26 +00:00
|
|
|
if handler != nil {
|
2021-01-12 23:18:53 +00:00
|
|
|
return handler(d, matchingNodes, expressionNode)
|
2020-10-08 23:59:03 +00:00
|
|
|
}
|
2021-01-12 23:18:53 +00:00
|
|
|
return nil, fmt.Errorf("Unknown operator %v", expressionNode.Operation.OperationType)
|
2020-10-08 23:59:03 +00:00
|
|
|
|
|
|
|
}
|