classSqlTokenScanner
final class SqlTokenScanner
Reads a statement into the lexemes it is written as, losing nothing.
Every byte of the statement ends up in exactly one token, whitespace and comments included, so that the statement can always be written back out unchanged. Nothing here knows any SQL: which quotes open a string, what begins a comment and what may spell an identifier are all asked of the profile, so one reader serves every dialect.
What each kind of lexeme is spelled like is a reader of its own; this one asks each in turn and keeps the depths, because only a statement read as a whole can say how deeply a lexeme is nested.
Methods§
public function __construct(
private SqlTriviaReader $trivia = new \ZtdQuery\Sql\Reader\SqlTriviaReader(),
private SqlDelimitedReader $delimited = new \ZtdQuery\Sql\Reader\SqlDelimitedReader(),
private SqlParameterReader $parameters = new \ZtdQuery\Sql\Reader\SqlParameterReader(),
private SqlWordReader $words = new \ZtdQuery\Sql\Reader\SqlWordReader(),
)Creates the scanner from the readers it asks.
Parameters
$trivia | SqlTriviaReader | What reads whitespace and comments |
$delimited | SqlDelimitedReader | What reads strings and quoted identifiers |
$parameters | SqlParameterReader | What reads placeholders |
$words | SqlWordReader | What reads bare words and numbers |
Test cases 5
SqlTokenScannerTest::testScanCountsHowDeeplyEachLexemeIsNestedcoversSqlTokenScannerTest::testScanLosesNothingOfTheStatementItReadcoversSqlTokenScannerTest::testScanReadsAnUnterminatedStringToTheEndOfTheStatementcoversSqlTokenScannerTest::testScanReadsAWholeCommentAsOneLexemecoversSqlTokenScannerTest::testScanReadsEachLexemeAsWhatItIscovers
Calls 4
public function scan(string $sql, SqlLexerProfile $profile): list<SqlToken>Reads a statement into its lexemes.
Parameters
$sql | string | The statement, as written |
$profile | SqlLexerProfile | What the dialect spells things with |
Returns
list<SqlToken> Every lexeme, in the order they were writtenTest cases 5
SqlTokenScannerTest::testScanCountsHowDeeplyEachLexemeIsNestedcovers and callsSqlTokenScannerTest::testScanLosesNothingOfTheStatementItReadcovers and callsSqlTokenScannerTest::testScanReadsAnUnterminatedStringToTheEndOfTheStatementcovers and callsSqlTokenScannerTest::testScanReadsAWholeCommentAsOneLexemecovers and callsSqlTokenScannerTest::testScanReadsEachLexemeAsWhatItIscovers and calls
Called from 1
Calls 12
- function-call
strlenline 54 - method-call SqlTriviaReader::readAt() line 61
- method-call SqlDelimitedReader::readAt() line 62
- method-call SqlParameterReader::readAt() line 63
- method-call SqlWordReader::readAt() line 64
- static-call SqlToken::slice() line 67
- method-call SqlLexerProfile::isNestingClosing() line 72
- function-call
maxline 73 - method-call SqlLexerProfile::isBracketClosing() line 74
- class-const SqlTokenKind::Symbol() line 78
- method-call SqlLexerProfile::isNestingOpening() line 79
- method-call SqlLexerProfile::isBracketOpening() line 81
Private surface 4§
Implementation details, listed for orientation only.
private SqlTriviaReader $trivia = new \ZtdQuery\Sql\Reader\SqlTriviaReader()private SqlDelimitedReader $delimited = new \ZtdQuery\Sql\Reader\SqlDelimitedReader()private SqlParameterReader $parameters = new \ZtdQuery\Sql\Reader\SqlParameterReader()private SqlWordReader $words = new \ZtdQuery\Sql\Reader\SqlWordReader()Test cases 8§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 5
SqlTokenScannerTest::testScanCountsHowDeeplyEachLexemeIsNestedcovers and callsSqlTokenScannerTest::testScanLosesNothingOfTheStatementItReadcovers and callsSqlTokenScannerTest::testScanReadsAnUnterminatedStringToTheEndOfTheStatementcovers and callsSqlTokenScannerTest::testScanReadsAWholeCommentAsOneLexemecovers and callsSqlTokenScannerTest::testScanReadsEachLexemeAsWhatItIscovers and calls
Other tests reaching this symbol 3
SqlIdentifierComponentTestcallsSqlKeywordSequenceTestcallsSqlTokenStreamTestcalls