yq/pkg/yqlib/operator_kind.go

35 lines
716 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"
}
}
func getKindOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
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
}