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 "RuleContext.h"
9 #include "atn/LexerAction.h"
15 /// This implementation of <seealso cref="LexerAction"/> is used for tracking input offsets
16 /// for position-dependent actions within a <seealso cref="LexerActionExecutor"/>.
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>
24 /// @author Sam Harwell
27 class ANTLR4CPP_PUBLIC LexerIndexedCustomAction final : public LexerAction {
30 /// Constructs a new indexed custom action by associating a character offset
31 /// with a <seealso cref="LexerAction"/>.
33 /// <para>Note: This class is only required for lexer actions for which
34 /// <seealso cref="LexerAction#isPositionDependent"/> returns {@code true}.</para>
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);
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.
48 /// <returns> The location in the input <seealso cref="CharStream"/> at which the lexer
49 /// action should be executed. </returns>
50 int getOffset() const;
53 /// Gets the lexer action to execute.
55 /// <returns> A <seealso cref="LexerAction"/> object which executes the lexer action. </returns>
56 Ref<LexerAction> getAction() const;
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;
66 /// {@inheritDoc} </summary>
67 /// <returns> This method returns {@code true}. </returns>
68 virtual bool isPositionDependent() const override;
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;
77 const Ref<LexerAction> _action;