TokenIterator: add save points

This commit is contained in:
Jan Tvrdik 2017-11-18 16:14:05 +01:00
parent 9983296e35
commit 3dda8122e1

View File

@ -13,6 +13,9 @@ class TokenIterator
/** @var int */
private $index;
/** @var int[] */
private $savePoints = [];
public function __construct(array $tokens, int $index = 0)
{
@ -147,6 +150,24 @@ class TokenIterator
}
public function pushSavePoint(): void
{
$this->savePoints[] = $this->index;
}
public function dropSavePoint(): void
{
array_pop($this->savePoints);
}
public function rollback(): void
{
$this->index = array_pop($this->savePoints);
}
/**
* @throws ParserException
*/