mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-13 22:38:04 +00:00
13d1bbb45f
Remove dependency on yaml.Node for internal AST representation. Yaml decoder is now just another decoder.
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package yqlib
|
|
|
|
import (
|
|
"container/list"
|
|
)
|
|
|
|
func evalOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
|
|
log.Debugf("Eval")
|
|
pathExpStrResults, err := d.GetMatchingNodes(context.ReadOnlyClone(), expressionNode.RHS)
|
|
if err != nil {
|
|
return Context{}, err
|
|
}
|
|
|
|
expressions := make([]*ExpressionNode, pathExpStrResults.MatchingNodes.Len())
|
|
expIndex := 0
|
|
//parse every expression
|
|
for pathExpStrEntry := pathExpStrResults.MatchingNodes.Front(); pathExpStrEntry != nil; pathExpStrEntry = pathExpStrEntry.Next() {
|
|
expressionStrCandidate := pathExpStrEntry.Value.(*CandidateNode)
|
|
|
|
expressions[expIndex], err = ExpressionParser.ParseExpression(expressionStrCandidate.Value)
|
|
if err != nil {
|
|
return Context{}, err
|
|
}
|
|
|
|
expIndex++
|
|
}
|
|
|
|
results := list.New()
|
|
|
|
for matchEl := context.MatchingNodes.Front(); matchEl != nil; matchEl = matchEl.Next() {
|
|
for expIndex = 0; expIndex < len(expressions); expIndex++ {
|
|
result, err := d.GetMatchingNodes(context, expressions[expIndex])
|
|
if err != nil {
|
|
return Context{}, err
|
|
}
|
|
results.PushBackList(result.MatchingNodes)
|
|
}
|
|
}
|
|
|
|
return context.ChildContext(results), nil
|
|
|
|
}
|