mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-05 17:36:59 +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"
|
||||
"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)
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user