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/LexerActionType.h"
9 #include "antlr4-common.h"
15 /// Represents a single action which can be executed following the successful
16 /// match of a lexer rule. Lexer actions are used for both embedded action syntax
17 /// and ANTLR 4's new lexer command syntax.
19 /// @author Sam Harwell
22 class ANTLR4CPP_PUBLIC LexerAction {
24 virtual ~LexerAction();
27 /// Gets the serialization type of the lexer action.
29 /// <returns> The serialization type of the lexer action. </returns>
30 virtual LexerActionType getActionType() const = 0;
33 /// Gets whether the lexer action is position-dependent. Position-dependent
34 /// actions may have different semantics depending on the <seealso cref="CharStream"/>
35 /// index at the time the action is executed.
37 /// <para>Many lexer commands, including {@code type}, {@code skip}, and
38 /// {@code more}, do not check the input index during their execution.
39 /// Actions like this are position-independent, and may be stored more
40 /// efficiently as part of the <seealso cref="LexerATNConfig#lexerActionExecutor"/>.</para>
42 /// <returns> {@code true} if the lexer action semantics can be affected by the
43 /// position of the input <seealso cref="CharStream"/> at the time it is executed;
44 /// otherwise, {@code false}. </returns>
45 virtual bool isPositionDependent() const = 0;
48 /// Execute the lexer action in the context of the specified <seealso cref="Lexer"/>.
50 /// <para>For position-dependent actions, the input stream must already be
51 /// positioned correctly prior to calling this method.</para>
53 /// <param name="lexer"> The lexer instance. </param>
54 virtual void execute(Lexer *lexer) = 0;
56 virtual size_t hashCode() const = 0;
57 virtual bool operator == (const LexerAction &obj) const = 0;
58 virtual bool operator != (const LexerAction &obj) const {
59 return !(*this == obj);
62 virtual std::string toString() const = 0;