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

$keywordsKeywordTableKeywords of the release
$versionMySqlVersionRelease the text is read for
$modeSqlModeMode the text is read under
$triviaTriviaScannerSkips whitespace and comments
$quotedQuotedScannerReads quoted tokens
$numbersNumberScannerReads numbers
$wordsWordScannerReads words
$operatorsOperatorScannerReads operators
$variablesVariableScannerReads what follows an at sign
Calls 7
public function scan(string $sql): list<Lexeme>

Reads SQL text into lexemes, the end-of-input terminal last.

Parameters

$sqlstringThe SQL text

Returns

list<Lexeme> The lexemes in text order

Throws

LexicalException When the text holds something no token starts with
Test cases 3
Called from 1
Calls 8
public function next(Scan $scan): Lexeme
public function merged(list<Lexeme> $lexemes, string $sql): list<Lexeme>

Joins WITH ROLLUP, and WITH CUBE where the release has it, into one lexeme.

Parameters

$lexemeslist<Lexeme>Lexemes as read
$sqlstringThe SQL text the joined lexeme spans

Returns

list<Lexeme> Lexemes with the pairs joined
Test cases 1
Called from 1
Calls 4

Private surface 9§

Implementation details, listed for orientation only.

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()

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

Relations§

Instantiated in 1
Method calls 1
Type declarations 1