final class SqlTokenStream

Lossless SQL token stream for structure-aware clause operations.

Methods§

public function __construct(
    private string $sql,
    private list<SqlToken> $tokens,
    private SqlLexerProfile $profile,
    private SqlKeywordSequence $keywords = new \ZtdQuery\Sql\SqlKeywordSequence(),
    private SqlIdentifierComponent $identifiers = new \ZtdQuery\Sql\SqlIdentifierComponent(),
)

Binds a stream to the tokens it was read as, and the profile it was read with.

Parameters

$sqlstringThe statement, as written
$tokenslist<SqlToken>The lexemes it was read as
$profileSqlLexerProfileWhat the dialect spells things with
$keywordsSqlKeywordSequenceFinds where a clause is opened
$identifiersSqlIdentifierComponentReads a name out of the tokens
Test cases 54
Calls 2
public static function tokenize(string $sql, SqlLexerProfile $profile): self

Tokenize.

Parameters

$sqlstring
$profileSqlLexerProfile

Returns

self
Test cases 63
Calls 3
public function significantTokens(): list<SqlToken>

Returns

list<SqlToken>
Test cases 44
Called from 9
Calls 5
public function identifierAt(int $index = 0): array{name: string, next: int}|null
public function topLevelClause(
    non-empty-list<string> $startKeywords,
    list<non-empty-list<string>> $endKeywords = [],
): ?string
public function topLevelClauseAfter(
    non-empty-list<string> $anchorKeywords,
    non-empty-list<string> $startKeywords,
    list<non-empty-list<string>> $endKeywords = [],
): ?string

Parameters

$anchorKeywordsnon-empty-list<string>
$startKeywordsnon-empty-list<string>
$endKeywordslist<non-empty-list<string>>

Returns

?string
Test cases 4
Calls 7
public function firstTopLevelKeyword(): ?string

Private surface 5§

Implementation details, listed for orientation only.

private string $sql
private list<SqlToken> $tokens
private SqlLexerProfile $profile
private SqlKeywordSequence $keywords = new \ZtdQuery\Sql\SqlKeywordSequence()
private SqlIdentifierComponent $identifiers = new \ZtdQuery\Sql\SqlIdentifierComponent()

Test cases 64§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 54
Other tests reaching this symbol 10