classWordScanner
final class WordScanner
Reads MySQL's words: keywords, identifiers, introducers and dollar-quoted strings.
A word followed at once by . and another word is an identifier whatever it spells, which is how a schema may be named after a keyword. Otherwise the word is looked up as a keyword, and as a function name too when a parenthesis follows it at once.
Methods§
Reads the word at the cursor, if one starts there.
Parameters
$scan | Scan | The tokenization in progress |
Returns
Lexeme|null The lexeme, or null when no word starts hereThrows
LexicalException When a dollar-quoted string never closesTest cases 1
Called from 1
Calls 4
- method-call WordScanner::dollarQuoted() line 36
- static-call Scan::isIdentifierByte() line 41
- function-call
ctype_digitline 41 - method-call WordScanner::word() line 45
Reads a word that may be a keyword.
Parameters
$scan | Scan | The tokenization in progress, positioned on the word |
$start | int | Offset the word began at |
Returns
Lexeme The lexemeTest cases 2
Called from 1
Calls 7
- method-call WordScanner::consume() line 59
- static-call Scan::isIdentifierByte() line 60
- class-const LexerState::IdentifierSeparator() line 61
- method-call WordScanner::identifierLexeme() line 63
- method-call Scan::lexeme() line 73
- static-call Charsets::has() line 75
- function-call
substrline 75
Reads a word that is an identifier whatever it spells, as after ..
Parameters
$scan | Scan | The tokenization in progress, positioned on the word |
$start | int | Offset the word began at |
Returns
Lexeme The lexemeTest cases 1
Called from 2
Calls 4
- method-call WordScanner::consume() line 93
- static-call Scan::isIdentifierByte() line 94
- class-const LexerState::IdentifierSeparator() line 95
- method-call WordScanner::identifierLexeme() line 98
public function consume(Cursor $cursor): stringConsumes the identifier bytes at the cursor.
Parameters
$cursor | Cursor | Reads the SQL text |
Returns
string The bytes consumedTest cases 1
Called from 3
- method-call SqlParser\MySql\Lexer\VariableScanner::identifierOrKeyword() packages/sql-parser/src/MySql/Lexer/VariableScanner.php:91
- method-call SqlParser\MySql\Lexer\WordScanner::word() packages/sql-parser/src/MySql/Lexer/WordScanner.php:59
- method-call SqlParser\MySql\Lexer\WordScanner::identifier() packages/sql-parser/src/MySql/Lexer/WordScanner.php:93
Calls 3
- static-call Scan::isIdentifierByte() line 111
- method-call Cursor::peek() line 111
- method-call Cursor::take() line 112
Makes the identifier lexeme MySQL would, quoted when it holds non-ASCII bytes.
Parameters
$scan | Scan | The tokenization in progress |
$start | int | Offset the identifier began at |
$text | string | The identifier as written |
Returns
Lexeme An IDENT or IDENT_QUOTED lexemeTest cases 1
Called from 4
- method-call SqlParser\MySql\Lexer\VariableScanner::identifierOrKeyword() packages/sql-parser/src/MySql/Lexer/VariableScanner.php:98
- method-call SqlParser\MySql\Lexer\WordScanner::word() packages/sql-parser/src/MySql/Lexer/WordScanner.php:63
- method-call SqlParser\MySql\Lexer\WordScanner::word() packages/sql-parser/src/MySql/Lexer/WordScanner.php:79
- method-call SqlParser\MySql\Lexer\WordScanner::identifier() packages/sql-parser/src/MySql/Lexer/WordScanner.php:98
Calls 2
- method-call Scan::lexeme() line 129
- function-call
preg_matchline 129
Reads a dollar-quoted string, if one starts at the cursor.
Parameters
$scan | Scan | The tokenization in progress, positioned on the dollar sign |
Returns
Lexeme|null The lexeme, or null when the dollar sign starts an identifierThrows
LexicalException When the string never closesTest cases 2
Called from 1
Calls 4
- function-call
strposline 149 - static-call LexicalException::unterminated() line 151
- function-call
strlenline 153 - method-call Scan::lexeme() line 155
Test cases 14§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 8
WordScannerTest::testConsumecallsWordScannerTest::testDollarQuotedcallsWordScannerTest::testDollarQuotedRejectsAnUnterminatedStringcallsWordScannerTest::testIdentifiercallsWordScannerTest::testIdentifierLexemecallsWordScannerTest::testScancallsWordScannerTest::testWordKeepsAKeywordBeforeADotAsAnIdentifiercallsWordScannerTest::testWordLooksUpFunctionsAcrossSpacesUnderIgnoreSpacecalls
Other tests reaching this symbol 6
Relations§
Instantiated in 1
Method calls 5
- method-call SqlParser\MySql\Lexer\MySqlLexer::next() packages/sql-parser/src/MySql/Lexer/MySqlLexer.php:95
- method-call SqlParser\MySql\Lexer\MySqlLexer::next() packages/sql-parser/src/MySql/Lexer/MySqlLexer.php:100
- method-call SqlParser\MySql\Lexer\NumberScanner::scan() packages/sql-parser/src/MySql/Lexer/NumberScanner.php:53
- method-call SqlParser\MySql\Lexer\VariableScanner::identifierOrKeyword() packages/sql-parser/src/MySql/Lexer/VariableScanner.php:91
- method-call SqlParser\MySql\Lexer\VariableScanner::identifierOrKeyword() packages/sql-parser/src/MySql/Lexer/VariableScanner.php:98