classSqlGenerator
final class SqlGenerator
Derives terminals, rewrites structural constraints, and realizes lexemes once. Dialect definitions supply the syntax and boundary rules; no completed SQL is retried or repaired.
Properties§
public ?TerminalSequence $lastSequence = nullThe latest terminal sequence retains both the original grammar choices and their rewrites.
public ?ResolvedOutput $lastOutput = nullSelected lexical candidates and resolved boundary rules from the latest generation.
Methods§
public function __construct(
private Grammar $grammar,
private Generator $faker,
private LexicalGrammar $lexicalGrammar,
private ?TokenRewriter $rewriter = null,
private Closure(string|null): string|null $startSymbol = null,
private ?GrammarCoverage $coverage = null,
?Grammar $original = null,
)Binds grammar, lexical definitions and structural rules before generation starts.
Parameters
$grammar | Grammar | |
$faker | Generator | |
$lexicalGrammar | LexicalGrammar | |
$rewriter | ?TokenRewriter | |
$startSymbol | Closure(string|null): string|null | Resolves explicitly requested release aliases |
$coverage | ?GrammarCoverage | |
$original | ?Grammar |
Calls 3
- new GrammarCoverageInventory line 58
- method-call LexicalGrammar::version() line 58
- static-call GeneratorRevision::current() line 58
public function planner(): PlanBuilderReuses the same grammar, rewrite rules and lexical definitions to compile plans.
Returns
Called from 3
- method-call SqlFaker\MySql\MySqlProvider::planner() packages/sql-faker/src/MySql/MySqlProvider.php:86
- method-call SqlFaker\PostgreSql\PostgreSqlProvider::planner() packages/sql-faker/src/PostgreSql/PostgreSqlProvider.php:72
- method-call SqlFaker\Sqlite\SqliteProvider::planner() packages/sql-faker/src/Sqlite/SqliteProvider.php:72
Calls 1
- new PlanBuilder line 66
public function generate<TRequiresNonEmpty of bool>(GenerationPlan<TRequiresNonEmpty> $plan): (TRequiresNonEmpty is true ? non-empty-string : string)Generates once through the declared stages; candidate absence remains an error.
Parameters
$plan | GenerationPlan<TRequiresNonEmpty> |
Returns
(TRequiresNonEmpty is true ? non-empty-string : string)Throws
GenerationException When the grammar or plan cannot produce the requested outputLexicalException When no applicable lexical realization existsTest cases 33
Bench::benchSqlGenerationcallsPlanBuilderTest::testBuildFreezesScopedValuesAndDefaultsWhenChoiceBytesRunOutcallsPlanBuilderTest::testBuildReservesAllPendingSiblingsAndRetainsTheOriginalOrdinalcallsPlanBuilderTest::testBuildUsesTheSameContextualRewriteAndPinsItsCompleteCandidatecallsPlanBuilderTest::testMinimumExpansionsIncludesTheConstrainedDescendantBeforeDrawingTheBudgetcallsPlanBuilderTest::testMinimumExpansionsIncludesTheSelectedRootAlternativeBeforeAllocatingInputBudgetcallsSqlGeneratorTest::testGenerateAllowsEmptyOutputWhenThePlanAllowsItcallsSqlGeneratorTest::testGenerateClearsPreviousGrammarTraceBeforeALexicalPlancallsSqlGeneratorTest::testGenerateClosesCoverageAfterARejectedEmptyLexicalResultcallsSqlGeneratorTest::testGenerateKeepsRewrittenSourcesReachedWithoutCreditingTheirOutputcallsSqlGeneratorTest::testGenerateLexicalPlansBypassGrammarDerivationcallsSqlGeneratorTest::testGeneratePreservesTheFirstLexicalFailureWithoutRetryingcallsSqlGeneratorTest::testGenerateRecordsACompleteCoverageObservationcallsSqlGeneratorTest::testGenerateRejectsUnexpectedEmptyOutputWithoutRetryingcallsSqlGeneratorTest::testGenerateReplacesGrammarCoverageWithTheLatestLexicalTracecallsSqlGeneratorTest::testGenerateReportsOnlyTheLatestRewrittenDerivationcallsSqlGeneratorTest::testGenerateReusesCompletionAnalysisAcrossDifferentPlanscallsSqlGeneratorTest::testGenerateUsesExplicitRulesAndSuppliedParserSemanticscallsSqlGeneratorTest::testGenerateUsesTheGrammarEntryPointWithoutDialectKnowledgecallsSqlGeneratorTest::testGenerateUsesTheSuppliedVersionSpecificRuleResolvercallsSqlGeneratorTest::testPlannerBindsTheSameGrammarEntryAndFreezesEveryChoicecallsGenerationContextTest::testLeavesThePlanInControlOfNullableProductionChoicescallsGenerationContextTest::testReportsAnUnknownNonterminalWithoutTreatingItAsSqlTextcallsGenerationContextTest::testReportsMissingLexicalImplementationWhenTheTerminalIsActuallyGeneratedcallsGenerationContextTest::testUsesTheGrammarStartWhenThePlanDoesNotSpecifyOnecallsGenerationContextTest::testLeavesThePlanInControlOfNullableProductionChoicescallsGenerationContextTest::testReportsAnUnknownNonterminalWithoutTreatingItAsSqlTextcallsGenerationContextTest::testReportsMissingLexicalImplementationWhenTheTerminalIsActuallyGeneratedcallsGenerationContextTest::testUsesTheGrammarStartWhenThePlanDoesNotSpecifyOnecallsGenerationContextTest::testLeavesThePlanInControlOfNullableProductionChoicescallsGenerationContextTest::testReportsAnUnknownNonterminalWithoutTreatingItAsSqlTextcallsGenerationContextTest::testReportsMissingLexicalImplementationWhenTheTerminalIsActuallyGeneratedcallsGenerationContextTest::testUsesTheGrammarStartWhenThePlanDoesNotSpecifyOnecalls
Called from 3
- method-call SqlFaker\MySql\MySqlProvider::generate() packages/sql-faker/src/MySql/MySqlProvider.php:106
- method-call SqlFaker\PostgreSql\PostgreSqlProvider::generate() packages/sql-faker/src/PostgreSql/PostgreSqlProvider.php:92
- method-call SqlFaker\Sqlite\SqliteProvider::generate() packages/sql-faker/src/Sqlite/SqliteProvider.php:92
Calls 11
- method-call GenerationPlan::startRule() line 81
- method-call GenerationPlan::expansionBudget() line 83
- method-call GenerationPlan::lexicalTarget() line 83
- method-call LexicalGrammar::generate() line 87
- method-call SqlGenerator::realize() line 87
- method-call GenerationPlan::requiresNonEmpty() line 88
- static-call GenerationException::planRequiresNonEmptyOutput() line 89
- method-call LexicalGrammar::version() line 89
- function-call
hashline 92 - method-call SequenceObservation::preserved() line 93
- new SequenceObservation line 93
public function realize(string $root, GenerationPlan<bool> $plan): stringDerives and realizes once, retaining source selection independently of transformed output.
Parameters
$root | string | |
$plan | GenerationPlan<bool> |
Returns
stringThrows
GenerationException When derivation cannot completeLexicalException When a terminal has no compatible realizationTest cases 2
Called from 1
Calls 6
- new TokenGenerator line 109
- method-call LexicalGrammar::isNonOutput() line 109
- method-call
Generator::numberBetween()line 113 - method-call LexicalGrammar::resolveSequence() line 114
- method-call SqlSerializer::serialize() line 116
- new SqlSerializer line 116
Private surface 7§
Implementation details, listed for orientation only.
private ?TokenGenerator $tokens = nullprivate Grammar $grammarprivate Generator $fakerprivate LexicalGrammar $lexicalGrammarprivate ?TokenRewriter $rewriter = nullprivate Closure(string|null): string|null $startSymbol = nullprivate ?GrammarCoverage $coverage = nullTest cases 42§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 17
SqlGeneratorTest::testGenerateAllowsEmptyOutputWhenThePlanAllowsItcallsSqlGeneratorTest::testGenerateClearsPreviousGrammarTraceBeforeALexicalPlancallsSqlGeneratorTest::testGenerateClosesCoverageAfterARejectedEmptyLexicalResultcallsSqlGeneratorTest::testGenerateKeepsRewrittenSourcesReachedWithoutCreditingTheirOutputcallsSqlGeneratorTest::testGenerateLexicalPlansBypassGrammarDerivationcallsSqlGeneratorTest::testGeneratePreservesTheFirstLexicalFailureWithoutRetryingcallsSqlGeneratorTest::testGenerateRecordsACompleteCoverageObservationcallsSqlGeneratorTest::testGenerateRejectsUnexpectedEmptyOutputWithoutRetryingcallsSqlGeneratorTest::testGenerateReplacesGrammarCoverageWithTheLatestLexicalTracecallsSqlGeneratorTest::testGenerateReportsOnlyTheLatestRewrittenDerivationcallsSqlGeneratorTest::testGenerateReusesCompletionAnalysisAcrossDifferentPlanscallsSqlGeneratorTest::testGenerateUsesExplicitRulesAndSuppliedParserSemanticscallsSqlGeneratorTest::testGenerateUsesTheGrammarEntryPointWithoutDialectKnowledgecallsSqlGeneratorTest::testGenerateUsesTheSuppliedVersionSpecificRuleResolvercallsSqlGeneratorTest::testPlannerBindsTheSameGrammarEntryAndFreezesEveryChoicecallsSqlGeneratorTest::testRealizeOffersTheWholeZeroBasedCandidateRangecallsSqlGeneratorTest::testRealizeRetainsTheActualTerminalAndLexicalTracecalls
Other tests reaching this symbol 25
Bench::benchSqlGenerationcallsBench::setUpcallsPlanBuilderTest::testBuildFreezesScopedValuesAndDefaultsWhenChoiceBytesRunOutcallsPlanBuilderTest::testBuildReservesAllPendingSiblingsAndRetainsTheOriginalOrdinalcallsPlanBuilderTest::testBuildUsesTheSameContextualRewriteAndPinsItsCompleteCandidatecallsPlanBuilderTest::testMinimumExpansionsIncludesTheConstrainedDescendantBeforeDrawingTheBudgetcallsPlanBuilderTest::testMinimumExpansionsIncludesTheSelectedRootAlternativeBeforeAllocatingInputBudgetcallsGenerationContextTest::testLeavesThePlanInControlOfNullableProductionChoicescallsGenerationContextTest::testReportsAnUnknownNonterminalWithoutTreatingItAsSqlTextcallsGenerationContextTest::testReportsMissingLexicalImplementationWhenTheTerminalIsActuallyGeneratedcallsGenerationContextTest::testUsesTheGrammarStartWhenThePlanDoesNotSpecifyOnecallsSqlGeneratorFactoryTestcallsMySqlProviderTestcallsGenerationContextTest::testLeavesThePlanInControlOfNullableProductionChoicescallsGenerationContextTest::testReportsAnUnknownNonterminalWithoutTreatingItAsSqlTextcallsGenerationContextTest::testReportsMissingLexicalImplementationWhenTheTerminalIsActuallyGeneratedcallsGenerationContextTest::testUsesTheGrammarStartWhenThePlanDoesNotSpecifyOnecallsSqlGeneratorFactoryTestcallsPostgreSqlProviderTestcallsGenerationContextTest::testLeavesThePlanInControlOfNullableProductionChoicescallsGenerationContextTest::testReportsAnUnknownNonterminalWithoutTreatingItAsSqlTextcallsGenerationContextTest::testReportsMissingLexicalImplementationWhenTheTerminalIsActuallyGeneratedcallsGenerationContextTest::testUsesTheGrammarStartWhenThePlanDoesNotSpecifyOnecallsSqlGeneratorFactoryTestcallsSqliteProviderTestcalls
Relations§
Instantiated in 3
- new SqlFaker\MySql\Generation\SqlGeneratorFactory::create() packages/sql-faker/src/MySql/Generation/SqlGeneratorFactory.php:27
- new SqlFaker\PostgreSql\Generation\SqlGeneratorFactory::create() packages/sql-faker/src/PostgreSql/Generation/SqlGeneratorFactory.php:27
- new SqlFaker\Sqlite\Generation\SqlGeneratorFactory::create() packages/sql-faker/src/Sqlite/Generation/SqlGeneratorFactory.php:27
Method calls 6
- method-call SqlFaker\MySql\MySqlProvider::planner() packages/sql-faker/src/MySql/MySqlProvider.php:86
- method-call SqlFaker\MySql\MySqlProvider::generate() packages/sql-faker/src/MySql/MySqlProvider.php:106
- method-call SqlFaker\PostgreSql\PostgreSqlProvider::planner() packages/sql-faker/src/PostgreSql/PostgreSqlProvider.php:72
- method-call SqlFaker\PostgreSql\PostgreSqlProvider::generate() packages/sql-faker/src/PostgreSql/PostgreSqlProvider.php:92
- method-call SqlFaker\Sqlite\SqliteProvider::planner() packages/sql-faker/src/Sqlite/SqliteProvider.php:72
- method-call SqlFaker\Sqlite\SqliteProvider::generate() packages/sql-faker/src/Sqlite/SqliteProvider.php:92
Type declarations 6
- type SqlFaker\MySql\Generation\SqlGeneratorFactory packages/sql-faker/src/MySql/Generation/SqlGeneratorFactory.php:22
- type SqlFaker\MySql\MySqlProvider packages/sql-faker/src/MySql/MySqlProvider.php:51
- type SqlFaker\PostgreSql\Generation\SqlGeneratorFactory packages/sql-faker/src/PostgreSql/Generation/SqlGeneratorFactory.php:22
- type SqlFaker\PostgreSql\PostgreSqlProvider packages/sql-faker/src/PostgreSql/PostgreSqlProvider.php:38
- type SqlFaker\Sqlite\Generation\SqlGeneratorFactory packages/sql-faker/src/Sqlite/Generation/SqlGeneratorFactory.php:22
- type SqlFaker\Sqlite\SqliteProvider packages/sql-faker/src/Sqlite/SqliteProvider.php:38