diff --git a/pkg/yqlib/lib.go b/pkg/yqlib/lib.go index db8402f3..eac99842 100644 --- a/pkg/yqlib/lib.go +++ b/pkg/yqlib/lib.go @@ -11,78 +11,77 @@ import ( var log = logging.MustGetLogger("yq-lib") -type OperationType struct { +type operationType struct { Type string NumArgs uint // number of arguments to the op Precedence uint - Handler OperatorHandler + Handler operatorHandler } // operators TODO: -// - keys operator for controlling key metadata (particularly anchors/aliases) // - mergeEmpty (sets only if the document is empty, do I do that now?) -var Or = &OperationType{Type: "OR", NumArgs: 2, Precedence: 20, Handler: OrOperator} -var And = &OperationType{Type: "AND", NumArgs: 2, Precedence: 20, Handler: AndOperator} +var orOpType = &operationType{Type: "OR", NumArgs: 2, Precedence: 20, Handler: orOperator} +var andOpType = &operationType{Type: "AND", NumArgs: 2, Precedence: 20, Handler: andOperator} -var Union = &OperationType{Type: "UNION", NumArgs: 2, Precedence: 10, Handler: UnionOperator} +var unionOpType = &operationType{Type: "UNION", NumArgs: 2, Precedence: 10, Handler: unionOperator} -var Pipe = &OperationType{Type: "PIPE", NumArgs: 2, Precedence: 30, Handler: PipeOperator} +var pipeOpType = &operationType{Type: "PIPE", NumArgs: 2, Precedence: 30, Handler: pipeOperator} -var Assign = &OperationType{Type: "ASSIGN", NumArgs: 2, Precedence: 40, Handler: AssignUpdateOperator} -var AddAssign = &OperationType{Type: "ADD_ASSIGN", NumArgs: 2, Precedence: 40, Handler: AddAssignOperator} +var assignOpType = &operationType{Type: "ASSIGN", NumArgs: 2, Precedence: 40, Handler: assignUpdateOperator} +var addAssignOpType = &operationType{Type: "ADD_ASSIGN", NumArgs: 2, Precedence: 40, Handler: addAssignOperator} -var AssignAttributes = &OperationType{Type: "ASSIGN_ATTRIBUTES", NumArgs: 2, Precedence: 40, Handler: AssignAttributesOperator} -var AssignStyle = &OperationType{Type: "ASSIGN_STYLE", NumArgs: 2, Precedence: 40, Handler: AssignStyleOperator} -var AssignTag = &OperationType{Type: "ASSIGN_TAG", NumArgs: 2, Precedence: 40, Handler: AssignTagOperator} -var AssignComment = &OperationType{Type: "ASSIGN_COMMENT", NumArgs: 2, Precedence: 40, Handler: AssignCommentsOperator} -var AssignAnchor = &OperationType{Type: "ASSIGN_ANCHOR", NumArgs: 2, Precedence: 40, Handler: AssignAnchorOperator} -var AssignAlias = &OperationType{Type: "ASSIGN_ALIAS", NumArgs: 2, Precedence: 40, Handler: AssignAliasOperator} +var assignAttributesOpType = &operationType{Type: "ASSIGN_ATTRIBUTES", NumArgs: 2, Precedence: 40, Handler: assignAttributesOperator} +var assignStyleOpType = &operationType{Type: "ASSIGN_STYLE", NumArgs: 2, Precedence: 40, Handler: assignStyleOperator} +var assignTagOpType = &operationType{Type: "ASSIGN_TAG", NumArgs: 2, Precedence: 40, Handler: assignTagOperator} +var assignCommentOpType = &operationType{Type: "ASSIGN_COMMENT", NumArgs: 2, Precedence: 40, Handler: assignCommentsOperator} +var assignAnchorOpType = &operationType{Type: "ASSIGN_ANCHOR", NumArgs: 2, Precedence: 40, Handler: assignAnchorOperator} +var assignAliasOpType = &operationType{Type: "ASSIGN_ALIAS", NumArgs: 2, Precedence: 40, Handler: assignAliasOperator} -var Multiply = &OperationType{Type: "MULTIPLY", NumArgs: 2, Precedence: 45, Handler: MultiplyOperator} -var Add = &OperationType{Type: "ADD", NumArgs: 2, Precedence: 45, Handler: AddOperator} -var Alternative = &OperationType{Type: "ALTERNATIVE", NumArgs: 2, Precedence: 45, Handler: AlternativeOperator} +var multiplyOpType = &operationType{Type: "MULTIPLY", NumArgs: 2, Precedence: 45, Handler: multiplyOperator} +var addOpType = &operationType{Type: "ADD", NumArgs: 2, Precedence: 45, Handler: addOperator} +var alternativeOpType = &operationType{Type: "ALTERNATIVE", NumArgs: 2, Precedence: 45, Handler: alternativeOperator} -var Equals = &OperationType{Type: "EQUALS", NumArgs: 2, Precedence: 40, Handler: EqualsOperator} -var CreateMap = &OperationType{Type: "CREATE_MAP", NumArgs: 2, Precedence: 40, Handler: CreateMapOperator} +var equalsOpType = &operationType{Type: "EQUALS", NumArgs: 2, Precedence: 40, Handler: equalsOperator} +var createMapOpType = &operationType{Type: "CREATE_MAP", NumArgs: 2, Precedence: 40, Handler: createMapOperator} -var ShortPipe = &OperationType{Type: "SHORT_PIPE", NumArgs: 2, Precedence: 45, Handler: PipeOperator} +var shortPipeOpType = &operationType{Type: "SHORT_PIPE", NumArgs: 2, Precedence: 45, Handler: pipeOperator} -var Length = &OperationType{Type: "LENGTH", NumArgs: 0, Precedence: 50, Handler: LengthOperator} -var Collect = &OperationType{Type: "COLLECT", NumArgs: 0, Precedence: 50, Handler: CollectOperator} -var GetStyle = &OperationType{Type: "GET_STYLE", NumArgs: 0, Precedence: 50, Handler: GetStyleOperator} -var GetTag = &OperationType{Type: "GET_TAG", NumArgs: 0, Precedence: 50, Handler: GetTagOperator} -var GetComment = &OperationType{Type: "GET_COMMENT", NumArgs: 0, Precedence: 50, Handler: GetCommentsOperator} -var GetAnchor = &OperationType{Type: "GET_ANCHOR", NumArgs: 0, Precedence: 50, Handler: GetAnchorOperator} -var GetAlias = &OperationType{Type: "GET_ALIAS", NumArgs: 0, Precedence: 50, Handler: GetAliasOperator} -var GetDocumentIndex = &OperationType{Type: "GET_DOCUMENT_INDEX", NumArgs: 0, Precedence: 50, Handler: GetDocumentIndexOperator} -var GetFilename = &OperationType{Type: "GET_FILENAME", NumArgs: 0, Precedence: 50, Handler: GetFilenameOperator} -var GetFileIndex = &OperationType{Type: "GET_FILE_INDEX", NumArgs: 0, Precedence: 50, Handler: GetFileIndexOperator} -var GetPath = &OperationType{Type: "GET_PATH", NumArgs: 0, Precedence: 50, Handler: GetPathOperator} +var lengthOpType = &operationType{Type: "LENGTH", NumArgs: 0, Precedence: 50, Handler: lengthOperator} +var collectOpType = &operationType{Type: "COLLECT", NumArgs: 0, Precedence: 50, Handler: collectOperator} +var getStyleOpType = &operationType{Type: "GET_STYLE", NumArgs: 0, Precedence: 50, Handler: getStyleOperator} +var getTagOpType = &operationType{Type: "GET_TAG", NumArgs: 0, Precedence: 50, Handler: getTagOperator} +var getCommentOpType = &operationType{Type: "GET_COMMENT", NumArgs: 0, Precedence: 50, Handler: getCommentsOperator} +var getAnchorOpType = &operationType{Type: "GET_ANCHOR", NumArgs: 0, Precedence: 50, Handler: getAnchorOperator} +var getAliasOptype = &operationType{Type: "GET_ALIAS", NumArgs: 0, Precedence: 50, Handler: getAliasOperator} +var getDocumentIndexOpType = &operationType{Type: "GET_DOCUMENT_INDEX", NumArgs: 0, Precedence: 50, Handler: getDocumentIndexOperator} +var getFilenameOpType = &operationType{Type: "GET_FILENAME", NumArgs: 0, Precedence: 50, Handler: getFilenameOperator} +var getFileIndexOpType = &operationType{Type: "GET_FILE_INDEX", NumArgs: 0, Precedence: 50, Handler: getFileIndexOperator} +var getPathOpType = &operationType{Type: "GET_PATH", NumArgs: 0, Precedence: 50, Handler: getPathOperator} -var Explode = &OperationType{Type: "EXPLODE", NumArgs: 1, Precedence: 50, Handler: ExplodeOperator} -var SortKeys = &OperationType{Type: "SORT_KEYS", NumArgs: 1, Precedence: 50, Handler: SortKeysOperator} +var explodeOpType = &operationType{Type: "EXPLODE", NumArgs: 1, Precedence: 50, Handler: explodeOperator} +var sortKeysOpType = &operationType{Type: "SORT_KEYS", NumArgs: 1, Precedence: 50, Handler: sortKeysOperator} -var CollectObject = &OperationType{Type: "COLLECT_OBJECT", NumArgs: 0, Precedence: 50, Handler: CollectObjectOperator} -var TraversePath = &OperationType{Type: "TRAVERSE_PATH", NumArgs: 0, Precedence: 50, Handler: TraversePathOperator} -var TraverseArray = &OperationType{Type: "TRAVERSE_ARRAY", NumArgs: 1, Precedence: 50, Handler: TraverseArrayOperator} +var collectObjectOpType = &operationType{Type: "COLLECT_OBJECT", NumArgs: 0, Precedence: 50, Handler: collectObjectOperator} +var traversePathOpType = &operationType{Type: "TRAVERSE_PATH", NumArgs: 0, Precedence: 50, Handler: traversePathOperator} +var traverseArrayOpType = &operationType{Type: "TRAVERSE_ARRAY", NumArgs: 1, Precedence: 50, Handler: traverseArrayOperator} -var DocumentFilter = &OperationType{Type: "DOCUMENT_FILTER", NumArgs: 0, Precedence: 50, Handler: TraversePathOperator} -var SelfReference = &OperationType{Type: "SELF", NumArgs: 0, Precedence: 50, Handler: SelfOperator} -var ValueOp = &OperationType{Type: "VALUE", NumArgs: 0, Precedence: 50, Handler: ValueOperator} -var EnvOp = &OperationType{Type: "ENV", NumArgs: 0, Precedence: 50, Handler: EnvOperator} -var Not = &OperationType{Type: "NOT", NumArgs: 0, Precedence: 50, Handler: NotOperator} -var Empty = &OperationType{Type: "EMPTY", NumArgs: 50, Handler: EmptyOperator} +var documentFilterOpType = &operationType{Type: "DOCUMENT_FILTER", NumArgs: 0, Precedence: 50, Handler: traversePathOperator} +var selfReferenceOpType = &operationType{Type: "SELF", NumArgs: 0, Precedence: 50, Handler: selfOperator} +var valueOpType = &operationType{Type: "VALUE", NumArgs: 0, Precedence: 50, Handler: valueOperator} +var envOpType = &operationType{Type: "ENV", NumArgs: 0, Precedence: 50, Handler: envOperator} +var notOpType = &operationType{Type: "NOT", NumArgs: 0, Precedence: 50, Handler: notOperator} +var emptyOpType = &operationType{Type: "EMPTY", NumArgs: 50, Handler: emptyOperator} -var RecursiveDescent = &OperationType{Type: "RECURSIVE_DESCENT", NumArgs: 0, Precedence: 50, Handler: RecursiveDescentOperator} +var recursiveDescentOpType = &operationType{Type: "RECURSIVE_DESCENT", NumArgs: 0, Precedence: 50, Handler: recursiveDescentOperator} -var Select = &OperationType{Type: "SELECT", NumArgs: 1, Precedence: 50, Handler: SelectOperator} -var Has = &OperationType{Type: "HAS", NumArgs: 1, Precedence: 50, Handler: HasOperator} -var DeleteChild = &OperationType{Type: "DELETE", NumArgs: 1, Precedence: 40, Handler: DeleteChildOperator} -var DeleteImmediateChild = &OperationType{Type: "DELETE_IMMEDIATE_CHILD", NumArgs: 1, Precedence: 40, Handler: DeleteImmediateChildOperator} +var selectOpType = &operationType{Type: "SELECT", NumArgs: 1, Precedence: 50, Handler: selectOperator} +var hasOpType = &operationType{Type: "HAS", NumArgs: 1, Precedence: 50, Handler: hasOperator} +var deleteChildOpType = &operationType{Type: "DELETE", NumArgs: 1, Precedence: 40, Handler: deleteChildOperator} +var deleteImmediateChildOpType = &operationType{Type: "DELETE_IMMEDIATE_CHILD", NumArgs: 1, Precedence: 40, Handler: deleteImmediateChildOperator} type Operation struct { - OperationType *OperationType + OperationType *operationType Value interface{} StringValue string CandidateNode *CandidateNode // used for Value Path elements @@ -90,7 +89,7 @@ type Operation struct { UpdateAssign bool // used for assign ops, when true it means we evaluate the rhs given the lhs (instead of matching nodes) } -func CreateValueOperation(value interface{}, stringValue string) *Operation { +func createValueOperation(value interface{}, stringValue string) *Operation { var node yaml.Node = yaml.Node{Kind: yaml.ScalarNode} node.Value = stringValue @@ -108,7 +107,7 @@ func CreateValueOperation(value interface{}, stringValue string) *Operation { } return &Operation{ - OperationType: ValueOp, + OperationType: valueOpType, Value: value, StringValue: stringValue, CandidateNode: &CandidateNode{Node: &node}, @@ -117,13 +116,13 @@ func CreateValueOperation(value interface{}, stringValue string) *Operation { // debugging purposes only func (p *Operation) toString() string { - if p.OperationType == TraversePath { + if p.OperationType == traversePathOpType { return fmt.Sprintf("%v", p.Value) - } else if p.OperationType == DocumentFilter { + } else if p.OperationType == documentFilterOpType { return fmt.Sprintf("d%v", p.Value) - } else if p.OperationType == SelfReference { + } else if p.OperationType == selfReferenceOpType { return "SELF" - } else if p.OperationType == ValueOp { + } else if p.OperationType == valueOpType { return fmt.Sprintf("%v (%T)", p.Value, p.Value) } else { return fmt.Sprintf("%v", p.OperationType.Type) diff --git a/pkg/yqlib/matchKeyString.go b/pkg/yqlib/matchKeyString.go index 0ccb4f91..d89a90f9 100644 --- a/pkg/yqlib/matchKeyString.go +++ b/pkg/yqlib/matchKeyString.go @@ -1,6 +1,6 @@ package yqlib -func Match(name string, pattern string) (matched bool) { +func matchKey(name string, pattern string) (matched bool) { if pattern == "" { return name == pattern } diff --git a/pkg/yqlib/operator_add.go b/pkg/yqlib/operator_add.go index a397d8f1..227c837a 100644 --- a/pkg/yqlib/operator_add.go +++ b/pkg/yqlib/operator_add.go @@ -10,13 +10,13 @@ import ( ) func createAddOp(lhs *PathTreeNode, rhs *PathTreeNode) *PathTreeNode { - return &PathTreeNode{Operation: &Operation{OperationType: Add}, + return &PathTreeNode{Operation: &Operation{OperationType: addOpType}, Lhs: lhs, Rhs: rhs} } -func AddAssignOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { - assignmentOp := &Operation{OperationType: Assign} +func addAssignOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { + assignmentOp := &Operation{OperationType: assignOpType} assignmentOp.UpdateAssign = false assignmentOpNode := &PathTreeNode{Operation: assignmentOp, Lhs: pathNode.Lhs, Rhs: createAddOp(pathNode.Lhs, pathNode.Rhs)} @@ -37,7 +37,7 @@ 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, pathNode *PathTreeNode) (*list.List, error) { log.Debugf("Add operator") return crossFunction(d, matchingNodes, pathNode, add) diff --git a/pkg/yqlib/operator_alternative.go b/pkg/yqlib/operator_alternative.go index 9f8d97f5..3efedbc2 100644 --- a/pkg/yqlib/operator_alternative.go +++ b/pkg/yqlib/operator_alternative.go @@ -7,7 +7,7 @@ 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, pathNode *PathTreeNode) (*list.List, error) { log.Debugf("-- alternative") return crossFunction(d, matchingNodes, pathNode, alternativeFunc) } diff --git a/pkg/yqlib/operator_anchors_aliases.go b/pkg/yqlib/operator_anchors_aliases.go index e558c222..689371d3 100644 --- a/pkg/yqlib/operator_anchors_aliases.go +++ b/pkg/yqlib/operator_anchors_aliases.go @@ -6,7 +6,7 @@ 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, pathNode *PathTreeNode) (*list.List, error) { log.Debugf("AssignAlias operator!") @@ -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, pathNode *PathTreeNode) (*list.List, error) { log.Debugf("GetAlias operator!") var results = list.New() @@ -60,7 +60,7 @@ 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, pathNode *PathTreeNode) (*list.List, error) { log.Debugf("AssignAnchor operator!") @@ -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, pathNode *PathTreeNode) (*list.List, error) { log.Debugf("GetAnchor operator!") var results = list.New() @@ -116,7 +116,7 @@ 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, pathNode *PathTreeNode) (*list.List, error) { log.Debugf("-- ExplodeOperation") for el := matchMap.Front(); el != nil; el = el.Next() { diff --git a/pkg/yqlib/operator_assign.go b/pkg/yqlib/operator_assign.go index 898bee85..fe0048bb 100644 --- a/pkg/yqlib/operator_assign.go +++ b/pkg/yqlib/operator_assign.go @@ -2,7 +2,7 @@ package yqlib import "container/list" -func AssignUpdateOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { +func assignUpdateOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { lhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Lhs) if err != nil { return nil, err @@ -41,7 +41,7 @@ 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) { +func assignAttributesOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { lhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Lhs) if err != nil { return nil, err diff --git a/pkg/yqlib/operator_booleans.go b/pkg/yqlib/operator_booleans.go index 575ac785..8adcd795 100644 --- a/pkg/yqlib/operator_booleans.go +++ b/pkg/yqlib/operator_booleans.go @@ -44,7 +44,7 @@ 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, pathNode *PathTreeNode) (*list.List, error) { log.Debugf("-- orOp") return crossFunction(d, matchingNodes, pathNode, performBoolOp( func(b1 bool, b2 bool) bool { @@ -52,7 +52,7 @@ func OrOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTr })) } -func AndOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { +func andOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { log.Debugf("-- AndOp") return crossFunction(d, matchingNodes, pathNode, performBoolOp( func(b1 bool, b2 bool) bool { @@ -60,7 +60,7 @@ func AndOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathT })) } -func NotOperator(d *dataTreeNavigator, matchMap *list.List, pathNode *PathTreeNode) (*list.List, error) { +func notOperator(d *dataTreeNavigator, matchMap *list.List, pathNode *PathTreeNode) (*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 b27b17cb..fb9cf955 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, pathNode *PathTreeNode) (*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 79a96d0a..eee0f7e0 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, pathNode *PathTreeNode) (*list.List, error) { log.Debugf("-- collectObjectOperation") if matchMap.Len() == 0 { @@ -68,8 +68,8 @@ func collect(d *dataTreeNavigator, aggregate *list.List, remainingMatches *list. candidate := remainingMatches.Remove(remainingMatches.Front()).(*CandidateNode) - splatted, err := Splat(d, nodeToMap(candidate), - &TraversePreferences{FollowAlias: false, IncludeMapKeys: false}) + splatted, err := splat(d, nodeToMap(candidate), + &traversePreferences{FollowAlias: false, IncludeMapKeys: false}) for splatEl := splatted.Front(); splatEl != nil; splatEl = splatEl.Next() { splatEl.Value.(*CandidateNode).Path = nil @@ -96,7 +96,7 @@ func collect(d *dataTreeNavigator, aggregate *list.List, remainingMatches *list. newCandidate.Path = nil - newCandidate, err = multiply(&MultiplyPreferences{AppendArrays: false})(d, newCandidate, splatCandidate) + newCandidate, err = multiply(&multiplyPreferences{AppendArrays: false})(d, newCandidate, splatCandidate) if err != nil { return nil, err } diff --git a/pkg/yqlib/operator_comments.go b/pkg/yqlib/operator_comments.go index 4d8d3428..3e5e9e29 100644 --- a/pkg/yqlib/operator_comments.go +++ b/pkg/yqlib/operator_comments.go @@ -7,13 +7,13 @@ import ( yaml "gopkg.in/yaml.v3" ) -type CommentOpPreferences struct { +type commentOpPreferences struct { LineComment bool HeadComment bool FootComment bool } -func AssignCommentsOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { +func assignCommentsOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { log.Debugf("AssignComments operator!") @@ -23,7 +23,7 @@ func AssignCommentsOperator(d *dataTreeNavigator, matchingNodes *list.List, path return nil, err } - preferences := pathNode.Operation.Preferences.(*CommentOpPreferences) + preferences := pathNode.Operation.Preferences.(*commentOpPreferences) comment := "" if !pathNode.Operation.UpdateAssign { @@ -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, pathNode *PathTreeNode) (*list.List, error) { + preferences := pathNode.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 28cbad9d..ed243222 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, pathNode *PathTreeNode) (*list.List, error) { log.Debugf("-- createMapOperation") //each matchingNodes entry should turn into a sequence of keys to create. diff --git a/pkg/yqlib/operator_delete.go b/pkg/yqlib/operator_delete.go index 9d2f53ba..7634a377 100644 --- a/pkg/yqlib/operator_delete.go +++ b/pkg/yqlib/operator_delete.go @@ -7,7 +7,7 @@ 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, pathNode *PathTreeNode) (*list.List, error) { nodesToDelete, err := d.GetMatchingNodes(matchingNodes, pathNode.Rhs) @@ -19,7 +19,7 @@ func DeleteChildOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNod candidate := el.Value.(*CandidateNode) deleteImmediateChildOp := &Operation{ - OperationType: DeleteImmediateChild, + OperationType: deleteImmediateChildOpType, Value: candidate.Path[len(candidate.Path)-1], } @@ -36,7 +36,7 @@ func DeleteChildOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNod return matchingNodes, nil } -func DeleteImmediateChildOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { +func deleteImmediateChildOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { parents, err := d.GetMatchingNodes(matchingNodes, pathNode.Rhs) if err != nil { diff --git a/pkg/yqlib/operator_document_index.go b/pkg/yqlib/operator_document_index.go index 52ec7a52..72334a96 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, pathNode *PathTreeNode) (*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 f80a700c..8c77a4ab 100644 --- a/pkg/yqlib/operator_env.go +++ b/pkg/yqlib/operator_env.go @@ -9,17 +9,17 @@ import ( yaml "gopkg.in/yaml.v3" ) -type EnvOpPreferences struct { +type envOpPreferences struct { StringValue bool } -func EnvOperator(d *dataTreeNavigator, matchMap *list.List, pathNode *PathTreeNode) (*list.List, error) { +func envOperator(d *dataTreeNavigator, matchMap *list.List, pathNode *PathTreeNode) (*list.List, error) { envName := pathNode.Operation.CandidateNode.Node.Value log.Debug("EnvOperator, env name:", envName) rawValue := os.Getenv(envName) - preferences := pathNode.Operation.Preferences.(*EnvOpPreferences) + preferences := pathNode.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 8f663f37..ecacb2a9 100644 --- a/pkg/yqlib/operator_equals.go +++ b/pkg/yqlib/operator_equals.go @@ -4,7 +4,7 @@ import ( "container/list" ) -func EqualsOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { +func equalsOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { log.Debugf("-- equalsOperation") return crossFunction(d, matchingNodes, pathNode, isEquals) } @@ -15,7 +15,7 @@ func isEquals(d *dataTreeNavigator, lhs *CandidateNode, rhs *CandidateNode) (*Ca if lhs.Node.Tag == "!!null" { value = (rhs.Node.Tag == "!!null") } else { - value = Match(lhs.Node.Value, rhs.Node.Value) + value = matchKey(lhs.Node.Value, rhs.Node.Value) } log.Debugf("%v == %v ? %v", NodeToString(lhs), NodeToString(rhs), value) return createBooleanCandidate(lhs, value), nil diff --git a/pkg/yqlib/operator_file.go b/pkg/yqlib/operator_file.go index 23331951..292145df 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, pathNode *PathTreeNode) (*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, pathNode *PathTreeNode) (*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 91e7a8e5..17372514 100644 --- a/pkg/yqlib/operator_has.go +++ b/pkg/yqlib/operator_has.go @@ -7,7 +7,7 @@ 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, pathNode *PathTreeNode) (*list.List, error) { log.Debugf("-- hasOperation") var results = list.New() diff --git a/pkg/yqlib/operator_length.go b/pkg/yqlib/operator_length.go index 38c959a9..c82c00fd 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, pathNode *PathTreeNode) (*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 8a2d2c6d..7a8006f0 100644 --- a/pkg/yqlib/operator_multiply.go +++ b/pkg/yqlib/operator_multiply.go @@ -8,9 +8,9 @@ import ( yaml "gopkg.in/yaml.v3" ) -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, pathNode *PathTreeNode, calculation crossFunctionCalculation) (*list.List, error) { lhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Lhs) if err != nil { return nil, err @@ -43,16 +43,16 @@ func crossFunction(d *dataTreeNavigator, matchingNodes *list.List, pathNode *Pat return results, nil } -type MultiplyPreferences struct { +type multiplyPreferences struct { AppendArrays bool } -func MultiplyOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { +func multiplyOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { log.Debugf("-- MultiplyOperator") - return crossFunction(d, matchingNodes, pathNode, multiply(pathNode.Operation.Preferences.(*MultiplyPreferences))) + return crossFunction(d, matchingNodes, pathNode, multiply(pathNode.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) { return func(d *dataTreeNavigator, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) { lhs.Node = UnwrapDoc(lhs.Node) rhs.Node = UnwrapDoc(rhs.Node) @@ -85,8 +85,8 @@ func mergeObjects(d *dataTreeNavigator, lhs *CandidateNode, rhs *CandidateNode, var results = list.New() // shouldn't recurse arrays if appending - prefs := &RecursiveDescentPreferences{RecurseArray: !shouldAppendArrays, - TraversePreferences: &TraversePreferences{FollowAlias: false}} + prefs := &recursiveDescentPreferences{RecurseArray: !shouldAppendArrays, + TraversePreferences: &traversePreferences{FollowAlias: false}} err := recursiveDecent(d, results, nodeToMap(rhs), prefs) if err != nil { return nil, err @@ -112,14 +112,14 @@ func applyAssignment(d *dataTreeNavigator, pathIndexToStartFrom int, lhs *Candid lhsPath := rhs.Path[pathIndexToStartFrom:] - assignmentOp := &Operation{OperationType: AssignAttributes} + assignmentOp := &Operation{OperationType: assignAttributesOpType} if rhs.Node.Kind == yaml.ScalarNode || rhs.Node.Kind == yaml.AliasNode { - assignmentOp.OperationType = Assign + assignmentOp.OperationType = assignOpType assignmentOp.UpdateAssign = false } else if shouldAppendArrays && rhs.Node.Kind == yaml.SequenceNode { - assignmentOp.OperationType = AddAssign + assignmentOp.OperationType = addAssignOpType } - rhsOp := &Operation{OperationType: ValueOp, CandidateNode: rhs} + rhsOp := &Operation{OperationType: valueOpType, CandidateNode: rhs} assignmentOpNode := &PathTreeNode{Operation: assignmentOp, Lhs: createTraversalTree(lhsPath), Rhs: &PathTreeNode{Operation: rhsOp}} diff --git a/pkg/yqlib/operator_path.go b/pkg/yqlib/operator_path.go index 2f27f48e..3dc60ac5 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, pathNode *PathTreeNode) (*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 189bd2de..4133d477 100644 --- a/pkg/yqlib/operator_pipe.go +++ b/pkg/yqlib/operator_pipe.go @@ -2,7 +2,7 @@ package yqlib import "container/list" -func PipeOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { +func pipeOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { lhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Lhs) if err != nil { return nil, err diff --git a/pkg/yqlib/operator_recursive_descent.go b/pkg/yqlib/operator_recursive_descent.go index 0ac3af01..a30bf08e 100644 --- a/pkg/yqlib/operator_recursive_descent.go +++ b/pkg/yqlib/operator_recursive_descent.go @@ -6,15 +6,15 @@ import ( yaml "gopkg.in/yaml.v3" ) -type RecursiveDescentPreferences struct { - TraversePreferences *TraversePreferences +type recursiveDescentPreferences struct { + TraversePreferences *traversePreferences RecurseArray bool } -func RecursiveDescentOperator(d *dataTreeNavigator, matchMap *list.List, pathNode *PathTreeNode) (*list.List, error) { +func recursiveDescentOperator(d *dataTreeNavigator, matchMap *list.List, pathNode *PathTreeNode) (*list.List, error) { var results = list.New() - preferences := pathNode.Operation.Preferences.(*RecursiveDescentPreferences) + preferences := pathNode.Operation.Preferences.(*recursiveDescentPreferences) err := recursiveDecent(d, results, matchMap, preferences) if err != nil { return nil, err @@ -23,7 +23,7 @@ func RecursiveDescentOperator(d *dataTreeNavigator, matchMap *list.List, pathNod return results, nil } -func recursiveDecent(d *dataTreeNavigator, results *list.List, matchMap *list.List, preferences *RecursiveDescentPreferences) error { +func recursiveDecent(d *dataTreeNavigator, results *list.List, matchMap *list.List, preferences *recursiveDescentPreferences) error { for el := matchMap.Front(); el != nil; el = el.Next() { candidate := el.Value.(*CandidateNode) @@ -35,7 +35,7 @@ func recursiveDecent(d *dataTreeNavigator, results *list.List, matchMap *list.Li if candidate.Node.Kind != yaml.AliasNode && len(candidate.Node.Content) > 0 && (preferences.RecurseArray || candidate.Node.Kind != yaml.SequenceNode) { - children, err := Splat(d, nodeToMap(candidate), preferences.TraversePreferences) + children, err := splat(d, nodeToMap(candidate), preferences.TraversePreferences) if err != nil { return err diff --git a/pkg/yqlib/operator_select.go b/pkg/yqlib/operator_select.go index 72ba06a1..d29e6c40 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, pathNode *PathTreeNode) (*list.List, error) { log.Debugf("-- selectOperation") var results = list.New() diff --git a/pkg/yqlib/operator_self.go b/pkg/yqlib/operator_self.go index 58bf2aa1..56c944cb 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, pathNode *PathTreeNode) (*list.List, error) { return matchMap, nil } diff --git a/pkg/yqlib/operator_sort_keys.go b/pkg/yqlib/operator_sort_keys.go index e8f39381..ba508b74 100644 --- a/pkg/yqlib/operator_sort_keys.go +++ b/pkg/yqlib/operator_sort_keys.go @@ -7,7 +7,7 @@ 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, pathNode *PathTreeNode) (*list.List, error) { for el := matchingNodes.Front(); el != nil; el = el.Next() { candidate := el.Value.(*CandidateNode) diff --git a/pkg/yqlib/operator_style.go b/pkg/yqlib/operator_style.go index 1b359cdb..d9326c17 100644 --- a/pkg/yqlib/operator_style.go +++ b/pkg/yqlib/operator_style.go @@ -26,7 +26,7 @@ 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, pathNode *PathTreeNode) (*list.List, error) { log.Debugf("AssignStyleOperator: %v") var style yaml.Style @@ -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, pathNode *PathTreeNode) (*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 c9a9099e..52d3ccef 100644 --- a/pkg/yqlib/operator_tag.go +++ b/pkg/yqlib/operator_tag.go @@ -6,7 +6,7 @@ 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, pathNode *PathTreeNode) (*list.List, error) { log.Debugf("AssignTagOperator: %v") tag := "" @@ -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, pathNode *PathTreeNode) (*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 14456fe4..3d22b59d 100644 --- a/pkg/yqlib/operator_traverse_path.go +++ b/pkg/yqlib/operator_traverse_path.go @@ -9,16 +9,16 @@ import ( yaml "gopkg.in/yaml.v3" ) -type TraversePreferences struct { +type traversePreferences struct { FollowAlias bool IncludeMapKeys bool } -func Splat(d *dataTreeNavigator, matches *list.List, prefs *TraversePreferences) (*list.List, error) { +func splat(d *dataTreeNavigator, matches *list.List, prefs *traversePreferences) (*list.List, error) { 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, pathNode *PathTreeNode) (*list.List, error) { log.Debugf("-- Traversing") var matchingNodeMap = list.New() @@ -54,7 +54,7 @@ func traverse(d *dataTreeNavigator, matchingNode *CandidateNode, operation *Oper switch value.Kind { case yaml.MappingNode: log.Debug("its a map with %v entries", len(value.Content)/2) - prefs := &TraversePreferences{FollowAlias: true} + prefs := &traversePreferences{FollowAlias: true} return traverseMap(matchingNode, operation.StringValue, prefs, false) case yaml.SequenceNode: @@ -77,7 +77,7 @@ 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, pathNode *PathTreeNode) (*list.List, error) { // rhs is a collect expression that will yield indexes to retreive of the arrays rhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Rhs) @@ -86,11 +86,11 @@ func TraverseArrayOperator(d *dataTreeNavigator, matchingNodes *list.List, pathN } var indicesToTraverse = rhs.Front().Value.(*CandidateNode).Node.Content - prefs := &TraversePreferences{FollowAlias: true} + prefs := &traversePreferences{FollowAlias: true} return traverseNodesWithArrayIndices(matchingNodes, indicesToTraverse, prefs) } -func traverseNodesWithArrayIndices(matchingNodes *list.List, indicesToTraverse []*yaml.Node, prefs *TraversePreferences) (*list.List, error) { +func traverseNodesWithArrayIndices(matchingNodes *list.List, indicesToTraverse []*yaml.Node, prefs *traversePreferences) (*list.List, error) { var matchingNodeMap = list.New() for el := matchingNodes.Front(); el != nil; el = el.Next() { candidate := el.Value.(*CandidateNode) @@ -104,7 +104,7 @@ func traverseNodesWithArrayIndices(matchingNodes *list.List, indicesToTraverse [ return matchingNodeMap, nil } -func traverseArrayIndices(matchingNode *CandidateNode, indicesToTraverse []*yaml.Node, prefs *TraversePreferences) (*list.List, error) { // call this if doc / alias like the other traverse +func traverseArrayIndices(matchingNode *CandidateNode, indicesToTraverse []*yaml.Node, prefs *traversePreferences) (*list.List, error) { // call this if doc / alias like the other traverse node := matchingNode.Node if node.Tag == "!!null" { log.Debugf("OperatorArrayTraverse got a null - turning it into an empty array") @@ -131,7 +131,7 @@ func traverseArrayIndices(matchingNode *CandidateNode, indicesToTraverse []*yaml return list.New(), nil } -func traverseMapWithIndices(candidate *CandidateNode, indices []*yaml.Node, prefs *TraversePreferences) (*list.List, error) { +func traverseMapWithIndices(candidate *CandidateNode, indices []*yaml.Node, prefs *traversePreferences) (*list.List, error) { if len(indices) == 0 { return traverseMap(candidate, "", prefs, true) } @@ -200,10 +200,10 @@ func traverseArrayWithIndices(candidate *CandidateNode, indices []*yaml.Node) (* } func keyMatches(key *yaml.Node, wantedKey string) bool { - return Match(key.Value, wantedKey) + return matchKey(key.Value, wantedKey) } -func traverseMap(matchingNode *CandidateNode, key string, prefs *TraversePreferences, splat bool) (*list.List, error) { +func traverseMap(matchingNode *CandidateNode, key string, prefs *traversePreferences, splat bool) (*list.List, error) { var newMatches = orderedmap.NewOrderedMap() err := doTraverseMap(newMatches, matchingNode, key, prefs, splat) @@ -234,7 +234,7 @@ func traverseMap(matchingNode *CandidateNode, key string, prefs *TraversePrefere return results, nil } -func doTraverseMap(newMatches *orderedmap.OrderedMap, candidate *CandidateNode, wantedKey string, prefs *TraversePreferences, splat bool) error { +func doTraverseMap(newMatches *orderedmap.OrderedMap, candidate *CandidateNode, wantedKey string, prefs *traversePreferences, splat bool) error { // value.Content is a concatenated array of key, value, // so keys are in the even indexes, values in odd. // merge aliases are defined first, but we only want to traverse them @@ -277,7 +277,7 @@ func doTraverseMap(newMatches *orderedmap.OrderedMap, candidate *CandidateNode, return nil } -func traverseMergeAnchor(newMatches *orderedmap.OrderedMap, originalCandidate *CandidateNode, value *yaml.Node, wantedKey string, prefs *TraversePreferences, splat bool) error { +func traverseMergeAnchor(newMatches *orderedmap.OrderedMap, originalCandidate *CandidateNode, value *yaml.Node, wantedKey string, prefs *traversePreferences, splat bool) error { switch value.Kind { case yaml.AliasNode: candidateNode := &CandidateNode{ diff --git a/pkg/yqlib/operator_union.go b/pkg/yqlib/operator_union.go index f436fa0e..3120db86 100644 --- a/pkg/yqlib/operator_union.go +++ b/pkg/yqlib/operator_union.go @@ -2,7 +2,7 @@ package yqlib import "container/list" -func UnionOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { +func unionOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) { lhs, err := d.GetMatchingNodes(matchingNodes, pathNode.Lhs) if err != nil { return nil, err diff --git a/pkg/yqlib/operator_value.go b/pkg/yqlib/operator_value.go index 94650050..a84db9f0 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) { +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 } diff --git a/pkg/yqlib/operators.go b/pkg/yqlib/operators.go index 2013d544..b557dcfc 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, pathNode *PathTreeNode) (*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, pathNode *PathTreeNode) (*list.List, error) { return list.New(), nil } @@ -37,12 +37,12 @@ func nodeToMap(candidate *CandidateNode) *list.List { func createTraversalTree(path []interface{}) *PathTreeNode { if len(path) == 0 { - return &PathTreeNode{Operation: &Operation{OperationType: SelfReference}} + return &PathTreeNode{Operation: &Operation{OperationType: selfReferenceOpType}} } else if len(path) == 1 { - return &PathTreeNode{Operation: &Operation{OperationType: TraversePath, Value: path[0], StringValue: fmt.Sprintf("%v", path[0])}} + return &PathTreeNode{Operation: &Operation{OperationType: traversePathOpType, Value: path[0], StringValue: fmt.Sprintf("%v", path[0])}} } return &PathTreeNode{ - Operation: &Operation{OperationType: ShortPipe}, + Operation: &Operation{OperationType: shortPipeOpType}, Lhs: createTraversalTree(path[0:1]), Rhs: createTraversalTree(path[1:])} } diff --git a/pkg/yqlib/path_postfix.go b/pkg/yqlib/path_postfix.go index cb56bdad..1c6e780e 100644 --- a/pkg/yqlib/path_postfix.go +++ b/pkg/yqlib/path_postfix.go @@ -36,10 +36,10 @@ func (p *pathPostFixer) ConvertToPostfix(infixTokens []*token) ([]*Operation, er opStack = append(opStack, currentToken) case CloseCollect, CloseCollectObject: var opener tokenType = OpenCollect - var collectOperator *OperationType = Collect + var collectOperator *operationType = collectOpType if currentToken.TokenType == CloseCollectObject { opener = OpenCollectObject - collectOperator = CollectObject + collectOperator = collectObjectOpType } itemsInMiddle := false for len(opStack) > 0 && opStack[len(opStack)-1].TokenType != opener { @@ -48,7 +48,7 @@ func (p *pathPostFixer) ConvertToPostfix(infixTokens []*token) ([]*Operation, er } if !itemsInMiddle { // must be an empty collection, add the empty object as a LHS parameter - result = append(result, &Operation{OperationType: Empty}) + result = append(result, &Operation{OperationType: emptyOpType}) } if len(opStack) == 0 { return nil, errors.New("Bad path expression, got close collect brackets without matching opening bracket") @@ -56,7 +56,7 @@ func (p *pathPostFixer) ConvertToPostfix(infixTokens []*token) ([]*Operation, er // now we should have [] as the last element on the opStack, get rid of it opStack = opStack[0 : len(opStack)-1] //and append a collect to the opStack - opStack = append(opStack, &token{TokenType: OperationToken, Operation: &Operation{OperationType: ShortPipe}}) + opStack = append(opStack, &token{TokenType: OperationToken, Operation: &Operation{OperationType: shortPipeOpType}}) opStack = append(opStack, &token{TokenType: OperationToken, Operation: &Operation{OperationType: collectOperator}}) case CloseBracket: for len(opStack) > 0 && opStack[len(opStack)-1].TokenType != OpenBracket { diff --git a/pkg/yqlib/path_tokeniser.go b/pkg/yqlib/path_tokeniser.go index 950d97bb..e5e50b96 100644 --- a/pkg/yqlib/path_tokeniser.go +++ b/pkg/yqlib/path_tokeniser.go @@ -65,7 +65,7 @@ func pathToken(wrapped bool) lex.Action { value = unwrap(value) } log.Debug("PathToken %v", value) - op := &Operation{OperationType: TraversePath, Value: value, StringValue: value} + op := &Operation{OperationType: traversePathOpType, Value: value, StringValue: value} return &token{TokenType: OperationToken, Operation: op, CheckForPostTraverse: true}, nil } } @@ -79,16 +79,16 @@ func documentToken() lex.Action { return nil, errParsingInt } log.Debug("documentToken %v", string(m.Bytes)) - op := &Operation{OperationType: DocumentFilter, Value: number, StringValue: numberString} + op := &Operation{OperationType: documentFilterOpType, Value: number, StringValue: numberString} return &token{TokenType: OperationToken, Operation: op, CheckForPostTraverse: true}, nil } } -func opToken(op *OperationType) lex.Action { +func opToken(op *operationType) lex.Action { return opTokenWithPrefs(op, nil, nil) } -func opAssignableToken(opType *OperationType, assignOpType *OperationType) lex.Action { +func opAssignableToken(opType *operationType, assignOpType *operationType) lex.Action { return opTokenWithPrefs(opType, assignOpType, nil) } @@ -96,12 +96,12 @@ func assignOpToken(updateAssign bool) lex.Action { return func(s *lex.Scanner, m *machines.Match) (interface{}, error) { log.Debug("assignOpToken %v", string(m.Bytes)) value := string(m.Bytes) - op := &Operation{OperationType: Assign, Value: Assign.Type, StringValue: value, UpdateAssign: updateAssign} + op := &Operation{OperationType: assignOpType, Value: assignOpType.Type, StringValue: value, UpdateAssign: updateAssign} return &token{TokenType: OperationToken, Operation: op}, nil } } -func opTokenWithPrefs(op *OperationType, assignOpType *OperationType, preferences interface{}) lex.Action { +func opTokenWithPrefs(op *operationType, assignOpType *operationType, preferences interface{}) lex.Action { return func(s *lex.Scanner, m *machines.Match) (interface{}, error) { log.Debug("opTokenWithPrefs %v", string(m.Bytes)) value := string(m.Bytes) @@ -119,11 +119,11 @@ func assignAllCommentsOp(updateAssign bool) lex.Action { log.Debug("assignAllCommentsOp %v", string(m.Bytes)) value := string(m.Bytes) op := &Operation{ - OperationType: AssignComment, - Value: AssignComment.Type, + OperationType: assignCommentOpType, + Value: assignCommentOpType.Type, StringValue: value, UpdateAssign: updateAssign, - Preferences: &CommentOpPreferences{LineComment: true, HeadComment: true, FootComment: true}, + Preferences: &commentOpPreferences{LineComment: true, HeadComment: true, FootComment: true}, } return &token{TokenType: OperationToken, Operation: op}, nil } @@ -147,7 +147,7 @@ func numberValue() lex.Action { return nil, errParsingInt } - return &token{TokenType: OperationToken, Operation: CreateValueOperation(number, numberString)}, nil + return &token{TokenType: OperationToken, Operation: createValueOperation(number, numberString)}, nil } } @@ -158,13 +158,13 @@ func floatValue() lex.Action { if errParsingInt != nil { return nil, errParsingInt } - return &token{TokenType: OperationToken, Operation: CreateValueOperation(number, numberString)}, nil + return &token{TokenType: OperationToken, Operation: createValueOperation(number, numberString)}, nil } } func booleanValue(val bool) lex.Action { return func(s *lex.Scanner, m *machines.Match) (interface{}, error) { - return &token{TokenType: OperationToken, Operation: CreateValueOperation(val, string(m.Bytes))}, nil + return &token{TokenType: OperationToken, Operation: createValueOperation(val, string(m.Bytes))}, nil } } @@ -174,14 +174,14 @@ func stringValue(wrapped bool) lex.Action { if wrapped { value = unwrap(value) } - return &token{TokenType: OperationToken, Operation: CreateValueOperation(value, value)}, nil + return &token{TokenType: OperationToken, Operation: createValueOperation(value, value)}, nil } } func envOp(strenv bool) lex.Action { return func(s *lex.Scanner, m *machines.Match) (interface{}, error) { value := string(m.Bytes) - preferences := &EnvOpPreferences{} + preferences := &envOpPreferences{} if strenv { // strenv( ) @@ -192,8 +192,8 @@ func envOp(strenv bool) lex.Action { value = value[4 : len(value)-1] } - envOperation := CreateValueOperation(value, value) - envOperation.OperationType = EnvOp + envOperation := createValueOperation(value, value) + envOperation.OperationType = envOpType envOperation.Preferences = preferences return &token{TokenType: OperationToken, Operation: envOperation}, nil @@ -202,13 +202,13 @@ func envOp(strenv bool) lex.Action { func nullValue() lex.Action { return func(s *lex.Scanner, m *machines.Match) (interface{}, error) { - return &token{TokenType: OperationToken, Operation: CreateValueOperation(nil, string(m.Bytes))}, nil + return &token{TokenType: OperationToken, Operation: createValueOperation(nil, string(m.Bytes))}, nil } } func selfToken() lex.Action { return func(s *lex.Scanner, m *machines.Match) (interface{}, error) { - op := &Operation{OperationType: SelfReference} + op := &Operation{OperationType: selfReferenceOpType} return &token{TokenType: OperationToken, Operation: op}, nil } } @@ -219,52 +219,52 @@ func initLexer() (*lex.Lexer, error) { lexer.Add([]byte(`\)`), literalToken(CloseBracket, true)) lexer.Add([]byte(`\.\[`), literalToken(TraverseArrayCollect, false)) - lexer.Add([]byte(`\.\.`), opTokenWithPrefs(RecursiveDescent, nil, &RecursiveDescentPreferences{RecurseArray: true, - TraversePreferences: &TraversePreferences{FollowAlias: false, IncludeMapKeys: false}})) + lexer.Add([]byte(`\.\.`), opTokenWithPrefs(recursiveDescentOpType, nil, &recursiveDescentPreferences{RecurseArray: true, + TraversePreferences: &traversePreferences{FollowAlias: false, IncludeMapKeys: false}})) - lexer.Add([]byte(`\.\.\.`), opTokenWithPrefs(RecursiveDescent, nil, &RecursiveDescentPreferences{RecurseArray: true, - TraversePreferences: &TraversePreferences{FollowAlias: false, IncludeMapKeys: true}})) + lexer.Add([]byte(`\.\.\.`), opTokenWithPrefs(recursiveDescentOpType, nil, &recursiveDescentPreferences{RecurseArray: true, + TraversePreferences: &traversePreferences{FollowAlias: false, IncludeMapKeys: true}})) - lexer.Add([]byte(`,`), opToken(Union)) - lexer.Add([]byte(`:\s*`), opToken(CreateMap)) - lexer.Add([]byte(`length`), opToken(Length)) - lexer.Add([]byte(`sortKeys`), opToken(SortKeys)) - lexer.Add([]byte(`select`), opToken(Select)) - lexer.Add([]byte(`has`), opToken(Has)) - lexer.Add([]byte(`explode`), opToken(Explode)) - lexer.Add([]byte(`or`), opToken(Or)) - lexer.Add([]byte(`and`), opToken(And)) - lexer.Add([]byte(`not`), opToken(Not)) - lexer.Add([]byte(`\/\/`), opToken(Alternative)) + lexer.Add([]byte(`,`), opToken(unionOpType)) + lexer.Add([]byte(`:\s*`), opToken(createMapOpType)) + lexer.Add([]byte(`length`), opToken(lengthOpType)) + lexer.Add([]byte(`sortKeys`), opToken(sortKeysOpType)) + lexer.Add([]byte(`select`), opToken(selectOpType)) + lexer.Add([]byte(`has`), opToken(hasOpType)) + lexer.Add([]byte(`explode`), opToken(explodeOpType)) + lexer.Add([]byte(`or`), opToken(orOpType)) + lexer.Add([]byte(`and`), opToken(andOpType)) + lexer.Add([]byte(`not`), opToken(notOpType)) + lexer.Add([]byte(`\/\/`), opToken(alternativeOpType)) - lexer.Add([]byte(`documentIndex`), opToken(GetDocumentIndex)) - lexer.Add([]byte(`di`), opToken(GetDocumentIndex)) + lexer.Add([]byte(`documentIndex`), opToken(getDocumentIndexOpType)) + lexer.Add([]byte(`di`), opToken(getDocumentIndexOpType)) - lexer.Add([]byte(`style`), opAssignableToken(GetStyle, AssignStyle)) + lexer.Add([]byte(`style`), opAssignableToken(getStyleOpType, assignStyleOpType)) - lexer.Add([]byte(`tag`), opAssignableToken(GetTag, AssignTag)) - lexer.Add([]byte(`anchor`), opAssignableToken(GetAnchor, AssignAnchor)) - lexer.Add([]byte(`alias`), opAssignableToken(GetAlias, AssignAlias)) - lexer.Add([]byte(`filename`), opToken(GetFilename)) - lexer.Add([]byte(`fileIndex`), opToken(GetFileIndex)) - lexer.Add([]byte(`fi`), opToken(GetFileIndex)) - lexer.Add([]byte(`path`), opToken(GetPath)) + lexer.Add([]byte(`tag`), opAssignableToken(getTagOpType, assignTagOpType)) + lexer.Add([]byte(`anchor`), opAssignableToken(getAnchorOpType, assignAnchorOpType)) + lexer.Add([]byte(`alias`), opAssignableToken(getAliasOptype, assignAliasOpType)) + lexer.Add([]byte(`filename`), opToken(getFilenameOpType)) + lexer.Add([]byte(`fileIndex`), opToken(getFileIndexOpType)) + lexer.Add([]byte(`fi`), opToken(getFileIndexOpType)) + lexer.Add([]byte(`path`), opToken(getPathOpType)) - lexer.Add([]byte(`lineComment`), opTokenWithPrefs(GetComment, AssignComment, &CommentOpPreferences{LineComment: true})) + lexer.Add([]byte(`lineComment`), opTokenWithPrefs(getCommentOpType, assignCommentOpType, &commentOpPreferences{LineComment: true})) - lexer.Add([]byte(`headComment`), opTokenWithPrefs(GetComment, AssignComment, &CommentOpPreferences{HeadComment: true})) + lexer.Add([]byte(`headComment`), opTokenWithPrefs(getCommentOpType, assignCommentOpType, &commentOpPreferences{HeadComment: true})) - lexer.Add([]byte(`footComment`), opTokenWithPrefs(GetComment, AssignComment, &CommentOpPreferences{FootComment: true})) + lexer.Add([]byte(`footComment`), opTokenWithPrefs(getCommentOpType, assignCommentOpType, &commentOpPreferences{FootComment: true})) lexer.Add([]byte(`comments\s*=`), assignAllCommentsOp(false)) lexer.Add([]byte(`comments\s*\|=`), assignAllCommentsOp(true)) - lexer.Add([]byte(`collect`), opToken(Collect)) + lexer.Add([]byte(`collect`), opToken(collectOpType)) - lexer.Add([]byte(`\s*==\s*`), opToken(Equals)) + lexer.Add([]byte(`\s*==\s*`), opToken(equalsOpType)) lexer.Add([]byte(`\s*=\s*`), assignOpToken(false)) - lexer.Add([]byte(`del`), opToken(DeleteChild)) + lexer.Add([]byte(`del`), opToken(deleteChildOpType)) lexer.Add([]byte(`\s*\|=\s*`), assignOpToken(true)) @@ -275,7 +275,7 @@ func initLexer() (*lex.Lexer, error) { lexer.Add([]byte(`\.[^ \}\{\:\[\],\|\.\[\(\)=]+`), pathToken(false)) lexer.Add([]byte(`\.`), selfToken()) - lexer.Add([]byte(`\|`), opToken(Pipe)) + lexer.Add([]byte(`\|`), opToken(pipeOpType)) lexer.Add([]byte(`-?\d+(\.\d+)`), floatValue()) lexer.Add([]byte(`-?[1-9](\.\d+)?[Ee][-+]?\d+`), floatValue()) @@ -295,10 +295,10 @@ func initLexer() (*lex.Lexer, error) { lexer.Add([]byte(`\]`), literalToken(CloseCollect, true)) lexer.Add([]byte(`\{`), literalToken(OpenCollectObject, false)) lexer.Add([]byte(`\}`), literalToken(CloseCollectObject, true)) - lexer.Add([]byte(`\*`), opTokenWithPrefs(Multiply, nil, &MultiplyPreferences{AppendArrays: false})) - lexer.Add([]byte(`\*\+`), opTokenWithPrefs(Multiply, nil, &MultiplyPreferences{AppendArrays: true})) - lexer.Add([]byte(`\+`), opToken(Add)) - lexer.Add([]byte(`\+=`), opToken(AddAssign)) + lexer.Add([]byte(`\*`), opTokenWithPrefs(multiplyOpType, nil, &multiplyPreferences{AppendArrays: false})) + lexer.Add([]byte(`\*\+`), opTokenWithPrefs(multiplyOpType, nil, &multiplyPreferences{AppendArrays: true})) + lexer.Add([]byte(`\+`), opToken(addOpType)) + lexer.Add([]byte(`\+=`), opToken(addAssignOpType)) err := lexer.Compile() if err != nil { @@ -364,7 +364,7 @@ func (p *pathTokeniser) handleToken(tokens []*token, index int, postProcessedTok //need to put a traverse array then a collect currentToken // do this by adding traverse then converting currentToken to collect - op := &Operation{OperationType: TraverseArray, StringValue: "TRAVERSE_ARRAY"} + op := &Operation{OperationType: traverseArrayOpType, StringValue: "TRAVERSE_ARRAY"} postProcessedTokens = append(postProcessedTokens, &token{TokenType: OperationToken, Operation: op}) currentToken = &token{TokenType: OpenCollect} @@ -373,7 +373,7 @@ func (p *pathTokeniser) handleToken(tokens []*token, index int, postProcessedTok if index != len(tokens)-1 && currentToken.AssignOperation != nil && tokens[index+1].TokenType == OperationToken && - tokens[index+1].Operation.OperationType == Assign { + tokens[index+1].Operation.OperationType == assignOpType { currentToken.Operation = currentToken.AssignOperation currentToken.Operation.UpdateAssign = tokens[index+1].Operation.UpdateAssign skipNextToken = true @@ -383,23 +383,23 @@ func (p *pathTokeniser) handleToken(tokens []*token, index int, postProcessedTok if index != len(tokens)-1 && currentToken.CheckForPostTraverse && tokens[index+1].TokenType == OperationToken && - tokens[index+1].Operation.OperationType == TraversePath { - op := &Operation{OperationType: ShortPipe, Value: "PIPE"} + tokens[index+1].Operation.OperationType == traversePathOpType { + op := &Operation{OperationType: shortPipeOpType, Value: "PIPE"} postProcessedTokens = append(postProcessedTokens, &token{TokenType: OperationToken, Operation: op}) } if index != len(tokens)-1 && currentToken.CheckForPostTraverse && tokens[index+1].TokenType == OpenCollect { - op := &Operation{OperationType: ShortPipe, Value: "PIPE"} + op := &Operation{OperationType: shortPipeOpType, Value: "PIPE"} postProcessedTokens = append(postProcessedTokens, &token{TokenType: OperationToken, Operation: op}) - op = &Operation{OperationType: TraverseArray} + op = &Operation{OperationType: traverseArrayOpType} postProcessedTokens = append(postProcessedTokens, &token{TokenType: OperationToken, Operation: op}) } if index != len(tokens)-1 && currentToken.CheckForPostTraverse && tokens[index+1].TokenType == TraverseArrayCollect { - op := &Operation{OperationType: ShortPipe, Value: "PIPE"} + op := &Operation{OperationType: shortPipeOpType, Value: "PIPE"} postProcessedTokens = append(postProcessedTokens, &token{TokenType: OperationToken, Operation: op}) } diff --git a/pkg/yqlib/printer.go b/pkg/yqlib/printer.go index 340abef6..17af7ca2 100644 --- a/pkg/yqlib/printer.go +++ b/pkg/yqlib/printer.go @@ -74,7 +74,7 @@ func (p *resultsPrinter) PrintResults(matchingNodes *list.List) error { log.Debug("PrintResults for %v matches", matchingNodes.Len()) var err error if p.outputToJSON { - explodeOp := Operation{OperationType: Explode} + explodeOp := Operation{OperationType: explodeOpType} explodeNode := PathTreeNode{Operation: &explodeOp} matchingNodes, err = treeNavigator.GetMatchingNodes(matchingNodes, &explodeNode) if err != nil {