File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff 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 ()) {
You can’t perform that action at this time.
0 commit comments