classCursor
final class Cursor
Reads SQL text from left to right, one token at a time.
Properties§
public string $sourceMethods§
public function __construct(public string $source)Parameters
$source | string | The whole SQL text |
public function eof(): boolReports whether everything has been read.
Returns
bool True at the end of the textTest cases 3
Calls 1
- function-call
strlenline 30
public function peek(int $ahead = 0): stringAnswers the byte at a distance ahead without consuming it.
Parameters
$ahead | int | Distance from the current position |
Returns
string The byte, or an empty string past the endTest cases 3
CursorTest::testPeekcallsCursorTest::testSeekcallsWordScannerTest::testConsumecalls
Called from 1
public function offset(): intAnswers the current byte offset.
Returns
int Offset from the start of the textTest cases 4
CursorTest::testLookingAtcallsCursorTest::testOffsetcallsCursorTest::testSkipPastOrEndcallsCursorTest::testTakecalls
Called from 3
- method-call SqlParser\MySql\Lexer\Scan::lexeme() packages/sql-parser/src/MySql/Lexer/Scan.php:53
- method-call SqlParser\PostgreSql\Lexer\Scan::lexeme() packages/sql-parser/src/PostgreSql/Lexer/Scan.php:37
- method-call SqlParser\Sqlite\Lexer\Scan::lexeme() packages/sql-parser/src/Sqlite/Lexer/Scan.php:46
public function seek(int $offset): voidMoves to a byte offset.
Parameters
$offset | int | Offset to move to |
Test cases 1
CursorTest::testSeekcalls
Called from 1
public function startsWith(string $prefix): boolReports whether the unread text starts with a string.
Parameters
$prefix | string | Text to look for |
Returns
bool True when the next bytes spell the prefixTest cases 1
public function startsWithIgnoringCase(string $prefix): boolReports whether the unread text starts with a string, regardless of case.
Parameters
$prefix | string | Text to look for |
Returns
bool True when the next bytes spell the prefix in any caseTest cases 1
public function take(int $length): stringConsumes a number of bytes and answers them.
Parameters
$length | int | How many bytes to consume |
Returns
string The consumed bytesTest cases 6
CursorTest::testEofcallsCursorTest::testOffsetcallsCursorTest::testStartsWithcallsCursorTest::testTakecallsCursorTest::testTakeQuotedcallsWordScannerTest::testSkipQuotedcalls
Called from 1
public function match(string $pattern): string|nullConsumes what a pattern matches at the current position.
Parameters
$pattern | string | Regular expression without anchors or delimiters |
Returns
string|null The matched text, or null when nothing matches hereTest cases 1
CursorTest::testMatchcalls
public function lookingAt(string $pattern): boolReports whether a pattern matches at the current position, without consuming it.
Parameters
$pattern | string | Regular expression without anchors or delimiters |
Returns
bool True when it matches hereTest cases 1
public function skipPastOrEnd(string $needle): boolConsumes everything up to and including a delimiter, or to the end when it is missing.
Parameters
$needle | string | Text that ends the run |
Returns
bool True when the delimiter was foundTest cases 1
public function takeQuoted(string $quote, bool $backslashEscapes = false): string|nullConsumes a quoted run whose quote escapes itself by doubling, and optionally by a backslash.
Parameters
$quote | string | The quote character the run opens with |
$backslashEscapes | bool | Whether a backslash escapes the next byte |
Returns
string|null The run including both quotes, or null when it never closesTest cases 2
Called from 1
Private surface 1§
Implementation details, listed for orientation only.
private int $offset = 0Test cases 96§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 12
CursorTest::testEofcallsCursorTest::testLookingAtcallsCursorTest::testMatchcallsCursorTest::testOffsetcallsCursorTest::testPeekcallsCursorTest::testSeekcallsCursorTest::testSkipPastOrEndcallsCursorTest::testStartsWithcallsCursorTest::testStartsWithIgnoringCasecallsCursorTest::testTakecallsCursorTest::testTakeQuotedcallsCursorTest::testTakeQuotedWithBackslashEscapescalls
Other tests reaching this symbol 84
MySqlLexerTest::testNextcallsNumberScannerTest::testFractioncallsNumberScannerTest::testScancallsNumberScannerTest::testScanNotesAQualifiedIdentifierThatStartsWithADigitcallsOperatorScannerTest::testMultiCharactercallsOperatorScannerTest::testScancallsOperatorScannerTest::testScanRejectsAForeignCharactercallsOperatorScannerTest::testScanRejectsAParameterMarkerGluedToANamecallsOperatorScannerTest::testSeparatorcallsQuotedScannerTest::testQuotedIdentifiercallsQuotedScannerTest::testQuotedIdentifierRejectsAnUnterminatedIdentifiercallsQuotedScannerTest::testScanReadsPrefixedLiteralscallsQuotedScannerTest::testScanReadsStringsAndIdentifierscallsQuotedScannerTest::testScanRejectsAnOddHexadecimalLiteralcallsQuotedScannerTest::testStringcallsQuotedScannerTest::testStringRejectsAnUnterminatedStringcallsScanTest::testLexemecallsTriviaScannerTest::testBlockCommentcallsTriviaScannerTest::testBlockCommentRejectsAnUnterminatedCommentcallsTriviaScannerTest::testSkipDropsAVersionCommentForANewerReleasecallsTriviaScannerTest::testSkipPassesWhitespaceAndCommentscallsTriviaScannerTest::testSkipReadsAVersionCommentBodyAsSqlcallsVariableScannerTest::testAtcallsVariableScannerTest::testHostnamecallsVariableScannerTest::testIdentifierOrKeywordcallsVariableScannerTest::testIdentifierOrKeywordRejectsAMissingNamecallsVariableScannerTest::testSystemVariablecallsWordScannerTest::testConsumecallsWordScannerTest::testDollarQuotedcallsWordScannerTest::testDollarQuotedRejectsAnUnterminatedStringcallsWordScannerTest::testIdentifiercallsWordScannerTest::testIdentifierLexemecallsWordScannerTest::testScancallsWordScannerTest::testWordKeepsAKeywordBeforeADotAsAnIdentifiercallsWordScannerTest::testWordLooksUpFunctionsAcrossSpacesUnderIgnoreSpacecallsMySqlParserTestcallsNumberScannerTest::testRejectJunkcallsNumberScannerTest::testScancallsNumberScannerTest::testScanRejectsAnEmptyHexadecimalLiteralcallsNumberScannerTest::testScanRejectsAnIncompleteExponentcallsNumberScannerTest::testScanRejectsTrailingJunkcallsOperatorScannerTest::testScancallsOperatorScannerTest::testScanRejectsAForeignCharactercallsOperatorScannerTest::testScanRejectsAnOverlongOperatorcallsPostgreSqlLexerTestcallsQuotedScannerTest::testBodycallsQuotedScannerTest::testDollarQuotedcallsQuotedScannerTest::testDollarQuotedRejectsAnUnterminatedStringcallsQuotedScannerTest::testIdentifiercallsQuotedScannerTest::testIdentifierRejectsAnEmptyIdentifiercallsQuotedScannerTest::testIdentifierRejectsAnUnterminatedIdentifiercallsQuotedScannerTest::testScanReadsEverySpellingOfAStringcallsQuotedScannerTest::testScanReadsTheNationalPrefixAsAKeywordcallsQuotedScannerTest::testStringcallsQuotedScannerTest::testStringRejectsAnUnterminatedStringcallsScanTest::testLexemecallsTriviaScannerTest::testBlockCommentcallsTriviaScannerTest::testBlockCommentRejectsAnUnterminatedCommentcallsTriviaScannerTest::testSkipcallsWordScannerTest::testScancallsPostgreSqlParserTestcallsNumberScannerTest::testScancallsNumberScannerTest::testScanRejectsTrailingJunkcallsOperatorScannerTest::testScancallsOperatorScannerTest::testScanRejectsAForeignCharactercallsQuotedScannerTest::testScancallsQuotedScannerTest::testScanRejectsAnOddBlobcallsQuotedScannerTest::testScanRejectsAnUnterminatedBracketcallsQuotedScannerTest::testScanRejectsAnUnterminatedStringcallsScanTest::testLastcallsScanTest::testLexemecallsSqliteLexerTestcallsTriviaScannerTest::testSkipcallsTriviaScannerTest::testSkipLeavesASlashBeforeTheEndAlonecallsTriviaScannerTest::testSkipRunsAnUnterminatedCommentToTheEndcallsVariableScannerTest::testScancallsVariableScannerTest::testScanRejectsAnUnterminatedSuffixcallsVariableScannerTest::testScanRejectsASigilWithoutANamecallsWordScannerTest::testAheadcallsWordScannerTest::testContextualcallsWordScannerTest::testProbecallsWordScannerTest::testScancallsWordScannerTest::testSkipQuotedcallsSqliteParserTestcalls
Relations§
Instantiated in 4
- new SqlParser\MySql\Lexer\MySqlLexer::scan() packages/sql-parser/src/MySql/Lexer/MySqlLexer.php:59
- new SqlParser\PostgreSql\Lexer\PostgreSqlLexer::scan() packages/sql-parser/src/PostgreSql/Lexer/PostgreSqlLexer.php:49
- new SqlParser\Sqlite\Lexer\SqliteLexer::scan() packages/sql-parser/src/Sqlite/Lexer/SqliteLexer.php:54
- new SqlParser\Sqlite\Lexer\WordScanner::ahead() packages/sql-parser/src/Sqlite/Lexer/WordScanner.php:84
Method calls 7
- method-call SqlParser\MySql\Lexer\Scan::lexeme() packages/sql-parser/src/MySql/Lexer/Scan.php:53
- method-call SqlParser\MySql\Lexer\WordScanner::consume() packages/sql-parser/src/MySql/Lexer/WordScanner.php:111
- method-call SqlParser\MySql\Lexer\WordScanner::consume() packages/sql-parser/src/MySql/Lexer/WordScanner.php:112
- method-call SqlParser\PostgreSql\Lexer\Scan::lexeme() packages/sql-parser/src/PostgreSql/Lexer/Scan.php:37
- method-call SqlParser\Sqlite\Lexer\Scan::lexeme() packages/sql-parser/src/Sqlite/Lexer/Scan.php:46
- method-call SqlParser\Sqlite\Lexer\WordScanner::skipQuoted() packages/sql-parser/src/Sqlite/Lexer/WordScanner.php:154
- method-call SqlParser\Sqlite\Lexer\WordScanner::skipQuoted() packages/sql-parser/src/Sqlite/Lexer/WordScanner.php:155
Type declarations 5
- type SqlParser\MySql\Lexer\Scan packages/sql-parser/src/MySql/Lexer/Scan.php:36
- type SqlParser\MySql\Lexer\WordScanner packages/sql-parser/src/MySql/Lexer/WordScanner.php:108
- type SqlParser\PostgreSql\Lexer\Scan packages/sql-parser/src/PostgreSql/Lexer/Scan.php:22
- type SqlParser\Sqlite\Lexer\Scan packages/sql-parser/src/Sqlite/Lexer/Scan.php:30
- type SqlParser\Sqlite\Lexer\WordScanner packages/sql-parser/src/Sqlite/Lexer/WordScanner.php:152