|
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\SDL\Compiler\System\Provider; |
|
11
|
|
|
|
|
12
|
|
|
use Railt\Parser\Ast\RuleInterface; |
|
13
|
|
|
use Railt\Reflection\Contracts\Definition; |
|
14
|
|
|
use Railt\Reflection\Contracts\Definition\TypeDefinition; |
|
15
|
|
|
use Railt\Reflection\Contracts\Document; |
|
16
|
|
|
use Railt\Reflection\Contracts\Invocation\DirectiveInvocation; |
|
17
|
|
|
use Railt\SDL\Compiler\System\System; |
|
18
|
|
|
use Railt\SDL\Exception\TypeConflictException; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class DocumentSystem |
|
22
|
|
|
*/ |
|
23
|
|
|
class DocumentSystem extends System |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @param Definition|\Railt\Reflection\Document $document |
|
27
|
|
|
* @param RuleInterface $ast |
|
28
|
|
|
*/ |
|
29
|
119 |
|
public function resolve(Definition $document, RuleInterface $ast): void |
|
30
|
|
|
{ |
|
31
|
119 |
|
if ($document instanceof Document) { |
|
32
|
119 |
|
foreach ($ast as $child) { |
|
33
|
119 |
|
$this->deferred(function () use ($document, $child) { |
|
34
|
119 |
|
$definition = $this->process->build($child, $document); |
|
35
|
|
|
|
|
36
|
119 |
|
if ($definition instanceof TypeDefinition) { |
|
37
|
119 |
|
$this->deferred(function () use ($definition, $document) { |
|
38
|
119 |
|
if ($document->getDictionary()->has($definition->getName())) { |
|
39
|
|
|
throw $this->redeclareException($definition); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
119 |
|
$document->withDefinition($definition); |
|
43
|
119 |
|
}); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
119 |
|
if ($definition instanceof DirectiveInvocation) { |
|
48
|
|
|
$this->complete(function () use ($definition, $document) { |
|
49
|
|
|
$document->withDirective($definition); |
|
50
|
|
|
}); |
|
51
|
|
|
} |
|
52
|
119 |
|
}); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
119 |
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|