|
22 | 22 |
|
23 | 23 | namespace PackageFactory\ComponentEngine\Transpiler\Php\Expression; |
24 | 24 |
|
| 25 | +use PackageFactory\ComponentEngine\Parser\Ast\AccessNode; |
25 | 26 | use PackageFactory\ComponentEngine\Parser\Ast\BinaryOperationNode; |
26 | 27 | use PackageFactory\ComponentEngine\Parser\Ast\BooleanLiteralNode; |
27 | 28 | use PackageFactory\ComponentEngine\Parser\Ast\ExpressionNode; |
28 | 29 | use PackageFactory\ComponentEngine\Parser\Ast\IdentifierNode; |
| 30 | +use PackageFactory\ComponentEngine\Parser\Ast\MatchNode; |
29 | 31 | use PackageFactory\ComponentEngine\Parser\Ast\NumberLiteralNode; |
30 | 32 | use PackageFactory\ComponentEngine\Parser\Ast\StringLiteralNode; |
31 | 33 | use PackageFactory\ComponentEngine\Parser\Ast\TagNode; |
32 | 34 | use PackageFactory\ComponentEngine\Parser\Ast\TernaryOperationNode; |
| 35 | +use PackageFactory\ComponentEngine\Transpiler\Php\Access\AccessTranspiler; |
33 | 36 | use PackageFactory\ComponentEngine\Transpiler\Php\BinaryOperation\BinaryOperationTranspiler; |
34 | 37 | use PackageFactory\ComponentEngine\Transpiler\Php\BooleanLiteral\BooleanLiteralTranspiler; |
35 | 38 | use PackageFactory\ComponentEngine\Transpiler\Php\Identifier\IdentifierTranspiler; |
| 39 | +use PackageFactory\ComponentEngine\Transpiler\Php\Match\MatchTranspiler; |
36 | 40 | use PackageFactory\ComponentEngine\Transpiler\Php\NumberLiteral\NumberLiteralTranspiler; |
37 | 41 | use PackageFactory\ComponentEngine\Transpiler\Php\StringLiteral\StringLiteralTranspiler; |
38 | 42 | use PackageFactory\ComponentEngine\Transpiler\Php\Tag\TagTranspiler; |
39 | 43 | use PackageFactory\ComponentEngine\Transpiler\Php\TernaryOperation\TernaryOperationTranspiler; |
| 44 | +use PackageFactory\ComponentEngine\TypeSystem\ScopeInterface; |
40 | 45 |
|
41 | 46 | final class ExpressionTranspiler |
42 | 47 | { |
43 | 48 | public function __construct( |
44 | | - private bool $shouldAddQuotesIfNecessary = false |
| 49 | + private readonly ScopeInterface $scope, |
| 50 | + private readonly bool $shouldAddQuotesIfNecessary = false |
45 | 51 | ) { |
46 | 52 | } |
47 | 53 |
|
48 | 54 | public function transpile(ExpressionNode $expressionNode): string |
49 | 55 | { |
50 | 56 | $rootTranspiler = match ($expressionNode->root::class) { |
51 | | - IdentifierNode::class => new IdentifierTranspiler(), |
52 | | - TernaryOperationNode::class => new TernaryOperationTranspiler(), |
53 | | - BinaryOperationNode::class => new BinaryOperationTranspiler(), |
| 57 | + AccessNode::class => new AccessTranspiler( |
| 58 | + scope: $this->scope |
| 59 | + ), |
| 60 | + IdentifierNode::class => new IdentifierTranspiler( |
| 61 | + scope: $this->scope |
| 62 | + ), |
| 63 | + TernaryOperationNode::class => new TernaryOperationTranspiler( |
| 64 | + scope: $this->scope |
| 65 | + ), |
| 66 | + BinaryOperationNode::class => new BinaryOperationTranspiler( |
| 67 | + scope: $this->scope |
| 68 | + ), |
54 | 69 | BooleanLiteralNode::class => new BooleanLiteralTranspiler(), |
| 70 | + MatchNode::class => new MatchTranspiler( |
| 71 | + scope: $this->scope |
| 72 | + ), |
55 | 73 | NumberLiteralNode::class => new NumberLiteralTranspiler(), |
56 | 74 | StringLiteralNode::class => new StringLiteralTranspiler( |
57 | 75 | shouldAddQuotes: $this->shouldAddQuotesIfNecessary |
58 | 76 | ), |
59 | 77 | TagNode::class => new TagTranspiler( |
| 78 | + scope: $this->scope, |
60 | 79 | shouldAddQuotes: $this->shouldAddQuotesIfNecessary |
61 | 80 | ), |
62 | 81 | default => throw new \Exception('@TODO: Transpile ' . $expressionNode->root::class) |
|
0 commit comments