HasOptionalOutput returns whether the rule returns a concrete or optional value. The rule may return an optional value if all match expressions under the rule are conditional.
()
| 69 | // HasOptionalOutput returns whether the rule returns a concrete or optional value. |
| 70 | // The rule may return an optional value if all match expressions under the rule are conditional. |
| 71 | func (r *CompiledRule) HasOptionalOutput() bool { |
| 72 | optionalOutput := false |
| 73 | for _, m := range r.Matches() { |
| 74 | if m.NestedRule() != nil && m.NestedRule().HasOptionalOutput() { |
| 75 | // If the nested rule is unconditional, the matching may fallthrough to the next match |
| 76 | // in this context (unwrapping the optional value from the nested rule). |
| 77 | if !m.ConditionIsLiteral(types.True) { |
| 78 | return true |
| 79 | } |
| 80 | optionalOutput = true |
| 81 | } else if m.ConditionIsLiteral(types.True) { |
| 82 | return false |
| 83 | } else { |
| 84 | optionalOutput = true |
| 85 | } |
| 86 | } |
| 87 | return optionalOutput |
| 88 | } |
| 89 | |
| 90 | // CompiledVariable represents the variable name, expression, and associated type-check declaration. |
| 91 | type CompiledVariable struct { |