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