1<?php
2
3declare(strict_types=1);
4
5namespace Antlr\Antlr4\Runtime\Atn\Transitions;
6
7use Antlr\Antlr4\Runtime\Atn\States\ATNState;
8
9final class ActionTransition extends Transition
10{
11    /** @var int */
12    public $ruleIndex;
13
14    /** @var int */
15    public $actionIndex;
16
17    /**
18     * e.g. $i ref in action
19     *
20     * @var bool
21     */
22    public $isCtxDependent;
23
24    public function __construct(ATNState $target, int $ruleIndex, int $actionIndex = -1, bool $isCtxDependent = false)
25    {
26        parent::__construct($target);
27
28        $this->ruleIndex = $ruleIndex;
29        $this->actionIndex = $actionIndex;
30        $this->isCtxDependent = $isCtxDependent;
31    }
32
33    public function matches(int $symbol, int $minVocabSymbol, int $maxVocabSymbol) : bool
34    {
35        return false;
36    }
37
38    /**
39     * {@inheritdoc}
40     */
41    public function isEpsilon() : bool
42    {
43        return true;
44    }
45
46    public function getSerializationType() : int
47    {
48        return self::ACTION;
49    }
50
51    public function equals(object $other) : bool
52    {
53        if ($this === $other) {
54            return true;
55        }
56
57        if (!$other instanceof self) {
58            return false;
59        }
60
61        return $this->ruleIndex === $other->ruleIndex
62            && $this->actionIndex === $other->actionIndex
63            && $this->isCtxDependent === $other->isCtxDependent
64            && $this->target->equals($other->target);
65    }
66
67    public function __toString() : string
68    {
69        return \sprintf('action_%d:%d', $this->ruleIndex, $this->actionIndex);
70    }
71}
72