final class LexicalGrammar
    implements LexicalGrammar
Restricted visibility: declared "@visibility root". Code outside that scope must not name this declaration.

MySQL 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

$fakerGeneratorSource of the choices realization makes
$profileVersionstringExact server version to generate for, e.g. "mysql-8.4.7"
$indexKeywordIndex|nullInverts the profile's terminal-to-spelling maps

Throws

RuntimeException When the exact release has no declaration
Calls 6
public function version(): string

Names the server version this grammar generates for.

Returns

string Profile version, e.g. "mysql-8.4.7"
Test cases 1
public function isNonOutput(string $terminal): bool

Reports parser markers that intentionally write no characters.

Parameters

$terminalstring

Returns

bool
Test cases 2
Calls 1
public function realizeSequence(
    TerminalSequence $sequence,
    GenerationPlan<bool>|null $plan = null,
): string

Resolves candidates and boundaries from right to left, then concatenates the chosen output.

Parameters

$sequenceTerminalSequence
$planGenerationPlan<bool>|null

Returns

string

Throws

LexicalException When a terminal has no applicable realization
Test cases 3
Called from 1
Calls 4
public function resolveSequence(
    TerminalSequence $sequence,
    GenerationPlan<bool>|null $plan,
    Closure(int): int $choose,
    Closure(positive-int): ?int|null $valueChoice = null,
): ResolvedOutput

Exposes the resolved choices to a plan compiler without interpreting its input.

Parameters

$sequenceTerminalSequence
$planGenerationPlan<bool>|null
$chooseClosure(int): int
$valueChoiceClosure(positive-int): ?int|nullConstructive values selected only while compiling a plan

Throws

LexicalException When no compatible candidate exists
Test cases 1
Called from 1
Calls 1
public function tokenize(string $sql): list<string>

Reads SQL text into the tokens MySQL's own lexer would produce.

Parameters

$sqlstringText to read

Returns

list<string> Parser token names, in order

Throws

LexicalException When the text holds something the lexer cannot read
Test cases 25
Calls 1
public function generateQuotedIdentifier(
    int $minLength = 1,
    int $maxLength = 64,
): non-empty-string

Writes a backtick-quoted identifier of a bounded length.

Parameters

$minLengthintShortest identifier body to write
$maxLengthintLongest identifier body to write

Returns

non-empty-string A quoted identifier
Test cases 3
Called from 1
Calls 1
public function generateStringLiteral(
    int $minLength = 1,
    int $maxLength = 255,
): non-empty-string
public function generateNationalStringLiteral(
    int $minLength = 1,
    int $maxLength = 255,
): non-empty-string

Writes a national character string literal.

Parameters

$minLengthintShortest body to write
$maxLengthintLongest body to write

Returns

non-empty-string An N-prefixed string literal
Test cases 3
Called from 1
Calls 1
public function generateDollarQuotedString(
    int $minLength = 1,
    int $maxLength = 255,
): non-empty-string

Writes a dollar-quoted string literal.

Parameters

$minLengthintShortest body to write
$maxLengthintLongest body to write

Returns

non-empty-string A dollar-quoted string
Test cases 3
Called from 1
Calls 1
public function generateIntegerLiteral(int $min = 1, int $max = 2147483647): non-empty-string

Writes an integer literal inside the range MySQL reads as NUM.

Parameters

$minintSmallest value to write
$maxintLargest value to write

Returns

non-empty-string An integer literal
Test cases 3
Called from 1
Calls 1
public function generateLongIntegerLiteral(
    int $min = 0,
    int $max = 2147483647,
): non-empty-string

Writes an integer literal wide enough for MySQL to read as LONG_NUM.

Parameters

$minintSmallest value to write
$maxintLargest value to write

Returns

non-empty-string An integer literal
Test cases 3
Called from 1
Calls 1
public function generateUnsignedBigIntLiteral(
    int $minLength = 1,
    int $maxLength = 20,
): non-empty-string

Writes an integer literal wide enough for MySQL to read as ULONGLONG_NUM.

Parameters

$minLengthintFewest digits to write
$maxLengthintMost digits to write

Returns

non-empty-string An integer literal
Test cases 3
Called from 1
Calls 1
public function generateDecimalLiteral(int $precision = 10, int $scale = 2): non-empty-string
public function generateFloatLiteral(
    int $precision = 10,
    int $scale = 2,
    int $minExponent = -38,
    int $maxExponent = 38,
): non-empty-string

Writes a floating-point literal in exponent form.

Parameters

$precisionintTotal digits of the mantissa
$scaleintDigits after the point in the mantissa
$minExponentintSmallest exponent to write
$maxExponentintLargest exponent to write

Returns

non-empty-string A float literal
Test cases 3
Called from 1
Calls 2
public function generateHexLiteral(int $minLength = 1, int $maxLength = 16): non-empty-string

Writes a hexadecimal literal in 0x form.

Parameters

$minLengthintFewest hex digits to write
$maxLengthintMost hex digits to write

Returns

non-empty-string A hexadecimal literal
Test cases 3
Called from 1
Calls 1
public function generateQuotedHexLiteral(int $minBytes = 1, int $maxBytes = 8): non-empty-string

Writes a hexadecimal literal in X'..' form, which takes whole bytes.

Parameters

$minBytesintFewest bytes to write
$maxBytesintMost bytes to write

Returns

non-empty-string A quoted hexadecimal literal
Test cases 3
Called from 1
Calls 2
public function generateBinaryLiteral(int $minLength = 1, int $maxLength = 64): non-empty-string

Writes a binary literal in 0b form.

Parameters

$minLengthintFewest bits to write
$maxLengthintMost bits to write

Returns

non-empty-string A binary literal
Test cases 3
Called from 1
Calls 1
public function generateHostname(
    int $minParts = 1,
    int $maxParts = 4,
    int $maxPartLength = 63,
): non-empty-string

Writes a hostname, as it appears after the @ of a user specification.

Parameters

$minPartsintFewest dot-separated parts to write
$maxPartsintMost dot-separated parts to write
$maxPartLengthintLongest single part to write

Returns

non-empty-string A hostname
Test cases 3
Called from 1
Calls 1
public function generate(GenerationPlan<bool> $plan): non-empty-string

Private surface 6§

Implementation details, listed for orientation only.

private LiteralGenerator $strings
private ReverseLexemeGenerator $pipeline
private list<string> $nonOutput
private MySqlTokenizer $tokenizer
private Generator $faker
private string $profileVersion

Test cases 56§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 36
Other tests reaching this symbol 20

Relations§

Instantiated in 1