fixing exposed functions and interfaces

This commit is contained in:
Mike Farah
2021-02-11 10:58:40 +11:00
parent 461661112c
commit c1cf8b4e34
7 changed files with 87 additions and 76 deletions
+14 -7
View File
@@ -2,11 +2,13 @@ package yqlib
import "container/list"
/**
Loads all yaml documents of all files given into memory, then runs the given expression once.
**/
// A yaml expression evaluator that runs the expression once against all files/nodes in memory.
type Evaluator interface {
EvaluateFiles(expression string, filenames []string, printer Printer) error
// Runs the expression once against the list of candidate nodes, returns the
// resulting nodes.
EvaluateNodes(expression string, inputCandidateNodes *list.List) (*list.List, error)
}
type allAtOnceEvaluator struct {
@@ -18,12 +20,17 @@ func NewAllAtOnceEvaluator() Evaluator {
return &allAtOnceEvaluator{treeNavigator: NewDataTreeNavigator(), treeCreator: NewPathTreeCreator()}
}
func (e *allAtOnceEvaluator) EvaluateFiles(expression string, filenames []string, printer Printer) error {
fileIndex := 0
func (e *allAtOnceEvaluator) EvaluateNodes(expression string, inputCandidates *list.List) (*list.List, error) {
node, err := treeCreator.ParsePath(expression)
if err != nil {
return err
return nil, err
}
return treeNavigator.GetMatchingNodes(inputCandidates, node)
}
func (e *allAtOnceEvaluator) EvaluateFiles(expression string, filenames []string, printer Printer) error {
fileIndex := 0
var allDocuments *list.List = list.New()
for _, filename := range filenames {
reader, err := readStream(filename)
@@ -37,7 +44,7 @@ func (e *allAtOnceEvaluator) EvaluateFiles(expression string, filenames []string
allDocuments.PushBackList(fileDocuments)
fileIndex = fileIndex + 1
}
matches, err := treeNavigator.GetMatchingNodes(allDocuments, node)
matches, err := e.EvaluateNodes(expression, allDocuments)
if err != nil {
return err
}