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\Console; |
11
|
|
|
|
12
|
|
|
use Railt\Compiler\Compiler; |
13
|
|
|
use Railt\Io\File; |
14
|
|
|
use Symfony\Component\Console\Command\Command; |
15
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class GrammarCompileCommand |
20
|
|
|
*/ |
21
|
|
|
final class GrammarCompileCommand extends Command |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var string Default parser output path |
25
|
|
|
*/ |
26
|
|
|
private const PARSER_GRAMMAR = __DIR__ . '/../../resources/grammar.pp2'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var string Default parser output path |
30
|
|
|
*/ |
31
|
|
|
private const OUT_PATH = __DIR__ . '/../Grammar'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var string Default generated parser class name |
35
|
|
|
*/ |
36
|
|
|
private const OUT_CLASS_NAME = 'Parser'; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var string Default generated parser class name |
40
|
|
|
*/ |
41
|
|
|
private const OUT_NAMESPACE = 'Railt\\Compiler\\Grammar'; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param InputInterface $in |
45
|
|
|
* @param OutputInterface $out |
46
|
|
|
* @throws \Railt\Io\Exception\ExternalFileException |
47
|
|
|
* @throws \Railt\Io\Exception\NotReadableException |
48
|
|
|
* @throws \Throwable |
49
|
|
|
*/ |
50
|
|
|
public function execute(InputInterface $in, OutputInterface $out): void |
51
|
|
|
{ |
52
|
|
|
$compiler = Compiler::load(File::fromPathname(self::PARSER_GRAMMAR)); |
|
|
|
|
53
|
|
|
|
54
|
|
|
$compiler |
55
|
|
|
->setNamespace(self::OUT_NAMESPACE) |
56
|
|
|
->setClassName(self::OUT_CLASS_NAME) |
57
|
|
|
->saveTo(self::OUT_PATH); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return void |
62
|
|
|
* @throws \Symfony\Component\Console\Exception\InvalidArgumentException |
63
|
|
|
*/ |
64
|
|
|
protected function configure(): void |
65
|
|
|
{ |
66
|
|
|
$this->setName('compiler:grammar'); |
67
|
|
|
$this->setDescription('Builds a new grammar parser from .pp/.pp2 grammar file.'); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.