1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of Railt package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
declare(strict_types=1); |
9
|
|
|
|
10
|
|
|
namespace Railt\Compiler\Grammar\Delegate; |
11
|
|
|
|
12
|
|
|
use Railt\Compiler\Grammar\LookaheadIterator; |
13
|
|
|
use Railt\Lexer\Result\Eoi; |
14
|
|
|
use Railt\Lexer\Result\Token; |
15
|
|
|
use Railt\Lexer\TokenInterface; |
16
|
|
|
use Railt\Parser\Ast\LeafInterface; |
17
|
|
|
use Railt\Parser\Ast\NodeInterface; |
18
|
|
|
use Railt\Parser\Ast\Rule; |
19
|
|
|
use Railt\Parser\Ast\RuleInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class RuleDelegate |
23
|
|
|
*/ |
24
|
|
|
class RuleDelegate extends Rule |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @return iterable|TokenInterface[]|LookaheadIterator |
28
|
|
|
*/ |
29
|
|
|
public function getInnerTokens(): iterable |
30
|
|
|
{ |
31
|
|
|
return new LookaheadIterator((function () { |
32
|
|
|
yield from $this->getTokens($this->first('RuleProduction')); |
|
|
|
|
33
|
|
|
yield new Eoi(0); |
34
|
|
|
})->call($this)); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param RuleInterface|NodeInterface $rule |
39
|
|
|
* @return \Traversable |
40
|
|
|
*/ |
41
|
|
|
private function getTokens(RuleInterface $rule): \Traversable |
42
|
|
|
{ |
43
|
|
|
/** @var LeafInterface $child */ |
44
|
|
|
foreach ($rule->getChildren() as $child) { |
45
|
|
|
if ($child instanceof RuleInterface) { |
46
|
|
|
yield from $this->getTokens($child); |
47
|
|
|
} else { |
48
|
|
|
yield new Token($child->getName(), $child->getValues(), $child->getOffset()); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return string |
55
|
|
|
* @throws \Railt\Parser\Exception\InternalException |
56
|
|
|
* @throws \Railt\Parser\Exception\ParserException |
57
|
|
|
*/ |
58
|
|
|
public function getRuleName(): string |
59
|
|
|
{ |
60
|
|
|
return $this->find('RuleName > T_NAME')->value(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return bool |
65
|
|
|
* @throws \Railt\Parser\Exception\InternalException |
66
|
|
|
* @throws \Railt\Parser\Exception\ParserException |
67
|
|
|
*/ |
68
|
|
|
public function isKept(): bool |
69
|
|
|
{ |
70
|
|
|
return (bool)$this->first('ShouldKeep'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return null|string |
75
|
|
|
* @throws \Railt\Parser\Exception\InternalException |
76
|
|
|
* @throws \Railt\Parser\Exception\ParserException |
77
|
|
|
*/ |
78
|
|
|
public function getDelegate(): ?string |
79
|
|
|
{ |
80
|
|
|
return $this->find('RuleDelegate > T_NAME')->value(); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: