classLexicalGrammar
final class LexicalGrammar
implements LexicalGrammar
PostgreSQL lexical generation using source-based candidate and boundary definitions. Tokenization is exposed separately for diagnostics and does not decide generation success.
Methods§
public function __construct(
private Generator $faker,
private string $profileVersion,
KeywordIndex|null $index = null,
)Parameters
$faker | Generator | Source of the choices realization makes |
$profileVersion | string | Exact server version to generate for, e.g. "pg-17.2" |
$index | KeywordIndex|null | Inverts the profile's terminal-to-spelling map |
Throws
RuntimeException When the exact release has no declarationCalls 7
- method-call DefinitionFactory::create() line 67
- new DefinitionFactory line 67
- new KeywordIndex line 68
- new LiteralGenerator line 69
- new PgLookahead line 72
- static-call PgLookahead::definitions() line 72
- new PgTokenizer line 73
public function version(): stringNames the server version this grammar generates for.
Returns
string Profile version, e.g. "pg-17.2"Test cases 1
public function isNonOutput(string $terminal): boolReports parser selector tokens that intentionally write no characters.
Parameters
$terminal | string |
Returns
boolCalls 1
- function-call
in_arrayline 93
public function normalizeLookahead(list<string> $terminals): list<string>Settles each terminal on the spelling its neighbour calls for.
Parameters
$terminals | list<string> | Terminals a derivation produced |
Returns
list<string> The terminals with each lookahead substitution settledCalls 1
- method-call PgLookahead::normalized() line 105
public function realize(list<string> $terminals, GenerationPlan<bool>|null $plan = null): stringRealizes a terminal sequence using the same candidate and spacing pipeline as grammar generation.
Parameters
$terminals | list<string> | |
$plan | GenerationPlan<bool>|null |
Returns
stringThrows
LexicalException When a requested realization is unavailableTest cases 3
Calls 2
- method-call LexicalGrammar::realizeSequence() line 117
- static-call TerminalSequence::fromNames() line 117
public function realizeSequence(
TerminalSequence $sequence,
GenerationPlan<bool>|null $plan = null,
): stringResolves candidates and boundaries before serialization; tokenization remains a diagnostic API.
Parameters
$sequence | TerminalSequence | |
$plan | GenerationPlan<bool>|null |
Returns
stringThrows
LexicalException When the selected terminals have no applicable realizationTest cases 1
Called from 1
Calls 4
- method-call LexicalGrammar::resolveSequence() line 127
- method-call
Generator::numberBetween()line 127 - method-call SqlSerializer::serialize() line 128
- new SqlSerializer line 128
public function resolveSequence(
TerminalSequence $sequence,
GenerationPlan<bool>|null $plan,
Closure(int): int $choose,
Closure(positive-int): ?int|null $valueChoice = null,
): ResolvedOutputExposes the resolved choices to a plan compiler without interpreting its input.
Parameters
$sequence | TerminalSequence | |
$plan | GenerationPlan<bool>|null | |
$choose | Closure(int): int | |
$valueChoice | Closure(positive-int): ?int|null | Constructive values selected only while compiling a plan |
Returns
Throws
LexicalException When no compatible candidate existsCalled from 1
Calls 1
- method-call ReverseLexemeGenerator::generate() line 141
public function tokenize(string $sql): list<string>Reads SQL text into the tokens PostgreSQL's own lexer would produce.
Parameters
$sql | string | Text to read |
Returns
list<string> Parser token names, in orderThrows
LexicalException When the text holds something the lexer cannot readTest cases 27
LexicalGrammarTest::testAppliesParserLookaheadOnlyInItsVersionedContextcallsLexicalGrammarTest::testGenerateBinaryLiteralWritesWhatTheLexerReadsBackAsABitStringcallsLexicalGrammarTest::testGenerateDecimalLiteralWritesWhatTheLexerReadsBackAsAFloatcallsLexicalGrammarTest::testGenerateDollarQuotedStringWritesWhatTheLexerReadsBackAsAStringcallsLexicalGrammarTest::testGenerateFloatLiteralWritesWhatTheLexerReadsBackAsAFloatcallsLexicalGrammarTest::testGenerateHexLiteralWritesWhatTheLexerReadsBackAsAHexStringcallsLexicalGrammarTest::testGenerateIntegerLiteralWritesWhatTheLexerReadsBackAsAnIntegercallsLexicalGrammarTest::testGenerateParameterMarkerWritesWhatTheLexerReadsBackAsAParametercallsLexicalGrammarTest::testGenerateQuotedIdentifierWritesWhatTheLexerReadsBackAsAnIdentifiercallsLexicalGrammarTest::testGenerateStringLiteralWritesWhatTheLexerReadsBackAsAStringcallsLexicalGrammarTest::testRealizesLookaheadTokenWithRequiredFollowercallsLexicalGrammarTest::testTokenizesAllProblematicLiteralAndOperatorFamiliescallsLexicalGrammarTest::testTokenizesCommentsAdjacentToOperatorscallsPostgreSqlProviderTest::testDomainDmlStatementDerivesDmlFromGrammarcallsPostgreSqlProviderTest::testDoStatementDerivesAnonymousBlockFromGrammarcallsPostgreSqlProviderTest::testForeignKeyCascadeStatementcallsPostgreSqlProviderTest::testForeignKeyConstraintcallsPostgreSqlProviderTest::testFullTextSearchStatementDerivesMatchOperatorFromGrammarAndLexercallsPostgreSqlProviderTest::testGeneratedColumnStatementcallsPostgreSqlProviderTest::testInsertFunctionUpsertStatementDerivesFunctionExpressionFromGrammarcallsPostgreSqlProviderTest::testMergeStatementDerivesEveryActionFromGrammarcallsPostgreSqlProviderTest::testPartialIndexUpsertStatementIncludesArbiterPredicatecallsPostgreSqlProviderTest::testPartitionOfStatementGeneratesRangeChildDdlcallsPostgreSqlProviderTest::testSortClausecallsPostgreSqlProviderTest::testTableSampleStatementDerivesSamplingClauseFromGrammarcallsPostgreSqlProviderTest::testTemporaryTableStatementcallsPostgreSqlProviderTest::testViewStatementcalls
Calls 1
- method-call PgTokenizer::tokenize() line 155
public function generateQuotedIdentifier(
int $minLength = 1,
int $maxLength = 63,
): non-empty-stringWrites a double-quoted identifier of a bounded length.
Parameters
$minLength | int | Shortest identifier body to write |
$maxLength | int | Longest identifier body to write |
Returns
non-empty-string A quoted identifierTest cases 2
Called from 1
Calls 1
- method-call LiteralGenerator::rawIdentifier() line 168
public function generateStringLiteral(
int $minLength = 1,
int $maxLength = 255,
): non-empty-stringWrites a single-quoted string literal of a bounded length.
Parameters
$minLength | int | Shortest body to write |
$maxLength | int | Longest body to write |
Returns
non-empty-string A string literalTest cases 2
Called from 1
Calls 1
- method-call LiteralGenerator::mixedAlnumString() line 181
public function generateIntegerLiteral(int $min = 1, int $max = 2147483647): non-empty-stringWrites an integer literal.
Parameters
$min | int | Smallest value to write |
$max | int | Largest value to write |
Returns
non-empty-string An integer literalTest cases 2
Called from 1
Calls 1
- method-call LiteralGenerator::integerString() line 194
public function generateDecimalLiteral(int $precision = 10, int $scale = 2): non-empty-stringWrites a fixed-point literal.
Parameters
$precision | int | Total digits to write |
$scale | int | Digits after the point |
Returns
non-empty-string A decimal literalTest cases 2
Called from 2
Calls 1
- method-call LiteralGenerator::decimalString() line 207
public function generateFloatLiteral(
int $precision = 10,
int $scale = 2,
int $minExponent = -307,
int $maxExponent = 308,
): non-empty-stringWrites a floating-point literal in exponent form.
Parameters
$precision | int | Total digits of the mantissa |
$scale | int | Digits after the point in the mantissa |
$minExponent | int | Smallest exponent to write |
$maxExponent | int | Largest exponent to write |
Returns
non-empty-string A float literalTest cases 2
Called from 1
Calls 2
- method-call LiteralGenerator::floatString() line 226
- method-call LexicalGrammar::generateDecimalLiteral() line 227
public function generateHexLiteral(int $minLength = 1, int $maxLength = 16): non-empty-stringWrites a hexadecimal bit-string literal.
Parameters
$minLength | int | Fewest hex digits to write |
$maxLength | int | Most hex digits to write |
Returns
non-empty-string A hexadecimal literalTest cases 2
Called from 1
Calls 1
- method-call LiteralGenerator::hexString() line 243
public function generateBinaryLiteral(int $minLength = 1, int $maxLength = 64): non-empty-stringWrites a binary bit-string literal.
Parameters
$minLength | int | Fewest bits to write |
$maxLength | int | Most bits to write |
Returns
non-empty-string A binary literalTest cases 2
Called from 1
Calls 1
- method-call LiteralGenerator::binaryString() line 256
public function generateDollarQuotedString(
int $minLength = 1,
int $maxLength = 255,
): non-empty-stringWrites a dollar-quoted string literal.
Parameters
$minLength | int | Shortest body to write |
$maxLength | int | Longest body to write |
Returns
non-empty-string A dollar-quoted stringTest cases 2
Called from 1
Calls 1
- method-call LiteralGenerator::mixedAlnumString() line 269
public function generateParameterMarker(int $min = 1, int $max = 99): non-empty-stringWrites a positional parameter marker.
Parameters
$min | int | Smallest position to write |
$max | int | Largest position to write |
Returns
non-empty-string A parameter markerTest cases 2
Called from 1
Calls 1
- method-call LiteralGenerator::parameterIndex() line 282
public function generate(GenerationPlan<bool> $plan): non-empty-stringWrites the one lexeme a lexical generation plan asks for.
Parameters
$plan | GenerationPlan<bool> | Plan naming the lexeme kind and its bounds |
Returns
non-empty-string The lexemeThrows
InvalidArgumentException When the plan names a lexeme kind this dialect has none ofCalls 12
- method-call GenerationPlan::lexicalTarget() line 297
- method-call GenerationPlan::parameters() line 298
- method-call LexicalGrammar::generateQuotedIdentifier() line 301
- method-call LexicalGrammar::generateStringLiteral() line 302
- method-call LexicalGrammar::generateIntegerLiteral() line 303
- method-call LexicalGrammar::generateDecimalLiteral() line 304
- method-call LexicalGrammar::generateFloatLiteral() line 305
- method-call LexicalGrammar::generateHexLiteral() line 311
- method-call LexicalGrammar::generateBinaryLiteral() line 312
- method-call LexicalGrammar::generateDollarQuotedString() line 313
- method-call LexicalGrammar::generateParameterMarker() line 317
- new
InvalidArgumentExceptionline 318
Private surface 7§
Implementation details, listed for orientation only.
private LiteralGenerator $stringsprivate ReverseLexemeGenerator $pipelineprivate list<string> $nonOutputprivate PgLookahead $lookaheadprivate PgTokenizer $tokenizerprivate Generator $fakerprivate string $profileVersionTest cases 41§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 23
LexicalGrammarTest::providerDialectLexicalGrammarcallsLexicalGrammarTest::providerPublicLexemeDefaultscallsLexicalGrammarTest::testAppliesParserLookaheadOnlyInItsVersionedContextcallsLexicalGrammarTest::testGenerateBinaryLiteralWritesWhatTheLexerReadsBackAsABitStringcallsLexicalGrammarTest::testGenerateDecimalLiteralWritesWhatTheLexerReadsBackAsAFloatcallsLexicalGrammarTest::testGenerateDollarQuotedStringWritesWhatTheLexerReadsBackAsAStringcallsLexicalGrammarTest::testGenerateFloatLiteralWritesWhatTheLexerReadsBackAsAFloatcallsLexicalGrammarTest::testGenerateHexLiteralWritesWhatTheLexerReadsBackAsAHexStringcallsLexicalGrammarTest::testGenerateIntegerLiteralWritesWhatTheLexerReadsBackAsAnIntegercallsLexicalGrammarTest::testGenerateParameterMarkerWritesWhatTheLexerReadsBackAsAParametercallsLexicalGrammarTest::testGenerateQuotedIdentifierWritesWhatTheLexerReadsBackAsAnIdentifiercallsLexicalGrammarTest::testGenerateStringLiteralWritesWhatTheLexerReadsBackAsAStringcallsLexicalGrammarTest::testIsNonOutputDoesNotConfuseOrdinaryValuesWithParserMarkerscallsLexicalGrammarTest::testNormalizeLookaheadSettlesDerivedTokensFromTheirFollowerscallsLexicalGrammarTest::testPublicLexemeDefaultBoundscallsLexicalGrammarTest::testRealizeReportsAnUnimplementedTerminalAtItsActualUsecallsLexicalGrammarTest::testRealizeSequenceHonorsThePlannedStringWithoutRequiringTriviacallsLexicalGrammarTest::testRealizesLookaheadTokenWithRequiredFollowercallsLexicalGrammarTest::testRejectsLookaheadTokenWithoutRequiredFollowercallsLexicalGrammarTest::testResolveSequenceExposesTheChosenCandidateAndItsOutputcallsLexicalGrammarTest::testTokenizesAllProblematicLiteralAndOperatorFamiliescallsLexicalGrammarTest::testTokenizesCommentsAdjacentToOperatorscallsLexicalGrammarTest::testVersionReportsTheReleaseTheProfileWasBuiltForcalls
Other tests reaching this symbol 18
MySqlProviderTestcallsGenerationContextTestcallsSqlGeneratorFactoryTestcallsPostgreSqlProviderTest::testDomainDmlStatementDerivesDmlFromGrammarcallsPostgreSqlProviderTest::testDoStatementDerivesAnonymousBlockFromGrammarcallsPostgreSqlProviderTest::testForeignKeyCascadeStatementcallsPostgreSqlProviderTest::testForeignKeyConstraintcallsPostgreSqlProviderTest::testFullTextSearchStatementDerivesMatchOperatorFromGrammarAndLexercallsPostgreSqlProviderTest::testGeneratedColumnStatementcallsPostgreSqlProviderTest::testInsertFunctionUpsertStatementDerivesFunctionExpressionFromGrammarcallsPostgreSqlProviderTest::testMergeStatementDerivesEveryActionFromGrammarcallsPostgreSqlProviderTest::testPartialIndexUpsertStatementIncludesArbiterPredicatecallsPostgreSqlProviderTest::testPartitionOfStatementGeneratesRangeChildDdlcallsPostgreSqlProviderTest::testSortClausecallsPostgreSqlProviderTest::testTableSampleStatementDerivesSamplingClauseFromGrammarcallsPostgreSqlProviderTest::testTemporaryTableStatementcallsPostgreSqlProviderTest::testViewStatementcallsSqliteProviderTestcalls