mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-06 18:24:57 +08:00
Generic ast (#1829)
Remove dependency on yaml.Node for internal AST representation. Yaml decoder is now just another decoder.
This commit is contained in:
@@ -3,8 +3,6 @@ package yqlib
|
||||
import (
|
||||
"container/list"
|
||||
"strconv"
|
||||
|
||||
yaml "gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func hasOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
|
||||
@@ -19,20 +17,18 @@ func hasOperator(d *dataTreeNavigator, context Context, expressionNode *Expressi
|
||||
}
|
||||
|
||||
wantedKey := "null"
|
||||
wanted := &yaml.Node{Tag: "!!null"}
|
||||
wanted := &CandidateNode{Tag: "!!null"}
|
||||
if rhs.MatchingNodes.Len() != 0 {
|
||||
wanted = rhs.MatchingNodes.Front().Value.(*CandidateNode).Node
|
||||
wanted = rhs.MatchingNodes.Front().Value.(*CandidateNode)
|
||||
wantedKey = wanted.Value
|
||||
}
|
||||
|
||||
for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {
|
||||
candidate := el.Value.(*CandidateNode)
|
||||
|
||||
// grab the first value
|
||||
candidateNode := unwrapDoc(candidate.Node)
|
||||
var contents = candidateNode.Content
|
||||
switch candidateNode.Kind {
|
||||
case yaml.MappingNode:
|
||||
var contents = candidate.Content
|
||||
switch candidate.Kind {
|
||||
case MappingNode:
|
||||
candidateHasKey := false
|
||||
for index := 0; index < len(contents) && !candidateHasKey; index = index + 2 {
|
||||
key := contents[index]
|
||||
@@ -41,7 +37,7 @@ func hasOperator(d *dataTreeNavigator, context Context, expressionNode *Expressi
|
||||
}
|
||||
}
|
||||
results.PushBack(createBooleanCandidate(candidate, candidateHasKey))
|
||||
case yaml.SequenceNode:
|
||||
case SequenceNode:
|
||||
candidateHasKey := false
|
||||
if wanted.Tag == "!!int" {
|
||||
var number, errParsingInt = strconv.ParseInt(wantedKey, 10, 64)
|
||||
|
||||
Reference in New Issue
Block a user