classGrammarCompiler
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
$grammar | Grammar |
public function compile(string $root, array<string, RulePlan> $plans): PreparedGrammarParameters
$root | string | |
$plans | array<string, RulePlan> |
Returns
Throws
InvalidArgumentException When a declaration names an unknown ruleGenerationException When no finite derivation satisfies the conditionsTest cases 9
GrammarCompilerTest::testCompileAppliesProductionConditionsToEachListItemcallsGrammarCompilerTest::testCompileContradictoryProductionConditionsAreRejectedcallsGrammarCompilerTest::testCompileListItemsPreserveOutputOrderForBothRecursionDirectionscallsGrammarCompilerTest::testHasChildrenConditionsPruneIncompatibleProductionscallsGrammarCompilerTest::testRuleMemoizesRecursiveScopesBeforeWalkingTheirChildrencallsGrammarCompilerTest::testSymbolsApplyChildConditionsToARecursiveListTailcallsGrammarCompilerTest::testSymbolsKeepInfeasibleBranchesFromInvalidatingOtherAlternativescallsGrammarCompilerTest::testSymbolsPreserveInheritedRulesWhenSelectingAnOperandcallsGrammarCompilerTest::testValidateAcceptsNestedChildAndListDeclarationscalls
Called from 1
Calls 8
- method-call GrammarCompiler::validate() line 46
- method-call GrammarCompiler::rule() line 47
- new Scope line 47
- new Grammar line 48
- method-call TerminationAnalyzer::getMinLength() line 49
- new TerminationAnalyzer line 49
- static-call GenerationException::noAlternativeMatchingPlan() line 50
- new PreparedGrammar line 52
public function validate(array<string, RulePlan> $plans): voidChecks all declarations, including conditionally visited branches.
Parameters
$plans | array<string, RulePlan> |
Throws
InvalidArgumentException When a planned rule is absent from this grammarTest cases 1
Called from 4
- method-call SqlFaker\Generation\Plan\Compilation\GrammarCompiler::compile() packages/sql-faker/src/Generation/Plan/Compilation/GrammarCompiler.php:46
- method-call SqlFaker\Generation\Plan\Compilation\GrammarCompiler::validate() packages/sql-faker/src/Generation/Plan/Compilation/GrammarCompiler.php:66
- method-call SqlFaker\Generation\Plan\Compilation\GrammarCompiler::validate() packages/sql-faker/src/Generation/Plan/Compilation/GrammarCompiler.php:69
- method-call SqlFaker\Generation\Plan\Compilation\GrammarCompiler::validate() packages/sql-faker/src/Generation/Plan/Compilation/GrammarCompiler.php:73
Calls 2
- new
InvalidArgumentExceptionline 64 - method-call GrammarCompiler::validate() line 66
public function rule(
string $name,
Scope $scope,
non-empty-list<RulePlan>|null $items = null,
): stringMemoizes recursive scopes before visiting their descendants.
Parameters
Returns
stringTest cases 2
Called from 3
- method-call SqlFaker\Generation\Plan\Compilation\GrammarCompiler::compile() packages/sql-faker/src/Generation/Plan/Compilation/GrammarCompiler.php:47
- method-call SqlFaker\Generation\Plan\Compilation\GrammarCompiler::symbols() packages/sql-faker/src/Generation/Plan/Compilation/GrammarCompiler.php:193
- method-call SqlFaker\Generation\Plan\Compilation\GrammarCompiler::symbols() packages/sql-faker/src/Generation/Plan/Compilation/GrammarCompiler.php:196
Calls 10
- static-call RulePlan::any() line 84
- function-call
serializeline 87 - function-call
countline 91 - new ProductionRule line 94
- function-call
array_mapline 97 - method-call Symbol::value() line 97
- method-call GrammarCompiler::item() line 101
- method-call GrammarCompiler::hasChildren() line 106
- method-call GrammarCompiler::symbols() line 110
- new Production line 112
public function item(
string $name,
Production $production,
non-empty-list<RulePlan>|null $items,
): RulePlan|false|nullLists may recurse at either end; item order always means output order.
Parameters
$name | string | |
$production | Production | |
$items | non-empty-list<RulePlan>|null |
Returns
RulePlan|false|nullTest cases 2
Called from 1
Calls 1
- function-call
countline 133
public function hasChildren(
Production $production,
array<string, array<int, RulePlan>> $children,
): boolRequired child roles prune incompatible alternatives before generation.
Parameters
$production | Production | |
$children | array<string, array<int, RulePlan>> |
Returns
boolpublic 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
$name | string | |
$production | Production | |
$scope | Scope | |
$inner | Scope | |
$items | non-empty-list<RulePlan>|null | |
$children | array<string, array<int, RulePlan>> |
Returns
list<Symbol>Throws
InvalidArgumentException When a recursive list tail has no itemsCalled from 1
Calls 7
- function-call
countline 187 - function-call
array_sliceline 188 - new
InvalidArgumentExceptionline 190 - new Scope line 192
- function-call
array_replaceline 192 - new NonTerminal line 193
- method-call GrammarCompiler::rule() line 193
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 $grammarTest cases 17§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 13
GrammarCompilerTest::testCompileAppliesProductionConditionsToEachListItemcallsGrammarCompilerTest::testCompileContradictoryProductionConditionsAreRejectedcallsGrammarCompilerTest::testCompileListItemsPreserveOutputOrderForBothRecursionDirectionscallsGrammarCompilerTest::testHasChildrenConditionsPruneIncompatibleProductionscallsGrammarCompilerTest::testHasChildrenRejectsARequiredRoleAbsentFromTheProductioncallsGrammarCompilerTest::testItemRejectsNullableAndBranchingRecursionForOrderedListscallsGrammarCompilerTest::testItemSupportsUnseparatedListsButRejectsRecursionBetweenFieldscallsGrammarCompilerTest::testRuleDoesNotShareACompiledSubtreeBetweenDifferentLexicalScopescallsGrammarCompilerTest::testRuleMemoizesRecursiveScopesBeforeWalkingTheirChildrencallsGrammarCompilerTest::testSymbolsApplyChildConditionsToARecursiveListTailcallsGrammarCompilerTest::testSymbolsKeepInfeasibleBranchesFromInvalidatingOtherAlternativescallsGrammarCompilerTest::testSymbolsPreserveInheritedRulesWhenSelectingAnOperandcallsGrammarCompilerTest::testValidateAcceptsNestedChildAndListDeclarationscalls
Other tests reaching this symbol 4
PlanBuilderTestcallsTokenGeneratorTestcallsMySqlProviderTestcallsPostgreSqlProviderTestcalls