Skip to content

Commit a6347c2

Browse files
committed
Add method to initialize lexer
1 parent 3ec6fb3 commit a6347c2

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/Phlexer/Phlexer.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,34 @@ abstract class Phlexer
99
/**
1010
* @var string[]
1111
*/
12-
private array $states = [self::INITIAL_STATE];
12+
private array $states;
1313
private string $text;
14-
private int $cursor = 0;
14+
private int $cursor;
1515

1616
/**
1717
* The current matched value
1818
*/
19-
protected string $yytext = '';
19+
protected string $yytext;
2020

2121
/**
2222
* @param Rule[] $rules
2323
*/
2424
public function __construct(protected array $rules) {}
2525

26+
public function initialize(string $text): void
27+
{
28+
$this->states = [self::INITIAL_STATE];
29+
$this->text = $text;
30+
$this->cursor = 0;
31+
$this->yytext = '';
32+
}
33+
2634
/**
2735
* @return Token[]
2836
*/
2937
public function tokenize(string $text): array
3038
{
31-
$this->text = $text;
39+
$this->initialize($text);
3240
$tokens = [];
3341

3442
while ($token = $this->getNextToken()) {

0 commit comments

Comments
 (0)