final class BytePlanEncoder

Records the decisions of one guided plan construction as the bytes BytePlanCompiler decodes to the same plan.

Methods§

public function encode(
    PlanBuilder $builder,
    GenerationPlan<bool>|null $constraints,
    int $budget,
    Closure(int, non-empty-list<Production>): int $productionChoice,
    Closure(int): ?int|null $lexicalChoice = null,
): string

Runs the builder once with the caller's choices and writes the header, production and lexical bytes the compiler reads. Lexical choices end at the first null answer; the compiler makes the remaining ones from the padding bytes. The constraints must be ones the compiler accepts.

Parameters

$builderPlanBuilder
$constraintsGenerationPlan<bool>|null
$budgetint
$productionChoiceClosure(int, non-empty-list<Production>): intSelects one candidate at every expansion
$lexicalChoiceClosure(int): ?int|nullSelects lexical candidates until it answers null

Returns

string

Throws

InvalidArgumentException When the budget lies outside the range the compiler decodes for these constraints
Test cases 4
Calls 8
public static function interleave(string $structure, string $lexical): string

Pairs production bytes with lexical bytes the way the compiler splits them, padding the shorter stream with zero.

Parameters

$structurestring
$lexicalstring

Returns

string
Test cases 1
Called from 1
Calls 3

Test cases 5§

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

Dedicated tests 5