classMySqlLexer
final class MySqlLexer
Restricted visibility: declared "@visibility root". Code outside that scope must not name this declaration.
Reads MySQL text into the terminals of its grammar, as sql_lex.cc does.
The lexer is a port of MySQL's own state machine: the state a token leaves behind decides how the next one is read, WITH ROLLUP is one token, and the input ends with an explicit end-of-input terminal.
Methods§
public function __construct(
private KeywordTable $keywords,
private MySqlVersion $version,
private SqlMode $mode = new \SqlParser\MySql\SqlMode(),
private TriviaScanner $trivia = new \SqlParser\MySql\Lexer\TriviaScanner(),
private QuotedScanner $quoted = new \SqlParser\MySql\Lexer\QuotedScanner(),
private NumberScanner $numbers = new \SqlParser\MySql\Lexer\NumberScanner(),
private WordScanner $words = new \SqlParser\MySql\Lexer\WordScanner(),
private OperatorScanner $operators = new \SqlParser\MySql\Lexer\OperatorScanner(),
private VariableScanner $variables = new \SqlParser\MySql\Lexer\VariableScanner(),
)Parameters
$keywords | KeywordTable | Keywords of the release |
$version | MySqlVersion | Release the text is read for |
$mode | SqlMode | Mode the text is read under |
$trivia | TriviaScanner | Skips whitespace and comments |
$quoted | QuotedScanner | Reads quoted tokens |
$numbers | NumberScanner | Reads numbers |
$words | WordScanner | Reads words |
$operators | OperatorScanner | Reads operators |
$variables | VariableScanner | Reads what follows an at sign |
Calls 7
- new SqlMode line 38
- new TriviaScanner line 39
- new QuotedScanner line 40
- new NumberScanner line 41
- new WordScanner line 42
- new OperatorScanner line 43
- new VariableScanner line 44
public function scan(string $sql): list<Lexeme>Reads SQL text into lexemes, the end-of-input terminal last.
Parameters
$sql | string | The SQL text |
Returns
list<Lexeme> The lexemes in text orderThrows
LexicalException When the text holds something no token starts withTest cases 3
Called from 1
Calls 8
- new Scan line 59
- new Cursor line 59
- class-const LexerState::Start() line 62
- method-call TriviaScanner::skip() line 63
- method-call MySqlLexer::next() line 68
- new Lexeme line 70
- function-call
strlenline 70 - method-call MySqlLexer::merged() line 72
Reads one lexeme in the state the previous one left behind.
Parameters
$scan | Scan | The tokenization in progress |
Returns
Lexeme The lexemeThrows
LexicalException When the text holds something no token starts withTest cases 1
MySqlLexerTest::testNextcalls
Called from 1
Calls 16
- class-const LexerState::Start() line 87
- class-const LexerState::Hostname() line 91
- method-call VariableScanner::hostname() line 91
- class-const LexerState::SystemVariable() line 92
- method-call VariableScanner::systemVariable() line 92
- class-const LexerState::IdentifierOrKeyword() line 93
- method-call VariableScanner::identifierOrKeyword() line 93
- class-const LexerState::IdentifierSeparator() line 94
- method-call OperatorScanner::separator() line 94
- class-const LexerState::IdentifierStart() line 95
- method-call WordScanner::identifier() line 95
- method-call VariableScanner::at() line 97
- method-call QuotedScanner::scan() line 98
- method-call NumberScanner::scan() line 99
- method-call WordScanner::scan() line 100
- method-call OperatorScanner::scan() line 101
Private surface 9§
Implementation details, listed for orientation only.
private KeywordTable $keywordsprivate MySqlVersion $versionprivate SqlMode $mode = new \SqlParser\MySql\SqlMode()private TriviaScanner $trivia = new \SqlParser\MySql\Lexer\TriviaScanner()private QuotedScanner $quoted = new \SqlParser\MySql\Lexer\QuotedScanner()private NumberScanner $numbers = new \SqlParser\MySql\Lexer\NumberScanner()private WordScanner $words = new \SqlParser\MySql\Lexer\WordScanner()private OperatorScanner $operators = new \SqlParser\MySql\Lexer\OperatorScanner()private VariableScanner $variables = new \SqlParser\MySql\Lexer\VariableScanner()Test cases 6§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 5
Other tests reaching this symbol 1
MySqlParserTestcalls