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
Calls 2
public static function tokenize(string $sql, SqlLexerProfile $profile): self

Tokenize.

Parameters

$sqlstring
$profileSqlLexerProfile

Returns

self
Test cases 260
Called from 167
Calls 3
public function tokens(): list<SqlToken>

Returns

list<SqlToken>
public function significantTokens(): list<SqlToken>

Returns

list<SqlToken>
Called from 13
Calls 5
public function identifierAt(int $index = 0): array{name: string, next: int}|null

Parameters

$indexint

Returns

array{name: string, next: int}|null
Called from 15
Calls 2
public function splitStatements(): list<string>

Returns

list<string>
Calls 5
public function topLevelClause(
    non-empty-list<string> $startKeywords,
    list<non-empty-list<string>> $endKeywords = [],
): ?string

Parameters

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

Returns

?string
Calls 7
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
Calls 7
public function splitTopLevel(?string $delimiter = null): list<string>

Parameters

$delimiter?string

Returns

list<string>
Calls 5
public function firstTopLevelKeyword(): ?string

First top level keyword.

Returns

?string
Calls 3

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 261§

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 207

Relations§

Static calls 167
Method calls 26
Type declarations 18