Initial commit
This commit is contained in:
42
src/TokenList.php
Normal file
42
src/TokenList.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\PhpCalc;
|
||||
/**
|
||||
* Helper class to iterate over a list of tokens
|
||||
*
|
||||
* @license GPL V3 or later
|
||||
* @copyright (c) 2022, NoccyLabs
|
||||
*/
|
||||
class TokenList
|
||||
{
|
||||
|
||||
private array $toks;
|
||||
|
||||
private int $ptr = 0;
|
||||
|
||||
public function __construct(array $toks)
|
||||
{
|
||||
$this->toks = $toks;
|
||||
}
|
||||
|
||||
public function current(): ?string
|
||||
{
|
||||
return ($this->ptr >= count($this->toks) ? null : $this->toks[$this->ptr]);
|
||||
}
|
||||
|
||||
public function read(): ?string
|
||||
{
|
||||
$v = $this->current();
|
||||
$this->next();
|
||||
return $v;
|
||||
}
|
||||
|
||||
public function next(): ?string
|
||||
{
|
||||
if ($this->ptr < count($this->toks)) {
|
||||
$this->ptr++;
|
||||
return ($this->ptr < count($this->toks) ? $this->toks[$this->ptr] : null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user