classSqlLexerProfile
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
$lineCommentPrefixes | list<string> | |
$whitespaceDelimitedLineCommentPrefixes | list<string> | |
$blockCommentPairs | array<string, string> | |
$stringQuotePairs | array<string, string> | |
$identifierQuotePairs | array<string, string> | |
$namedParameterSeparators | array<string, list<string>> | |
$namedParameterSuffixPatterns | array<string, string> | |
$namedParameterForbiddenPredecessors | array<string, list<string>> | |
$backslashEscapedStringPrefixes | list<string> | |
$positionalParameterPatterns | list<string> | |
$dollarQuoteDelimiterPattern | ?string | |
$numericLiteralPattern | string | |
$identifierStartPattern | string | |
$identifierPartPattern | string | |
$bracketPair | array{string, string}|null | |
$nestingPair | array{string, string} | |
$statementDelimiter | string | |
$listDelimiter | string | |
$nestedBlockComments | bool | |
$backslashEscapedStrings | bool |
Throws
InvalidDefinitionException When lexical configuration is invalid.Test cases 22
SqlLexerProfileTest::testBlockCommentAtAnswersTheDelimitersThatOpenAndCloseOnecoversSqlLexerProfileTest::testDollarQuoteDelimiterAtAnswersTheDelimiterStartingTherecoversSqlLexerProfileTest::testIdentifierQuoteClosingAnswersWhatClosesAnIdentifierThisOpenedcoversSqlLexerProfileTest::testIsBracketClosingAnswersForTheCharacterThatClosesOnecoversSqlLexerProfileTest::testIsBracketOpeningAnswersForTheCharacterThatOpensOnecoversSqlLexerProfileTest::testIsIdentifierPartAnswersForEveryLaterCharacterOfANamecoversSqlLexerProfileTest::testIsIdentifierStartAnswersForTheFirstCharacterOfANamecoversSqlLexerProfileTest::testIsNestingClosingAnswersForTheCharacterThatClosesOnecoversSqlLexerProfileTest::testIsNestingOpeningAnswersForTheCharacterThatOpensOnecoversSqlLexerProfileTest::testIsStatementDelimiterAnswersForTheSymbolThatEndsAStatementcoversSqlLexerProfileTest::testListDelimiterAnswersTheSeparatorBetweenListItemscoversSqlLexerProfileTest::testNamedParameterPrefixAtTellsAParameterFromAnOperatorSpelledAlikecoversSqlLexerProfileTest::testNumberLengthAtMeasuresTheNumberStartingTherecoversSqlLexerProfileTest::testParameterNameSeparatorAtAnswersWhatSeparatesAPrefixFromItsNamecoversSqlLexerProfileTest::testParameterSuffixLengthMeasuresWhatFollowsAParameterNamecoversSqlLexerProfileTest::testPositionalParameterLengthAtMeasuresTheParameterStartingTherecoversSqlLexerProfileTest::testQuotedIdentifierValueSpeaksOnlyForACompleteQuotedIdentifiercoversSqlLexerProfileTest::testStartsLineCommentSeesEveryPrefixTheDialectDeclarescoversSqlLexerProfileTest::testStringQuoteClosingAnswersWhatClosesAStringThisOpenedcoversSqlLexerProfileTest::testStringUsesBackslashEscapesLooksAtWhatIntroducedTheStringcoversSqlLexerProfileTest::testSupportsNestedBlockCommentsFollowsTheDialectcoversSqlLexerProfileTest::testUnquoteIdentifierReadsTheNameAQuotedIdentifierStandsForcovers
Calls 4
public function startsLineComment(string $sql, int $offset): boolReports whether a comment running to the end of the line starts here.
Parameters
$sql | string | Statement being scanned |
$offset | int | Position to look at |
Returns
bool True when one starts thereTest cases 1
Called from 1
Calls 1
- method-call SqlCommentProfile::startsLineComment() line 87
public function blockCommentAt(
string $sql,
int $offset,
): array{non-empty-string, non-empty-string}|nullAnswers the block comment delimiters starting here, if any.
Parameters
$sql | string | Statement being scanned |
$offset | int | Position to look at |
Returns
array{non-empty-string, non-empty-string}|null The opening and closing delimiters, or null when no comment starts thereCalled from 1
Calls 1
- method-call SqlCommentProfile::blockCommentAt() line 100
public function supportsNestedBlockComments(): boolReports whether a block comment may contain another.
Returns
bool True when the dialect nests themTest cases 1
Called from 1
Calls 1
public function stringQuoteClosing(string $opening): string|nullAnswers the quote that closes a string this one opened.
Parameters
$opening | string | Quote that opened it |
Returns
string|null The closing quote, or null when nothing opens a string with thatCalled from 1
Calls 1
- method-call SqlQuoteProfile::stringQuoteClosing() line 122
public function identifierQuoteClosing(string $opening): string|nullAnswers the quote that closes an identifier this one opened.
Parameters
$opening | string | Quote that opened it |
Returns
string|null The closing quote, or null when nothing opens an identifier with thatTest cases 1
Called from 1
Calls 1
- method-call SqlQuoteProfile::identifierQuoteClosing() line 134
public function unquoteIdentifier(string $identifier): stringAnswers the name a quoted identifier stands for.
Parameters
$identifier | string | Identifier as it was written |
Returns
string The name, or the identifier unchanged when it was not quotedCalls 1
- method-call SqlQuoteProfile::unquoteIdentifier() line 146
public function quotedIdentifierValue(string $identifier): string|nullAnswers the name a quoted identifier stands for, and nothing for anything else.
Parameters
$identifier | string | Identifier as it was written |
Returns
string|null The name, or null when it was not a complete quoted identifierTest cases 1
Called from 1
Calls 1
- method-call SqlQuoteProfile::quotedIdentifierValue() line 158
public function dollarQuoteDelimiterAt(string $sql, int $offset): string|nullAnswers the dollar-quoted delimiter starting here, if any.
Parameters
$sql | string | Statement being scanned |
$offset | int | Position to look at |
Returns
string|null The delimiter, or null when none starts thereCalled from 1
Calls 1
- method-call SqlQuoteProfile::dollarQuoteDelimiterAt() line 171
public function stringUsesBackslashEscapes(string $sql, int $quoteOffset): boolReports whether the string opening here treats a backslash as an escape.
Parameters
$sql | string | Statement being scanned |
$quoteOffset | int | Position of the quote that opens the string |
Returns
bool True when a backslash escapes inside itTest cases 1
Called from 1
Calls 1
public function positionalParameterLengthAt(string $sql, int $offset): intAnswers how long the positional parameter starting here is.
Parameters
$sql | string | Statement being scanned |
$offset | int | Position to look at |
Returns
int Its length, or zero when none starts thereTest cases 1
Called from 1
Calls 1
public function namedParameterPrefixAt(string $sql, int $offset): string|nullAnswers the prefix of the named parameter starting here, if any.
Parameters
$sql | string | Statement being scanned |
$offset | int | Position to look at |
Returns
string|null The prefix, or null when no parameter starts thereTest cases 1
Called from 1
Calls 1
public function parameterNameSeparatorAt(string $prefix, string $sql, int $offset): string|nullAnswers what separates a parameter prefix from its name here, if anything.
Parameters
$prefix | string | Prefix the parameter was written with |
$sql | string | Statement being scanned |
$offset | int | Position to look at |
Returns
string|null The separator, or null when none is written thereTest cases 1
Called from 1
Calls 1
public function parameterSuffixLength(string $prefix, string $sql, int $offset): intAnswers how much a parameter written with this prefix carries after its name.
Parameters
$prefix | string | Prefix the parameter was written with |
$sql | string | Statement being scanned |
$offset | int | Position to look at |
Returns
int How long it is, or zero when nothing followsCalled from 1
Calls 1
- method-call SqlParameterProfile::parameterSuffixLength() line 238
public function numberLengthAt(string $sql, int $offset): intAnswers how long the number starting here is.
Parameters
$sql | string | Statement being scanned |
$offset | int | Position to look at |
Returns
int Its length, or zero when no number starts thereTest cases 1
Called from 1
Calls 1
- method-call SqlSymbolProfile::numberLengthAt() line 251
public function isIdentifierStart(string $character): boolReports whether an identifier may begin with this character.
Parameters
$character | string | Character to test |
Returns
bool True when it mayTest cases 1
Called from 3
- method-call ZtdQuery\Sql\Reader\SqlParameterReader::readAt() packages/ztd-query-core/src/Sql/Reader/SqlParameterReader.php:37
- method-call ZtdQuery\Sql\Reader\SqlParameterReader::endOfName() packages/ztd-query-core/src/Sql/Reader/SqlParameterReader.php:73
- method-call ZtdQuery\Sql\Reader\SqlWordReader::readAt() packages/ztd-query-core/src/Sql/Reader/SqlWordReader.php:31
Calls 1
- method-call SqlSymbolProfile::isIdentifierStart() line 263
public function isIdentifierPart(string $character): boolReports whether an identifier may continue with this character.
Parameters
$character | string | Character to test |
Returns
bool True when it mayCalled from 2
Calls 1
- method-call SqlSymbolProfile::isIdentifierPart() line 275
public function isBracketOpening(string $character): boolReports whether this character opens a bracket.
Parameters
$character | string | Character to test |
Returns
bool True when it does, and false where the dialect brackets nothingTest cases 1
Called from 1
Calls 1
- method-call SqlSymbolProfile::isBracketOpening() line 287
public function isBracketClosing(string $character): boolReports whether this character closes a bracket.
Parameters
$character | string | Character to test |
Returns
bool True when it does, and false where the dialect brackets nothingTest cases 1
Called from 1
Calls 1
- method-call SqlSymbolProfile::isBracketClosing() line 299
public function isNestingOpening(string $character): boolReports whether this character opens a nesting.
Parameters
$character | string | Character to test |
Returns
bool True when it doesTest cases 1
Called from 2
Calls 1
- method-call SqlSymbolProfile::isNestingOpening() line 311
public function isNestingClosing(string $character): boolReports whether this character closes a nesting.
Parameters
$character | string | Character to test |
Returns
bool True when it doesTest cases 1
Called from 2
Calls 1
- method-call SqlSymbolProfile::isNestingClosing() line 323
public function isStatementDelimiter(string $symbol): boolReports whether this symbol ends a statement.
Parameters
$symbol | string | Symbol to test |
Returns
bool True when it doesTest cases 1
Called from 1
Calls 1
- method-call SqlSymbolProfile::isStatementDelimiter() line 335
public function listDelimiter(): stringAnswers the character that separates list items.
Returns
string The separatorTest cases 1
Called from 1
Calls 1
- method-call SqlSymbolProfile::listDelimiter() line 345
Private surface 4§
Implementation details, listed for orientation only.
private SqlCommentProfile $commentsprivate SqlQuoteProfile $quotesprivate SqlParameterProfile $parametersprivate SqlSymbolProfile $symbolsTest cases 34§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 22
SqlLexerProfileTest::testBlockCommentAtAnswersTheDelimitersThatOpenAndCloseOnecoversSqlLexerProfileTest::testDollarQuoteDelimiterAtAnswersTheDelimiterStartingTherecoversSqlLexerProfileTest::testIdentifierQuoteClosingAnswersWhatClosesAnIdentifierThisOpenedcoversSqlLexerProfileTest::testIsBracketClosingAnswersForTheCharacterThatClosesOnecoversSqlLexerProfileTest::testIsBracketOpeningAnswersForTheCharacterThatOpensOnecoversSqlLexerProfileTest::testIsIdentifierPartAnswersForEveryLaterCharacterOfANamecoversSqlLexerProfileTest::testIsIdentifierStartAnswersForTheFirstCharacterOfANamecoversSqlLexerProfileTest::testIsNestingClosingAnswersForTheCharacterThatClosesOnecoversSqlLexerProfileTest::testIsNestingOpeningAnswersForTheCharacterThatOpensOnecoversSqlLexerProfileTest::testIsStatementDelimiterAnswersForTheSymbolThatEndsAStatementcoversSqlLexerProfileTest::testListDelimiterAnswersTheSeparatorBetweenListItemscoversSqlLexerProfileTest::testNamedParameterPrefixAtTellsAParameterFromAnOperatorSpelledAlikecoversSqlLexerProfileTest::testNumberLengthAtMeasuresTheNumberStartingTherecoversSqlLexerProfileTest::testParameterNameSeparatorAtAnswersWhatSeparatesAPrefixFromItsNamecoversSqlLexerProfileTest::testParameterSuffixLengthMeasuresWhatFollowsAParameterNamecoversSqlLexerProfileTest::testPositionalParameterLengthAtMeasuresTheParameterStartingTherecoversSqlLexerProfileTest::testQuotedIdentifierValueSpeaksOnlyForACompleteQuotedIdentifiercoversSqlLexerProfileTest::testStartsLineCommentSeesEveryPrefixTheDialectDeclarescoversSqlLexerProfileTest::testStringQuoteClosingAnswersWhatClosesAStringThisOpenedcoversSqlLexerProfileTest::testStringUsesBackslashEscapesLooksAtWhatIntroducedTheStringcoversSqlLexerProfileTest::testSupportsNestedBlockCommentsFollowsTheDialectcoversSqlLexerProfileTest::testUnquoteIdentifierReadsTheNameAQuotedIdentifierStandsForcovers
Other tests reaching this symbol 12
FakeSqlLexerProfiles::allCapabilitiescallsFakeSqlLexerProfiles::customcallsFakeSqlLexerProfiles::standardcallsSqlBlockCommentReaderTestcallsSqlDelimitedReaderTestcallsSqlParameterReaderTestcallsSqlTriviaReaderTestcallsSqlWordReaderTestcallsSqlIdentifierComponentTestcallsSqlKeywordSequenceTestcallsSqlTokenScannerTestcallsSqlTokenStreamTestcalls
Relations§
Method calls 26
- method-call ZtdQuery\Sql\Reader\SqlBlockCommentReader::endAt() packages/ztd-query-core/src/Sql/Reader/SqlBlockCommentReader.php:30
- method-call ZtdQuery\Sql\Reader\SqlBlockCommentReader::endAt() packages/ztd-query-core/src/Sql/Reader/SqlBlockCommentReader.php:39
- method-call ZtdQuery\Sql\Reader\SqlDelimitedReader::readAt() packages/ztd-query-core/src/Sql/Reader/SqlDelimitedReader.php:33
- method-call ZtdQuery\Sql\Reader\SqlDelimitedReader::readAt() packages/ztd-query-core/src/Sql/Reader/SqlDelimitedReader.php:35
- method-call ZtdQuery\Sql\Reader\SqlDelimitedReader::readAt() packages/ztd-query-core/src/Sql/Reader/SqlDelimitedReader.php:43
- method-call ZtdQuery\Sql\Reader\SqlDelimitedReader::readAt() packages/ztd-query-core/src/Sql/Reader/SqlDelimitedReader.php:51
- method-call ZtdQuery\Sql\Reader\SqlParameterReader::readAt() packages/ztd-query-core/src/Sql/Reader/SqlParameterReader.php:31
- method-call ZtdQuery\Sql\Reader\SqlParameterReader::readAt() packages/ztd-query-core/src/Sql/Reader/SqlParameterReader.php:36
- method-call ZtdQuery\Sql\Reader\SqlParameterReader::readAt() packages/ztd-query-core/src/Sql/Reader/SqlParameterReader.php:37
- method-call ZtdQuery\Sql\Reader\SqlParameterReader::readAt() packages/ztd-query-core/src/Sql/Reader/SqlParameterReader.php:45
- method-call ZtdQuery\Sql\Reader\SqlParameterReader::endOfName() packages/ztd-query-core/src/Sql/Reader/SqlParameterReader.php:67
- method-call ZtdQuery\Sql\Reader\SqlParameterReader::endOfName() packages/ztd-query-core/src/Sql/Reader/SqlParameterReader.php:71
- method-call ZtdQuery\Sql\Reader\SqlParameterReader::endOfName() packages/ztd-query-core/src/Sql/Reader/SqlParameterReader.php:73
- method-call ZtdQuery\Sql\Reader\SqlTriviaReader::readAt() packages/ztd-query-core/src/Sql/Reader/SqlTriviaReader.php:51
- method-call ZtdQuery\Sql\Reader\SqlWordReader::readAt() packages/ztd-query-core/src/Sql/Reader/SqlWordReader.php:31
- method-call ZtdQuery\Sql\Reader\SqlWordReader::readAt() packages/ztd-query-core/src/Sql/Reader/SqlWordReader.php:34
- method-call ZtdQuery\Sql\Reader\SqlWordReader::readAt() packages/ztd-query-core/src/Sql/Reader/SqlWordReader.php:42
- method-call ZtdQuery\Sql\SqlIdentifierComponent::at() packages/ztd-query-core/src/Sql/SqlIdentifierComponent.php:36
- method-call ZtdQuery\Sql\SqlTokenScanner::scan() packages/ztd-query-core/src/Sql/SqlTokenScanner.php:72
- method-call ZtdQuery\Sql\SqlTokenScanner::scan() packages/ztd-query-core/src/Sql/SqlTokenScanner.php:74
- method-call ZtdQuery\Sql\SqlTokenScanner::scan() packages/ztd-query-core/src/Sql/SqlTokenScanner.php:79
- method-call ZtdQuery\Sql\SqlTokenScanner::scan() packages/ztd-query-core/src/Sql/SqlTokenScanner.php:81
- method-call ZtdQuery\Sql\SqlTokenStream::matchingClosingNestingToken() packages/ztd-query-core/src/Sql/SqlTokenStream.php:111
- method-call ZtdQuery\Sql\SqlTokenStream::matchingClosingNestingToken() packages/ztd-query-core/src/Sql/SqlTokenStream.php:124
- method-call ZtdQuery\Sql\SqlTokenStream::splitStatements() packages/ztd-query-core/src/Sql/SqlTokenStream.php:162
- method-call ZtdQuery\Sql\SqlTokenStream::splitTopLevel() packages/ztd-query-core/src/Sql/SqlTokenStream.php:243
Type declarations 10
- type ZtdQuery\Sql\Reader\SqlBlockCommentReader packages/ztd-query-core/src/Sql/Reader/SqlBlockCommentReader.php:28
- type ZtdQuery\Sql\Reader\SqlDelimitedReader packages/ztd-query-core/src/Sql/Reader/SqlDelimitedReader.php:29
- type ZtdQuery\Sql\Reader\SqlParameterReader packages/ztd-query-core/src/Sql/Reader/SqlParameterReader.php:29
- type ZtdQuery\Sql\Reader\SqlParameterReader packages/ztd-query-core/src/Sql/Reader/SqlParameterReader.php:63
- type ZtdQuery\Sql\Reader\SqlTriviaReader packages/ztd-query-core/src/Sql/Reader/SqlTriviaReader.php:38
- type ZtdQuery\Sql\Reader\SqlWordReader packages/ztd-query-core/src/Sql/Reader/SqlWordReader.php:29
- type ZtdQuery\Sql\SqlIdentifierComponent packages/ztd-query-core/src/Sql/SqlIdentifierComponent.php:26
- type ZtdQuery\Sql\SqlTokenScanner packages/ztd-query-core/src/Sql/SqlTokenScanner.php:51
- type ZtdQuery\Sql\SqlTokenStream packages/ztd-query-core/src/Sql/SqlTokenStream.php:24
- type ZtdQuery\Sql\SqlTokenStream packages/ztd-query-core/src/Sql/SqlTokenStream.php:37