Completed
Push — master ( 1bc299...b12741 )
by Kirill
03:33
created

BaseParser::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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 Serafim\Properties\Parser;
11
12
use Railt\Lexer\Factory;
13
use Railt\Lexer\LexerInterface;
14
use Railt\Parser\Driver\Llk;
15
use Railt\Parser\Driver\Stateful;
16
use Railt\Parser\Grammar;
17
use Railt\Parser\ParserInterface;
18
use Railt\Parser\Rule\Alternation;
19
use Railt\Parser\Rule\Concatenation;
20
use Railt\Parser\Rule\Repetition;
21
use Railt\Parser\Rule\Terminal;
22
use Railt\Parser\GrammarInterface;
23
24
/**
25
 * --- DO NOT EDIT THIS FILE ---
26
 *
27
 * Class BaseParser has been auto-generated.
28
 * Generated at: 13-10-2018 15:06:23
29
 *
30
 * --- DO NOT EDIT THIS FILE ---
31
 */
32
class BaseParser extends Stateful
33
{
34
    public const T_DOC_DEFINITION = 'T_DOC_DEFINITION';
35
    public const T_VARIABLE = 'T_VARIABLE';
36
    public const T_WORD = 'T_WORD';
37
    public const T_SUFFIX_ARRAY = 'T_SUFFIX_ARRAY';
38
    public const T_NAMESPACE = 'T_NAMESPACE';
39
    public const T_AND = 'T_AND';
40
    public const T_OR = 'T_OR';
41
    public const T_WHITESPACE = 'T_WHITESPACE';
42
    public const T_COMMENT = 'T_COMMENT';
43
    public const T_ANY = 'T_ANY';
44
45
    /**
46
     * Lexical tokens list.
47
     *
48
     * @var string[]
49
     */
50
    protected const LEXER_TOKENS = [
51
        self::T_DOC_DEFINITION => '@([\\w\\-]+)',
52
        self::T_VARIABLE => '\\$([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)',
53
        self::T_WORD => '[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*',
54
        self::T_SUFFIX_ARRAY => '\\[\\]',
55
        self::T_NAMESPACE => '\\\\',
56
        self::T_AND => '&',
57
        self::T_OR => '\\|',
58
        self::T_WHITESPACE => '\\s+',
59
        self::T_COMMENT => '\\*',
60
        self::T_ANY => '\\S+?',
61
    ];
62
63
    /**
64
     * List of skipped tokens.
65
     *
66
     * @var string[]
67
     */
68
    protected const LEXER_SKIPPED_TOKENS = [
69
        'T_WHITESPACE',
70
        'T_COMMENT',
71
        'T_ANY',
72
    ];
73
74
    /**
75
     * @var int
76
     */
77
    protected const LEXER_FLAGS = Factory::LOOKAHEAD;
78
79
    /**
80
     * List of rule delegates.
81
     *
82
     * @var string[]
83
     */
84
    protected const PARSER_DELEGATES = [
85
    ];
86
87
    /**
88
     * Parser root rule name.
89
     *
90
     * @var string
91
     */
92
    protected const PARSER_ROOT_RULE = 'Document';
93
94
    /**
95
     * @return ParserInterface
96
     * @throws \InvalidArgumentException
97
     * @throws \Railt\Lexer\Exception\BadLexemeException
98
     */
99
    protected function boot(): ParserInterface
100
    {
101
        return new Llk($this->bootLexer(), $this->bootGrammar());
102
    }
103
104
    /**
105
     * @return LexerInterface
106
     * @throws \InvalidArgumentException
107
     * @throws \Railt\Lexer\Exception\BadLexemeException
108
     */
109
    protected function bootLexer(): LexerInterface
110
    {
111
        return Factory::create(static::LEXER_TOKENS, static::LEXER_SKIPPED_TOKENS, static::LEXER_FLAGS);
112
    }
113
114
    /**
115
     * @return GrammarInterface
116
     */
117
    protected function bootGrammar(): GrammarInterface
118
    {
119
        return new Grammar([
120
            new Concatenation(0, ['DocBlock'], 'Document'), 
121
            new Concatenation(1, ['Any'], 'Document'), 
122
            new Alternation(2, [0, 1], null), 
123
            (new Repetition('Document', 0, -1, 2, null))->setDefaultId('Document'), 
124
            new Terminal(4, 'T_WORD', false), 
125
            new Terminal(5, 'T_DOC_DEFINITION', false), 
126
            new Terminal(6, 'T_VARIABLE', false), 
127
            new Terminal(7, 'T_SUFFIX_ARRAY', false), 
128
            new Terminal(8, 'T_NAMESPACE', false), 
129
            new Terminal(9, 'T_AND', false), 
130
            new Terminal(10, 'T_OR', false), 
131
            new Alternation('Any', [4, 5, 6, 7, 8, 9, 10], null), 
132
            new Concatenation(12, ['DocBlockVariable'], null), 
133
            (new Concatenation('DocBlock', ['DocBlockTitle', 'TypeHint', 12], 'DocBlock'))->setDefaultId('DocBlock'), 
134
            new Terminal(14, 'T_DOC_DEFINITION', true), 
135
            (new Concatenation('DocBlockTitle', [14], 'DocBlockTitle'))->setDefaultId('DocBlockTitle'), 
136
            new Terminal(16, 'T_VARIABLE', true), 
137
            (new Concatenation('DocBlockVariable', [16], 'DocBlockVariable'))->setDefaultId('DocBlockVariable'), 
138
            new Repetition(18, 0, 1, 'TypeHintContinuation', null), 
139
            (new Concatenation('TypeHint', ['TypeHintDefinition', 18], 'TypeHint'))->setDefaultId('TypeHint'), 
140
            new Concatenation(20, ['TypeHintDefinitionOr'], null), 
141
            new Alternation('TypeHintContinuation', ['TypeHintDefinitionAnd', 20], null), 
142
            new Terminal(22, 'T_OR', false), 
143
            new Concatenation('TypeHintDefinitionOr', [22, 'TypeHint'], 'Or'), 
144
            new Terminal(24, 'T_AND', false), 
145
            new Concatenation('TypeHintDefinitionAnd', [24, 'TypeHint'], 'And'), 
146
            new Concatenation(26, ['ScalarTypeHint'], null), 
147
            new Alternation('TypeHintDefinition', ['ArrayTypeHint', 26], null), 
148
            new Terminal(28, 'T_SUFFIX_ARRAY', false), 
149
            new Concatenation('ArrayTypeHint', ['TypeDefinition', 28], 'Array'), 
150
            new Concatenation('ScalarTypeHint', ['TypeDefinition'], 'Scalar'), 
151
            new Terminal(31, 'T_NAMESPACE', false), 
152
            new Repetition(32, 0, 1, 31, null), 
153
            new Terminal(33, 'T_WORD', true), 
154
            new Terminal(34, 'T_NAMESPACE', false), 
155
            new Terminal(35, 'T_WORD', true), 
156
            new Concatenation(36, [34, 35], null), 
157
            new Repetition(37, 0, -1, 36, null), 
158
            new Concatenation('TypeDefinition', [32, 33, 37], 'Type')
159
        ], static::PARSER_ROOT_RULE, static::PARSER_DELEGATES);
160
    }
161
}
162