2023-10-02 03:43:12 +00:00
|
|
|
package yqlib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"container/list"
|
|
|
|
)
|
|
|
|
|
2023-10-18 01:11:53 +00:00
|
|
|
func kindToText(kind Kind) string {
|
2023-10-02 03:43:12 +00:00
|
|
|
switch kind {
|
2023-10-18 01:11:53 +00:00
|
|
|
case MappingNode:
|
2023-10-02 03:43:12 +00:00
|
|
|
return "map"
|
2023-10-18 01:11:53 +00:00
|
|
|
case SequenceNode:
|
2023-10-02 03:43:12 +00:00
|
|
|
return "seq"
|
2023-10-18 01:11:53 +00:00
|
|
|
case ScalarNode:
|
2023-10-02 03:43:12 +00:00
|
|
|
return "scalar"
|
2023-10-18 01:11:53 +00:00
|
|
|
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)
|
2023-10-18 01:11:53 +00:00
|
|
|
result := candidate.CreateReplacement(ScalarNode, "!!str", kindToText(candidate.Kind))
|
2023-10-02 03:43:12 +00:00
|
|
|
results.PushBack(result)
|
|
|
|
}
|
|
|
|
|
|
|
|
return context.ChildContext(results), nil
|
|
|
|
}
|