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 an value inside the container.

Token|null
offsetGet(mixed $offset)

Gets a value from the container.

bool
offsetExists(mixed $offset)

Checks if an offset was previously set.

void
offsetUnset(mixed $offset)

Unsets the value of an offset.

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 an value inside the container.

Parameters

mixed $offset

the offset to be set

mixed $value

the token to be saved

Return Value

void

Token|null offsetGet(mixed $offset)

Gets a value from the container.

Parameters

mixed $offset

the offset to be returned

Return Value

Token|null

bool offsetExists(mixed $offset)

Checks if an offset was previously set.

Parameters

mixed $offset

the offset to be checked

Return Value

bool

void offsetUnset(mixed $offset)

Unsets the value of an offset.

Parameters

mixed $offset

the offset to be unset

Return Value

void