2022-02-22 03:15:31 +00:00
|
|
|
package yqlib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"container/list"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
func reverseOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
|
|
|
|
results := list.New()
|
|
|
|
|
|
|
|
for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {
|
|
|
|
candidate := el.Value.(*CandidateNode)
|
|
|
|
|
2023-10-18 01:11:53 +00:00
|
|
|
if candidate.Kind != SequenceNode {
|
|
|
|
return context, fmt.Errorf("node at path [%v] is not an array (it's a %v)", candidate.GetNicePath(), candidate.Tag)
|
2022-02-22 03:15:31 +00:00
|
|
|
}
|
|
|
|
|
2023-10-18 01:11:53 +00:00
|
|
|
reverseList := candidate.CreateReplacementWithComments(SequenceNode, "!!seq", candidate.Style)
|
|
|
|
reverseContent := make([]*CandidateNode, len(candidate.Content))
|
2022-02-22 03:15:31 +00:00
|
|
|
|
2023-10-18 01:11:53 +00:00
|
|
|
for i, originalNode := range candidate.Content {
|
|
|
|
reverseContent[len(candidate.Content)-i-1] = originalNode
|
2022-02-22 03:15:31 +00:00
|
|
|
}
|
2023-10-18 01:11:53 +00:00
|
|
|
reverseList.AddChildren(reverseContent)
|
|
|
|
results.PushBack(reverseList)
|
2022-02-22 03:15:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return context.ChildContext(results), nil
|
|
|
|
|
|
|
|
}
|