diff --git a/pkg/yqlib/all_at_once_evaluator.go b/pkg/yqlib/all_at_once_evaluator.go index e7cd1ffe..7de4a0b0 100644 --- a/pkg/yqlib/all_at_once_evaluator.go +++ b/pkg/yqlib/all_at_once_evaluator.go @@ -19,11 +19,11 @@ type Evaluator interface { type allAtOnceEvaluator struct { treeNavigator DataTreeNavigator - treeCreator PathTreeCreator + treeCreator ExpressionParser } 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) { @@ -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) { - node, err := e.treeCreator.ParsePath(expression) + node, err := e.treeCreator.ParseExpression(expression) if err != nil { return nil, err } diff --git a/pkg/yqlib/data_tree_navigator.go b/pkg/yqlib/data_tree_navigator.go index f8acc73f..e9b43506 100644 --- a/pkg/yqlib/data_tree_navigator.go +++ b/pkg/yqlib/data_tree_navigator.go @@ -9,10 +9,10 @@ import ( ) type DataTreeNavigator interface { - // given a list of CandidateEntities and a pathNode, - // this will process the list against the given pathNode and return + // given a list of CandidateEntities and a expressionNode, + // this will process the list against the given expressionNode and return // 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 { @@ -22,22 +22,22 @@ func NewDataTreeNavigator() DataTreeNavigator { return &dataTreeNavigator{} } -func (d *dataTreeNavigator) GetMatchingNodes(matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { - if pathNode == nil { +func (d *dataTreeNavigator) GetMatchingNodes(matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { + if expressionNode == nil { log.Debugf("getMatchingNodes - nothing to do") return matchingNodes, nil } - log.Debugf("Processing Op: %v", pathNode.Operation.toString()) + log.Debugf("Processing Op: %v", expressionNode.Operation.toString()) if log.IsEnabledFor(logging.DEBUG) { for el := matchingNodes.Front(); el != nil; el = el.Next() { log.Debug(NodeToString(el.Value.(*CandidateNode))) } } log.Debug(">>") - handler := pathNode.Operation.OperationType.Handler + handler := expressionNode.Operation.OperationType.Handler 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) } diff --git a/pkg/yqlib/path_tree.go b/pkg/yqlib/expression_parser.go similarity index 63% rename from pkg/yqlib/path_tree.go rename to pkg/yqlib/expression_parser.go index b2a752ff..56d56789 100644 --- a/pkg/yqlib/path_tree.go +++ b/pkg/yqlib/expression_parser.go @@ -5,29 +5,28 @@ import ( "strings" ) -var myPathTokeniser = newPathTokeniser() -var myPathPostfixer = newPathPostFixer() +var myPathTokeniser = newExpressionTokeniser() +var myPathPostfixer = newExpressionPostFixer() -type PathTreeNode struct { +type ExpressionNode struct { Operation *Operation - Lhs *PathTreeNode - Rhs *PathTreeNode + Lhs *ExpressionNode + Rhs *ExpressionNode } -type PathTreeCreator interface { - ParsePath(path string) (*PathTreeNode, error) - CreatePathTree(postFixPath []*Operation) (*PathTreeNode, error) +type ExpressionParser interface { + ParseExpression(expression string) (*ExpressionNode, error) } -type pathTreeCreator struct { +type expressionParserImpl struct { } -func NewPathTreeCreator() PathTreeCreator { - return &pathTreeCreator{} +func NewExpressionParser() ExpressionParser { + return &expressionParserImpl{} } -func (p *pathTreeCreator) ParsePath(path string) (*PathTreeNode, error) { - tokens, err := myPathTokeniser.Tokenise(path) +func (p *expressionParserImpl) ParseExpression(expression string) (*ExpressionNode, error) { + tokens, err := myPathTokeniser.Tokenise(expression) if err != nil { return nil, err } @@ -36,18 +35,18 @@ func (p *pathTreeCreator) ParsePath(path string) (*PathTreeNode, error) { if err != nil { return nil, err } - return p.CreatePathTree(Operations) + return p.createExpressionTree(Operations) } -func (p *pathTreeCreator) CreatePathTree(postFixPath []*Operation) (*PathTreeNode, error) { - var stack = make([]*PathTreeNode, 0) +func (p *expressionParserImpl) createExpressionTree(postFixPath []*Operation) (*ExpressionNode, error) { + var stack = make([]*ExpressionNode, 0) if len(postFixPath) == 0 { return nil, nil } for _, Operation := range postFixPath { - var newNode = PathTreeNode{Operation: Operation} + var newNode = ExpressionNode{Operation: Operation} log.Debugf("pathTree %v ", Operation.toString()) if Operation.OperationType.NumArgs > 0 { numArgs := Operation.OperationType.NumArgs diff --git a/pkg/yqlib/path_tree_test.go b/pkg/yqlib/expression_parser_test.go similarity index 69% rename from pkg/yqlib/path_tree_test.go rename to pkg/yqlib/expression_parser_test.go index 268c63a8..3a24e984 100644 --- a/pkg/yqlib/path_tree_test.go +++ b/pkg/yqlib/expression_parser_test.go @@ -7,36 +7,36 @@ import ( ) func TestPathTreeNoArgsForTwoArgOp(t *testing.T) { - _, err := NewPathTreeCreator().ParsePath("=") + _, err := NewExpressionParser().ParseExpression("=") test.AssertResultComplex(t, "'=' expects 2 args but there is 0", err.Error()) } 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()) } 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()) } func TestPathTreeTwoArgsForTwoArgOp(t *testing.T) { - _, err := NewPathTreeCreator().ParsePath(".a = .b") + _, err := NewExpressionParser().ParseExpression(".a = .b") test.AssertResultComplex(t, nil, err) } 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()) } func TestPathTreeOneArgForOneArgOp(t *testing.T) { - _, err := NewPathTreeCreator().ParsePath("explode(.)") + _, err := NewExpressionParser().ParseExpression("explode(.)") test.AssertResultComplex(t, nil, err) } 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()) } diff --git a/pkg/yqlib/path_postfix.go b/pkg/yqlib/expression_postfix.go similarity index 92% rename from pkg/yqlib/path_postfix.go rename to pkg/yqlib/expression_postfix.go index dffe1cd9..d55fec9b 100644 --- a/pkg/yqlib/path_postfix.go +++ b/pkg/yqlib/expression_postfix.go @@ -6,15 +6,15 @@ import ( logging "gopkg.in/op/go-logging.v1" ) -type pathPostFixer interface { +type expressionPostFixer interface { ConvertToPostfix([]*token) ([]*Operation, error) } -type pathPostFixerImpl struct { +type expressionPostFixerImpl struct { } -func newPathPostFixer() pathPostFixer { - return &pathPostFixerImpl{} +func newExpressionPostFixer() expressionPostFixer { + return &expressionPostFixerImpl{} } 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) } -func (p *pathPostFixerImpl) ConvertToPostfix(infixTokens []*token) ([]*Operation, error) { +func (p *expressionPostFixerImpl) ConvertToPostfix(infixTokens []*token) ([]*Operation, error) { var result []*Operation // surround the whole thing with quotes var opStack = []*token{&token{TokenType: openBracket}} diff --git a/pkg/yqlib/path_parse_test.go b/pkg/yqlib/expression_processing_test.go similarity index 98% rename from pkg/yqlib/path_parse_test.go rename to pkg/yqlib/expression_processing_test.go index d077559a..45226b70 100644 --- a/pkg/yqlib/path_parse_test.go +++ b/pkg/yqlib/expression_processing_test.go @@ -164,8 +164,8 @@ var pathTests = []struct { }, } -var tokeniser = newPathTokeniser() -var postFixer = newPathPostFixer() +var tokeniser = newExpressionTokeniser() +var postFixer = newExpressionPostFixer() func TestPathParsing(t *testing.T) { for _, tt := range pathTests { diff --git a/pkg/yqlib/path_tokeniser.go b/pkg/yqlib/expression_tokeniser.go similarity index 96% rename from pkg/yqlib/path_tokeniser.go rename to pkg/yqlib/expression_tokeniser.go index 753d6138..1c317bc2 100644 --- a/pkg/yqlib/path_tokeniser.go +++ b/pkg/yqlib/expression_tokeniser.go @@ -307,24 +307,24 @@ func initLexer() (*lex.Lexer, error) { return lexer, nil } -type pathTokeniser interface { - Tokenise(path string) ([]*token, error) +type expressionTokeniser interface { + Tokenise(expression string) ([]*token, error) } -type pathTokeniserImpl struct { +type expressionTokeniserImpl struct { lexer *lex.Lexer } -func newPathTokeniser() pathTokeniser { +func newExpressionTokeniser() expressionTokeniser { var lexer, err = initLexer() if err != nil { panic(err) } - return &pathTokeniserImpl{lexer} + return &expressionTokeniserImpl{lexer} } -func (p *pathTokeniserImpl) Tokenise(path string) ([]*token, error) { - scanner, err := p.lexer.Scanner([]byte(path)) +func (p *expressionTokeniserImpl) Tokenise(expression string) ([]*token, error) { + scanner, err := p.lexer.Scanner([]byte(expression)) if err != nil { return nil, fmt.Errorf("Parsing expression: %v", err) @@ -356,7 +356,7 @@ func (p *pathTokeniserImpl) Tokenise(path string) ([]*token, error) { 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 currentToken := tokens[index] diff --git a/pkg/yqlib/operator_add.go b/pkg/yqlib/operator_add.go index 674b9962..d8ead709 100644 --- a/pkg/yqlib/operator_add.go +++ b/pkg/yqlib/operator_add.go @@ -9,17 +9,17 @@ import ( yaml "gopkg.in/yaml.v3" ) -func createAddOp(lhs *PathTreeNode, rhs *PathTreeNode) *PathTreeNode { - return &PathTreeNode{Operation: &Operation{OperationType: addOpType}, +func createAddOp(lhs *ExpressionNode, rhs *ExpressionNode) *ExpressionNode { + return &ExpressionNode{Operation: &Operation{OperationType: addOpType}, Lhs: lhs, 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.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) } @@ -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") - return crossFunction(d, matchingNodes, pathNode, add) + return crossFunction(d, matchingNodes, expressionNode, add) } func add(d *dataTreeNavigator, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) { diff --git a/pkg/yqlib/operator_alternative.go b/pkg/yqlib/operator_alternative.go index a099f324..0823c8c5 100644 --- a/pkg/yqlib/operator_alternative.go +++ b/pkg/yqlib/operator_alternative.go @@ -7,9 +7,9 @@ import ( // corssFunction no matches // 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") - return crossFunction(d, matchingNodes, pathNode, alternativeFunc) + return crossFunction(d, matchingNodes, expressionNode, alternativeFunc) } func alternativeFunc(d *dataTreeNavigator, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) { diff --git a/pkg/yqlib/operator_anchors_aliases.go b/pkg/yqlib/operator_anchors_aliases.go index 9f15a161..da84869e 100644 --- a/pkg/yqlib/operator_anchors_aliases.go +++ b/pkg/yqlib/operator_anchors_aliases.go @@ -6,13 +6,13 @@ import ( 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!") aliasName := "" - if !pathNode.Operation.UpdateAssign { - rhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Rhs) + if !expressionNode.Operation.UpdateAssign { + rhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Rhs) if err != nil { 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 { return nil, err @@ -31,8 +31,8 @@ func assignAliasOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNod candidate := el.Value.(*CandidateNode) log.Debugf("Setting aliasName : %v", candidate.GetKey()) - if pathNode.Operation.UpdateAssign { - rhs, err := d.GetMatchingNodes(nodeToMap(candidate), pathNode.Rhs) + if expressionNode.Operation.UpdateAssign { + rhs, err := d.GetMatchingNodes(nodeToMap(candidate), expressionNode.Rhs) if err != nil { return nil, err } @@ -47,7 +47,7 @@ func assignAliasOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNod 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!") var results = list.New() @@ -60,13 +60,13 @@ func getAliasOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode * 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!") anchorName := "" - if !pathNode.Operation.UpdateAssign { - rhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Rhs) + if !expressionNode.Operation.UpdateAssign { + rhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Rhs) if err != nil { 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 { return nil, err @@ -86,8 +86,8 @@ func assignAnchorOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNo candidate := el.Value.(*CandidateNode) log.Debugf("Setting anchorName of : %v", candidate.GetKey()) - if pathNode.Operation.UpdateAssign { - rhs, err := d.GetMatchingNodes(nodeToMap(candidate), pathNode.Rhs) + if expressionNode.Operation.UpdateAssign { + rhs, err := d.GetMatchingNodes(nodeToMap(candidate), expressionNode.Rhs) if err != nil { return nil, err } @@ -102,7 +102,7 @@ func assignAnchorOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNo 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!") var results = list.New() @@ -116,13 +116,13 @@ func getAnchorOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode 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") for el := matchMap.Front(); el != nil; el = el.Next() { candidate := el.Value.(*CandidateNode) - rhs, err := d.GetMatchingNodes(nodeToMap(candidate), pathNode.Rhs) + rhs, err := d.GetMatchingNodes(nodeToMap(candidate), expressionNode.Rhs) if err != nil { return nil, err diff --git a/pkg/yqlib/operator_assign.go b/pkg/yqlib/operator_assign.go index a4078911..2d6bc407 100644 --- a/pkg/yqlib/operator_assign.go +++ b/pkg/yqlib/operator_assign.go @@ -2,21 +2,21 @@ package yqlib import "container/list" -func assignUpdateOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { - lhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Lhs) +func assignUpdateOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { + lhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Lhs) if err != nil { return nil, err } var rhs *list.List - if !pathNode.Operation.UpdateAssign { - rhs, err = d.GetMatchingNodes(matchingNodes, pathNode.Rhs) + if !expressionNode.Operation.UpdateAssign { + rhs, err = d.GetMatchingNodes(matchingNodes, expressionNode.Rhs) } for el := lhs.Front(); el != nil; el = el.Next() { candidate := el.Value.(*CandidateNode) - if pathNode.Operation.UpdateAssign { - rhs, err = d.GetMatchingNodes(nodeToMap(candidate), pathNode.Rhs) + if expressionNode.Operation.UpdateAssign { + rhs, err = d.GetMatchingNodes(nodeToMap(candidate), expressionNode.Rhs) } if err != nil { @@ -37,15 +37,15 @@ func assignUpdateOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNo } // does not update content or values -func assignAttributesOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { - lhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Lhs) +func assignAttributesOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { + lhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Lhs) if err != nil { return nil, err } for el := lhs.Front(); el != nil; el = el.Next() { candidate := el.Value.(*CandidateNode) - rhs, err := d.GetMatchingNodes(nodeToMap(candidate), pathNode.Rhs) + rhs, err := d.GetMatchingNodes(nodeToMap(candidate), expressionNode.Rhs) if err != nil { return nil, err diff --git a/pkg/yqlib/operator_booleans.go b/pkg/yqlib/operator_booleans.go index a6e1f135..123007f3 100644 --- a/pkg/yqlib/operator_booleans.go +++ b/pkg/yqlib/operator_booleans.go @@ -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") - return crossFunction(d, matchingNodes, pathNode, performBoolOp( + return crossFunction(d, matchingNodes, expressionNode, performBoolOp( func(b1 bool, b2 bool) bool { 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") - return crossFunction(d, matchingNodes, pathNode, performBoolOp( + return crossFunction(d, matchingNodes, expressionNode, performBoolOp( func(b1 bool, b2 bool) bool { 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") var results = list.New() diff --git a/pkg/yqlib/operator_collect.go b/pkg/yqlib/operator_collect.go index 50a7fac4..1b6ad5be 100644 --- a/pkg/yqlib/operator_collect.go +++ b/pkg/yqlib/operator_collect.go @@ -6,7 +6,7 @@ import ( 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") if matchMap.Len() == 0 { diff --git a/pkg/yqlib/operator_collect_object.go b/pkg/yqlib/operator_collect_object.go index 03fcd46b..8be51611 100644 --- a/pkg/yqlib/operator_collect_object.go +++ b/pkg/yqlib/operator_collect_object.go @@ -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") if matchMap.Len() == 0 { diff --git a/pkg/yqlib/operator_comments.go b/pkg/yqlib/operator_comments.go index 226248f3..95b528b4 100644 --- a/pkg/yqlib/operator_comments.go +++ b/pkg/yqlib/operator_comments.go @@ -13,21 +13,21 @@ type commentOpPreferences struct { 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!") - lhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Lhs) + lhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Lhs) if err != nil { return nil, err } - preferences := pathNode.Operation.Preferences.(*commentOpPreferences) + preferences := expressionNode.Operation.Preferences.(*commentOpPreferences) comment := "" - if !pathNode.Operation.UpdateAssign { - rhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Rhs) + if !expressionNode.Operation.UpdateAssign { + rhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Rhs) if err != nil { return nil, err } @@ -40,8 +40,8 @@ func assignCommentsOperator(d *dataTreeNavigator, matchingNodes *list.List, path for el := lhs.Front(); el != nil; el = el.Next() { candidate := el.Value.(*CandidateNode) - if pathNode.Operation.UpdateAssign { - rhs, err := d.GetMatchingNodes(nodeToMap(candidate), pathNode.Rhs) + if expressionNode.Operation.UpdateAssign { + rhs, err := d.GetMatchingNodes(nodeToMap(candidate), expressionNode.Rhs) if err != nil { return nil, err } @@ -66,8 +66,8 @@ func assignCommentsOperator(d *dataTreeNavigator, matchingNodes *list.List, path return matchingNodes, nil } -func getCommentsOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { - preferences := pathNode.Operation.Preferences.(*commentOpPreferences) +func getCommentsOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { + preferences := expressionNode.Operation.Preferences.(*commentOpPreferences) log.Debugf("GetComments operator!") var results = list.New() diff --git a/pkg/yqlib/operator_create_map.go b/pkg/yqlib/operator_create_map.go index d3fb21d4..cd83922f 100644 --- a/pkg/yqlib/operator_create_map.go +++ b/pkg/yqlib/operator_create_map.go @@ -6,7 +6,7 @@ import ( "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") //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() { matchingNode := matchingNodeEl.Value.(*CandidateNode) - sequenceNode, err := sequenceFor(d, matchingNode, pathNode) + sequenceNode, err := sequenceFor(d, matchingNode, expressionNode) if err != nil { return nil, err } sequences.PushBack(sequenceNode) } } else { - sequenceNode, err := sequenceFor(d, nil, pathNode) + sequenceNode, err := sequenceFor(d, nil, expressionNode) if err != nil { 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 document uint = 0 var matches = list.New() @@ -51,7 +51,7 @@ func sequenceFor(d *dataTreeNavigator, matchingNode *CandidateNode, pathNode *Pa matches = nodeToMap(matchingNode) } - mapPairs, err := crossFunction(d, matches, pathNode, + mapPairs, err := crossFunction(d, matches, expressionNode, func(d *dataTreeNavigator, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) { node := yaml.Node{Kind: yaml.MappingNode, Tag: "!!map"} log.Debugf("LHS:", NodeToString(lhs)) diff --git a/pkg/yqlib/operator_delete.go b/pkg/yqlib/operator_delete.go index 729a4a8e..cecacaeb 100644 --- a/pkg/yqlib/operator_delete.go +++ b/pkg/yqlib/operator_delete.go @@ -7,9 +7,9 @@ import ( 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 { return nil, err @@ -23,7 +23,7 @@ func deleteChildOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNod Value: candidate.Path[len(candidate.Path)-1], } - deleteImmediateChildOpNode := &PathTreeNode{ + deleteImmediateChildOpNode := &ExpressionNode{ Operation: deleteImmediateChildOp, Rhs: createTraversalTree(candidate.Path[0 : len(candidate.Path)-1]), } @@ -36,14 +36,14 @@ func deleteChildOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNod return matchingNodes, nil } -func deleteImmediateChildOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { - parents, err := d.GetMatchingNodes(matchingNodes, pathNode.Rhs) +func deleteImmediateChildOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { + parents, err := d.GetMatchingNodes(matchingNodes, expressionNode.Rhs) if err != nil { return nil, err } - childPath := pathNode.Operation.Value + childPath := expressionNode.Operation.Value log.Debug("childPath to remove %v", childPath) diff --git a/pkg/yqlib/operator_document_index.go b/pkg/yqlib/operator_document_index.go index 0ef444bc..2647800c 100644 --- a/pkg/yqlib/operator_document_index.go +++ b/pkg/yqlib/operator_document_index.go @@ -7,7 +7,7 @@ import ( "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() for el := matchingNodes.Front(); el != nil; el = el.Next() { diff --git a/pkg/yqlib/operator_env.go b/pkg/yqlib/operator_env.go index ba05e4d9..07a0aee6 100644 --- a/pkg/yqlib/operator_env.go +++ b/pkg/yqlib/operator_env.go @@ -13,13 +13,13 @@ type envOpPreferences struct { StringValue bool } -func envOperator(d *dataTreeNavigator, matchMap *list.List, pathNode *PathTreeNode) (*list.List, error) { - envName := pathNode.Operation.CandidateNode.Node.Value +func envOperator(d *dataTreeNavigator, matchMap *list.List, expressionNode *ExpressionNode) (*list.List, error) { + envName := expressionNode.Operation.CandidateNode.Node.Value log.Debug("EnvOperator, env name:", envName) rawValue := os.Getenv(envName) - preferences := pathNode.Operation.Preferences.(*envOpPreferences) + preferences := expressionNode.Operation.Preferences.(*envOpPreferences) var node *yaml.Node if preferences.StringValue { diff --git a/pkg/yqlib/operator_equals.go b/pkg/yqlib/operator_equals.go index 4912e7da..0c1ddb29 100644 --- a/pkg/yqlib/operator_equals.go +++ b/pkg/yqlib/operator_equals.go @@ -4,9 +4,9 @@ import ( "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") - return crossFunction(d, matchingNodes, pathNode, isEquals) + return crossFunction(d, matchingNodes, expressionNode, isEquals) } func isEquals(d *dataTreeNavigator, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) { diff --git a/pkg/yqlib/operator_file.go b/pkg/yqlib/operator_file.go index c7c5de14..06ad9469 100644 --- a/pkg/yqlib/operator_file.go +++ b/pkg/yqlib/operator_file.go @@ -7,7 +7,7 @@ import ( 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") var results = list.New() @@ -22,7 +22,7 @@ func getFilenameOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNod 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") var results = list.New() diff --git a/pkg/yqlib/operator_has.go b/pkg/yqlib/operator_has.go index 5cc3f2da..cc433a74 100644 --- a/pkg/yqlib/operator_has.go +++ b/pkg/yqlib/operator_has.go @@ -7,12 +7,12 @@ import ( 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") var results = list.New() - rhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Rhs) + rhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Rhs) wanted := rhs.Front().Value.(*CandidateNode).Node wantedKey := wanted.Value diff --git a/pkg/yqlib/operator_length.go b/pkg/yqlib/operator_length.go index ad375f58..b9d6dded 100644 --- a/pkg/yqlib/operator_length.go +++ b/pkg/yqlib/operator_length.go @@ -7,7 +7,7 @@ import ( 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") var results = list.New() diff --git a/pkg/yqlib/operator_multiply.go b/pkg/yqlib/operator_multiply.go index f590d1b0..2428c465 100644 --- a/pkg/yqlib/operator_multiply.go +++ b/pkg/yqlib/operator_multiply.go @@ -10,14 +10,14 @@ import ( 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) { - lhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Lhs) +func crossFunction(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode, calculation crossFunctionCalculation) (*list.List, error) { + lhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Lhs) if err != nil { return nil, err } 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 { return nil, err @@ -47,9 +47,9 @@ type multiplyPreferences struct { 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") - 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) { @@ -116,7 +116,7 @@ func applyAssignment(d *dataTreeNavigator, pathIndexToStartFrom int, lhs *Candid } 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) diff --git a/pkg/yqlib/operator_path.go b/pkg/yqlib/operator_path.go index 26756225..677d9b14 100644 --- a/pkg/yqlib/operator_path.go +++ b/pkg/yqlib/operator_path.go @@ -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") var results = list.New() diff --git a/pkg/yqlib/operator_pipe.go b/pkg/yqlib/operator_pipe.go index 4133d477..d922fcb8 100644 --- a/pkg/yqlib/operator_pipe.go +++ b/pkg/yqlib/operator_pipe.go @@ -2,10 +2,10 @@ package yqlib import "container/list" -func pipeOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { - lhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Lhs) +func pipeOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { + lhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Lhs) if err != nil { return nil, err } - return d.GetMatchingNodes(lhs, pathNode.Rhs) + return d.GetMatchingNodes(lhs, expressionNode.Rhs) } diff --git a/pkg/yqlib/operator_recursive_descent.go b/pkg/yqlib/operator_recursive_descent.go index 0d1a2fb9..52257312 100644 --- a/pkg/yqlib/operator_recursive_descent.go +++ b/pkg/yqlib/operator_recursive_descent.go @@ -11,10 +11,10 @@ type recursiveDescentPreferences struct { 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() - preferences := pathNode.Operation.Preferences.(*recursiveDescentPreferences) + preferences := expressionNode.Operation.Preferences.(*recursiveDescentPreferences) err := recursiveDecent(d, results, matchMap, preferences) if err != nil { return nil, err diff --git a/pkg/yqlib/operator_select.go b/pkg/yqlib/operator_select.go index d29e6c40..9a29f892 100644 --- a/pkg/yqlib/operator_select.go +++ b/pkg/yqlib/operator_select.go @@ -4,7 +4,7 @@ import ( "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") 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() { candidate := el.Value.(*CandidateNode) - rhs, err := d.GetMatchingNodes(nodeToMap(candidate), pathNode.Rhs) + rhs, err := d.GetMatchingNodes(nodeToMap(candidate), expressionNode.Rhs) if err != nil { return nil, err diff --git a/pkg/yqlib/operator_self.go b/pkg/yqlib/operator_self.go index 56c944cb..a18a68d6 100644 --- a/pkg/yqlib/operator_self.go +++ b/pkg/yqlib/operator_self.go @@ -2,6 +2,6 @@ package yqlib 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 } diff --git a/pkg/yqlib/operator_sort_keys.go b/pkg/yqlib/operator_sort_keys.go index 5cf61fae..58199495 100644 --- a/pkg/yqlib/operator_sort_keys.go +++ b/pkg/yqlib/operator_sort_keys.go @@ -7,11 +7,11 @@ import ( 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() { candidate := el.Value.(*CandidateNode) - rhs, err := d.GetMatchingNodes(nodeToMap(candidate), pathNode.Rhs) + rhs, err := d.GetMatchingNodes(nodeToMap(candidate), expressionNode.Rhs) if err != nil { return nil, err } diff --git a/pkg/yqlib/operator_style.go b/pkg/yqlib/operator_style.go index 698c1a17..96408c91 100644 --- a/pkg/yqlib/operator_style.go +++ b/pkg/yqlib/operator_style.go @@ -26,12 +26,12 @@ func parseStyle(customStyle string) (yaml.Style, error) { 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") var style yaml.Style - if !pathNode.Operation.UpdateAssign { - rhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Rhs) + if !expressionNode.Operation.UpdateAssign { + rhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Rhs) if err != nil { 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 { return nil, err @@ -53,8 +53,8 @@ func assignStyleOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNod for el := lhs.Front(); el != nil; el = el.Next() { candidate := el.Value.(*CandidateNode) log.Debugf("Setting style of : %v", candidate.GetKey()) - if pathNode.Operation.UpdateAssign { - rhs, err := d.GetMatchingNodes(nodeToMap(candidate), pathNode.Rhs) + if expressionNode.Operation.UpdateAssign { + rhs, err := d.GetMatchingNodes(nodeToMap(candidate), expressionNode.Rhs) if err != nil { return nil, err } @@ -73,7 +73,7 @@ func assignStyleOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNod 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") var results = list.New() diff --git a/pkg/yqlib/operator_tag.go b/pkg/yqlib/operator_tag.go index e6d71a11..a3c4b84f 100644 --- a/pkg/yqlib/operator_tag.go +++ b/pkg/yqlib/operator_tag.go @@ -6,13 +6,13 @@ import ( 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") tag := "" - if !pathNode.Operation.UpdateAssign { - rhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Rhs) + if !expressionNode.Operation.UpdateAssign { + rhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Rhs) if err != nil { 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 { return nil, err @@ -31,8 +31,8 @@ func assignTagOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode for el := lhs.Front(); el != nil; el = el.Next() { candidate := el.Value.(*CandidateNode) log.Debugf("Setting tag of : %v", candidate.GetKey()) - if pathNode.Operation.UpdateAssign { - rhs, err := d.GetMatchingNodes(nodeToMap(candidate), pathNode.Rhs) + if expressionNode.Operation.UpdateAssign { + rhs, err := d.GetMatchingNodes(nodeToMap(candidate), expressionNode.Rhs) if err != nil { return nil, err } @@ -47,7 +47,7 @@ func assignTagOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode 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") var results = list.New() diff --git a/pkg/yqlib/operator_traverse_path.go b/pkg/yqlib/operator_traverse_path.go index 4d9f5cf2..b7825bab 100644 --- a/pkg/yqlib/operator_traverse_path.go +++ b/pkg/yqlib/operator_traverse_path.go @@ -18,12 +18,12 @@ func splat(d *dataTreeNavigator, matches *list.List, prefs *traversePreferences) 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") var matchingNodeMap = list.New() 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 { 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, err := d.GetMatchingNodes(matchingNodes, pathNode.Rhs) + rhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Rhs) if err != nil { return nil, err } diff --git a/pkg/yqlib/operator_union.go b/pkg/yqlib/operator_union.go index 3120db86..b95c986f 100644 --- a/pkg/yqlib/operator_union.go +++ b/pkg/yqlib/operator_union.go @@ -2,12 +2,12 @@ package yqlib import "container/list" -func unionOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { - lhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Lhs) +func unionOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) { + lhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Lhs) if err != nil { return nil, err } - rhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Rhs) + rhs, err := d.GetMatchingNodes(matchingNodes, expressionNode.Rhs) if err != nil { return nil, err } diff --git a/pkg/yqlib/operator_value.go b/pkg/yqlib/operator_value.go index a84db9f0..f30459a0 100644 --- a/pkg/yqlib/operator_value.go +++ b/pkg/yqlib/operator_value.go @@ -2,7 +2,7 @@ package yqlib import "container/list" -func valueOperator(d *dataTreeNavigator, matchMap *list.List, pathNode *PathTreeNode) (*list.List, error) { - log.Debug("value = %v", pathNode.Operation.CandidateNode.Node.Value) - return nodeToMap(pathNode.Operation.CandidateNode), nil +func valueOperator(d *dataTreeNavigator, matchMap *list.List, expressionNode *ExpressionNode) (*list.List, error) { + log.Debug("value = %v", expressionNode.Operation.CandidateNode.Node.Value) + return nodeToMap(expressionNode.Operation.CandidateNode), nil } diff --git a/pkg/yqlib/operators.go b/pkg/yqlib/operators.go index f72e32d0..01e7087f 100644 --- a/pkg/yqlib/operators.go +++ b/pkg/yqlib/operators.go @@ -7,7 +7,7 @@ import ( "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 { if node.Kind == yaml.DocumentNode { @@ -16,7 +16,7 @@ func unwrapDoc(node *yaml.Node) *yaml.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 } @@ -35,13 +35,13 @@ func nodeToMap(candidate *CandidateNode) *list.List { return elMap } -func createTraversalTree(path []interface{}) *PathTreeNode { +func createTraversalTree(path []interface{}) *ExpressionNode { if len(path) == 0 { - return &PathTreeNode{Operation: &Operation{OperationType: selfReferenceOpType}} + return &ExpressionNode{Operation: &Operation{OperationType: selfReferenceOpType}} } 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}, Lhs: createTraversalTree(path[0:1]), Rhs: createTraversalTree(path[1:])} diff --git a/pkg/yqlib/operators_test.go b/pkg/yqlib/operators_test.go index 838f34a8..904c81ac 100644 --- a/pkg/yqlib/operators_test.go +++ b/pkg/yqlib/operators_test.go @@ -30,7 +30,7 @@ func testScenario(t *testing.T, s *expressionScenario) { var results *list.List var err error - node, err := NewPathTreeCreator().ParsePath(s.expression) + node, err := NewExpressionParser().ParseExpression(s.expression) if err != nil { t.Error(fmt.Errorf("Error parsing expression %v of %v: %v", s.expression, s.description, err)) return @@ -110,7 +110,7 @@ func formatYaml(yaml string, filename string) string { var output bytes.Buffer printer := NewPrinter(bufio.NewWriter(&output), false, true, false, 2, true) - node, err := NewPathTreeCreator().ParsePath(".. style= \"\"") + node, err := NewExpressionParser().ParseExpression(".. style= \"\"") if err != nil { panic(err) } @@ -219,7 +219,7 @@ func documentOutput(t *testing.T, w *bufio.Writer, s expressionScenario, formatt var err error 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 { t.Error(fmt.Errorf("Error parsing expression %v of %v: %v", s.expression, s.description, err)) return diff --git a/pkg/yqlib/printer.go b/pkg/yqlib/printer.go index d558962f..082c02dd 100644 --- a/pkg/yqlib/printer.go +++ b/pkg/yqlib/printer.go @@ -77,7 +77,7 @@ func (p *resultsPrinter) PrintResults(matchingNodes *list.List) error { var err error if p.outputToJSON { explodeOp := Operation{OperationType: explodeOpType} - explodeNode := PathTreeNode{Operation: &explodeOp} + explodeNode := ExpressionNode{Operation: &explodeOp} matchingNodes, err = p.treeNavigator.GetMatchingNodes(matchingNodes, &explodeNode) if err != nil { return err diff --git a/pkg/yqlib/stream_evaluator.go b/pkg/yqlib/stream_evaluator.go index 67286f57..355a7ab3 100644 --- a/pkg/yqlib/stream_evaluator.go +++ b/pkg/yqlib/stream_evaluator.go @@ -12,23 +12,23 @@ import ( // Uses less memory than loading all documents and running the expression once, but this cannot process // cross document expressions. 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 EvaluateNew(expression string, printer Printer) error } type streamEvaluator struct { treeNavigator DataTreeNavigator - treeCreator PathTreeCreator + treeCreator ExpressionParser fileIndex int } func NewStreamEvaluator() StreamEvaluator { - return &streamEvaluator{treeNavigator: NewDataTreeNavigator(), treeCreator: NewPathTreeCreator()} + return &streamEvaluator{treeNavigator: NewDataTreeNavigator(), treeCreator: NewExpressionParser()} } func (s *streamEvaluator) EvaluateNew(expression string, printer Printer) error { - node, err := s.treeCreator.ParsePath(expression) + node, err := s.treeCreator.ParseExpression(expression) if err != nil { 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 { - node, err := s.treeCreator.ParsePath(expression) + node, err := s.treeCreator.ParseExpression(expression) if err != nil { return err } @@ -73,7 +73,7 @@ func (s *streamEvaluator) EvaluateFiles(expression string, filenames []string, p 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