final class GrammarCompiler

Specializes grammar subtrees before making choices; every alternative retains its source production.

Methods§

public function __construct(private Grammar $grammar)

Keeps the dialect grammar immutable across different plans.

Parameters

$grammarGrammar
public function compile(string $root, array<string, RulePlan> $plans): PreparedGrammar
public function item(
    string $name,
    Production $production,
    non-empty-list<RulePlan>|null $items,
): RulePlan|false|null

Lists may recurse at either end; item order always means output order.

Parameters

$namestring
$productionProduction
$itemsnon-empty-list<RulePlan>|null

Returns

RulePlan|false|null
Test cases 2
Called from 1
Calls 1
public function hasChildren(
    Production $production,
    array<string, array<int, RulePlan>> $children,
): bool

Required child roles prune incompatible alternatives before generation.

Parameters

$productionProduction
$childrenarray<string, array<int, RulePlan>>

Returns

bool
Test cases 1
Called from 1
public function symbols(
    string $name,
    Production $production,
    Scope $scope,
    Scope $inner,
    non-empty-list<RulePlan>|null $items,
    array<string, array<int, RulePlan>> $children,
): list<Symbol>

Compiles list tails in the list scope and each item's fields in its own scope.

Parameters

$namestring
$productionProduction
$scopeScope
$innerScope
$itemsnon-empty-list<RulePlan>|null
$childrenarray<string, array<int, RulePlan>>

Returns

list<Symbol>

Throws

InvalidArgumentException When a recursive list tail has no items
Test cases 1
Called from 1
Calls 7

Private surface 5§

Implementation details, listed for orientation only.

private array<string, string> $names = []
private array<string, string> $aliases = []
private array<string, ProductionRule> $rules = []
private array<string, array<int, array<string, LexemeConstraint>>> $lexemes = []
private Grammar $grammar

Test cases 17§

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 4

Relations§

Instantiated in 1
Method calls 1