classLexicalGrammar
final class LexicalGrammar
implements LexicalGrammar
SQLite lexical generation using source-based candidate and boundary definitions. Tokenization is exposed separately for diagnostics and does not decide generation success.
Constants§
public const STRICT_TABLE_OPTION = 'STRICT_TABLE_OPTION'The table option that makes a table reject values of the wrong type.
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 release to generate for, e.g. "sqlite-3.47.2" |
$index | KeywordIndex|null | Inverts the profile's terminal-to-spelling map |
Throws
RuntimeException When the exact release has no declarationCalls 5
- method-call DefinitionFactory::create() line 61
- new DefinitionFactory line 61
- new KeywordIndex line 62
- new LiteralGenerator line 63
- new SqliteTokenizer line 65
public function version(): stringNames the release this grammar generates for.
Returns
string Profile version, e.g. "sqlite-3.47.2"Test cases 1
public function isNonOutput(string $terminal): boolSQLite's grammar terminals all emit text; its implicit EOF is outside the terminal sequence.
Parameters
$terminal | string |
Returns
boolpublic 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 6
LexicalGrammarTest::testRealizeOfFixedTerminalcallsLexicalGrammarTest::testRealizeOfGeneratedTerminalscallsLexicalGrammarTest::testRealizeOfIdentifiercallsLexicalGrammarTest::testRealizeOfStringcallsLexicalGrammarTest::testRealizeReportsAnUnimplementedTerminalAtItsActualUsecallsLexicalGrammarTest::testRealizesStrictTableOptionAsIdentifierTokencalls
Calls 2
- method-call LexicalGrammar::realizeSequence() line 97
- static-call TerminalSequence::fromNames() line 97
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 107
- method-call
Generator::numberBetween()line 107 - method-call SqlSerializer::serialize() line 108
- new SqlSerializer line 108
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 existsTest cases 2
Called from 1
Calls 1
- method-call ReverseLexemeGenerator::generate() line 121
public function tokenize(string $sql): list<string>Reads SQL text into the tokens SQLite'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 20
LexicalGrammarTest::testGenerateDecimalLiteralWritesWhatTheLexerReadsBackAsAFloatcallsLexicalGrammarTest::testGenerateIntegerLiteralWritesWhatTheLexerReadsBackAsAnIntegercallsLexicalGrammarTest::testGenerateQuotedIdentifierWritesWhatTheLexerReadsBackAsAnIdentifiercallsLexicalGrammarTest::testGenerateStringLiteralWritesWhatTheLexerReadsBackAsAStringcallsLexicalGrammarTest::testRealizesStrictTableOptionAsIdentifierTokencallsLexicalGrammarTest::testRejectsInvalidSqlcallsLexicalGrammarTest::testTokenizesEveryNumberAndOperatorClasscallsLexicalGrammarTest::testTokenizesKeywordsCaseInsensitivelyAndSkipsEmbeddedCommentscallsLexicalGrammarTest::testTokenizesQuotedIdentifiersStringsVariablesAndCommentscallsLexicalGrammarTest::testUsesVersionedKeywordFamiliescallsSqliteProviderTest::testDropTableContainsDropTablecallsSqliteProviderTest::testForeignKeyCascadeStatementcallsSqliteProviderTest::testForeignKeyConstraintcallsSqliteProviderTest::testFullTextSearchStatementDerivesMatchExpressionFromGrammarcallsSqliteProviderTest::testGeneratedColumnStatementcallsSqliteProviderTest::testInsertFunctionUpsertStatementDerivesFunctionExpressionFromGrammarcallsSqliteProviderTest::testMultiDmlStatementCanSelectEveryDmlFamilycallsSqliteProviderTest::testMultiDmlStatementDerivesTwoStatementBatchFromGrammarcallsSqliteProviderTest::testTemporaryTableStatementcallsSqliteProviderTest::testViewStatementcalls
Calls 1
- method-call SqliteTokenizer::tokenize() line 135
public function generateQuotedIdentifier(
int $minLength = 1,
int $maxLength = 128,
): 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 148
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 161
public function generateIntegerLiteral(int $min = 1, int $max = PHP_INT_MAX): 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 174
public function generateDecimalLiteral(int $precision = 15, 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 1
Calls 1
- method-call LiteralGenerator::decimalString() line 187
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 7
- method-call GenerationPlan::lexicalTarget() line 202
- method-call GenerationPlan::parameters() line 203
- method-call LexicalGrammar::generateQuotedIdentifier() line 206
- method-call LexicalGrammar::generateStringLiteral() line 207
- method-call LexicalGrammar::generateIntegerLiteral() line 208
- method-call LexicalGrammar::generateDecimalLiteral() line 209
- new
InvalidArgumentExceptionline 210
Private surface 5§
Implementation details, listed for orientation only.
private LiteralGenerator $stringsprivate ReverseLexemeGenerator $pipelineprivate SqliteTokenizer $tokenizerprivate Generator $fakerprivate string $profileVersionTest cases 37§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 23
LexicalGrammarTest::providerDialectLexicalGrammarcallsLexicalGrammarTest::testResolveSequenceUsesTheCommonContractForCandidateInspectioncallsLexicalGrammarTest::providerPublicLexemeDefaultscallsLexicalGrammarTest::testGenerateDecimalLiteralWritesWhatTheLexerReadsBackAsAFloatcallsLexicalGrammarTest::testGenerateIntegerLiteralWritesWhatTheLexerReadsBackAsAnIntegercallsLexicalGrammarTest::testGenerateQuotedIdentifierWritesWhatTheLexerReadsBackAsAnIdentifiercallsLexicalGrammarTest::testGenerateStringLiteralWritesWhatTheLexerReadsBackAsAStringcallsLexicalGrammarTest::testIsNonOutputDoesNotConfuseOrdinaryValuesWithParserMarkerscallsLexicalGrammarTest::testPublicLexemeDefaultBoundscallsLexicalGrammarTest::testRealizeOfFixedTerminalcallsLexicalGrammarTest::testRealizeOfGeneratedTerminalscallsLexicalGrammarTest::testRealizeOfIdentifiercallsLexicalGrammarTest::testRealizeOfStringcallsLexicalGrammarTest::testRealizeReportsAnUnimplementedTerminalAtItsActualUsecallsLexicalGrammarTest::testRealizeSequenceHonorsThePlannedStringWithoutRequiringTriviacallsLexicalGrammarTest::testRealizesStrictTableOptionAsIdentifierTokencallsLexicalGrammarTest::testRejectsInvalidSqlcallsLexicalGrammarTest::testResolveSequenceExposesTheChosenCandidateAndItsOutputcallsLexicalGrammarTest::testTokenizesEveryNumberAndOperatorClasscallsLexicalGrammarTest::testTokenizesKeywordsCaseInsensitivelyAndSkipsEmbeddedCommentscallsLexicalGrammarTest::testTokenizesQuotedIdentifiersStringsVariablesAndCommentscallsLexicalGrammarTest::testUsesVersionedKeywordFamiliescallsLexicalGrammarTest::testVersionReportsTheReleaseTheProfileWasBuiltForcalls
Other tests reaching this symbol 14
MySqlProviderTestcallsPostgreSqlProviderTestcallsGenerationContextTestcallsSqlGeneratorFactoryTestcallsSqliteProviderTest::testDropTableContainsDropTablecallsSqliteProviderTest::testForeignKeyCascadeStatementcallsSqliteProviderTest::testForeignKeyConstraintcallsSqliteProviderTest::testFullTextSearchStatementDerivesMatchExpressionFromGrammarcallsSqliteProviderTest::testGeneratedColumnStatementcallsSqliteProviderTest::testInsertFunctionUpsertStatementDerivesFunctionExpressionFromGrammarcallsSqliteProviderTest::testMultiDmlStatementCanSelectEveryDmlFamilycallsSqliteProviderTest::testMultiDmlStatementDerivesTwoStatementBatchFromGrammarcallsSqliteProviderTest::testTemporaryTableStatementcallsSqliteProviderTest::testViewStatementcalls