Generic ast (#1829)

Remove dependency on yaml.Node for internal AST representation. Yaml decoder is now just another decoder.
This commit is contained in:
Mike Farah
2023-10-18 12:11:53 +11:00
committed by GitHub
parent 7430419413
commit 13d1bbb45f
171 changed files with 6402 additions and 2421 deletions
+8 -11
View File
@@ -3,8 +3,6 @@ package yqlib
import (
"container/list"
"fmt"
yaml "gopkg.in/yaml.v3"
)
func reverseOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
@@ -13,19 +11,18 @@ func reverseOperator(d *dataTreeNavigator, context Context, expressionNode *Expr
for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {
candidate := el.Value.(*CandidateNode)
candidateNode := unwrapDoc(candidate.Node)
if candidateNode.Kind != yaml.SequenceNode {
return context, fmt.Errorf("node at path [%v] is not an array (it's a %v)", candidate.GetNicePath(), candidate.GetNiceTag())
if candidate.Kind != SequenceNode {
return context, fmt.Errorf("node at path [%v] is not an array (it's a %v)", candidate.GetNicePath(), candidate.Tag)
}
reverseList := &yaml.Node{Kind: yaml.SequenceNode, Tag: "!!seq", Style: candidateNode.Style}
reverseList.Content = make([]*yaml.Node, len(candidateNode.Content))
reverseList := candidate.CreateReplacementWithComments(SequenceNode, "!!seq", candidate.Style)
reverseContent := make([]*CandidateNode, len(candidate.Content))
for i, originalNode := range candidateNode.Content {
reverseList.Content[len(candidateNode.Content)-i-1] = originalNode
for i, originalNode := range candidate.Content {
reverseContent[len(candidate.Content)-i-1] = originalNode
}
results.PushBack(candidate.CreateReplacementWithDocWrappers(reverseList))
reverseList.AddChildren(reverseContent)
results.PushBack(reverseList)
}