Completed
Push — master ( 296743...12eab9 )
by Kirill
36:17
created

Parser::pattern()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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\Parser;
11
12
/**
13
 * Class Parser
14
 */
15
final class Parser extends BaseParser
16
{
17
    /**
18
     * @var string
19
     */
20
    public const GRAMMAR_PATHNAME = __DIR__ . '/../../../resources/grammar/sdl.pp';
21
22
    /**
23
     * Make tokens public
24
     * @var string[]
25
     */
26
    public const LEXER_TOKENS = parent::LEXER_TOKENS;
27
28
    /**
29
     * @param string $lexeme
30
     * @return string
31
     */
32
    public static function pattern(string $lexeme): string
33
    {
34
        return \sprintf('/^%s$/', self::LEXER_TOKENS[$lexeme]);
35
    }
36
37
    /**
38
     * @param string $lexeme
39
     * @param string $value
40
     * @return bool
41
     */
42
    public static function match(string $lexeme, string $value): bool
43
    {
44
        return (bool)\preg_match(self::pattern($lexeme), $value);
45
    }
46
}
47