]> gitweb.ps.run Git - toc/blob - antlr4-cpp-runtime-4.9.2-source/runtime/src/atn/LexerCustomAction.h
add antlr source code and ReadMe
[toc] / antlr4-cpp-runtime-4.9.2-source / runtime / src / atn / LexerCustomAction.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/LexerAction.h"
9 #include "atn/LexerActionType.h"
10
11 namespace antlr4 {
12 namespace atn {
13
14   /// <summary>
15   /// Executes a custom lexer action by calling <seealso cref="Recognizer#action"/> with the
16   /// rule and action indexes assigned to the custom action. The implementation of
17   /// a custom action is added to the generated code for the lexer in an override
18   /// of <seealso cref="Recognizer#action"/> when the grammar is compiled.
19   ///
20   /// <para>This class may represent embedded actions created with the <code>{...}</code>
21   /// syntax in ANTLR 4, as well as actions created for lexer commands where the
22   /// command argument could not be evaluated when the grammar was compiled.</para>
23   ///
24   /// @author Sam Harwell
25   /// @since 4.2
26   /// </summary>
27   class ANTLR4CPP_PUBLIC LexerCustomAction final : public LexerAction {
28   public:
29     /// <summary>
30     /// Constructs a custom lexer action with the specified rule and action
31     /// indexes.
32     /// </summary>
33     /// <param name="ruleIndex"> The rule index to use for calls to
34     /// <seealso cref="Recognizer#action"/>. </param>
35     /// <param name="actionIndex"> The action index to use for calls to
36     /// <seealso cref="Recognizer#action"/>. </param>
37     LexerCustomAction(size_t ruleIndex, size_t actionIndex);
38
39     /// <summary>
40     /// Gets the rule index to use for calls to <seealso cref="Recognizer#action"/>.
41     /// </summary>
42     /// <returns> The rule index for the custom action. </returns>
43     size_t getRuleIndex() const;
44
45     /// <summary>
46     /// Gets the action index to use for calls to <seealso cref="Recognizer#action"/>.
47     /// </summary>
48     /// <returns> The action index for the custom action. </returns>
49     size_t getActionIndex() const;
50
51     /// <summary>
52     /// {@inheritDoc}
53     /// </summary>
54     /// <returns> This method returns <seealso cref="LexerActionType#CUSTOM"/>. </returns>
55     virtual LexerActionType getActionType() const override;
56
57     /// <summary>
58     /// Gets whether the lexer action is position-dependent. Position-dependent
59     /// actions may have different semantics depending on the <seealso cref="CharStream"/>
60     /// index at the time the action is executed.
61     ///
62     /// <para>Custom actions are position-dependent since they may represent a
63     /// user-defined embedded action which makes calls to methods like
64     /// <seealso cref="Lexer#getText"/>.</para>
65     /// </summary>
66     /// <returns> This method returns {@code true}. </returns>
67     virtual bool isPositionDependent() const override;
68
69     /// <summary>
70     /// {@inheritDoc}
71     ///
72     /// <para>Custom actions are implemented by calling <seealso cref="Lexer#action"/> with the
73     /// appropriate rule and action indexes.</para>
74     /// </summary>
75     virtual void execute(Lexer *lexer) override;
76
77     virtual size_t hashCode() const override;
78     virtual bool operator == (const LexerAction &obj) const override;
79     virtual std::string toString() const override;
80
81   private:
82     const size_t _ruleIndex;
83     const size_t _actionIndex;
84   };
85
86 } // namespace atn
87 } // namespace antlr4