Skip to content

Commit 0d0904c

Browse files
committed
Proxy SelectedNode::$value to its subnode
1 parent 73f31dc commit 0d0904c

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

src/GrammarProcessing/Ebnf/Nodes/Factor.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff 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->value[0],
19+
yield $node->value[0],
2020
0,
2121
1,
2222
),
2323
1 => new GrammarProcessing\Vocabulary\Repeat(
24-
yield $node->value->value[0],
24+
yield $node->value[0],
2525
0,
2626
null,
2727
),
2828
2 => new GrammarProcessing\Vocabulary\Repeat(
29-
yield $node->value->value[0],
29+
yield $node->value[0],
3030
1,
3131
null,
3232
),
3333
3 => new GrammarProcessing\Vocabulary\Subtract(
34-
yield $node->value->value[0],
35-
yield $node->value->value[4],
34+
yield $node->value[0],
35+
yield $node->value[4],
3636
),
37-
4 => yield $node->value->value[0],
37+
4 => yield $node->value[0],
3838
default => throw new LogicException("This can't happen"),
3939
};
4040
}

src/GrammarProcessing/Ebnf/Nodes/Term.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ public function interpret(GrammarProcessing\Node $node): Generator
1515
/** @var GrammarProcessing\SelectedNode $node */
1616

1717
return match ($node->index) {
18-
0 => yield $node->value->value[2],
18+
0 => yield $node->value[2],
1919
1 => new GrammarProcessing\Vocabulary\Repeat(
20-
yield $node->value->value[2],
20+
yield $node->value[2],
2121
0,
2222
1,
2323
),
2424
2 => new GrammarProcessing\Vocabulary\Repeat(
25-
yield $node->value->value[2],
25+
yield $node->value[2],
2626
0,
2727
null,
2828
),

src/GrammarProcessing/SelectedNode.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,21 @@ final class SelectedNode implements Node
1818

1919
}
2020

21+
public mixed $value {
22+
23+
get {
24+
return $this->subnode instanceof ListNode
25+
? $this->subnode->value
26+
: $this->subnode;
27+
}
28+
29+
}
30+
2131

2232

2333
public function __construct(
2434
public readonly int $index,
25-
public readonly Node $value,
35+
public readonly Node $subnode,
2636
) {}
2737

2838
}

0 commit comments

Comments
 (0)