TranslationScheme::applyProductionActions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Remorhaz\UniLex\RegExp\Grammar;
6
7
use Remorhaz\UniLex\Exception;
8
use Remorhaz\UniLex\Grammar\SDD\TranslationSchemeInterface;
9
use Remorhaz\UniLex\Parser\Production;
10
use Remorhaz\UniLex\Parser\Symbol;
11
use Remorhaz\UniLex\AST\Tree;
12
use Remorhaz\UniLex\Lexer\Token;
13
14
class TranslationScheme implements TranslationSchemeInterface
15
{
16
    private $tree;
17
18
    private $symbolScheme;
19
20
    private $productionScheme;
21
22
    private $tokenScheme;
23
24
    public function __construct(Tree $tree)
25
    {
26
        $this->tree = $tree;
27
        $this->symbolScheme = new SymbolTranslationScheme($tree);
28
        $this->productionScheme = new ProductionTranslationScheme($tree);
29
        $this->tokenScheme = new TokenTranslationScheme();
30
    }
31
32
    /**
33
     * @param Production $production
34
     * @param int $symbolIndex
35
     * @throws Exception
36
     */
37
    public function applySymbolActions(Production $production, int $symbolIndex): void
38
    {
39
        $this
40
            ->symbolScheme
41
            ->applyActions($production, $symbolIndex);
42
    }
43
44
    /**
45
     * @param Production $production
46
     * @throws Exception
47
     */
48
    public function applyProductionActions(Production $production): void
49
    {
50
        $this
51
            ->productionScheme
52
            ->applyActions($production);
53
    }
54
55
    /**
56
     * @param Symbol $symbol
57
     * @param Token $token
58
     * @throws Exception
59
     */
60
    public function applyTokenActions(Symbol $symbol, Token $token): void
61
    {
62
        $this
63
            ->tokenScheme
64
            ->applyActions($symbol, $token);
65
    }
66
}
67