$tokens
*/
public function __construct(array $tokens, int $index = 0)
{
if ($tokens === []) {
$index = 0;
}
parent::__construct($tokens, $index);
}
/**
* @param int[] $types
*/
public function isNextTokenTypes(array $types) : bool
{
foreach ($types as $type) {
if ($this->isNextTokenType($type)) {
return \true;
}
}
return \false;
}
public function isTokenTypeOnPosition(int $tokenType, int $position) : bool
{
$tokens = $this->getTokens();
$token = $tokens[$position] ?? null;
if ($token === null) {
return \false;
}
return $token[1] === $tokenType;
}
public function isNextTokenType(int $tokenType) : bool
{
if ($this->nextTokenType() === null) {
return \false;
}
return $this->nextTokenType() === $tokenType;
}
public function printFromTo(int $from, int $to) : string
{
if ($to < $from) {
throw new ShouldNotHappenException('Arguments are flipped');
}
$tokens = $this->getTokens();
$content = '';
foreach ($tokens as $key => $token) {
if ($key < $from) {
continue;
}
if ($key >= $to) {
continue;
}
$content .= $token[0];
}
return $content;
}
public function currentPosition() : int
{
return $this->currentTokenIndex();
}
public function count() : int
{
return \count($this->getTokens());
}
/**
* @return array