BaseParser::bootGrammar()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 58

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 58
rs 8.9163
c 0
b 0
f 0
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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: 20-10-2018 14:21:32
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_ANGLE_LEFT = 'T_ANGLE_LEFT';
42
    public const T_ANGLE_RIGHT = 'T_ANGLE_RIGHT';
43
    public const T_COMMA = 'T_COMMA';
44
    public const T_WHITESPACE = 'T_WHITESPACE';
45
    public const T_COMMENT = 'T_COMMENT';
46
    public const T_ANY = 'T_ANY';
47
48
    /**
49
     * Lexical tokens list.
50
     *
51
     * @var string[]
52
     */
53
    protected const LEXER_TOKENS = [
54
        self::T_DOC_DEFINITION => '@([\\w\\-]+)',
55
        self::T_VARIABLE => '\\$([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)',
56
        self::T_WORD => '[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*',
57
        self::T_SUFFIX_ARRAY => '\\[\\]',
58
        self::T_NAMESPACE => '\\\\',
59
        self::T_AND => '&',
60
        self::T_OR => '\\|',
61
        self::T_ANGLE_LEFT => '<',
62
        self::T_ANGLE_RIGHT => '>',
63
        self::T_COMMA => ',',
64
        self::T_WHITESPACE => '\\s+',
65
        self::T_COMMENT => '\\*',
66
        self::T_ANY => '\\S+?',
67
    ];
68
69
    /**
70
     * List of skipped tokens.
71
     *
72
     * @var string[]
73
     */
74
    protected const LEXER_SKIPPED_TOKENS = [
75
        'T_WHITESPACE',
76
        'T_COMMENT',
77
        'T_ANY',
78
    ];
79
80
    /**
81
     * @var int
82
     */
83
    protected const LEXER_FLAGS = Factory::LOOKAHEAD;
84
85
    /**
86
     * List of rule delegates.
87
     *
88
     * @var string[]
89
     */
90
    protected const PARSER_DELEGATES = [
91
    ];
92
93
    /**
94
     * Parser root rule name.
95
     *
96
     * @var string
97
     */
98
    protected const PARSER_ROOT_RULE = 'Document';
99
100
    /**
101
     * @return ParserInterface
102
     * @throws \InvalidArgumentException
103
     * @throws \Railt\Lexer\Exception\BadLexemeException
104
     */
105
    protected function boot(): ParserInterface
106
    {
107
        return new Llk($this->bootLexer(), $this->bootGrammar());
108
    }
109
110
    /**
111
     * @return LexerInterface
112
     * @throws \InvalidArgumentException
113
     * @throws \Railt\Lexer\Exception\BadLexemeException
114
     */
115
    protected function bootLexer(): LexerInterface
116
    {
117
        return Factory::create(static::LEXER_TOKENS, static::LEXER_SKIPPED_TOKENS, static::LEXER_FLAGS);
118
    }
119
120
    /**
121
     * @return GrammarInterface
122
     */
123
    protected function bootGrammar(): GrammarInterface
124
    {
125
        return new Grammar([
126
            new Concatenation(0, ['DocBlock'], 'Document'), 
127
            new Concatenation(1, ['__any'], 'Document'), 
128
            new Alternation(2, [0, 1], null), 
129
            (new Repetition('Document', 0, -1, 2, null))->setDefaultId('Document'), 
130
            new Terminal(4, 'T_WORD', false), 
131
            new Terminal(5, 'T_DOC_DEFINITION', false), 
132
            new Terminal(6, 'T_VARIABLE', false), 
133
            new Terminal(7, 'T_SUFFIX_ARRAY', false), 
134
            new Terminal(8, 'T_NAMESPACE', false), 
135
            new Terminal(9, 'T_AND', false), 
136
            new Terminal(10, 'T_OR', false), 
137
            new Terminal(11, 'T_ANGLE_LEFT', false), 
138
            new Terminal(12, 'T_ANGLE_RIGHT', false), 
139
            new Terminal(13, 'T_COMMA', false), 
140
            new Alternation('__any', [4, 5, 6, 7, 8, 9, 10, 11, 12, 13], null), 
141
            new Repetition(15, 0, 1, 'TypeHint', null), 
142
            new Concatenation(16, ['DocBlockVariable'], null), 
143
            (new Concatenation('DocBlock', ['DocBlockTitle', 15, 16], 'DocBlock'))->setDefaultId('DocBlock'), 
144
            new Terminal(18, 'T_DOC_DEFINITION', true), 
145
            (new Concatenation('DocBlockTitle', [18], 'DocBlockTitle'))->setDefaultId('DocBlockTitle'), 
146
            new Terminal(20, 'T_VARIABLE', true), 
147
            (new Concatenation('DocBlockVariable', [20], 'DocBlockVariable'))->setDefaultId('DocBlockVariable'), 
148
            new Concatenation(22, ['__arrayTypeHint'], 'TypeHint'), 
149
            new Concatenation(23, ['__genericTypeHint'], 'TypeHint'), 
150
            new Concatenation(24, ['__scalarTypeHint'], 'TypeHint'), 
151
            new Alternation(25, [22, 23, 24], null), 
152
            new Repetition(26, 0, 1, '__typeHintContinuation', null), 
153
            (new Concatenation('TypeHint', [25, 26], null))->setDefaultId('TypeHint'), 
154
            new Concatenation(28, ['__typeHintDisjunction'], null), 
155
            new Alternation('__typeHintContinuation', ['__typeHintConjunction', 28], null), 
156
            new Terminal(30, 'T_OR', false), 
157
            new Concatenation('__typeHintDisjunction', [30, 'TypeHint'], 'Disjunction'), 
158
            new Terminal(32, 'T_AND', false), 
159
            new Concatenation('__typeHintConjunction', [32, 'TypeHint'], 'Conjunction'), 
160
            new Terminal(34, 'T_SUFFIX_ARRAY', false), 
161
            new Concatenation('__arrayTypeHint', ['__typeDefinition', 34], 'Array'), 
162
            new Terminal(36, 'T_ANGLE_LEFT', false), 
163
            new Repetition(37, 0, 1, '__genericArguments', null), 
164
            new Terminal(38, 'T_ANGLE_RIGHT', false), 
165
            new Concatenation('__genericTypeHint', ['__typeDefinition', 36, 37, 38], 'Generic'), 
166
            new Terminal(40, 'T_COMMA', false), 
167
            new Concatenation(41, [40, '__scalarTypeHint'], null), 
168
            new Repetition(42, 0, 1, 41, null), 
169
            new Concatenation('__genericArguments', ['__scalarTypeHint', 42], 'GenericArguments'), 
170
            new Concatenation('__scalarTypeHint', ['__typeDefinition'], 'Scalar'), 
171
            new Terminal(45, 'T_NAMESPACE', false), 
172
            new Repetition(46, 0, 1, 45, null), 
173
            new Terminal(47, 'T_WORD', true), 
174
            new Terminal(48, 'T_NAMESPACE', false), 
175
            new Terminal(49, 'T_WORD', true), 
176
            new Concatenation(50, [48, 49], null), 
177
            new Repetition(51, 0, -1, 50, null), 
178
            new Concatenation('__typeDefinition', [46, 47, 51], 'Type')
179
        ], static::PARSER_ROOT_RULE, static::PARSER_DELEGATES);
180
    }
181
}
182