final class TerminationAnalyzer
Restricted visibility: declared "@visibility root". Code outside that scope must not name this declaration.

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

$grammarGrammarGrammar whose rules are being costed
$terminalSupportedcallable(string): bool|nullAnswers whether a terminal can be written at all, or null when every terminal can
Test cases 1011
Calls 2
public function getMinLength(string $nonTerminal): int

Answers the fewest tokens a non-terminal can be finished in.

Parameters

$nonTerminalstringRule to measure

Returns

int Fewest tokens, or PHP_INT_MAX when it can never be finished
Test cases 7
Calls 1
public function estimateProductionLength(Production $production): int

Answers the fewest tokens a production can be finished in.

Parameters

$productionProductionProduction to measure

Returns

int Fewest tokens, or PHP_INT_MAX when it can never be finished
Test cases 1005
Called from 2
Calls 1
public function estimateProductionSteps(Production $production): int

Answers the fewest rule expansions a production can be finished in.

Parameters

$productionProductionProduction to measure

Returns

int Fewest expansions, or PHP_INT_MAX when it can never be finished
Test cases 253
Called from 3
Calls 1
public function isProductionViable(Production $production): bool

Reports 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

$productionProductionProduction to judge

Returns

bool True when some derivation of it ends in terminals
Test cases 999
Called from 1
Calls 1

Private surface 2§

Implementation details, listed for orientation only.

private TerminationCost $lengths
private TerminationCost $steps

Test cases 1041§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 15
Other tests reaching this symbol 1026

Relations§

Instantiated in 1
Method calls 5
Type declarations 2