Class BooleanTruthGuard
- All Implemented Interfaces:
BiFunction<EK9Parser.PreFlowStatementContext, ISymbol, Optional<ISymbol>>
An if or else if head whose pre-flow is a declaration guard (<-) or an assign-if-unset
(:=?), and whose target's DECLARED type is exactly Boolean, enters only when the target is SET
AND TRUE. Every other guard enters when its target is set. So if ok <- check() skips the body when
check() returns false, exactly as a reader expects; before this rule a set false entered it.
Deliberately narrow:
- Only
if/else if(and theirwhenspelling). Aswitchkeeps enter-if-set, or itscase falsecould never be reached;while,do,forandtrykeep enter-if-set too. - Only
<-and:=?. A:=head is blind (no gate at all). - Only a target whose type IS
Boolean(by symbol identity,isExactSameType). A type that merely promotes to Boolean (#^) keeps enter-if-set; so does a generic'sT, whatever it is parameterised with, because the declared type isT.
Phase 7 adds the _true() test to the guard's gate (GuardedConditionEvaluator); phase 5 narrows the
target to true inside the body and does not narrow it to unset on the skip path (it may be false).
It answers with the guard's TARGET, given the pre-flow and the built-in Boolean type; the caller says, when it makes one, how it reads the symbol recorded against a parse tree node.
-
Constructor Summary
ConstructorsConstructorDescriptionBooleanTruthGuard(Function<org.antlr.v4.runtime.tree.ParseTree, ISymbol> recordedSymbol) The rule, reading recorded symbols the caller's way. -
Method Summary
Modifier and TypeMethodDescriptionapply(EK9Parser.PreFlowStatementContext preFlow, ISymbol ek9Boolean) The target of a Boolean truth guard, if this pre-flow is one.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface BiFunction
andThen
-
Constructor Details
-
BooleanTruthGuard
-
-
Method Details
-
apply
The target of a Boolean truth guard, if this pre-flow is one.- Specified by:
applyin interfaceBiFunction<EK9Parser.PreFlowStatementContext, ISymbol, Optional<ISymbol>>- Parameters:
preFlow- the pre-flow statement (may be null)ek9Boolean- the built-in Boolean type- Returns:
- the guard's target when the truth guard applies, otherwise empty
-