final class Token
Public API: explicitly declared with @visibility public.

One terminal as the lexer read it from the SQL text.

A token carries the whitespace and comments written before it, so a run of tokens spells the text it was read from, byte for byte. The end marker and other tokens a lexer synthesises have no text and stand at the offset where the lexer produced them, which is how the trivia before them still has an owner.

Reading a token's positiondoctest
$token = new \SqlParser\Lexer\Token(7, 'SELECT_SYM', 'SELECT', 0);
    $token->end() // => 6
Writing a token back as it was writtendoctest
$token = new \SqlParser\Lexer\Token(7, 'NUM', '1', 9, '   ');
    $token->toString() // => '   1'

Properties§

public int $symbol
public string $name
public string $text
public int $offset
public string $leading = ''

Methods§

public function __construct(
    public int $symbol,
    public string $name,
    public string $text,
    public int $offset,
    public string $leading = '',
)

Parameters

$symbolintTerminal number in the grammar's symbol table
$namestringTerminal name as the grammar spells it
$textstringText as written in the SQL
$offsetintByte offset of the first character
$leadingstringWhitespace and comments written before the token
public function end(): int

Answers the byte offset just past the token.

Returns

int End offset
Test cases 1
Calls 1
public function is(string $name): bool

Reports whether the token is a given terminal.

Parameters

$namestringTerminal name

Returns

bool True when the names match
Test cases 1
public function toString(): string

Answers the text the token was read from, the trivia before it included.

Returns

string The trivia written before the token followed by its text
Test cases 1

Test cases 63§

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

Dedicated tests 3
Other tests reaching this symbol 60

Relations§

Instantiated in 6
Type checks 19
Type declarations 47