diff --git a/src/Parser/TokenIterator.php b/src/Parser/TokenIterator.php index 5ae393e..65c9761 100644 --- a/src/Parser/TokenIterator.php +++ b/src/Parser/TokenIterator.php @@ -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 */