TokenMatcher   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 43
dl 0
loc 72
rs 10
c 0
b 0
f 0
wmc 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B match() 0 70 10
1
<?php
2
3
/**
4
 * Brainfuck token matcher.
5
 *
6
 * Auto-generated file, please don't edit manually.
7
 * Generated by UniLex.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Remorhaz\UniLex\Example\Brainfuck\Grammar;
13
14
use Remorhaz\UniLex\IO\CharBufferInterface;
15
use Remorhaz\UniLex\Lexer\TokenFactoryInterface;
16
use Remorhaz\UniLex\Lexer\TokenMatcherTemplate;
17
18
class TokenMatcher extends TokenMatcherTemplate
19
{
20
    public function match(CharBufferInterface $buffer, TokenFactoryInterface $tokenFactory): bool
21
    {
22
        $context = $this->createContext($buffer, $tokenFactory);
23
        goto state1;
24
25
        state1:
26
        if ($context->getBuffer()->isEnd()) {
27
            goto error;
28
        }
29
        $char = $context->getBuffer()->getSymbol();
30
        if (0x3E == $char) {
31
            $context->getBuffer()->nextSymbol();
32
            // >
33
            $context->setNewToken(TokenType::NEXT);
34
35
            return true;
36
        }
37
        if (0x3C == $char) {
38
            $context->getBuffer()->nextSymbol();
39
            // <
40
            $context->setNewToken(TokenType::PREV);
41
42
            return true;
43
        }
44
        if (0x2B == $char) {
45
            $context->getBuffer()->nextSymbol();
46
            // \+
47
            $context->setNewToken(TokenType::INC);
48
49
            return true;
50
        }
51
        if (0x2D == $char) {
52
            $context->getBuffer()->nextSymbol();
53
            // -
54
            $context->setNewToken(TokenType::DEC);
55
56
            return true;
57
        }
58
        if (0x2E == $char) {
59
            $context->getBuffer()->nextSymbol();
60
            // \.
61
            $context->setNewToken(TokenType::OUTPUT);
62
63
            return true;
64
        }
65
        if (0x2C == $char) {
66
            $context->getBuffer()->nextSymbol();
67
            // ,
68
            $context->setNewToken(TokenType::INPUT);
69
70
            return true;
71
        }
72
        if (0x5B == $char) {
73
            $context->getBuffer()->nextSymbol();
74
            // \[
75
            $context->setNewToken(TokenType::LOOP);
76
77
            return true;
78
        }
79
        if (0x5D == $char) {
80
            $context->getBuffer()->nextSymbol();
81
            // ]
82
            $context->setNewToken(TokenType::END_LOOP);
83
84
            return true;
85
        }
86
        goto error;
87
88
        error:
89
        return false;
90
    }
91
}
92