1 /*
2  * Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
3  * Use of this file is governed by the BSD 3-clause license that
4  * can be found in the LICENSE.txt file in the project root.
5  */
6 
7 module antlr.v4.runtime.atn.Transition;
8 
9 import std.conv;
10 import antlr.v4.runtime.atn.TransitionStates;
11 import antlr.v4.runtime.atn.EpsilonTransition;
12 import antlr.v4.runtime.atn.RuleTransition;
13 import antlr.v4.runtime.atn.PredicateTransition;
14 import antlr.v4.runtime.atn.RangeTransition;
15 import antlr.v4.runtime.atn.AtomTransition;
16 import antlr.v4.runtime.atn.ActionTransition;
17 import antlr.v4.runtime.atn.SetTransition;
18 import antlr.v4.runtime.atn.NotSetTransition;
19 import antlr.v4.runtime.atn.WildcardTransition;
20 import antlr.v4.runtime.atn.PrecedencePredicateTransition;
21 import antlr.v4.runtime.atn.ATNState;
22 import antlr.v4.runtime.misc.IntervalSet;
23 
24 // Class Transition
25 /**
26  * An ATN transition between any two ATN states.  Subclasses define
27  * atom, set, epsilon, action, predicate, rule transitions.
28  *
29  * <p>This is a one way link.  It emanates from a state (usually via a list of
30  * transitions) and has a target state.</p>
31  *
32  * <p>Since we never have to change the ATN transitions once we construct it,
33  * we can fix these transitions as specific classes. The DFA transitions
34  * on the other hand need to update the labels as it adds transitions to
35  * the states. We'll use the term Edge for the DFA to distinguish them from
36  * ATN transitions.</p>
37  */
38 abstract class Transition
39 {
40 
41     /**
42      * The target of this transition.
43      */
44     public ATNState target;
45 
46     public static string[] serializationNames = [
47         "INVALID",
48         "EPSILON",
49         "RANGE",
50         "RULE",
51         "PREDICATE",
52         "ATOM",
53         "ACTION",
54         "SET",
55         "NOT_SET",
56         "WILDCARD",
57         "PRECEDENCE"
58     ];
59 
60     public this(ATNState target)
61     {
62         this.target = target;
63     }
64 
65     public this()
66     {
67     }
68 
69     abstract public int getSerializationType();
70 
71     /**
72      * Determines if the transition is an "epsilon" transition.
73      *
74      * <p>The default implementation returns {@code false}.</p>
75      *
76      *  @return {@code true} if traversing this transition in the ATN does not
77      *  consume an input symbol; otherwise, {@code false} if traversing this
78      *  transition consumes (matches) an input symbol.
79      */
80     public bool isEpsilon()
81     {
82         return false;
83     }
84 
85     public IntervalSet label()
86     {
87         return null;
88     }
89 
90     abstract public bool matches(int symbol, int minVocabSymbol, int maxVocabSymbol);
91 
92 }