2020-12-21 00:32:34 +00:00
|
|
|
package yqlib
|
|
|
|
|
2021-02-02 07:17:59 +00:00
|
|
|
func alternativeOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
|
2020-12-21 00:32:34 +00:00
|
|
|
log.Debugf("-- alternative")
|
2021-09-02 05:36:23 +00:00
|
|
|
return crossFunction(d, context, expressionNode, alternativeFunc, true)
|
2020-12-21 00:32:34 +00:00
|
|
|
}
|
|
|
|
|
2021-02-02 07:17:59 +00:00
|
|
|
func alternativeFunc(d *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) {
|
2021-04-13 00:42:20 +00:00
|
|
|
if lhs == nil {
|
|
|
|
return rhs, nil
|
|
|
|
}
|
2021-06-09 23:35:07 +00:00
|
|
|
if rhs == nil {
|
|
|
|
return lhs, nil
|
|
|
|
}
|
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
|
|
|
|
}
|