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.
8 #include "atn/LexerAction.h"
9 #include "atn/LexerActionType.h"
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.
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>
24 /// @author Sam Harwell
27 class ANTLR4CPP_PUBLIC LexerCustomAction final : public LexerAction {
30 /// Constructs a custom lexer action with the specified rule and action
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);
40 /// Gets the rule index to use for calls to <seealso cref="Recognizer#action"/>.
42 /// <returns> The rule index for the custom action. </returns>
43 size_t getRuleIndex() const;
46 /// Gets the action index to use for calls to <seealso cref="Recognizer#action"/>.
48 /// <returns> The action index for the custom action. </returns>
49 size_t getActionIndex() const;
54 /// <returns> This method returns <seealso cref="LexerActionType#CUSTOM"/>. </returns>
55 virtual LexerActionType getActionType() const override;
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.
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>
66 /// <returns> This method returns {@code true}. </returns>
67 virtual bool isPositionDependent() const override;
72 /// <para>Custom actions are implemented by calling <seealso cref="Lexer#action"/> with the
73 /// appropriate rule and action indexes.</para>
75 virtual void execute(Lexer *lexer) override;
77 virtual size_t hashCode() const override;
78 virtual bool operator == (const LexerAction &obj) const override;
79 virtual std::string toString() const override;
82 const size_t _ruleIndex;
83 const size_t _actionIndex;