]> gitweb.ps.run Git - toc/blob - antlr4-cpp-runtime-4.9.2-source/runtime/src/atn/LexerIndexedCustomAction.h
add antlr source code and ReadMe
[toc] / antlr4-cpp-runtime-4.9.2-source / runtime / src / atn / LexerIndexedCustomAction.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 "RuleContext.h"
9 #include "atn/LexerAction.h"
10
11 namespace antlr4 {
12 namespace atn {
13
14   /// <summary>
15   /// This implementation of <seealso cref="LexerAction"/> is used for tracking input offsets
16   /// for position-dependent actions within a <seealso cref="LexerActionExecutor"/>.
17   ///
18   /// <para>This action is not serialized as part of the ATN, and is only required for
19   /// position-dependent lexer actions which appear at a location other than the
20   /// end of a rule. For more information about DFA optimizations employed for
21   /// lexer actions, see <seealso cref="LexerActionExecutor#append"/> and
22   /// <seealso cref="LexerActionExecutor#fixOffsetBeforeMatch"/>.</para>
23   ///
24   /// @author Sam Harwell
25   /// @since 4.2
26   /// </summary>
27   class ANTLR4CPP_PUBLIC LexerIndexedCustomAction final : public LexerAction {
28   public:
29     /// <summary>
30     /// Constructs a new indexed custom action by associating a character offset
31     /// with a <seealso cref="LexerAction"/>.
32     ///
33     /// <para>Note: This class is only required for lexer actions for which
34     /// <seealso cref="LexerAction#isPositionDependent"/> returns {@code true}.</para>
35     /// </summary>
36     /// <param name="offset"> The offset into the input <seealso cref="CharStream"/>, relative to
37     /// the token start index, at which the specified lexer action should be
38     /// executed. </param>
39     /// <param name="action"> The lexer action to execute at a particular offset in the
40     /// input <seealso cref="CharStream"/>. </param>
41     LexerIndexedCustomAction(int offset, Ref<LexerAction> const& action);
42
43     /// <summary>
44     /// Gets the location in the input <seealso cref="CharStream"/> at which the lexer
45     /// action should be executed. The value is interpreted as an offset relative
46     /// to the token start index.
47     /// </summary>
48     /// <returns> The location in the input <seealso cref="CharStream"/> at which the lexer
49     /// action should be executed. </returns>
50     int getOffset() const;
51
52     /// <summary>
53     /// Gets the lexer action to execute.
54     /// </summary>
55     /// <returns> A <seealso cref="LexerAction"/> object which executes the lexer action. </returns>
56     Ref<LexerAction> getAction() const;
57
58     /// <summary>
59     /// {@inheritDoc}
60     /// </summary>
61     /// <returns> This method returns the result of calling <seealso cref="#getActionType"/>
62     /// on the <seealso cref="LexerAction"/> returned by <seealso cref="#getAction"/>. </returns>
63     virtual LexerActionType getActionType() const override;
64
65     /// <summary>
66     /// {@inheritDoc} </summary>
67     /// <returns> This method returns {@code true}. </returns>
68     virtual bool isPositionDependent() const override;
69
70     virtual void execute(Lexer *lexer) override;
71     virtual size_t hashCode() const override;
72     virtual bool operator == (const LexerAction &obj) const override;
73     virtual std::string toString() const override;
74
75   private:
76     const int _offset;
77     const Ref<LexerAction> _action;
78   };
79
80 } // namespace atn
81 } // namespace antlr4
82