classTerminationAnalyzer
final class TerminationAnalyzer
Answers what it still costs to finish a rule or a production.
A derivation has to stop, and to stop it has to know which way out is shortest. Two measures of "shortest" matter: how many tokens will be written, which decides how long the SQL gets, and how many rules will be expanded, which decides whether the walk fits in its step budget. Both are asked of the same grammar, so both are answered here.
Methods§
public function __construct(
Grammar $grammar,
callable(string): bool|null $terminalSupported = null,
)Parameters
$grammar | Grammar | Grammar whose rules are being costed |
$terminalSupported | callable(string): bool|null | Answers whether a terminal can be written at all, or null when every terminal can |
Calls 2
- static-call
Closure::fromCallable()line 35 - new TerminationCost line 37
public function getMinLength(string $nonTerminal): intAnswers the fewest tokens a non-terminal can be finished in.
Parameters
$nonTerminal | string | Rule to measure |
Returns
int Fewest tokens, or PHP_INT_MAX when it can never be finishedTest cases 7
TerminationAnalyzerTest::testComputesAViewThatExcludesUnsupportedTerminalscallsTerminationAnalyzerTest::testGetMinLengthChoosesShortestAlternativecallsTerminationAnalyzerTest::testGetMinLengthEmptyProductioncallsTerminationAnalyzerTest::testGetMinLengthNestedRulescallsTerminationAnalyzerTest::testGetMinLengthTerminalOnlycallsTerminationAnalyzerTest::testPropagatesLexicalImpossibilityThroughNonTerminalscallsTerminationAnalyzerTest::testTreatsUnknownSupportedNonTerminalAsOneTokencalls
Called from 1
Calls 1
- method-call TerminationCost::of() line 50
public function estimateProductionLength(Production $production): intAnswers the fewest tokens a production can be finished in.
Parameters
$production | Production | Production to measure |
Returns
int Fewest tokens, or PHP_INT_MAX when it can never be finishedTest cases 6
TerminationAnalyzerTest::testEstimateProductionLengthEmptycallsTerminationAnalyzerTest::testEstimateProductionLengthMixedcallsTerminationAnalyzerTest::testEstimateProductionLengthNonTerminalscallsTerminationAnalyzerTest::testEstimateProductionLengthTerminalscallsTerminationAnalyzerTest::testEstimateProductionStepsBreaksARecursiveLengthTiecallsTerminationAnalyzerTest::testTreatsUnknownSupportedNonTerminalAsOneTokencalls
Called from 2
Calls 1
- method-call TerminationCost::ofProduction() line 62
public function estimateProductionSteps(Production $production): intAnswers the fewest rule expansions a production can be finished in.
Parameters
$production | Production | Production to measure |
Returns
int Fewest expansions, or PHP_INT_MAX when it can never be finishedTest cases 3
Called from 3
- method-call SqlFaker\Generation\Derivation\Derivation::affordable() packages/sql-faker/src/Generation/Derivation/Derivation.php:142
- method-call SqlFaker\Generation\Derivation\Derivation::affordable() packages/sql-faker/src/Generation/Derivation/Derivation.php:149
- method-call SqlFaker\Generation\Derivation\Derivation::selectProduction() packages/sql-faker/src/Generation/Derivation/Derivation.php:185
Calls 1
- method-call TerminationCost::ofProduction() line 74
public function isProductionViable(Production $production): boolReports whether a production can be finished at all.
A production whose shortest completion is unbounded contains a rule that can only expand into itself, so a walk that took it would never arrive at terminals.
Parameters
$production | Production | Production to judge |
Returns
bool True when some derivation of it ends in terminalsTest cases 3
Called from 1
Calls 1
Private surface 2§
Implementation details, listed for orientation only.
private TerminationCost $lengthsprivate TerminationCost $stepsTest cases 55§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 15
TerminationAnalyzerTest::testComputesAViewThatExcludesUnsupportedTerminalscallsTerminationAnalyzerTest::testEstimateProductionLengthEmptycallsTerminationAnalyzerTest::testEstimateProductionLengthMixedcallsTerminationAnalyzerTest::testEstimateProductionLengthNonTerminalscallsTerminationAnalyzerTest::testEstimateProductionLengthTerminalscallsTerminationAnalyzerTest::testEstimateProductionStepsBreaksARecursiveLengthTiecallsTerminationAnalyzerTest::testEstimateProductionStepsRejectsUnsupportedTerminalcallsTerminationAnalyzerTest::testGetMinLengthChoosesShortestAlternativecallsTerminationAnalyzerTest::testGetMinLengthEmptyProductioncallsTerminationAnalyzerTest::testGetMinLengthNestedRulescallsTerminationAnalyzerTest::testGetMinLengthTerminalOnlycallsTerminationAnalyzerTest::testIsProductionViableAcceptsAProductionSomeDerivationFinishescallsTerminationAnalyzerTest::testIsProductionViableRejectsAProductionThatCanNeverBeFinishedcallsTerminationAnalyzerTest::testPropagatesLexicalImpossibilityThroughNonTerminalscallsTerminationAnalyzerTest::testTreatsUnknownSupportedNonTerminalAsOneTokencalls
Other tests reaching this symbol 40
BytePlanCompilerTestcallsBytePlanEncoderTestcallsPlanBuilderTestcallsDerivationTest::testAffordableAcceptsAnAlternativeThatExactlyUsesTheBudgetcallsDerivationTest::testAffordableAllowsATerminalOnlyProductionWithNoExpansionBudgetLeftcallsDerivationTest::testAffordableCompletionRetainsOnlyProductionsWithAnAffordableNonEmptyContinuationcallsDerivationTest::testAffordableKeepsAnAlternativeThatStillLeavesRoomToFinishcallsDerivationTest::testAffordableRejectsAnAlternativeThatCannotFitAfterTheRemaindercallsDerivationTest::testAffordableRejectsARemainderThatExceedsTheWholeBudgetcallsDerivationTest::testAffordableReturnsAListAfterDiscardingAnOverBudgetAlternativecallsDerivationTest::testAlternativesRespectsTheOccurrenceAndRejectsUnrealizableProductionscallsDerivationTest::testCompletableKeepsAnEmptyAlternativeWhenTheRemainingSiblingSatisfiesNonEmptycallsDerivationTest::testFirstNonTerminalAnswersNothingWhenOnlyTerminalsAreLeftcallsDerivationTest::testFirstNonTerminalAnswersTheLeftmostPositionTheWalkActsOncallsDerivationTest::testOfCountsOccurrencesAcrossSpecializedCopiesOfTheSameRulecallsDerivationTest::testOfOffersTheCandidatesToTheChoicePolicycallsDerivationTest::testOfReportsAPlanNoAlternativeCanSatisfycallsDerivationTest::testOfReportsASymbolTheGrammarDeclaresNoRuleForcallsDerivationTest::testOfRewritesTheStartSymbolUntilOnlyTerminalsAreLeftcallsDerivationTest::testOfSelectsTerminationPolicyFromThePlancallsDerivationTest::testOfStillRejectsAnEntirelyForcedPlanWhoseDescendantCannotSatisfyNonEmptycallsDerivationTest::testSelectProductionChoosesFreelyWhileThePlanStillAllowsDepthcallsDerivationTest::testSelectProductionDrawsUniformlyAmongTheEligibleAlternativesBeforeTheThresholdcallsDerivationTest::testSelectProductionTakesTheShortestAlternativeOncePastThePlanDepthcallsDerivationTraceTestcallsTokenGeneratorTestcallsLexemeSequenceTestcallsCandidateResolverTestcallsGrammarCompilerTestcallsSqlGeneratorTestcallsTerminalSequenceTestcallsGenerationContextTestcallsSqlGeneratorFactoryTestcallsMySqlProviderTestcallsGenerationContextTestcallsSqlGeneratorFactoryTestcallsPostgreSqlProviderTestcallsGenerationContextTestcallsSqlGeneratorFactoryTestcallsSqliteProviderTestcalls
Relations§
Instantiated in 2
Method calls 6
- method-call SqlFaker\Generation\Derivation\Derivation::affordable() packages/sql-faker/src/Generation/Derivation/Derivation.php:142
- method-call SqlFaker\Generation\Derivation\Derivation::affordable() packages/sql-faker/src/Generation/Derivation/Derivation.php:149
- method-call SqlFaker\Generation\Derivation\Derivation::selectProduction() packages/sql-faker/src/Generation/Derivation/Derivation.php:185
- method-call SqlFaker\Generation\Derivation\Derivation::selectProduction() packages/sql-faker/src/Generation/Derivation/Derivation.php:186
- method-call SqlFaker\Generation\Derivation\Derivation::alternatives() packages/sql-faker/src/Generation/Derivation/Derivation.php:212
- method-call SqlFaker\Generation\Plan\Compilation\GrammarCompiler::compile() packages/sql-faker/src/Generation/Plan/Compilation/GrammarCompiler.php:49