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\Comparison\Equatable;
9use Antlr\Antlr4\Runtime\IntervalSet;
10
11/**
12 * An ATN transition between any two ATN states. Subclasses define atom, set,
13 * epsilon, action, predicate, rule transitions.
14 *
15 * This is a one way link. It emanates from a state (usually via a list of
16 * transitions) and has a target state.
17 *
18 * Since we never have to change the ATN transitions once we construct it,
19 * we can fix these transitions as specific classes. The DFA transitions
20 * on the other hand need to update the labels as it adds transitions to
21 * the states. We'll use the term Edge for the DFA to distinguish them from
22 * ATN transitions.
23 */
24abstract class Transition implements Equatable
25{
26    public const EPSILON = 1;
27    public const RANGE = 2;
28    public const RULE = 3;
29    public const PREDICATE = 4;
30    public const ATOM = 5;
31    public const ACTION = 6;
32    public const SET = 7;
33    public const NOT_SET = 8;
34    public const WILDCARD = 9;
35    public const PRECEDENCE = 10;
36
37    /**
38     * The target of this transition.
39     *
40     * @var ATNState
41     */
42    public $target;
43
44    public function __construct(ATNState $target)
45    {
46        $this->target = $target;
47    }
48
49    /**
50     * Determines if the transition is an "epsilon" transition. The default
51     * implementation returns `false`.
52     *
53     * @return bool `true` if traversing this transition in the ATN does not
54     *              consume an input symbol; otherwise, `false` if traversing
55     *              this transition consumes (matches) an input symbol.
56     */
57    public function isEpsilon() : bool
58    {
59        return false;
60    }
61
62    public function label() : ?IntervalSet
63    {
64        return null;
65    }
66
67    abstract public function getSerializationType() : int;
68    abstract public function matches(int $symbol, int $minVocabSymbol, int $maxVocabSymbol) : bool;
69    abstract public function __toString() : string;
70}
71