]> gitweb.ps.run Git - toc/blob - antlr4-cpp-runtime-4.9.2-source/runtime/src/atn/LexerAction.h
add antlr source code and ReadMe
[toc] / antlr4-cpp-runtime-4.9.2-source / runtime / src / atn / LexerAction.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 "atn/LexerActionType.h"
9 #include "antlr4-common.h"
10
11 namespace antlr4 {
12 namespace atn {
13
14   /// <summary>
15   /// Represents a single action which can be executed following the successful
16   /// match of a lexer rule. Lexer actions are used for both embedded action syntax
17   /// and ANTLR 4's new lexer command syntax.
18   ///
19   /// @author Sam Harwell
20   /// @since 4.2
21   /// </summary>
22   class ANTLR4CPP_PUBLIC LexerAction {
23   public:
24     virtual ~LexerAction();
25
26     /// <summary>
27     /// Gets the serialization type of the lexer action.
28     /// </summary>
29     /// <returns> The serialization type of the lexer action. </returns>
30     virtual LexerActionType getActionType() const = 0;
31
32     /// <summary>
33     /// Gets whether the lexer action is position-dependent. Position-dependent
34     /// actions may have different semantics depending on the <seealso cref="CharStream"/>
35     /// index at the time the action is executed.
36     ///
37     /// <para>Many lexer commands, including {@code type}, {@code skip}, and
38     /// {@code more}, do not check the input index during their execution.
39     /// Actions like this are position-independent, and may be stored more
40     /// efficiently as part of the <seealso cref="LexerATNConfig#lexerActionExecutor"/>.</para>
41     /// </summary>
42     /// <returns> {@code true} if the lexer action semantics can be affected by the
43     /// position of the input <seealso cref="CharStream"/> at the time it is executed;
44     /// otherwise, {@code false}. </returns>
45     virtual bool isPositionDependent() const = 0;
46
47     /// <summary>
48     /// Execute the lexer action in the context of the specified <seealso cref="Lexer"/>.
49     ///
50     /// <para>For position-dependent actions, the input stream must already be
51     /// positioned correctly prior to calling this method.</para>
52     /// </summary>
53     /// <param name="lexer"> The lexer instance. </param>
54     virtual void execute(Lexer *lexer) = 0;
55
56     virtual size_t hashCode() const = 0;
57     virtual bool operator == (const LexerAction &obj) const = 0;
58     virtual bool operator != (const LexerAction &obj) const {
59       return !(*this == obj);
60     }
61
62     virtual std::string toString() const = 0;
63   };
64
65 } // namespace atn
66 } // namespace antlr4