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

Computes minimum expansion costs separately for empty and non-empty output.

Methods§

public function __construct(Grammar $grammar, private Closure(string): bool $nonOutput)
public function rule(string $name, bool $nonEmpty): int

Returns the minimum total expansions from a rule.

Parameters

$namestring
$nonEmptybool

Returns

int
Test cases 1
Calls 1
public function sequence(list<Symbol> $symbols): array{int, int}

Costs all children and pending siblings together, preserving nullability.

Parameters

$symbolslist<Symbol>

Returns

array{int, int}
Test cases 5
Called from 8
Calls 1
public function affordable(
    list<Production> $alternatives,
    list<Symbol> $remainder,
    bool $nonEmpty,
    int $budget,
): list<Production>

Applies the candidate policy shared by token generation and planning.

Parameters

$alternativeslist<Production>
$remainderlist<Symbol>
$nonEmptybool
$budgetint

Returns

Test cases 1
Called from 1
Calls 3
public static function combine(array{int, int} $left, array{int, int} $right): array{int, int}

Combines independent prefix and suffix costs, including their empty-output alternatives.

Parameters

$leftarray{int, int}
$rightarray{int, int}

Returns

array{int, int}
Test cases 12
Called from 4
Calls 2
public static function add(int $left, int $right): int

Adds finite costs without overflowing the unreachable sentinel.

Parameters

$leftint
$rightint

Returns

int
Test cases 12
Called from 7

Private surface 3§

Implementation details, listed for orientation only.

private array<string, array{int, int}> $costs
private array<string, array{int, int}> $terminalCosts = []
private Closure(string): bool $nonOutput

Test cases 64§

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

Dedicated tests 13
Other tests reaching this symbol 51

Relations§

Instantiated in 3
Static calls 4
Method calls 12
Type declarations 8