|
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\Reader; |
|
11
|
|
|
use Railt\Compiler\Reader\Resolver\PragmaResolver; |
|
12
|
|
|
use Railt\Compiler\Reader\Resolver\RuleResolver; |
|
13
|
|
|
use Railt\Compiler\Reader\Resolver\TokenResolver; |
|
14
|
|
|
use Railt\Lexer\Driver\NativeStateless; |
|
15
|
|
|
use Railt\Lexer\LexerInterface; |
|
16
|
|
|
use Railt\Parser\Parser; |
|
17
|
|
|
use Railt\Parser\ParserInterface; |
|
18
|
|
|
use Railt\Parser\Rule\Token; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class Runtime |
|
22
|
|
|
*/ |
|
23
|
|
|
class Runtime |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var RuleResolver |
|
27
|
|
|
*/ |
|
28
|
|
|
private $rules; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var PragmaResolver |
|
32
|
|
|
*/ |
|
33
|
|
|
private $config; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var TokenResolver |
|
37
|
|
|
*/ |
|
38
|
|
|
private $tokens; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Runtime constructor. |
|
42
|
|
|
* @param Result $result |
|
43
|
|
|
*/ |
|
44
|
|
|
public function __construct(Result $result) |
|
45
|
|
|
{ |
|
46
|
|
|
$this->rules = $result->rulesResolver(); |
|
47
|
|
|
$this->tokens = $result->tokensResolver(); |
|
48
|
|
|
$this->config = $result->pragmasResolver(); |
|
49
|
|
|
} |
|
50
|
|
|
/** |
|
51
|
|
|
* @return LexerInterface |
|
52
|
|
|
*/ |
|
53
|
|
|
public function getLexer(): LexerInterface |
|
54
|
|
|
{ |
|
55
|
|
|
$lexer = new NativeStateless(); |
|
56
|
|
|
|
|
57
|
|
|
foreach ($this->tokens->getTokens() as $name => $pcre) { |
|
58
|
|
|
$lexer->add($name, $pcre, \in_array($name, $this->tokens->getSkip(), true)); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
return $lexer; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @return ParserInterface |
|
66
|
|
|
* @throws \InvalidArgumentException |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getParser(): ParserInterface |
|
69
|
|
|
{ |
|
70
|
|
|
$configs = $this->config->all(PragmaResolver::GROUP_PARSER); |
|
71
|
|
|
|
|
72
|
|
|
$parser = new Parser($this->getLexer(), $this->rules->getParsedRules(), $configs); |
|
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
foreach ($this->rules->getDelegates() as $name => $delegate) { |
|
75
|
|
|
$parser->addDelegate($name, $delegate); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return $parser; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
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: