LexerNoViableAltException   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 44
ccs 0
cts 16
cp 0
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDeadEndConfigs() 0 3 1
A __construct() 0 6 1
A __toString() 0 15 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Antlr\Antlr4\Runtime\Error\Exceptions;
6
7
use Antlr\Antlr4\Runtime\Atn\ATNConfigSet;
8
use Antlr\Antlr4\Runtime\CharStream;
9
use Antlr\Antlr4\Runtime\Lexer;
10
use Antlr\Antlr4\Runtime\Utils\StringUtils;
11
12
class LexerNoViableAltException extends RecognitionException
13
{
14
    /**
15
     * Matching attempted at what input index?
16
     *
17
     * @var int
18
     */
19
    private $startIndex;
20
21
    /**
22
     * Which configurations did we try at $input->index() that couldn't match $input->LA(1)?
23
     *
24
     * @var ATNConfigSet
25
     */
26
    private $deadEndConfigs;
27
28
    public function __construct(Lexer $lexer, CharStream $input, int $startIndex, ATNConfigSet $deadEndConfigs)
29
    {
30
        parent::__construct($lexer, $input, null);
31
32
        $this->startIndex = $startIndex;
33
        $this->deadEndConfigs = $deadEndConfigs;
34
    }
35
36
    public function getDeadEndConfigs() : ATNConfigSet
37
    {
38
        return $this->deadEndConfigs;
39
    }
40
41
    public function __toString() : string
42
    {
43
        $symbol = '';
44
        $input = $this->getInputStream();
45
46
        if (!$input instanceof CharStream) {
47
            throw new \RuntimeException('Unexpected stream type.');
48
        }
49
50
        if ($input !== null && $this->startIndex >= 0 && $this->startIndex < $input->getLength()) {
51
            $symbol = $input->getText($this->startIndex, $this->startIndex);
52
            $symbol = StringUtils::escapeWhitespace($symbol, false);
53
        }
54
55
        return \sprintf('%s(\'%s\')', self::class, $symbol);
56
    }
57
}
58