classLexicalPattern
final class LexicalPattern
Reads a regular expression against a position in a statement.
A scanner asks the same two questions over and over — does this pattern match right here, and does this one character match at all — and both have an answer that has to be exact: an empty match is no match, because a scanner that accepts one never advances.
Methods§
public function matchAt(string|null $pattern, string $subject, int $offset): string|nullAnswers what a pattern matches at a position, if anything.
Parameters
$pattern | string|null | Pattern to read, or null when the dialect has none |
$subject | string | Statement being scanned |
$offset | int | Position to read from |
Returns
string|null What it matched, or null when it matched nothingTest cases 5
LexicalPatternTest::testAssertValidAcceptsThatTheDialectDeclaredNoPatterncovers and callsLexicalPatternTest::testMatchAtAnswersWhatThePatternMatchedTherecovers and callsLexicalPatternTest::testMatchAtIsNothingWhereTheDialectDeclaredNoPatterncovers and callsLexicalPatternTest::testMatchAtIsNothingWhereThePatternDidNotMatchcovers and callsLexicalPatternTest::testMatchAtIsNothingWhereThePatternMatchedNoCharacterAtAllcovers and calls
Called from 4
- method-call ZtdQuery\Sql\Profile\SqlParameterProfile::positionalParameterLengthAt() packages/ztd-query-core/src/Sql/Profile/SqlParameterProfile.php:70
- method-call ZtdQuery\Sql\Profile\SqlParameterProfile::parameterSuffixLength() packages/ztd-query-core/src/Sql/Profile/SqlParameterProfile.php:141
- method-call ZtdQuery\Sql\Profile\SqlQuoteProfile::dollarQuoteDelimiterAt() packages/ztd-query-core/src/Sql/Profile/SqlQuoteProfile.php:143
- method-call ZtdQuery\Sql\Profile\SqlSymbolProfile::numberLengthAt() packages/ztd-query-core/src/Sql/Profile/SqlSymbolProfile.php:76
public function matchesCharacter(string $pattern, string $character): boolReports whether one character matches a pattern.
Parameters
$pattern | string | Pattern to read |
$character | string | Character to test |
Returns
bool True when it matches, and false for no character at allTest cases 3
Called from 2
Calls 1
- function-call
preg_matchline 47
public function assertValid(string|null $pattern): voidRefuses a pattern that is not one preg can read.
preg reports a bad pattern as a warning rather than by raising, so the warning is turned into the refusal here; a pattern kept and used later would fail at every position instead of once, at the point it was given.
Parameters
$pattern | string|null | Pattern to check, or null when the dialect has none |
Throws
InvalidDefinitionException When the pattern is empty or preg will not read itTest cases 2
Called from 6
- method-call ZtdQuery\Sql\LexicalDelimiters::perPrefixPatterns() packages/ztd-query-core/src/Sql/LexicalDelimiters.php:103
- method-call ZtdQuery\Sql\LexicalDelimiters::validPatterns() packages/ztd-query-core/src/Sql/LexicalDelimiters.php:122
- method-call ZtdQuery\Sql\Profile\SqlQuoteProfile::__construct() packages/ztd-query-core/src/Sql/Profile/SqlQuoteProfile.php:52
- method-call ZtdQuery\Sql\Profile\SqlSymbolProfile::__construct() packages/ztd-query-core/src/Sql/Profile/SqlSymbolProfile.php:48
- method-call ZtdQuery\Sql\Profile\SqlSymbolProfile::__construct() packages/ztd-query-core/src/Sql/Profile/SqlSymbolProfile.php:49
- method-call ZtdQuery\Sql\Profile\SqlSymbolProfile::__construct() packages/ztd-query-core/src/Sql/Profile/SqlSymbolProfile.php:50
Calls 4
- function-call
set_error_handlerline 66 - new InvalidDefinitionException line 67
- function-call
preg_matchline 70 - function-call
restore_error_handlerline 72
Test cases 23§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 9
LexicalPatternTest::testAssertValidAcceptsThatTheDialectDeclaredNoPatterncovers and callsLexicalPatternTest::testAssertValidLeavesTheErrorHandlerAsItFoundItcovers and callsLexicalPatternTest::testMatchAtAnswersWhatThePatternMatchedTherecovers and callsLexicalPatternTest::testMatchAtIsNothingWhereTheDialectDeclaredNoPatterncovers and callsLexicalPatternTest::testMatchAtIsNothingWhereThePatternDidNotMatchcovers and callsLexicalPatternTest::testMatchAtIsNothingWhereThePatternMatchedNoCharacterAtAllcovers and callsLexicalPatternTest::testMatchesCharacterIsFalseForACharacterThePatternRefusescovers and callsLexicalPatternTest::testMatchesCharacterIsFalseForNoCharacterAtAllcovers and callsLexicalPatternTest::testMatchesCharacterReportsACharacterThePatternAcceptscovers and calls
Other tests reaching this symbol 14
LexicalDelimitersTestcallsSqlParameterProfileTestcallsSqlQuoteProfileTestcallsSqlSymbolProfileTestcallsSqlBlockCommentReaderTestcallsSqlDelimitedReaderTestcallsSqlParameterReaderTestcallsSqlTriviaReaderTestcallsSqlWordReaderTestcallsSqlIdentifierComponentTestcallsSqlKeywordSequenceTestcallsSqlLexerProfileTestcallsSqlTokenScannerTestcallsSqlTokenStreamTestcalls
Relations§
Instantiated in 4
- new ZtdQuery\Sql\LexicalDelimiters::__construct() packages/ztd-query-core/src/Sql/LexicalDelimiters.php:22
- new ZtdQuery\Sql\Profile\SqlParameterProfile::__construct() packages/ztd-query-core/src/Sql/Profile/SqlParameterProfile.php:48
- new ZtdQuery\Sql\Profile\SqlQuoteProfile::__construct() packages/ztd-query-core/src/Sql/Profile/SqlQuoteProfile.php:46
- new ZtdQuery\Sql\Profile\SqlSymbolProfile::__construct() packages/ztd-query-core/src/Sql/Profile/SqlSymbolProfile.php:46
Method calls 12
- method-call ZtdQuery\Sql\LexicalDelimiters::perPrefixPatterns() packages/ztd-query-core/src/Sql/LexicalDelimiters.php:103
- method-call ZtdQuery\Sql\LexicalDelimiters::validPatterns() packages/ztd-query-core/src/Sql/LexicalDelimiters.php:122
- method-call ZtdQuery\Sql\Profile\SqlParameterProfile::positionalParameterLengthAt() packages/ztd-query-core/src/Sql/Profile/SqlParameterProfile.php:70
- method-call ZtdQuery\Sql\Profile\SqlParameterProfile::parameterSuffixLength() packages/ztd-query-core/src/Sql/Profile/SqlParameterProfile.php:141
- method-call ZtdQuery\Sql\Profile\SqlQuoteProfile::__construct() packages/ztd-query-core/src/Sql/Profile/SqlQuoteProfile.php:52
- method-call ZtdQuery\Sql\Profile\SqlQuoteProfile::dollarQuoteDelimiterAt() packages/ztd-query-core/src/Sql/Profile/SqlQuoteProfile.php:143
- method-call ZtdQuery\Sql\Profile\SqlSymbolProfile::__construct() packages/ztd-query-core/src/Sql/Profile/SqlSymbolProfile.php:48
- method-call ZtdQuery\Sql\Profile\SqlSymbolProfile::__construct() packages/ztd-query-core/src/Sql/Profile/SqlSymbolProfile.php:49
- method-call ZtdQuery\Sql\Profile\SqlSymbolProfile::__construct() packages/ztd-query-core/src/Sql/Profile/SqlSymbolProfile.php:50
- method-call ZtdQuery\Sql\Profile\SqlSymbolProfile::numberLengthAt() packages/ztd-query-core/src/Sql/Profile/SqlSymbolProfile.php:76
- method-call ZtdQuery\Sql\Profile\SqlSymbolProfile::isIdentifierStart() packages/ztd-query-core/src/Sql/Profile/SqlSymbolProfile.php:90
- method-call ZtdQuery\Sql\Profile\SqlSymbolProfile::isIdentifierPart() packages/ztd-query-core/src/Sql/Profile/SqlSymbolProfile.php:102
Type declarations 4
- type ZtdQuery\Sql\LexicalDelimiters packages/ztd-query-core/src/Sql/LexicalDelimiters.php:22
- type ZtdQuery\Sql\Profile\SqlParameterProfile packages/ztd-query-core/src/Sql/Profile/SqlParameterProfile.php:48
- type ZtdQuery\Sql\Profile\SqlQuoteProfile packages/ztd-query-core/src/Sql/Profile/SqlQuoteProfile.php:46
- type ZtdQuery\Sql\Profile\SqlSymbolProfile packages/ztd-query-core/src/Sql/Profile/SqlSymbolProfile.php:46