mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-01 14:14:52 +08:00
Pass context through operators
Allows more sophisticated functionality
This commit is contained in:
@@ -1,11 +1,18 @@
|
||||
package yqlib
|
||||
|
||||
import "container/list"
|
||||
func pipeOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
|
||||
|
||||
func pipeOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) {
|
||||
lhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Lhs)
|
||||
//lhs may update the variable context, we should pass that into the RHS
|
||||
// BUT we still return the original context back (see jq)
|
||||
// https://stedolan.github.io/jq/manual/#Variable/SymbolicBindingOperator:...as$identifier|...
|
||||
|
||||
lhs, err := d.GetMatchingNodes(context, expressionNode.Lhs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return Context{}, err
|
||||
}
|
||||
return d.GetMatchingNodes(lhs, expressionNode.Rhs)
|
||||
rhs, err := d.GetMatchingNodes(lhs, expressionNode.Rhs)
|
||||
if err != nil {
|
||||
return Context{}, err
|
||||
}
|
||||
return context.ChildContext(rhs.MatchingNodes), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user