Added pipe and length docs, fix pipe precedence

This commit is contained in:
Mike Farah
2020-12-01 17:58:07 +11:00
parent da027f69d7
commit c9dbf04da3
18 changed files with 233 additions and 71 deletions
-35
View File
@@ -2,7 +2,6 @@ package yqlib
import (
"container/list"
"fmt"
"gopkg.in/yaml.v3"
)
@@ -20,14 +19,6 @@ func EmptyOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *Pat
return list.New(), nil
}
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
}
return d.GetMatchingNodes(lhs, pathNode.Rhs)
}
func createBooleanCandidate(owner *CandidateNode, value bool) *CandidateNode {
valString := "true"
if !value {
@@ -42,29 +33,3 @@ func nodeToMap(candidate *CandidateNode) *list.List {
elMap.PushBack(candidate)
return elMap
}
func LengthOperator(d *dataTreeNavigator, matchMap *list.List, pathNode *PathTreeNode) (*list.List, error) {
log.Debugf("-- lengthOperation")
var results = list.New()
for el := matchMap.Front(); el != nil; el = el.Next() {
candidate := el.Value.(*CandidateNode)
var length int
switch candidate.Node.Kind {
case yaml.ScalarNode:
length = len(candidate.Node.Value)
case yaml.MappingNode:
length = len(candidate.Node.Content) / 2
case yaml.SequenceNode:
length = len(candidate.Node.Content)
default:
length = 0
}
node := &yaml.Node{Kind: yaml.ScalarNode, Value: fmt.Sprintf("%v", length), Tag: "!!int"}
lengthCand := &CandidateNode{Node: node, Document: candidate.Document, Path: candidate.Path}
results.PushBack(lengthCand)
}
return results, nil
}