classSqlLexer
final class SqlLexer
Restricted visibility: declared "@visibility root". Code outside that scope must not name this declaration.
Splits SQL into tokens without committing to one dialect's grammar.
Only enough structure is recognised to tell keywords, string bodies, comments and bind parameters apart, which is what reading a statement's kind, its tables and its placeholders needs. Anything unrecognised becomes a symbol.
Methods§
public function tokenize(string $sql): list<SqlToken>The tokens of a statement, in order.
Parameters
$sql | string |
Returns
list<SqlToken>Test cases 7
SqlLexerTest::testTokenizeKeepsStringBodiesTogethercallsSqlLexerTest::testTokenizeNeverLosesGroundOnUnbalancedParenthesescallsSqlLexerTest::testTokenizeSeparatesWordsAndSymbolscallsSqlLexerTest::testTokenizeTracksParenthesisDepthcallsStatementKindReaderTest::testReadAfterCommonTableIgnoresNestedKeywordscallsTableReaderTest::testReadNameIsNullWhenNothingNamesATablecallsTableReaderTest::testReadNameStopsAtATrailingSeparatorcalls
Called from 3
- method-call SqlCatalog\Core\Sql\PlaceholderScanner::scan() packages/sql-catalog/src/Core/Sql/PlaceholderScanner.php:40
- method-call SqlCatalog\Core\Sql\StatementKindReader::read() packages/sql-catalog/src/Core/Sql/StatementKindReader.php:68
- method-call SqlCatalog\Core\Sql\TableReader::read() packages/sql-catalog/src/Core/Sql/TableReader.php:57
Calls 6
- function-call
strlenline 28 - function-call
ctype_spaceline 34 - function-call
maxline 39 - new SqlToken line 40
- class-const SqlTokenKind::Symbol() line 40
- method-call SqlLexer::readToken() line 45
public function readToken(string $sql, int $offset, int $depth): SqlTokenThe token starting at the given offset.
Parameters
$sql | string | |
$offset | int | |
$depth | int |
Returns
Test cases 1
Called from 1
Calls 12
- method-call SqlLexer::readComment() line 58
- new SqlToken line 60
- class-const SqlTokenKind::Comment() line 60
- method-call SqlLexer::readQuoted() line 63
- class-const SqlTokenKind::Text() line 65
- class-const SqlTokenKind::Identifier() line 65
- class-const SqlTokenKind::Symbol() line 71
- method-call SqlLexer::readParameter() line 74
- class-const SqlTokenKind::Parameter() line 76
- function-call
preg_matchline 79 - class-const SqlTokenKind::Number() line 80
- class-const SqlTokenKind::Word() line 83
public function readComment(string $sql, int $offset): ?stringThe comment starting at the offset, or null when none starts there.
Parameters
$sql | string | |
$offset | int |
Returns
?stringTest cases 1
Called from 1
Calls 1
- function-call
preg_matchline 94
public function readQuoted(string $sql, int $offset): ?stringThe quoted run starting at the offset, or null when none starts there.
Parameters
$sql | string | |
$offset | int |
Returns
?stringTest cases 2
Called from 1
Calls 3
- class-const SqlLexer::QUOTES() line 110
- function-call
strlenline 115 - function-call
substrline 126
public function readParameter(string $sql, int $offset): ?stringThe bind parameter starting at the offset, or null when none starts there.
Parameters
$sql | string | |
$offset | int |
Returns
?stringTest cases 1
Called from 1
Calls 1
- function-call
preg_matchline 142
Private surface 1§
Implementation details, listed for orientation only.
private const QUOTES = ["'" => "'", '"' => '"', '`' => '`', '[' => ']']Test cases 20§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 9
SqlLexerTest::testReadCommentRecognisesEveryCommentSyntaxcallsSqlLexerTest::testReadParameterRecognisesEveryParameterSyntaxcallsSqlLexerTest::testReadQuotedHandlesEscapesAndDoublingcallsSqlLexerTest::testReadQuotedRunsToTheEndWhenTheQuoteIsNeverClosedcallsSqlLexerTest::testReadTokencallsSqlLexerTest::testTokenizeKeepsStringBodiesTogethercallsSqlLexerTest::testTokenizeNeverLosesGroundOnUnbalancedParenthesescallsSqlLexerTest::testTokenizeSeparatesWordsAndSymbolscallsSqlLexerTest::testTokenizeTracksParenthesisDepthcalls
Other tests reaching this symbol 11
CatalogCommandTestcallsEntryFactoryTestcallsExpressionEvaluatorTestcallsPlaceholderScannerTestcallsStatementKindReaderTest::testReadAfterCommonTableIgnoresNestedKeywordscallsTableReaderTest::testReadNameIsNullWhenNothingNamesATablecallsTableReaderTest::testReadNameStopsAtATrailingSeparatorcallsCallModelTestcallsAnalyzerTestcallsJsonReporterTestcallsTextReporterTestcalls
Relations§
Instantiated in 3
- new SqlCatalog\Core\Sql\PlaceholderScanner::__construct() packages/sql-catalog/src/Core/Sql/PlaceholderScanner.php:28
- new SqlCatalog\Core\Sql\StatementKindReader::__construct() packages/sql-catalog/src/Core/Sql/StatementKindReader.php:60
- new SqlCatalog\Core\Sql\TableReader::__construct() packages/sql-catalog/src/Core/Sql/TableReader.php:47
Method calls 3
- method-call SqlCatalog\Core\Sql\PlaceholderScanner::scan() packages/sql-catalog/src/Core/Sql/PlaceholderScanner.php:40
- method-call SqlCatalog\Core\Sql\StatementKindReader::read() packages/sql-catalog/src/Core/Sql/StatementKindReader.php:68
- method-call SqlCatalog\Core\Sql\TableReader::read() packages/sql-catalog/src/Core/Sql/TableReader.php:57
Type declarations 6
- type SqlCatalog\Core\Sql\PlaceholderScanner packages/sql-catalog/src/Core/Sql/PlaceholderScanner.php:21
- type SqlCatalog\Core\Sql\PlaceholderScanner packages/sql-catalog/src/Core/Sql/PlaceholderScanner.php:26
- type SqlCatalog\Core\Sql\StatementKindReader packages/sql-catalog/src/Core/Sql/StatementKindReader.php:53
- type SqlCatalog\Core\Sql\StatementKindReader packages/sql-catalog/src/Core/Sql/StatementKindReader.php:58
- type SqlCatalog\Core\Sql\TableReader packages/sql-catalog/src/Core/Sql/TableReader.php:40
- type SqlCatalog\Core\Sql\TableReader packages/sql-catalog/src/Core/Sql/TableReader.php:45