yq/pkg/yqlib/operator_kind.go

35 lines
703 B
Go
Raw Normal View History

2023-10-02 03:43:12 +00:00
package yqlib
import (
"container/list"
)
func kindToText(kind Kind) string {
2023-10-02 03:43:12 +00:00
switch kind {
case MappingNode:
2023-10-02 03:43:12 +00:00
return "map"
case SequenceNode:
2023-10-02 03:43:12 +00:00
return "seq"
case ScalarNode:
2023-10-02 03:43:12 +00:00
return "scalar"
case AliasNode:
2023-10-02 03:43:12 +00:00
return "alias"
default:
return "unknown"
}
}
2024-01-11 02:17:34 +00:00
func getKindOperator(_ *dataTreeNavigator, context Context, _ *ExpressionNode) (Context, error) {
2023-10-02 03:43:12 +00:00
log.Debugf("GetKindOperator")
var results = list.New()
for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {
candidate := el.Value.(*CandidateNode)
result := candidate.CreateReplacement(ScalarNode, "!!str", kindToText(candidate.Kind))
2023-10-02 03:43:12 +00:00
results.PushBack(result)
}
return context.ChildContext(results), nil
}