final class Token
Restricted visibility: declared "@visibility root". Code outside that scope must not name this declaration.

One token of a grammar file.

The text is what the token stands for: a string or code without its delimiters, a compound token without its | or /. The raw spelling is what was written, for error messages.

Properties§

public TokenKind $kind
public string $text
public Location $location
public string $raw

Methods§

public function __construct(
    public TokenKind $kind,
    public string $text,
    public Location $location,
    public string $raw,
)

Parameters

$kindTokenKindWhat the token is
$textstringWhat it stands for
$locationLocationWhere it begins
$rawstringWhat was written
public function is(TokenKind $kind): bool

Reports whether the token is of a given kind.

Parameters

$kindTokenKindKind to compare with

Returns

bool True when the kinds match
Test cases 1
public function isPunctuation(string $character): bool

Reports whether the token is a given punctuation character.

Parameters

$characterstringThe character

Returns

bool True for that character
Test cases 1
Calls 1
public function isUpperWord(): bool

Reports whether the token is a word starting with an upper-case letter.

Returns

bool True for a terminal name
Test cases 1
Calls 2
public function isLowerWord(): bool

Reports whether the token is a word starting with a lower-case letter.

Returns

bool True for a nonterminal name
Test cases 1
Calls 2
public function isAlphaWord(): bool

Reports whether the token is a word starting with a letter.

Returns

bool True for a symbol name
Test cases 1
Calls 2

Test cases 23§

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 18

Relations§

Instantiated in 7
Type declarations 9