final class SqlLexerProfile

Everything the neutral scanner needs to know about one dialect's spelling.

The scanner itself knows no dialect: which characters open a comment, how an identifier is quoted, what a parameter looks like, whether a backslash escapes inside a string — all of it is answered from here. A database package builds one of these, and it is checked as it is built rather than relied on to be usable while scanning.

What a dialect spells falls into four kinds, and each is a profile of its own that says whether the data it was given could be scanned with. This is the one thing the scanner and every rewriter ask, so that neither has to know which of the four an answer came from.

Methods§

public function __construct(
    list<string> $lineCommentPrefixes,
    list<string> $whitespaceDelimitedLineCommentPrefixes,
    array<string, string> $blockCommentPairs,
    array<string, string> $stringQuotePairs,
    array<string, string> $identifierQuotePairs,
    array<string, list<string>> $namedParameterSeparators,
    array<string, string> $namedParameterSuffixPatterns,
    array<string, list<string>> $namedParameterForbiddenPredecessors,
    list<string> $backslashEscapedStringPrefixes,
    list<string> $positionalParameterPatterns,
    ?string $dollarQuoteDelimiterPattern,
    string $numericLiteralPattern,
    string $identifierStartPattern,
    string $identifierPartPattern,
    array{string, string}|null $bracketPair,
    array{string, string} $nestingPair,
    string $statementDelimiter,
    string $listDelimiter,
    bool $nestedBlockComments,
    bool $backslashEscapedStrings,
)

Parameters

$lineCommentPrefixeslist<string>
$whitespaceDelimitedLineCommentPrefixeslist<string>
$blockCommentPairsarray<string, string>
$stringQuotePairsarray<string, string>
$identifierQuotePairsarray<string, string>
$namedParameterSeparatorsarray<string, list<string>>
$namedParameterSuffixPatternsarray<string, string>
$namedParameterForbiddenPredecessorsarray<string, list<string>>
$backslashEscapedStringPrefixeslist<string>
$positionalParameterPatternslist<string>
$dollarQuoteDelimiterPattern?string
$numericLiteralPatternstring
$identifierStartPatternstring
$identifierPartPatternstring
$bracketPairarray{string, string}|null
$nestingPairarray{string, string}
$statementDelimiterstring
$listDelimiterstring
$nestedBlockCommentsbool
$backslashEscapedStringsbool

Throws

InvalidDefinitionException When lexical configuration is invalid.
Test cases 22
Calls 4
public function startsLineComment(string $sql, int $offset): bool

Reports whether a comment running to the end of the line starts here.

Parameters

$sqlstringStatement being scanned
$offsetintPosition to look at

Returns

bool True when one starts there
Test cases 1
Called from 1
Calls 1
public function blockCommentAt(
    string $sql,
    int $offset,
): array{non-empty-string, non-empty-string}|null

Answers the block comment delimiters starting here, if any.

Parameters

$sqlstringStatement being scanned
$offsetintPosition to look at

Returns

array{non-empty-string, non-empty-string}|null The opening and closing delimiters, or null when no comment starts there
Test cases 1
Called from 1
Calls 1
public function supportsNestedBlockComments(): bool

Reports whether a block comment may contain another.

Returns

bool True when the dialect nests them
Test cases 1
Called from 1
Calls 1
public function stringQuoteClosing(string $opening): string|null

Answers the quote that closes a string this one opened.

Parameters

$openingstringQuote that opened it

Returns

string|null The closing quote, or null when nothing opens a string with that
Test cases 1
Called from 1
Calls 1
public function identifierQuoteClosing(string $opening): string|null

Answers the quote that closes an identifier this one opened.

Parameters

$openingstringQuote that opened it

Returns

string|null The closing quote, or null when nothing opens an identifier with that
Test cases 1
Called from 1
Calls 1
public function unquoteIdentifier(string $identifier): string

Answers the name a quoted identifier stands for.

Parameters

$identifierstringIdentifier as it was written

Returns

string The name, or the identifier unchanged when it was not quoted
Test cases 1
Calls 1
public function quotedIdentifierValue(string $identifier): string|null

Answers the name a quoted identifier stands for, and nothing for anything else.

Parameters

$identifierstringIdentifier as it was written

Returns

string|null The name, or null when it was not a complete quoted identifier
Test cases 1
Called from 1
Calls 1
public function dollarQuoteDelimiterAt(string $sql, int $offset): string|null

Answers the dollar-quoted delimiter starting here, if any.

Parameters

$sqlstringStatement being scanned
$offsetintPosition to look at

Returns

string|null The delimiter, or null when none starts there
Test cases 1
Called from 1
Calls 1
public function stringUsesBackslashEscapes(string $sql, int $quoteOffset): bool

Reports whether the string opening here treats a backslash as an escape.

Parameters

$sqlstringStatement being scanned
$quoteOffsetintPosition of the quote that opens the string

Returns

bool True when a backslash escapes inside it
Test cases 1
Called from 1
Calls 1
public function positionalParameterLengthAt(string $sql, int $offset): int

Answers how long the positional parameter starting here is.

Parameters

$sqlstringStatement being scanned
$offsetintPosition to look at

Returns

int Its length, or zero when none starts there
Test cases 1
Called from 1
Calls 1
public function namedParameterPrefixAt(string $sql, int $offset): string|null

Answers the prefix of the named parameter starting here, if any.

Parameters

$sqlstringStatement being scanned
$offsetintPosition to look at

Returns

string|null The prefix, or null when no parameter starts there
Test cases 1
Called from 1
Calls 1
public function parameterNameSeparatorAt(string $prefix, string $sql, int $offset): string|null

Answers what separates a parameter prefix from its name here, if anything.

Parameters

$prefixstringPrefix the parameter was written with
$sqlstringStatement being scanned
$offsetintPosition to look at

Returns

string|null The separator, or null when none is written there
Test cases 1
Called from 1
Calls 1
public function parameterSuffixLength(string $prefix, string $sql, int $offset): int

Answers how much a parameter written with this prefix carries after its name.

Parameters

$prefixstringPrefix the parameter was written with
$sqlstringStatement being scanned
$offsetintPosition to look at

Returns

int How long it is, or zero when nothing follows
Test cases 1
Called from 1
Calls 1
public function numberLengthAt(string $sql, int $offset): int

Answers how long the number starting here is.

Parameters

$sqlstringStatement being scanned
$offsetintPosition to look at

Returns

int Its length, or zero when no number starts there
Test cases 1
Called from 1
Calls 1
public function isIdentifierPart(string $character): bool
public function isBracketOpening(string $character): bool

Reports whether this character opens a bracket.

Parameters

$characterstringCharacter to test

Returns

bool True when it does, and false where the dialect brackets nothing
Test cases 1
Called from 1
Calls 1
public function isBracketClosing(string $character): bool

Reports whether this character closes a bracket.

Parameters

$characterstringCharacter to test

Returns

bool True when it does, and false where the dialect brackets nothing
Test cases 1
Called from 1
Calls 1
public function isNestingOpening(string $character): bool
public function isNestingClosing(string $character): bool
public function isStatementDelimiter(string $symbol): bool

Reports whether this symbol ends a statement.

Parameters

$symbolstringSymbol to test

Returns

bool True when it does
Test cases 1
Called from 1
Calls 1
public function listDelimiter(): string

Answers the character that separates list items.

Returns

string The separator
Test cases 1
Called from 1
Calls 1

Private surface 4§

Implementation details, listed for orientation only.

private SqlCommentProfile $comments
private SqlQuoteProfile $quotes
private SqlParameterProfile $parameters
private SqlSymbolProfile $symbols

Test cases 34§

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

Dedicated tests 22
Other tests reaching this symbol 12

Relations§

Method calls 26
Type declarations 10