mirror of
				https://github.com/taigrr/yq
				synced 2025-01-18 04:53:17 -08:00 
			
		
		
		
	Renaming pathtree to expression
This commit is contained in:
		
							parent
							
								
									f17cbfd007
								
							
						
					
					
						commit
						b0735d8152
					
				| @ -19,11 +19,11 @@ type Evaluator interface { | |||||||
| 
 | 
 | ||||||
| type allAtOnceEvaluator struct { | type allAtOnceEvaluator struct { | ||||||
| 	treeNavigator DataTreeNavigator | 	treeNavigator DataTreeNavigator | ||||||
| 	treeCreator   PathTreeCreator | 	treeCreator   ExpressionParser | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func NewAllAtOnceEvaluator() Evaluator { | func NewAllAtOnceEvaluator() Evaluator { | ||||||
| 	return &allAtOnceEvaluator{treeNavigator: NewDataTreeNavigator(), treeCreator: NewPathTreeCreator()} | 	return &allAtOnceEvaluator{treeNavigator: NewDataTreeNavigator(), treeCreator: NewExpressionParser()} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (e *allAtOnceEvaluator) EvaluateNodes(expression string, nodes ...*yaml.Node) (*list.List, error) { | func (e *allAtOnceEvaluator) EvaluateNodes(expression string, nodes ...*yaml.Node) (*list.List, error) { | ||||||
| @ -35,7 +35,7 @@ func (e *allAtOnceEvaluator) EvaluateNodes(expression string, nodes ...*yaml.Nod | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (e *allAtOnceEvaluator) EvaluateCandidateNodes(expression string, inputCandidates *list.List) (*list.List, error) { | func (e *allAtOnceEvaluator) EvaluateCandidateNodes(expression string, inputCandidates *list.List) (*list.List, error) { | ||||||
| 	node, err := e.treeCreator.ParsePath(expression) | 	node, err := e.treeCreator.ParseExpression(expression) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -9,10 +9,10 @@ import ( | |||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type DataTreeNavigator interface { | type DataTreeNavigator interface { | ||||||
| 	// given a list of CandidateEntities and a pathNode, | 	// given a list of CandidateEntities and a expressionNode, | ||||||
| 	// this will process the list against the given pathNode and return | 	// this will process the list against the given expressionNode and return | ||||||
| 	// a new list of matching candidates | 	// a new list of matching candidates | ||||||
| 	GetMatchingNodes(matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) | 	GetMatchingNodes(matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type dataTreeNavigator struct { | type dataTreeNavigator struct { | ||||||
| @ -22,22 +22,22 @@ func NewDataTreeNavigator() DataTreeNavigator { | |||||||
| 	return &dataTreeNavigator{} | 	return &dataTreeNavigator{} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (d *dataTreeNavigator) GetMatchingNodes(matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func (d *dataTreeNavigator) GetMatchingNodes(matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	if pathNode == nil { | 	if expressionNode == nil { | ||||||
| 		log.Debugf("getMatchingNodes - nothing to do") | 		log.Debugf("getMatchingNodes - nothing to do") | ||||||
| 		return matchingNodes, nil | 		return matchingNodes, nil | ||||||
| 	} | 	} | ||||||
| 	log.Debugf("Processing Op: %v", pathNode.Operation.toString()) | 	log.Debugf("Processing Op: %v", expressionNode.Operation.toString()) | ||||||
| 	if log.IsEnabledFor(logging.DEBUG) { | 	if log.IsEnabledFor(logging.DEBUG) { | ||||||
| 		for el := matchingNodes.Front(); el != nil; el = el.Next() { | 		for el := matchingNodes.Front(); el != nil; el = el.Next() { | ||||||
| 			log.Debug(NodeToString(el.Value.(*CandidateNode))) | 			log.Debug(NodeToString(el.Value.(*CandidateNode))) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	log.Debug(">>") | 	log.Debug(">>") | ||||||
| 	handler := pathNode.Operation.OperationType.Handler | 	handler := expressionNode.Operation.OperationType.Handler | ||||||
| 	if handler != nil { | 	if handler != nil { | ||||||
| 		return handler(d, matchingNodes, pathNode) | 		return handler(d, matchingNodes, expressionNode) | ||||||
| 	} | 	} | ||||||
| 	return nil, fmt.Errorf("Unknown operator %v", pathNode.Operation.OperationType) | 	return nil, fmt.Errorf("Unknown operator %v", expressionNode.Operation.OperationType) | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -5,29 +5,28 @@ import ( | |||||||
| 	"strings" | 	"strings" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| var myPathTokeniser = newPathTokeniser() | var myPathTokeniser = newExpressionTokeniser() | ||||||
| var myPathPostfixer = newPathPostFixer() | var myPathPostfixer = newExpressionPostFixer() | ||||||
| 
 | 
 | ||||||
| type PathTreeNode struct { | type ExpressionNode struct { | ||||||
| 	Operation *Operation | 	Operation *Operation | ||||||
| 	Lhs       *PathTreeNode | 	Lhs       *ExpressionNode | ||||||
| 	Rhs       *PathTreeNode | 	Rhs       *ExpressionNode | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type PathTreeCreator interface { | type ExpressionParser interface { | ||||||
| 	ParsePath(path string) (*PathTreeNode, error) | 	ParseExpression(expression string) (*ExpressionNode, error) | ||||||
| 	CreatePathTree(postFixPath []*Operation) (*PathTreeNode, error) |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type pathTreeCreator struct { | type expressionParserImpl struct { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func NewPathTreeCreator() PathTreeCreator { | func NewExpressionParser() ExpressionParser { | ||||||
| 	return &pathTreeCreator{} | 	return &expressionParserImpl{} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (p *pathTreeCreator) ParsePath(path string) (*PathTreeNode, error) { | func (p *expressionParserImpl) ParseExpression(expression string) (*ExpressionNode, error) { | ||||||
| 	tokens, err := myPathTokeniser.Tokenise(path) | 	tokens, err := myPathTokeniser.Tokenise(expression) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| @ -36,18 +35,18 @@ func (p *pathTreeCreator) ParsePath(path string) (*PathTreeNode, error) { | |||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 	return p.CreatePathTree(Operations) | 	return p.createExpressionTree(Operations) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (p *pathTreeCreator) CreatePathTree(postFixPath []*Operation) (*PathTreeNode, error) { | func (p *expressionParserImpl) createExpressionTree(postFixPath []*Operation) (*ExpressionNode, error) { | ||||||
| 	var stack = make([]*PathTreeNode, 0) | 	var stack = make([]*ExpressionNode, 0) | ||||||
| 
 | 
 | ||||||
| 	if len(postFixPath) == 0 { | 	if len(postFixPath) == 0 { | ||||||
| 		return nil, nil | 		return nil, nil | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	for _, Operation := range postFixPath { | 	for _, Operation := range postFixPath { | ||||||
| 		var newNode = PathTreeNode{Operation: Operation} | 		var newNode = ExpressionNode{Operation: Operation} | ||||||
| 		log.Debugf("pathTree %v ", Operation.toString()) | 		log.Debugf("pathTree %v ", Operation.toString()) | ||||||
| 		if Operation.OperationType.NumArgs > 0 { | 		if Operation.OperationType.NumArgs > 0 { | ||||||
| 			numArgs := Operation.OperationType.NumArgs | 			numArgs := Operation.OperationType.NumArgs | ||||||
| @ -7,36 +7,36 @@ import ( | |||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func TestPathTreeNoArgsForTwoArgOp(t *testing.T) { | func TestPathTreeNoArgsForTwoArgOp(t *testing.T) { | ||||||
| 	_, err := NewPathTreeCreator().ParsePath("=") | 	_, err := NewExpressionParser().ParseExpression("=") | ||||||
| 	test.AssertResultComplex(t, "'=' expects 2 args but there is 0", err.Error()) | 	test.AssertResultComplex(t, "'=' expects 2 args but there is 0", err.Error()) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestPathTreeOneLhsArgsForTwoArgOp(t *testing.T) { | func TestPathTreeOneLhsArgsForTwoArgOp(t *testing.T) { | ||||||
| 	_, err := NewPathTreeCreator().ParsePath(".a =") | 	_, err := NewExpressionParser().ParseExpression(".a =") | ||||||
| 	test.AssertResultComplex(t, "'=' expects 2 args but there is 1", err.Error()) | 	test.AssertResultComplex(t, "'=' expects 2 args but there is 1", err.Error()) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestPathTreeOneRhsArgsForTwoArgOp(t *testing.T) { | func TestPathTreeOneRhsArgsForTwoArgOp(t *testing.T) { | ||||||
| 	_, err := NewPathTreeCreator().ParsePath("= .a") | 	_, err := NewExpressionParser().ParseExpression("= .a") | ||||||
| 	test.AssertResultComplex(t, "'=' expects 2 args but there is 1", err.Error()) | 	test.AssertResultComplex(t, "'=' expects 2 args but there is 1", err.Error()) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestPathTreeTwoArgsForTwoArgOp(t *testing.T) { | func TestPathTreeTwoArgsForTwoArgOp(t *testing.T) { | ||||||
| 	_, err := NewPathTreeCreator().ParsePath(".a = .b") | 	_, err := NewExpressionParser().ParseExpression(".a = .b") | ||||||
| 	test.AssertResultComplex(t, nil, err) | 	test.AssertResultComplex(t, nil, err) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestPathTreeNoArgsForOneArgOp(t *testing.T) { | func TestPathTreeNoArgsForOneArgOp(t *testing.T) { | ||||||
| 	_, err := NewPathTreeCreator().ParsePath("explode") | 	_, err := NewExpressionParser().ParseExpression("explode") | ||||||
| 	test.AssertResultComplex(t, "'explode' expects 1 arg but received none", err.Error()) | 	test.AssertResultComplex(t, "'explode' expects 1 arg but received none", err.Error()) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestPathTreeOneArgForOneArgOp(t *testing.T) { | func TestPathTreeOneArgForOneArgOp(t *testing.T) { | ||||||
| 	_, err := NewPathTreeCreator().ParsePath("explode(.)") | 	_, err := NewExpressionParser().ParseExpression("explode(.)") | ||||||
| 	test.AssertResultComplex(t, nil, err) | 	test.AssertResultComplex(t, nil, err) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestPathTreeExtraArgs(t *testing.T) { | func TestPathTreeExtraArgs(t *testing.T) { | ||||||
| 	_, err := NewPathTreeCreator().ParsePath("sortKeys(.) explode(.)") | 	_, err := NewExpressionParser().ParseExpression("sortKeys(.) explode(.)") | ||||||
| 	test.AssertResultComplex(t, "expected end of expression but found 'explode', please check expression syntax", err.Error()) | 	test.AssertResultComplex(t, "expected end of expression but found 'explode', please check expression syntax", err.Error()) | ||||||
| } | } | ||||||
| @ -6,15 +6,15 @@ import ( | |||||||
| 	logging "gopkg.in/op/go-logging.v1" | 	logging "gopkg.in/op/go-logging.v1" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type pathPostFixer interface { | type expressionPostFixer interface { | ||||||
| 	ConvertToPostfix([]*token) ([]*Operation, error) | 	ConvertToPostfix([]*token) ([]*Operation, error) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type pathPostFixerImpl struct { | type expressionPostFixerImpl struct { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func newPathPostFixer() pathPostFixer { | func newExpressionPostFixer() expressionPostFixer { | ||||||
| 	return &pathPostFixerImpl{} | 	return &expressionPostFixerImpl{} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func popOpToResult(opStack []*token, result []*Operation) ([]*token, []*Operation) { | func popOpToResult(opStack []*token, result []*Operation) ([]*token, []*Operation) { | ||||||
| @ -23,7 +23,7 @@ func popOpToResult(opStack []*token, result []*Operation) ([]*token, []*Operatio | |||||||
| 	return opStack, append(result, newOp.Operation) | 	return opStack, append(result, newOp.Operation) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (p *pathPostFixerImpl) ConvertToPostfix(infixTokens []*token) ([]*Operation, error) { | func (p *expressionPostFixerImpl) ConvertToPostfix(infixTokens []*token) ([]*Operation, error) { | ||||||
| 	var result []*Operation | 	var result []*Operation | ||||||
| 	// surround the whole thing with quotes | 	// surround the whole thing with quotes | ||||||
| 	var opStack = []*token{&token{TokenType: openBracket}} | 	var opStack = []*token{&token{TokenType: openBracket}} | ||||||
| @ -164,8 +164,8 @@ var pathTests = []struct { | |||||||
| 	}, | 	}, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| var tokeniser = newPathTokeniser() | var tokeniser = newExpressionTokeniser() | ||||||
| var postFixer = newPathPostFixer() | var postFixer = newExpressionPostFixer() | ||||||
| 
 | 
 | ||||||
| func TestPathParsing(t *testing.T) { | func TestPathParsing(t *testing.T) { | ||||||
| 	for _, tt := range pathTests { | 	for _, tt := range pathTests { | ||||||
| @ -307,24 +307,24 @@ func initLexer() (*lex.Lexer, error) { | |||||||
| 	return lexer, nil | 	return lexer, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type pathTokeniser interface { | type expressionTokeniser interface { | ||||||
| 	Tokenise(path string) ([]*token, error) | 	Tokenise(expression string) ([]*token, error) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type pathTokeniserImpl struct { | type expressionTokeniserImpl struct { | ||||||
| 	lexer *lex.Lexer | 	lexer *lex.Lexer | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func newPathTokeniser() pathTokeniser { | func newExpressionTokeniser() expressionTokeniser { | ||||||
| 	var lexer, err = initLexer() | 	var lexer, err = initLexer() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		panic(err) | 		panic(err) | ||||||
| 	} | 	} | ||||||
| 	return &pathTokeniserImpl{lexer} | 	return &expressionTokeniserImpl{lexer} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (p *pathTokeniserImpl) Tokenise(path string) ([]*token, error) { | func (p *expressionTokeniserImpl) Tokenise(expression string) ([]*token, error) { | ||||||
| 	scanner, err := p.lexer.Scanner([]byte(path)) | 	scanner, err := p.lexer.Scanner([]byte(expression)) | ||||||
| 
 | 
 | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, fmt.Errorf("Parsing expression: %v", err) | 		return nil, fmt.Errorf("Parsing expression: %v", err) | ||||||
| @ -356,7 +356,7 @@ func (p *pathTokeniserImpl) Tokenise(path string) ([]*token, error) { | |||||||
| 	return postProcessedTokens, nil | 	return postProcessedTokens, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (p *pathTokeniserImpl) handleToken(tokens []*token, index int, postProcessedTokens []*token) (tokensAccum []*token, skipNextToken bool) { | func (p *expressionTokeniserImpl) handleToken(tokens []*token, index int, postProcessedTokens []*token) (tokensAccum []*token, skipNextToken bool) { | ||||||
| 	skipNextToken = false | 	skipNextToken = false | ||||||
| 	currentToken := tokens[index] | 	currentToken := tokens[index] | ||||||
| 
 | 
 | ||||||
| @ -9,17 +9,17 @@ import ( | |||||||
| 	yaml "gopkg.in/yaml.v3" | 	yaml "gopkg.in/yaml.v3" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func createAddOp(lhs *PathTreeNode, rhs *PathTreeNode) *PathTreeNode { | func createAddOp(lhs *ExpressionNode, rhs *ExpressionNode) *ExpressionNode { | ||||||
| 	return &PathTreeNode{Operation: &Operation{OperationType: addOpType}, | 	return &ExpressionNode{Operation: &Operation{OperationType: addOpType}, | ||||||
| 		Lhs: lhs, | 		Lhs: lhs, | ||||||
| 		Rhs: rhs} | 		Rhs: rhs} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func addAssignOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func addAssignOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	assignmentOp := &Operation{OperationType: assignOpType} | 	assignmentOp := &Operation{OperationType: assignOpType} | ||||||
| 	assignmentOp.UpdateAssign = false | 	assignmentOp.UpdateAssign = false | ||||||
| 
 | 
 | ||||||
| 	assignmentOpNode := &PathTreeNode{Operation: assignmentOp, Lhs: pathNode.Lhs, Rhs: createAddOp(pathNode.Lhs, pathNode.Rhs)} | 	assignmentOpNode := &ExpressionNode{Operation: assignmentOp, Lhs: expressionNode.Lhs, Rhs: createAddOp(expressionNode.Lhs, expressionNode.Rhs)} | ||||||
| 	return d.GetMatchingNodes(matchingNodes, assignmentOpNode) | 	return d.GetMatchingNodes(matchingNodes, assignmentOpNode) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -37,10 +37,10 @@ func toNodes(candidate *CandidateNode) []*yaml.Node { | |||||||
| 
 | 
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func addOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func addOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	log.Debugf("Add operator") | 	log.Debugf("Add operator") | ||||||
| 
 | 
 | ||||||
| 	return crossFunction(d, matchingNodes, pathNode, add) | 	return crossFunction(d, matchingNodes, expressionNode, add) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func add(d *dataTreeNavigator, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) { | func add(d *dataTreeNavigator, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) { | ||||||
|  | |||||||
| @ -7,9 +7,9 @@ import ( | |||||||
| // corssFunction no matches | // corssFunction no matches | ||||||
| // can boolean use crossfunction | // can boolean use crossfunction | ||||||
| 
 | 
 | ||||||
| func alternativeOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func alternativeOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	log.Debugf("-- alternative") | 	log.Debugf("-- alternative") | ||||||
| 	return crossFunction(d, matchingNodes, pathNode, alternativeFunc) | 	return crossFunction(d, matchingNodes, expressionNode, alternativeFunc) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func alternativeFunc(d *dataTreeNavigator, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) { | func alternativeFunc(d *dataTreeNavigator, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) { | ||||||
|  | |||||||
| @ -6,13 +6,13 @@ import ( | |||||||
| 	yaml "gopkg.in/yaml.v3" | 	yaml "gopkg.in/yaml.v3" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func assignAliasOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func assignAliasOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 
 | 
 | ||||||
| 	log.Debugf("AssignAlias operator!") | 	log.Debugf("AssignAlias operator!") | ||||||
| 
 | 
 | ||||||
| 	aliasName := "" | 	aliasName := "" | ||||||
| 	if !pathNode.Operation.UpdateAssign { | 	if !expressionNode.Operation.UpdateAssign { | ||||||
| 		rhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Rhs) | 		rhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Rhs) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, err | 			return nil, err | ||||||
| 		} | 		} | ||||||
| @ -21,7 +21,7 @@ func assignAliasOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNod | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Lhs) | 	lhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Lhs) | ||||||
| 
 | 
 | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| @ -31,8 +31,8 @@ func assignAliasOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNod | |||||||
| 		candidate := el.Value.(*CandidateNode) | 		candidate := el.Value.(*CandidateNode) | ||||||
| 		log.Debugf("Setting aliasName : %v", candidate.GetKey()) | 		log.Debugf("Setting aliasName : %v", candidate.GetKey()) | ||||||
| 
 | 
 | ||||||
| 		if pathNode.Operation.UpdateAssign { | 		if expressionNode.Operation.UpdateAssign { | ||||||
| 			rhs, err := d.GetMatchingNodes(nodeToMap(candidate), pathNode.Rhs) | 			rhs, err := d.GetMatchingNodes(nodeToMap(candidate), expressionNode.Rhs) | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
| 				return nil, err | 				return nil, err | ||||||
| 			} | 			} | ||||||
| @ -47,7 +47,7 @@ func assignAliasOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNod | |||||||
| 	return matchingNodes, nil | 	return matchingNodes, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func getAliasOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func getAliasOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	log.Debugf("GetAlias operator!") | 	log.Debugf("GetAlias operator!") | ||||||
| 	var results = list.New() | 	var results = list.New() | ||||||
| 
 | 
 | ||||||
| @ -60,13 +60,13 @@ func getAliasOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode * | |||||||
| 	return results, nil | 	return results, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func assignAnchorOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func assignAnchorOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 
 | 
 | ||||||
| 	log.Debugf("AssignAnchor operator!") | 	log.Debugf("AssignAnchor operator!") | ||||||
| 
 | 
 | ||||||
| 	anchorName := "" | 	anchorName := "" | ||||||
| 	if !pathNode.Operation.UpdateAssign { | 	if !expressionNode.Operation.UpdateAssign { | ||||||
| 		rhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Rhs) | 		rhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Rhs) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, err | 			return nil, err | ||||||
| 		} | 		} | ||||||
| @ -76,7 +76,7 @@ func assignAnchorOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNo | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Lhs) | 	lhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Lhs) | ||||||
| 
 | 
 | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| @ -86,8 +86,8 @@ func assignAnchorOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNo | |||||||
| 		candidate := el.Value.(*CandidateNode) | 		candidate := el.Value.(*CandidateNode) | ||||||
| 		log.Debugf("Setting anchorName of : %v", candidate.GetKey()) | 		log.Debugf("Setting anchorName of : %v", candidate.GetKey()) | ||||||
| 
 | 
 | ||||||
| 		if pathNode.Operation.UpdateAssign { | 		if expressionNode.Operation.UpdateAssign { | ||||||
| 			rhs, err := d.GetMatchingNodes(nodeToMap(candidate), pathNode.Rhs) | 			rhs, err := d.GetMatchingNodes(nodeToMap(candidate), expressionNode.Rhs) | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
| 				return nil, err | 				return nil, err | ||||||
| 			} | 			} | ||||||
| @ -102,7 +102,7 @@ func assignAnchorOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNo | |||||||
| 	return matchingNodes, nil | 	return matchingNodes, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func getAnchorOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func getAnchorOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	log.Debugf("GetAnchor operator!") | 	log.Debugf("GetAnchor operator!") | ||||||
| 	var results = list.New() | 	var results = list.New() | ||||||
| 
 | 
 | ||||||
| @ -116,13 +116,13 @@ func getAnchorOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode | |||||||
| 	return results, nil | 	return results, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func explodeOperator(d *dataTreeNavigator, matchMap *list.List, pathNode *PathTreeNode) (*list.List, error) { | func explodeOperator(d *dataTreeNavigator, matchMap *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	log.Debugf("-- ExplodeOperation") | 	log.Debugf("-- ExplodeOperation") | ||||||
| 
 | 
 | ||||||
| 	for el := matchMap.Front(); el != nil; el = el.Next() { | 	for el := matchMap.Front(); el != nil; el = el.Next() { | ||||||
| 		candidate := el.Value.(*CandidateNode) | 		candidate := el.Value.(*CandidateNode) | ||||||
| 
 | 
 | ||||||
| 		rhs, err := d.GetMatchingNodes(nodeToMap(candidate), pathNode.Rhs) | 		rhs, err := d.GetMatchingNodes(nodeToMap(candidate), expressionNode.Rhs) | ||||||
| 
 | 
 | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, err | 			return nil, err | ||||||
|  | |||||||
| @ -2,21 +2,21 @@ package yqlib | |||||||
| 
 | 
 | ||||||
| import "container/list" | import "container/list" | ||||||
| 
 | 
 | ||||||
| func assignUpdateOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func assignUpdateOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	lhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Lhs) | 	lhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Lhs) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 	var rhs *list.List | 	var rhs *list.List | ||||||
| 	if !pathNode.Operation.UpdateAssign { | 	if !expressionNode.Operation.UpdateAssign { | ||||||
| 		rhs, err = d.GetMatchingNodes(matchingNodes, pathNode.Rhs) | 		rhs, err = d.GetMatchingNodes(matchingNodes, expressionNode.Rhs) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	for el := lhs.Front(); el != nil; el = el.Next() { | 	for el := lhs.Front(); el != nil; el = el.Next() { | ||||||
| 		candidate := el.Value.(*CandidateNode) | 		candidate := el.Value.(*CandidateNode) | ||||||
| 
 | 
 | ||||||
| 		if pathNode.Operation.UpdateAssign { | 		if expressionNode.Operation.UpdateAssign { | ||||||
| 			rhs, err = d.GetMatchingNodes(nodeToMap(candidate), pathNode.Rhs) | 			rhs, err = d.GetMatchingNodes(nodeToMap(candidate), expressionNode.Rhs) | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| @ -37,15 +37,15 @@ func assignUpdateOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNo | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // does not update content or values | // does not update content or values | ||||||
| func assignAttributesOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func assignAttributesOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	lhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Lhs) | 	lhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Lhs) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 	for el := lhs.Front(); el != nil; el = el.Next() { | 	for el := lhs.Front(); el != nil; el = el.Next() { | ||||||
| 		candidate := el.Value.(*CandidateNode) | 		candidate := el.Value.(*CandidateNode) | ||||||
| 
 | 
 | ||||||
| 		rhs, err := d.GetMatchingNodes(nodeToMap(candidate), pathNode.Rhs) | 		rhs, err := d.GetMatchingNodes(nodeToMap(candidate), expressionNode.Rhs) | ||||||
| 
 | 
 | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, err | 			return nil, err | ||||||
|  | |||||||
| @ -44,23 +44,23 @@ func performBoolOp(op boolOp) func(d *dataTreeNavigator, lhs *CandidateNode, rhs | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func orOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func orOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	log.Debugf("-- orOp") | 	log.Debugf("-- orOp") | ||||||
| 	return crossFunction(d, matchingNodes, pathNode, performBoolOp( | 	return crossFunction(d, matchingNodes, expressionNode, performBoolOp( | ||||||
| 		func(b1 bool, b2 bool) bool { | 		func(b1 bool, b2 bool) bool { | ||||||
| 			return b1 || b2 | 			return b1 || b2 | ||||||
| 		})) | 		})) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func andOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func andOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	log.Debugf("-- AndOp") | 	log.Debugf("-- AndOp") | ||||||
| 	return crossFunction(d, matchingNodes, pathNode, performBoolOp( | 	return crossFunction(d, matchingNodes, expressionNode, performBoolOp( | ||||||
| 		func(b1 bool, b2 bool) bool { | 		func(b1 bool, b2 bool) bool { | ||||||
| 			return b1 && b2 | 			return b1 && b2 | ||||||
| 		})) | 		})) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func notOperator(d *dataTreeNavigator, matchMap *list.List, pathNode *PathTreeNode) (*list.List, error) { | func notOperator(d *dataTreeNavigator, matchMap *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	log.Debugf("-- notOperation") | 	log.Debugf("-- notOperation") | ||||||
| 	var results = list.New() | 	var results = list.New() | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -6,7 +6,7 @@ import ( | |||||||
| 	yaml "gopkg.in/yaml.v3" | 	yaml "gopkg.in/yaml.v3" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func collectOperator(d *dataTreeNavigator, matchMap *list.List, pathNode *PathTreeNode) (*list.List, error) { | func collectOperator(d *dataTreeNavigator, matchMap *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	log.Debugf("-- collectOperation") | 	log.Debugf("-- collectOperation") | ||||||
| 
 | 
 | ||||||
| 	if matchMap.Len() == 0 { | 	if matchMap.Len() == 0 { | ||||||
|  | |||||||
| @ -17,7 +17,7 @@ import ( | |||||||
| ... | ... | ||||||
| */ | */ | ||||||
| 
 | 
 | ||||||
| func collectObjectOperator(d *dataTreeNavigator, matchMap *list.List, pathNode *PathTreeNode) (*list.List, error) { | func collectObjectOperator(d *dataTreeNavigator, matchMap *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	log.Debugf("-- collectObjectOperation") | 	log.Debugf("-- collectObjectOperation") | ||||||
| 
 | 
 | ||||||
| 	if matchMap.Len() == 0 { | 	if matchMap.Len() == 0 { | ||||||
|  | |||||||
| @ -13,21 +13,21 @@ type commentOpPreferences struct { | |||||||
| 	FootComment bool | 	FootComment bool | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func assignCommentsOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func assignCommentsOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 
 | 
 | ||||||
| 	log.Debugf("AssignComments operator!") | 	log.Debugf("AssignComments operator!") | ||||||
| 
 | 
 | ||||||
| 	lhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Lhs) | 	lhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Lhs) | ||||||
| 
 | 
 | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	preferences := pathNode.Operation.Preferences.(*commentOpPreferences) | 	preferences := expressionNode.Operation.Preferences.(*commentOpPreferences) | ||||||
| 
 | 
 | ||||||
| 	comment := "" | 	comment := "" | ||||||
| 	if !pathNode.Operation.UpdateAssign { | 	if !expressionNode.Operation.UpdateAssign { | ||||||
| 		rhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Rhs) | 		rhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Rhs) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, err | 			return nil, err | ||||||
| 		} | 		} | ||||||
| @ -40,8 +40,8 @@ func assignCommentsOperator(d *dataTreeNavigator, matchingNodes *list.List, path | |||||||
| 	for el := lhs.Front(); el != nil; el = el.Next() { | 	for el := lhs.Front(); el != nil; el = el.Next() { | ||||||
| 		candidate := el.Value.(*CandidateNode) | 		candidate := el.Value.(*CandidateNode) | ||||||
| 
 | 
 | ||||||
| 		if pathNode.Operation.UpdateAssign { | 		if expressionNode.Operation.UpdateAssign { | ||||||
| 			rhs, err := d.GetMatchingNodes(nodeToMap(candidate), pathNode.Rhs) | 			rhs, err := d.GetMatchingNodes(nodeToMap(candidate), expressionNode.Rhs) | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
| 				return nil, err | 				return nil, err | ||||||
| 			} | 			} | ||||||
| @ -66,8 +66,8 @@ func assignCommentsOperator(d *dataTreeNavigator, matchingNodes *list.List, path | |||||||
| 	return matchingNodes, nil | 	return matchingNodes, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func getCommentsOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func getCommentsOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	preferences := pathNode.Operation.Preferences.(*commentOpPreferences) | 	preferences := expressionNode.Operation.Preferences.(*commentOpPreferences) | ||||||
| 	log.Debugf("GetComments operator!") | 	log.Debugf("GetComments operator!") | ||||||
| 	var results = list.New() | 	var results = list.New() | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -6,7 +6,7 @@ import ( | |||||||
| 	"gopkg.in/yaml.v3" | 	"gopkg.in/yaml.v3" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func createMapOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func createMapOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	log.Debugf("-- createMapOperation") | 	log.Debugf("-- createMapOperation") | ||||||
| 
 | 
 | ||||||
| 	//each matchingNodes entry should turn into a sequence of keys to create. | 	//each matchingNodes entry should turn into a sequence of keys to create. | ||||||
| @ -22,14 +22,14 @@ func createMapOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode | |||||||
| 
 | 
 | ||||||
| 		for matchingNodeEl := matchingNodes.Front(); matchingNodeEl != nil; matchingNodeEl = matchingNodeEl.Next() { | 		for matchingNodeEl := matchingNodes.Front(); matchingNodeEl != nil; matchingNodeEl = matchingNodeEl.Next() { | ||||||
| 			matchingNode := matchingNodeEl.Value.(*CandidateNode) | 			matchingNode := matchingNodeEl.Value.(*CandidateNode) | ||||||
| 			sequenceNode, err := sequenceFor(d, matchingNode, pathNode) | 			sequenceNode, err := sequenceFor(d, matchingNode, expressionNode) | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
| 				return nil, err | 				return nil, err | ||||||
| 			} | 			} | ||||||
| 			sequences.PushBack(sequenceNode) | 			sequences.PushBack(sequenceNode) | ||||||
| 		} | 		} | ||||||
| 	} else { | 	} else { | ||||||
| 		sequenceNode, err := sequenceFor(d, nil, pathNode) | 		sequenceNode, err := sequenceFor(d, nil, expressionNode) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, err | 			return nil, err | ||||||
| 		} | 		} | ||||||
| @ -40,7 +40,7 @@ func createMapOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode | |||||||
| 
 | 
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func sequenceFor(d *dataTreeNavigator, matchingNode *CandidateNode, pathNode *PathTreeNode) (*CandidateNode, error) { | func sequenceFor(d *dataTreeNavigator, matchingNode *CandidateNode, expressionNode *ExpressionNode) (*CandidateNode, error) { | ||||||
| 	var path []interface{} | 	var path []interface{} | ||||||
| 	var document uint = 0 | 	var document uint = 0 | ||||||
| 	var matches = list.New() | 	var matches = list.New() | ||||||
| @ -51,7 +51,7 @@ func sequenceFor(d *dataTreeNavigator, matchingNode *CandidateNode, pathNode *Pa | |||||||
| 		matches = nodeToMap(matchingNode) | 		matches = nodeToMap(matchingNode) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	mapPairs, err := crossFunction(d, matches, pathNode, | 	mapPairs, err := crossFunction(d, matches, expressionNode, | ||||||
| 		func(d *dataTreeNavigator, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) { | 		func(d *dataTreeNavigator, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) { | ||||||
| 			node := yaml.Node{Kind: yaml.MappingNode, Tag: "!!map"} | 			node := yaml.Node{Kind: yaml.MappingNode, Tag: "!!map"} | ||||||
| 			log.Debugf("LHS:", NodeToString(lhs)) | 			log.Debugf("LHS:", NodeToString(lhs)) | ||||||
|  | |||||||
| @ -7,9 +7,9 @@ import ( | |||||||
| 	yaml "gopkg.in/yaml.v3" | 	yaml "gopkg.in/yaml.v3" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func deleteChildOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func deleteChildOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 
 | 
 | ||||||
| 	nodesToDelete, err := d.GetMatchingNodes(matchingNodes, pathNode.Rhs) | 	nodesToDelete, err := d.GetMatchingNodes(matchingNodes, expressionNode.Rhs) | ||||||
| 
 | 
 | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| @ -23,7 +23,7 @@ func deleteChildOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNod | |||||||
| 			Value:         candidate.Path[len(candidate.Path)-1], | 			Value:         candidate.Path[len(candidate.Path)-1], | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		deleteImmediateChildOpNode := &PathTreeNode{ | 		deleteImmediateChildOpNode := &ExpressionNode{ | ||||||
| 			Operation: deleteImmediateChildOp, | 			Operation: deleteImmediateChildOp, | ||||||
| 			Rhs:       createTraversalTree(candidate.Path[0 : len(candidate.Path)-1]), | 			Rhs:       createTraversalTree(candidate.Path[0 : len(candidate.Path)-1]), | ||||||
| 		} | 		} | ||||||
| @ -36,14 +36,14 @@ func deleteChildOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNod | |||||||
| 	return matchingNodes, nil | 	return matchingNodes, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func deleteImmediateChildOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func deleteImmediateChildOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	parents, err := d.GetMatchingNodes(matchingNodes, pathNode.Rhs) | 	parents, err := d.GetMatchingNodes(matchingNodes, expressionNode.Rhs) | ||||||
| 
 | 
 | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	childPath := pathNode.Operation.Value | 	childPath := expressionNode.Operation.Value | ||||||
| 
 | 
 | ||||||
| 	log.Debug("childPath to remove %v", childPath) | 	log.Debug("childPath to remove %v", childPath) | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -7,7 +7,7 @@ import ( | |||||||
| 	"gopkg.in/yaml.v3" | 	"gopkg.in/yaml.v3" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func getDocumentIndexOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func getDocumentIndexOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	var results = list.New() | 	var results = list.New() | ||||||
| 
 | 
 | ||||||
| 	for el := matchingNodes.Front(); el != nil; el = el.Next() { | 	for el := matchingNodes.Front(); el != nil; el = el.Next() { | ||||||
|  | |||||||
| @ -13,13 +13,13 @@ type envOpPreferences struct { | |||||||
| 	StringValue bool | 	StringValue bool | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func envOperator(d *dataTreeNavigator, matchMap *list.List, pathNode *PathTreeNode) (*list.List, error) { | func envOperator(d *dataTreeNavigator, matchMap *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	envName := pathNode.Operation.CandidateNode.Node.Value | 	envName := expressionNode.Operation.CandidateNode.Node.Value | ||||||
| 	log.Debug("EnvOperator, env name:", envName) | 	log.Debug("EnvOperator, env name:", envName) | ||||||
| 
 | 
 | ||||||
| 	rawValue := os.Getenv(envName) | 	rawValue := os.Getenv(envName) | ||||||
| 
 | 
 | ||||||
| 	preferences := pathNode.Operation.Preferences.(*envOpPreferences) | 	preferences := expressionNode.Operation.Preferences.(*envOpPreferences) | ||||||
| 
 | 
 | ||||||
| 	var node *yaml.Node | 	var node *yaml.Node | ||||||
| 	if preferences.StringValue { | 	if preferences.StringValue { | ||||||
|  | |||||||
| @ -4,9 +4,9 @@ import ( | |||||||
| 	"container/list" | 	"container/list" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func equalsOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func equalsOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	log.Debugf("-- equalsOperation") | 	log.Debugf("-- equalsOperation") | ||||||
| 	return crossFunction(d, matchingNodes, pathNode, isEquals) | 	return crossFunction(d, matchingNodes, expressionNode, isEquals) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func isEquals(d *dataTreeNavigator, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) { | func isEquals(d *dataTreeNavigator, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) { | ||||||
|  | |||||||
| @ -7,7 +7,7 @@ import ( | |||||||
| 	yaml "gopkg.in/yaml.v3" | 	yaml "gopkg.in/yaml.v3" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func getFilenameOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func getFilenameOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	log.Debugf("GetFilename") | 	log.Debugf("GetFilename") | ||||||
| 
 | 
 | ||||||
| 	var results = list.New() | 	var results = list.New() | ||||||
| @ -22,7 +22,7 @@ func getFilenameOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNod | |||||||
| 	return results, nil | 	return results, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func getFileIndexOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func getFileIndexOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	log.Debugf("GetFileIndex") | 	log.Debugf("GetFileIndex") | ||||||
| 
 | 
 | ||||||
| 	var results = list.New() | 	var results = list.New() | ||||||
|  | |||||||
| @ -7,12 +7,12 @@ import ( | |||||||
| 	yaml "gopkg.in/yaml.v3" | 	yaml "gopkg.in/yaml.v3" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func hasOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func hasOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 
 | 
 | ||||||
| 	log.Debugf("-- hasOperation") | 	log.Debugf("-- hasOperation") | ||||||
| 	var results = list.New() | 	var results = list.New() | ||||||
| 
 | 
 | ||||||
| 	rhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Rhs) | 	rhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Rhs) | ||||||
| 	wanted := rhs.Front().Value.(*CandidateNode).Node | 	wanted := rhs.Front().Value.(*CandidateNode).Node | ||||||
| 	wantedKey := wanted.Value | 	wantedKey := wanted.Value | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -7,7 +7,7 @@ import ( | |||||||
| 	yaml "gopkg.in/yaml.v3" | 	yaml "gopkg.in/yaml.v3" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func lengthOperator(d *dataTreeNavigator, matchMap *list.List, pathNode *PathTreeNode) (*list.List, error) { | func lengthOperator(d *dataTreeNavigator, matchMap *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	log.Debugf("-- lengthOperation") | 	log.Debugf("-- lengthOperation") | ||||||
| 	var results = list.New() | 	var results = list.New() | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -10,14 +10,14 @@ import ( | |||||||
| 
 | 
 | ||||||
| type crossFunctionCalculation func(d *dataTreeNavigator, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) | type crossFunctionCalculation func(d *dataTreeNavigator, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) | ||||||
| 
 | 
 | ||||||
| func crossFunction(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode, calculation crossFunctionCalculation) (*list.List, error) { | func crossFunction(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode, calculation crossFunctionCalculation) (*list.List, error) { | ||||||
| 	lhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Lhs) | 	lhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Lhs) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 	log.Debugf("crossFunction LHS len: %v", lhs.Len()) | 	log.Debugf("crossFunction LHS len: %v", lhs.Len()) | ||||||
| 
 | 
 | ||||||
| 	rhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Rhs) | 	rhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Rhs) | ||||||
| 
 | 
 | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| @ -47,9 +47,9 @@ type multiplyPreferences struct { | |||||||
| 	AppendArrays bool | 	AppendArrays bool | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func multiplyOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func multiplyOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	log.Debugf("-- MultiplyOperator") | 	log.Debugf("-- MultiplyOperator") | ||||||
| 	return crossFunction(d, matchingNodes, pathNode, multiply(pathNode.Operation.Preferences.(*multiplyPreferences))) | 	return crossFunction(d, matchingNodes, expressionNode, multiply(expressionNode.Operation.Preferences.(*multiplyPreferences))) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func multiply(preferences *multiplyPreferences) func(d *dataTreeNavigator, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) { | func multiply(preferences *multiplyPreferences) func(d *dataTreeNavigator, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) { | ||||||
| @ -116,7 +116,7 @@ func applyAssignment(d *dataTreeNavigator, pathIndexToStartFrom int, lhs *Candid | |||||||
| 	} | 	} | ||||||
| 	rhsOp := &Operation{OperationType: valueOpType, CandidateNode: rhs} | 	rhsOp := &Operation{OperationType: valueOpType, CandidateNode: rhs} | ||||||
| 
 | 
 | ||||||
| 	assignmentOpNode := &PathTreeNode{Operation: assignmentOp, Lhs: createTraversalTree(lhsPath), Rhs: &PathTreeNode{Operation: rhsOp}} | 	assignmentOpNode := &ExpressionNode{Operation: assignmentOp, Lhs: createTraversalTree(lhsPath), Rhs: &ExpressionNode{Operation: rhsOp}} | ||||||
| 
 | 
 | ||||||
| 	_, err := d.GetMatchingNodes(nodeToMap(lhs), assignmentOpNode) | 	_, err := d.GetMatchingNodes(nodeToMap(lhs), assignmentOpNode) | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ func createPathNodeFor(pathElement interface{}) *yaml.Node { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func getPathOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func getPathOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	log.Debugf("GetPath") | 	log.Debugf("GetPath") | ||||||
| 
 | 
 | ||||||
| 	var results = list.New() | 	var results = list.New() | ||||||
|  | |||||||
| @ -2,10 +2,10 @@ package yqlib | |||||||
| 
 | 
 | ||||||
| import "container/list" | import "container/list" | ||||||
| 
 | 
 | ||||||
| func pipeOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func pipeOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	lhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Lhs) | 	lhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Lhs) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 	return d.GetMatchingNodes(lhs, pathNode.Rhs) | 	return d.GetMatchingNodes(lhs, expressionNode.Rhs) | ||||||
| } | } | ||||||
|  | |||||||
| @ -11,10 +11,10 @@ type recursiveDescentPreferences struct { | |||||||
| 	RecurseArray        bool | 	RecurseArray        bool | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func recursiveDescentOperator(d *dataTreeNavigator, matchMap *list.List, pathNode *PathTreeNode) (*list.List, error) { | func recursiveDescentOperator(d *dataTreeNavigator, matchMap *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	var results = list.New() | 	var results = list.New() | ||||||
| 
 | 
 | ||||||
| 	preferences := pathNode.Operation.Preferences.(*recursiveDescentPreferences) | 	preferences := expressionNode.Operation.Preferences.(*recursiveDescentPreferences) | ||||||
| 	err := recursiveDecent(d, results, matchMap, preferences) | 	err := recursiveDecent(d, results, matchMap, preferences) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
|  | |||||||
| @ -4,7 +4,7 @@ import ( | |||||||
| 	"container/list" | 	"container/list" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func selectOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func selectOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 
 | 
 | ||||||
| 	log.Debugf("-- selectOperation") | 	log.Debugf("-- selectOperation") | ||||||
| 	var results = list.New() | 	var results = list.New() | ||||||
| @ -12,7 +12,7 @@ func selectOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *Pa | |||||||
| 	for el := matchingNodes.Front(); el != nil; el = el.Next() { | 	for el := matchingNodes.Front(); el != nil; el = el.Next() { | ||||||
| 		candidate := el.Value.(*CandidateNode) | 		candidate := el.Value.(*CandidateNode) | ||||||
| 
 | 
 | ||||||
| 		rhs, err := d.GetMatchingNodes(nodeToMap(candidate), pathNode.Rhs) | 		rhs, err := d.GetMatchingNodes(nodeToMap(candidate), expressionNode.Rhs) | ||||||
| 
 | 
 | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, err | 			return nil, err | ||||||
|  | |||||||
| @ -2,6 +2,6 @@ package yqlib | |||||||
| 
 | 
 | ||||||
| import "container/list" | import "container/list" | ||||||
| 
 | 
 | ||||||
| func selfOperator(d *dataTreeNavigator, matchMap *list.List, pathNode *PathTreeNode) (*list.List, error) { | func selfOperator(d *dataTreeNavigator, matchMap *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	return matchMap, nil | 	return matchMap, nil | ||||||
| } | } | ||||||
|  | |||||||
| @ -7,11 +7,11 @@ import ( | |||||||
| 	yaml "gopkg.in/yaml.v3" | 	yaml "gopkg.in/yaml.v3" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func sortKeysOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func sortKeysOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 
 | 
 | ||||||
| 	for el := matchingNodes.Front(); el != nil; el = el.Next() { | 	for el := matchingNodes.Front(); el != nil; el = el.Next() { | ||||||
| 		candidate := el.Value.(*CandidateNode) | 		candidate := el.Value.(*CandidateNode) | ||||||
| 		rhs, err := d.GetMatchingNodes(nodeToMap(candidate), pathNode.Rhs) | 		rhs, err := d.GetMatchingNodes(nodeToMap(candidate), expressionNode.Rhs) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, err | 			return nil, err | ||||||
| 		} | 		} | ||||||
|  | |||||||
| @ -26,12 +26,12 @@ func parseStyle(customStyle string) (yaml.Style, error) { | |||||||
| 	return 0, nil | 	return 0, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func assignStyleOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func assignStyleOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 
 | 
 | ||||||
| 	log.Debugf("AssignStyleOperator: %v") | 	log.Debugf("AssignStyleOperator: %v") | ||||||
| 	var style yaml.Style | 	var style yaml.Style | ||||||
| 	if !pathNode.Operation.UpdateAssign { | 	if !expressionNode.Operation.UpdateAssign { | ||||||
| 		rhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Rhs) | 		rhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Rhs) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, err | 			return nil, err | ||||||
| 		} | 		} | ||||||
| @ -44,7 +44,7 @@ func assignStyleOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNod | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Lhs) | 	lhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Lhs) | ||||||
| 
 | 
 | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| @ -53,8 +53,8 @@ func assignStyleOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNod | |||||||
| 	for el := lhs.Front(); el != nil; el = el.Next() { | 	for el := lhs.Front(); el != nil; el = el.Next() { | ||||||
| 		candidate := el.Value.(*CandidateNode) | 		candidate := el.Value.(*CandidateNode) | ||||||
| 		log.Debugf("Setting style of : %v", candidate.GetKey()) | 		log.Debugf("Setting style of : %v", candidate.GetKey()) | ||||||
| 		if pathNode.Operation.UpdateAssign { | 		if expressionNode.Operation.UpdateAssign { | ||||||
| 			rhs, err := d.GetMatchingNodes(nodeToMap(candidate), pathNode.Rhs) | 			rhs, err := d.GetMatchingNodes(nodeToMap(candidate), expressionNode.Rhs) | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
| 				return nil, err | 				return nil, err | ||||||
| 			} | 			} | ||||||
| @ -73,7 +73,7 @@ func assignStyleOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNod | |||||||
| 	return matchingNodes, nil | 	return matchingNodes, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func getStyleOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func getStyleOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	log.Debugf("GetStyleOperator") | 	log.Debugf("GetStyleOperator") | ||||||
| 
 | 
 | ||||||
| 	var results = list.New() | 	var results = list.New() | ||||||
|  | |||||||
| @ -6,13 +6,13 @@ import ( | |||||||
| 	yaml "gopkg.in/yaml.v3" | 	yaml "gopkg.in/yaml.v3" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func assignTagOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func assignTagOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 
 | 
 | ||||||
| 	log.Debugf("AssignTagOperator: %v") | 	log.Debugf("AssignTagOperator: %v") | ||||||
| 	tag := "" | 	tag := "" | ||||||
| 
 | 
 | ||||||
| 	if !pathNode.Operation.UpdateAssign { | 	if !expressionNode.Operation.UpdateAssign { | ||||||
| 		rhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Rhs) | 		rhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Rhs) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, err | 			return nil, err | ||||||
| 		} | 		} | ||||||
| @ -22,7 +22,7 @@ func assignTagOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Lhs) | 	lhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Lhs) | ||||||
| 
 | 
 | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| @ -31,8 +31,8 @@ func assignTagOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode | |||||||
| 	for el := lhs.Front(); el != nil; el = el.Next() { | 	for el := lhs.Front(); el != nil; el = el.Next() { | ||||||
| 		candidate := el.Value.(*CandidateNode) | 		candidate := el.Value.(*CandidateNode) | ||||||
| 		log.Debugf("Setting tag of : %v", candidate.GetKey()) | 		log.Debugf("Setting tag of : %v", candidate.GetKey()) | ||||||
| 		if pathNode.Operation.UpdateAssign { | 		if expressionNode.Operation.UpdateAssign { | ||||||
| 			rhs, err := d.GetMatchingNodes(nodeToMap(candidate), pathNode.Rhs) | 			rhs, err := d.GetMatchingNodes(nodeToMap(candidate), expressionNode.Rhs) | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
| 				return nil, err | 				return nil, err | ||||||
| 			} | 			} | ||||||
| @ -47,7 +47,7 @@ func assignTagOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode | |||||||
| 	return matchingNodes, nil | 	return matchingNodes, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func getTagOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func getTagOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	log.Debugf("GetTagOperator") | 	log.Debugf("GetTagOperator") | ||||||
| 
 | 
 | ||||||
| 	var results = list.New() | 	var results = list.New() | ||||||
|  | |||||||
| @ -18,12 +18,12 @@ func splat(d *dataTreeNavigator, matches *list.List, prefs *traversePreferences) | |||||||
| 	return traverseNodesWithArrayIndices(matches, make([]*yaml.Node, 0), prefs) | 	return traverseNodesWithArrayIndices(matches, make([]*yaml.Node, 0), prefs) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func traversePathOperator(d *dataTreeNavigator, matchMap *list.List, pathNode *PathTreeNode) (*list.List, error) { | func traversePathOperator(d *dataTreeNavigator, matchMap *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	log.Debugf("-- Traversing") | 	log.Debugf("-- Traversing") | ||||||
| 	var matchingNodeMap = list.New() | 	var matchingNodeMap = list.New() | ||||||
| 
 | 
 | ||||||
| 	for el := matchMap.Front(); el != nil; el = el.Next() { | 	for el := matchMap.Front(); el != nil; el = el.Next() { | ||||||
| 		newNodes, err := traverse(d, el.Value.(*CandidateNode), pathNode.Operation) | 		newNodes, err := traverse(d, el.Value.(*CandidateNode), expressionNode.Operation) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, err | 			return nil, err | ||||||
| 		} | 		} | ||||||
| @ -74,10 +74,10 @@ func traverse(d *dataTreeNavigator, matchingNode *CandidateNode, operation *Oper | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func traverseArrayOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func traverseArrayOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	// rhs is a collect expression that will yield indexes to retreive of the arrays | 	// rhs is a collect expression that will yield indexes to retreive of the arrays | ||||||
| 
 | 
 | ||||||
| 	rhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Rhs) | 	rhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Rhs) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -2,12 +2,12 @@ package yqlib | |||||||
| 
 | 
 | ||||||
| import "container/list" | import "container/list" | ||||||
| 
 | 
 | ||||||
| func unionOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func unionOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	lhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Lhs) | 	lhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Lhs) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 	rhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Rhs) | 	rhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Rhs) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -2,7 +2,7 @@ package yqlib | |||||||
| 
 | 
 | ||||||
| import "container/list" | import "container/list" | ||||||
| 
 | 
 | ||||||
| func valueOperator(d *dataTreeNavigator, matchMap *list.List, pathNode *PathTreeNode) (*list.List, error) { | func valueOperator(d *dataTreeNavigator, matchMap *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	log.Debug("value = %v", pathNode.Operation.CandidateNode.Node.Value) | 	log.Debug("value = %v", expressionNode.Operation.CandidateNode.Node.Value) | ||||||
| 	return nodeToMap(pathNode.Operation.CandidateNode), nil | 	return nodeToMap(expressionNode.Operation.CandidateNode), nil | ||||||
| } | } | ||||||
|  | |||||||
| @ -7,7 +7,7 @@ import ( | |||||||
| 	"gopkg.in/yaml.v3" | 	"gopkg.in/yaml.v3" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type operatorHandler func(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) | type operatorHandler func(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) | ||||||
| 
 | 
 | ||||||
| func unwrapDoc(node *yaml.Node) *yaml.Node { | func unwrapDoc(node *yaml.Node) *yaml.Node { | ||||||
| 	if node.Kind == yaml.DocumentNode { | 	if node.Kind == yaml.DocumentNode { | ||||||
| @ -16,7 +16,7 @@ func unwrapDoc(node *yaml.Node) *yaml.Node { | |||||||
| 	return node | 	return node | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func emptyOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { | func emptyOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { | ||||||
| 	return list.New(), nil | 	return list.New(), nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -35,13 +35,13 @@ func nodeToMap(candidate *CandidateNode) *list.List { | |||||||
| 	return elMap | 	return elMap | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func createTraversalTree(path []interface{}) *PathTreeNode { | func createTraversalTree(path []interface{}) *ExpressionNode { | ||||||
| 	if len(path) == 0 { | 	if len(path) == 0 { | ||||||
| 		return &PathTreeNode{Operation: &Operation{OperationType: selfReferenceOpType}} | 		return &ExpressionNode{Operation: &Operation{OperationType: selfReferenceOpType}} | ||||||
| 	} else if len(path) == 1 { | 	} else if len(path) == 1 { | ||||||
| 		return &PathTreeNode{Operation: &Operation{OperationType: traversePathOpType, Value: path[0], StringValue: fmt.Sprintf("%v", path[0])}} | 		return &ExpressionNode{Operation: &Operation{OperationType: traversePathOpType, Value: path[0], StringValue: fmt.Sprintf("%v", path[0])}} | ||||||
| 	} | 	} | ||||||
| 	return &PathTreeNode{ | 	return &ExpressionNode{ | ||||||
| 		Operation: &Operation{OperationType: shortPipeOpType}, | 		Operation: &Operation{OperationType: shortPipeOpType}, | ||||||
| 		Lhs:       createTraversalTree(path[0:1]), | 		Lhs:       createTraversalTree(path[0:1]), | ||||||
| 		Rhs:       createTraversalTree(path[1:])} | 		Rhs:       createTraversalTree(path[1:])} | ||||||
|  | |||||||
| @ -30,7 +30,7 @@ func testScenario(t *testing.T, s *expressionScenario) { | |||||||
| 	var results *list.List | 	var results *list.List | ||||||
| 	var err error | 	var err error | ||||||
| 
 | 
 | ||||||
| 	node, err := NewPathTreeCreator().ParsePath(s.expression) | 	node, err := NewExpressionParser().ParseExpression(s.expression) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		t.Error(fmt.Errorf("Error parsing expression %v of %v: %v", s.expression, s.description, err)) | 		t.Error(fmt.Errorf("Error parsing expression %v of %v: %v", s.expression, s.description, err)) | ||||||
| 		return | 		return | ||||||
| @ -110,7 +110,7 @@ func formatYaml(yaml string, filename string) string { | |||||||
| 	var output bytes.Buffer | 	var output bytes.Buffer | ||||||
| 	printer := NewPrinter(bufio.NewWriter(&output), false, true, false, 2, true) | 	printer := NewPrinter(bufio.NewWriter(&output), false, true, false, 2, true) | ||||||
| 
 | 
 | ||||||
| 	node, err := NewPathTreeCreator().ParsePath(".. style= \"\"") | 	node, err := NewExpressionParser().ParseExpression(".. style= \"\"") | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		panic(err) | 		panic(err) | ||||||
| 	} | 	} | ||||||
| @ -219,7 +219,7 @@ func documentOutput(t *testing.T, w *bufio.Writer, s expressionScenario, formatt | |||||||
| 	var err error | 	var err error | ||||||
| 	printer := NewPrinter(bufio.NewWriter(&output), false, true, false, 2, true) | 	printer := NewPrinter(bufio.NewWriter(&output), false, true, false, 2, true) | ||||||
| 
 | 
 | ||||||
| 	node, err := NewPathTreeCreator().ParsePath(s.expression) | 	node, err := NewExpressionParser().ParseExpression(s.expression) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		t.Error(fmt.Errorf("Error parsing expression %v of %v: %v", s.expression, s.description, err)) | 		t.Error(fmt.Errorf("Error parsing expression %v of %v: %v", s.expression, s.description, err)) | ||||||
| 		return | 		return | ||||||
|  | |||||||
| @ -77,7 +77,7 @@ func (p *resultsPrinter) PrintResults(matchingNodes *list.List) error { | |||||||
| 	var err error | 	var err error | ||||||
| 	if p.outputToJSON { | 	if p.outputToJSON { | ||||||
| 		explodeOp := Operation{OperationType: explodeOpType} | 		explodeOp := Operation{OperationType: explodeOpType} | ||||||
| 		explodeNode := PathTreeNode{Operation: &explodeOp} | 		explodeNode := ExpressionNode{Operation: &explodeOp} | ||||||
| 		matchingNodes, err = p.treeNavigator.GetMatchingNodes(matchingNodes, &explodeNode) | 		matchingNodes, err = p.treeNavigator.GetMatchingNodes(matchingNodes, &explodeNode) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return err | 			return err | ||||||
|  | |||||||
| @ -12,23 +12,23 @@ import ( | |||||||
| // Uses less memory than loading all documents and running the expression once, but this cannot process | // Uses less memory than loading all documents and running the expression once, but this cannot process | ||||||
| // cross document expressions. | // cross document expressions. | ||||||
| type StreamEvaluator interface { | type StreamEvaluator interface { | ||||||
| 	Evaluate(filename string, reader io.Reader, node *PathTreeNode, printer Printer) error | 	Evaluate(filename string, reader io.Reader, node *ExpressionNode, printer Printer) error | ||||||
| 	EvaluateFiles(expression string, filenames []string, printer Printer) error | 	EvaluateFiles(expression string, filenames []string, printer Printer) error | ||||||
| 	EvaluateNew(expression string, printer Printer) error | 	EvaluateNew(expression string, printer Printer) error | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type streamEvaluator struct { | type streamEvaluator struct { | ||||||
| 	treeNavigator DataTreeNavigator | 	treeNavigator DataTreeNavigator | ||||||
| 	treeCreator   PathTreeCreator | 	treeCreator   ExpressionParser | ||||||
| 	fileIndex     int | 	fileIndex     int | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func NewStreamEvaluator() StreamEvaluator { | func NewStreamEvaluator() StreamEvaluator { | ||||||
| 	return &streamEvaluator{treeNavigator: NewDataTreeNavigator(), treeCreator: NewPathTreeCreator()} | 	return &streamEvaluator{treeNavigator: NewDataTreeNavigator(), treeCreator: NewExpressionParser()} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (s *streamEvaluator) EvaluateNew(expression string, printer Printer) error { | func (s *streamEvaluator) EvaluateNew(expression string, printer Printer) error { | ||||||
| 	node, err := s.treeCreator.ParsePath(expression) | 	node, err := s.treeCreator.ParseExpression(expression) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| @ -50,7 +50,7 @@ func (s *streamEvaluator) EvaluateNew(expression string, printer Printer) error | |||||||
| 
 | 
 | ||||||
| func (s *streamEvaluator) EvaluateFiles(expression string, filenames []string, printer Printer) error { | func (s *streamEvaluator) EvaluateFiles(expression string, filenames []string, printer Printer) error { | ||||||
| 
 | 
 | ||||||
| 	node, err := s.treeCreator.ParsePath(expression) | 	node, err := s.treeCreator.ParseExpression(expression) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| @ -73,7 +73,7 @@ func (s *streamEvaluator) EvaluateFiles(expression string, filenames []string, p | |||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (s *streamEvaluator) Evaluate(filename string, reader io.Reader, node *PathTreeNode, printer Printer) error { | func (s *streamEvaluator) Evaluate(filename string, reader io.Reader, node *ExpressionNode, printer Printer) error { | ||||||
| 
 | 
 | ||||||
| 	var currentIndex uint | 	var currentIndex uint | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user