yq/pkg/yqlib/operator_alternative.go

29 lines
736 B
Go
Raw Normal View History

2020-12-21 00:32:34 +00:00
package yqlib
import (
"container/list"
)
// corssFunction no matches
// can boolean use crossfunction
2021-01-12 23:18:53 +00:00
func alternativeOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) {
2020-12-21 00:32:34 +00:00
log.Debugf("-- alternative")
2021-01-12 23:18:53 +00:00
return crossFunction(d, matchingNodes, expressionNode, alternativeFunc)
2020-12-21 00:32:34 +00:00
}
func alternativeFunc(d *dataTreeNavigator, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) {
2021-01-12 23:00:51 +00:00
lhs.Node = unwrapDoc(lhs.Node)
rhs.Node = unwrapDoc(rhs.Node)
2020-12-21 00:32:34 +00:00
log.Debugf("Alternative LHS: %v", lhs.Node.Tag)
log.Debugf("- RHS: %v", rhs.Node.Tag)
isTrue, err := isTruthy(lhs)
if err != nil {
return nil, err
} else if isTrue {
return lhs, nil
}
return rhs, nil
}