1<?php
2
3declare(strict_types=1);
4
5namespace Antlr\Antlr4\Runtime\Atn\Transitions;
6
7use Antlr\Antlr4\Runtime\Atn\States\ATNState;
8use Antlr\Antlr4\Runtime\IntervalSet;
9use Antlr\Antlr4\Runtime\Utils\StringUtils;
10
11final class RangeTransition extends Transition
12{
13    /** @var int */
14    public $from;
15
16    /** @var int */
17    public $to;
18
19    public function __construct(ATNState $target, int $from, int $to)
20    {
21        parent::__construct($target);
22
23        $this->from = $from;
24        $this->to = $to;
25    }
26
27    public function label() : ?IntervalSet
28    {
29        return IntervalSet::fromRange($this->from, $this->to);
30    }
31
32    public function matches(int $symbol, int $minVocabSymbol, int $maxVocabSymbol) : bool
33    {
34        return $symbol >= $this->from && $symbol <= $this->to;
35    }
36
37    public function getSerializationType() : int
38    {
39        return self::RANGE;
40    }
41
42    public function equals(object $other) : bool
43    {
44        if ($this === $other) {
45            return true;
46        }
47
48        return $other instanceof self
49            && $this->from === $other->from
50            && $this->to === $other->to
51            && $this->target->equals($other->target);
52    }
53
54    public function __toString() : string
55    {
56        return \sprintf(
57            '\'%s\'..\'%s\'',
58            StringUtils::char($this->from),
59            StringUtils::char($this->to)
60        );
61    }
62}
63