File tree Expand file tree Collapse file tree 15 files changed +113
-68
lines changed
Expand file tree Collapse file tree 15 files changed +113
-68
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,23 @@ public function __construct(
1919
2020
2121
22+ /**
23+ * @return TName
24+ */
25+ public function getName (): string
26+ {
27+ return $ this ->name ;
28+ }
29+
30+
31+
32+ public function getValue (): mixed
33+ {
34+ return $ this ->value ;
35+ }
36+
37+
38+
2239 public function interpret (Interpretation $ interpretation ): mixed
2340 {
2441 $ nodeInterpretations = $ interpretation ->nodeInterpretations ;
@@ -33,17 +50,17 @@ public function interpret(Interpretation $interpretation): mixed
3350 $ subnode = $ currentGenerator ->current ();
3451
3552 if ($ subnode instanceof SelectedNode) {
36- $ subnode = $ subnode ->value ;
53+ $ subnode = $ subnode ->getValue () ;
3754 }
3855
3956 if ($ subnode === NULL ) {
4057 $ currentGenerator ->send (NULL );
4158 } elseif ($ subnode instanceof Token) {
4259 $ currentGenerator ->send ($ subnode ->value );
4360 } elseif ($ subnode instanceof TokenNode) {
44- if (isset ($ nodeInterpretations [$ subnode ->name ])) {
61+ if (isset ($ nodeInterpretations [$ subnode ->getName () ])) {
4562 $ generatorStack [] = $ currentGenerator ;
46- $ currentGenerator = $ nodeInterpretations [$ subnode ->name ]->interpret ($ subnode );
63+ $ currentGenerator = $ nodeInterpretations [$ subnode ->getName () ]->interpret ($ subnode );
4764 } else {
4865 $ currentGenerator ->send ($ subnode ->value ->value );
4966 }
Original file line number Diff line number Diff line change @@ -12,10 +12,10 @@ final class Alternation implements GrammarProcessing\NodeInterpretation
1212 public function interpret (GrammarProcessing \Node $ node ): Generator
1313 {
1414 $ result = [
15- yield $ node ->value [1 ],
15+ yield $ node ->getValue () [1 ],
1616 ];
1717
18- foreach ($ node ->value [3 ]->value as $ item ) {
18+ foreach ($ node ->getValue () [3 ]->value as $ item ) {
1919 $ result [] = yield $ item ->value [2 ];
2020 }
2121
Original file line number Diff line number Diff line change @@ -12,10 +12,10 @@ final class Concatenation implements GrammarProcessing\NodeInterpretation
1212 public function interpret (GrammarProcessing \Node $ node ): Generator
1313 {
1414 $ result = [
15- yield $ node ->value [1 ],
15+ yield $ node ->getValue () [1 ],
1616 ];
1717
18- foreach ($ node ->value [3 ]->value as $ item ) {
18+ foreach ($ node ->getValue () [3 ]->value as $ item ) {
1919 $ result [] = yield $ item ->value [2 ];
2020 }
2121
Original file line number Diff line number Diff line change @@ -16,25 +16,25 @@ public function interpret(GrammarProcessing\Node $node): Generator
1616
1717 return match ($ node ->index ) {
1818 0 => new GrammarProcessing \Vocabulary \Repeat (
19- yield $ node ->value [0 ],
19+ yield $ node ->getValue () [0 ],
2020 0 ,
2121 1 ,
2222 ),
2323 1 => new GrammarProcessing \Vocabulary \Repeat (
24- yield $ node ->value [0 ],
24+ yield $ node ->getValue () [0 ],
2525 0 ,
2626 null ,
2727 ),
2828 2 => new GrammarProcessing \Vocabulary \Repeat (
29- yield $ node ->value [0 ],
29+ yield $ node ->getValue () [0 ],
3030 1 ,
3131 null ,
3232 ),
3333 3 => new GrammarProcessing \Vocabulary \Subtract (
34- yield $ node ->value [0 ],
35- yield $ node ->value [4 ],
34+ yield $ node ->getValue () [0 ],
35+ yield $ node ->getValue () [4 ],
3636 ),
37- 4 => yield $ node ->value [0 ],
37+ 4 => yield $ node ->getValue () [0 ],
3838 default => throw new LogicException ("This can't happen " ),
3939 };
4040 }
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ public function interpret(GrammarProcessing\Node $node): Generator
3030 {
3131 $ result = [];
3232
33- foreach ($ node ->value as $ item ) {
33+ foreach ($ node ->getValue () as $ item ) {
3434 [$ identifier , $ production ] = yield $ item ->value [1 ];
3535
3636 $ result [$ identifier ->nonterminal ] = $ production ;
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ final class Identifier implements GrammarProcessing\NodeInterpretation
1111
1212 public function interpret (GrammarProcessing \Node $ node ): Generator
1313 {
14- return new GrammarProcessing \Vocabulary \Nonterminal (yield $ node ->value );
14+ return new GrammarProcessing \Vocabulary \Nonterminal (yield $ node ->getValue () );
1515 }
1616
1717}
Original file line number Diff line number Diff line change @@ -11,8 +11,8 @@ final class Rule implements GrammarProcessing\NodeInterpretation
1111
1212 public function interpret (GrammarProcessing \Node $ node ): Generator
1313 {
14- $ identifier = yield $ node ->value [0 ];
15- $ production = yield $ node ->value [4 ];
14+ $ identifier = yield $ node ->getValue () [0 ];
15+ $ production = yield $ node ->getValue () [4 ];
1616
1717 return [$ identifier , $ production ];
1818 }
Original file line number Diff line number Diff line change @@ -15,19 +15,19 @@ public function interpret(GrammarProcessing\Node $node): Generator
1515 /** @var GrammarProcessing\SelectedNode $node */
1616
1717 return match ($ node ->index ) {
18- 0 => yield $ node ->value [2 ],
18+ 0 => yield $ node ->getValue () [2 ],
1919 1 => new GrammarProcessing \Vocabulary \Repeat (
20- yield $ node ->value [2 ],
20+ yield $ node ->getValue () [2 ],
2121 0 ,
2222 1 ,
2323 ),
2424 2 => new GrammarProcessing \Vocabulary \Repeat (
25- yield $ node ->value [2 ],
25+ yield $ node ->getValue () [2 ],
2626 0 ,
2727 null ,
2828 ),
29- 3 => yield $ node ->value ,
30- 4 => yield $ node ->value ,
29+ 3 => yield $ node ->getValue () ,
30+ 4 => yield $ node ->getValue () ,
3131 default => throw new LogicException ("This can't happen " ),
3232 };
3333 }
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ final class Terminal implements GrammarProcessing\NodeInterpretation
1111
1212 public function interpret (GrammarProcessing \Node $ node ): Generator
1313 {
14- $ value = yield $ node ->value ;
14+ $ value = yield $ node ->getValue () ;
1515
1616 if (str_starts_with ($ value , '" ' )) {
1717 $ value = trim ($ value , '" ' );
Original file line number Diff line number Diff line change 66final class EmptyNode implements Node
77{
88
9- public null $ value {
9+ public function __construct (
10+ public readonly string $ name ,
11+ ) {}
12+
1013
11- get {
12- return null ;
13- }
1414
15+ public function getName (): string
16+ {
17+ return $ this ->name ;
1518 }
1619
1720
1821
19- public function __construct (
20- public readonly string $ name ,
21- ) {}
22+ public function getValue (): null
23+ {
24+ return null ;
25+ }
2226
2327}
You can’t perform that action at this time.
0 commit comments