Initial commit

This commit is contained in:
2022-02-13 15:31:49 +01:00
commit a6e8d252b1
6 changed files with 445 additions and 0 deletions

42
src/TokenList.php Normal file
View 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;
}
}