/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. * Use of this file is governed by the BSD 3-clause license that * can be found in the LICENSE.txt file in the project root. */ #pragma once #include "RuleContext.h" #include "atn/LexerAction.h" namespace antlr4 { namespace atn { /// /// This implementation of is used for tracking input offsets /// for position-dependent actions within a . /// /// This action is not serialized as part of the ATN, and is only required for /// position-dependent lexer actions which appear at a location other than the /// end of a rule. For more information about DFA optimizations employed for /// lexer actions, see and /// . /// /// @author Sam Harwell /// @since 4.2 /// class ANTLR4CPP_PUBLIC LexerIndexedCustomAction final : public LexerAction { public: static bool is(const LexerAction &lexerAction) { return lexerAction.getActionType() == LexerActionType::INDEXED_CUSTOM; } static bool is(const LexerAction *lexerAction) { return lexerAction != nullptr && is(*lexerAction); } /// /// Constructs a new indexed custom action by associating a character offset /// with a . /// /// Note: This class is only required for lexer actions for which /// returns {@code true}. /// /// The offset into the input , relative to /// the token start index, at which the specified lexer action should be /// executed. /// The lexer action to execute at a particular offset in the /// input . LexerIndexedCustomAction(int offset, Ref action); /// /// Gets the location in the input at which the lexer /// action should be executed. The value is interpreted as an offset relative /// to the token start index. /// /// The location in the input at which the lexer /// action should be executed. int getOffset() const { return _offset; } /// /// Gets the lexer action to execute. /// /// A object which executes the lexer action. const Ref& getAction() const { return _action; } void execute(Lexer *lexer) const override; bool equals(const LexerAction &other) const override; std::string toString() const override; protected: size_t hashCodeImpl() const override; private: const Ref _action; const int _offset; }; } // namespace atn } // namespace antlr4