File tree Expand file tree Collapse file tree 2 files changed +35
-2
lines changed
Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change 1+ <?php declare (strict_types=1 );
2+
3+ namespace Vojtechdobes \GrammarProcessing ;
4+
5+ use LogicException ;
6+
7+
8+ final class SelectedNode implements Node
9+ {
10+
11+ public string $ name {
12+
13+ get {
14+ throw new LogicException (
15+ self ::class . " must be parsed manually " ,
16+ );
17+ }
18+
19+ }
20+
21+
22+
23+ public function __construct (
24+ public readonly int $ index ,
25+ public readonly Node $ value ,
26+ ) {}
27+
28+ }
Original file line number Diff line number Diff line change @@ -36,13 +36,14 @@ public function acceptNode(
3636 $ attempts = [];
3737 $ localError = new GrammarProcessing \Error ();
3838
39- foreach ($ this ->symbols as $ symbol ) {
39+ foreach ($ this ->symbols as $ i => $ symbol ) {
4040 $ tokenStreamCopy = clone $ tokenStream ;
4141
4242 try {
4343 $ node = $ symbol ->acceptNode ($ error , $ tokenStreamCopy , $ nonterminals );
4444
4545 $ attempts [] = [
46+ 'index ' => $ i ,
4647 'node ' => $ node ,
4748 'tokenStream ' => $ tokenStreamCopy ,
4849 ];
@@ -64,7 +65,11 @@ public function acceptNode(
6465 $ result = array_pop ($ attempts );
6566
6667 $ tokenStream ->advanceTo ($ result ['tokenStream ' ]);
67- return $ result ['node ' ];
68+
69+ return new GrammarProcessing \SelectedNode (
70+ $ result ['index ' ],
71+ $ result ['node ' ],
72+ );
6873 }
6974
7075
You can’t perform that action at this time.
0 commit comments