mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 13:48:06 +00:00
29 lines
736 B
Go
29 lines
736 B
Go
package yqlib
|
|
|
|
import (
|
|
"container/list"
|
|
)
|
|
|
|
// corssFunction no matches
|
|
// can boolean use crossfunction
|
|
|
|
func alternativeOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) {
|
|
log.Debugf("-- alternative")
|
|
return crossFunction(d, matchingNodes, expressionNode, alternativeFunc)
|
|
}
|
|
|
|
func alternativeFunc(d *dataTreeNavigator, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) {
|
|
lhs.Node = unwrapDoc(lhs.Node)
|
|
rhs.Node = unwrapDoc(rhs.Node)
|
|
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
|
|
}
|