class TokensList implements ArrayAccess (View source)

Defines an array of tokens and utility functions to iterate through it.

A structure representing a list of tokens.

Properties

int $count

The count of tokens.

int $idx

The index of the next token to be returned.

Methods

__construct(array $tokens = [])

No description

string
build()

Builds an array of tokens by merging their raw value.

static string
buildFromArray(array $list)

Builds an array of tokens by merging their raw value.

void
add(Token $token)

Adds a new token.

Token|null
getNext()

Gets the next token. Skips any irrelevant token (whitespaces and comments).

Token|null
getPrevious()

Gets the previous token. Skips any irrelevant token (whitespaces and comments).

Token|null
getPreviousOfType(TokenType|array $type)

Gets the previous token.

Token|null
getNextOfType(TokenType|array $type)

Gets the next token.

Token|null
getNextOfTypeAndValue(TokenType $type, string $value)

Gets the next token.

Token|null
getNextOfTypeAndFlag(TokenType $type, int $flag)

Gets the next token.

void
offsetSet(mixed $offset, mixed $value)

Sets a Token inside the list of tokens.

Token|null
offsetGet(mixed $offset)

Gets a Token from the list of tokens.

bool
offsetExists(mixed $offset)

Checks if an offset was previously set.

void
offsetUnset(mixed $offset)

Unsets the value of an offset, if the offset exists.

Details

__construct(array $tokens = [])

No description

Parameters

array $tokens

The array of tokens.

string build()

Builds an array of tokens by merging their raw value.

Return Value

string

static string buildFromArray(array $list)

Builds an array of tokens by merging their raw value.

Parameters

array $list

the tokens to be built

Return Value

string

void add(Token $token)

Adds a new token.

Parameters

Token $token

token to be added in list

Return Value

void

Token|null getNext()

Gets the next token. Skips any irrelevant token (whitespaces and comments).

Return Value

Token|null

Token|null getPrevious()

Gets the previous token. Skips any irrelevant token (whitespaces and comments).

Return Value

Token|null

Token|null getPreviousOfType(TokenType|array $type)

Gets the previous token.

Parameters

TokenType|array $type

the type

Return Value

Token|null

Token|null getNextOfType(TokenType|array $type)

Gets the next token.

Parameters

TokenType|array $type

the type

Return Value

Token|null

Token|null getNextOfTypeAndValue(TokenType $type, string $value)

Gets the next token.

Parameters

TokenType $type

the type of the token

string $value

the value of the token

Return Value

Token|null

Token|null getNextOfTypeAndFlag(TokenType $type, int $flag)

Gets the next token.

Parameters

TokenType $type

the type of the token

int $flag

the flag of the token

Return Value

Token|null

void offsetSet(mixed $offset, mixed $value)

Sets a Token inside the list of tokens.

When defined, offset must be positive otherwise the offset is ignored. If the offset is not defined (like in array_push) or if it is greater than the number of Tokens already stored, the Token is appended to the list of tokens.

Parameters

mixed $offset

the offset to be set. Must be positive otherwise, nothing will be stored.

mixed $value

the token to be saved

Return Value

void

Token|null offsetGet(mixed $offset)

Gets a Token from the list of tokens.

If the offset is negative or above the number of tokens set in the list, will return null.

Parameters

mixed $offset

the offset to be returned

Return Value

Token|null

bool offsetExists(mixed $offset)

Checks if an offset was previously set.

If the offset is negative or above the number of tokens set in the list, will return false.

Parameters

mixed $offset

the offset to be checked

Return Value

bool

void offsetUnset(mixed $offset)

Unsets the value of an offset, if the offset exists.

Parameters

mixed $offset

the offset to be unset

Return Value

void