]> gitweb.ps.run Git - toc/blob - antlr4-cpp-runtime-4.9.2-source/runtime/src/atn/Transition.h
add antlr source code and ReadMe
[toc] / antlr4-cpp-runtime-4.9.2-source / runtime / src / atn / Transition.h
1 /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
2  * Use of this file is governed by the BSD 3-clause license that
3  * can be found in the LICENSE.txt file in the project root.
4  */
5
6 #pragma once
7
8 #include "misc/IntervalSet.h"
9
10 namespace antlr4 {
11 namespace atn {
12
13   /// <summary>
14   /// An ATN transition between any two ATN states.  Subclasses define
15   ///  atom, set, epsilon, action, predicate, rule transitions.
16   /// <p/>
17   ///  This is a one way link.  It emanates from a state (usually via a list of
18   ///  transitions) and has a target state.
19   /// <p/>
20   ///  Since we never have to change the ATN transitions once we construct it,
21   ///  we can fix these transitions as specific classes. The DFA transitions
22   ///  on the other hand need to update the labels as it adds transitions to
23   ///  the states. We'll use the term Edge for the DFA to distinguish them from
24   ///  ATN transitions.
25   /// </summary>
26   class ANTLR4CPP_PUBLIC Transition {
27   public:
28     // constants for serialization
29     enum SerializationType {
30       EPSILON = 1,
31       RANGE = 2,
32       RULE = 3,
33       PREDICATE = 4, // e.g., {isType(input.LT(1))}?
34       ATOM = 5,
35       ACTION = 6,
36       SET = 7, // ~(A|B) or ~atom, wildcard, which convert to next 2
37       NOT_SET = 8,
38       WILDCARD = 9,
39       PRECEDENCE = 10,
40     };
41
42     static const std::vector<std::string> serializationNames;
43
44     /// The target of this transition.
45     // ml: this is a reference into the ATN.
46     ATNState *target;
47
48     virtual ~Transition();
49
50   protected:
51     Transition(ATNState *target);
52
53   public:
54     virtual SerializationType getSerializationType() const = 0;
55
56     /**
57      * Determines if the transition is an "epsilon" transition.
58      *
59      * <p>The default implementation returns {@code false}.</p>
60      *
61      * @return {@code true} if traversing this transition in the ATN does not
62      * consume an input symbol; otherwise, {@code false} if traversing this
63      * transition consumes (matches) an input symbol.
64      */
65     virtual bool isEpsilon() const;
66     virtual misc::IntervalSet label() const;
67     virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const = 0;
68
69     virtual std::string toString() const;
70
71     Transition(Transition const&) = delete;
72     Transition& operator=(Transition const&) = delete;
73   };
74
75 } // namespace atn
76 } // namespace antlr4