Class LexerIndexedCustomAction
- All Implemented Interfaces:
LexerAction
LexerAction
is used for tracking input offsets
for position-dependent actions within a LexerActionExecutor
.
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 LexerActionExecutor.append(org.antlr.v4.runtime.atn.LexerActionExecutor, org.antlr.v4.runtime.atn.LexerAction)
and
LexerActionExecutor.fixOffsetBeforeMatch(int)
.
- Since:
- 4.2
- Author:
- Sam Harwell
-
Constructor Summary
ConstructorsConstructorDescriptionLexerIndexedCustomAction
(int offset, LexerAction action) Constructs a new indexed custom action by associating a character offset with aLexerAction
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
void
Execute the lexer action in the context of the specifiedLexer
.Gets the lexer action to execute.Gets the serialization type of the lexer action.int
Gets the location in the inputCharStream
at which the lexer action should be executed.int
hashCode()
boolean
Gets whether the lexer action is position-dependent.
-
Constructor Details
-
LexerIndexedCustomAction
Constructs a new indexed custom action by associating a character offset with aLexerAction
.Note: This class is only required for lexer actions for which
LexerAction.isPositionDependent()
returnstrue
.- Parameters:
offset
- The offset into the inputCharStream
, relative to the token start index, at which the specified lexer action should be executed.action
- The lexer action to execute at a particular offset in the inputCharStream
.
-
-
Method Details
-
getOffset
public int getOffset()Gets the location in the inputCharStream
at which the lexer action should be executed. The value is interpreted as an offset relative to the token start index.- Returns:
- The location in the input
CharStream
at which the lexer action should be executed.
-
getAction
Gets the lexer action to execute.- Returns:
- A
LexerAction
object which executes the lexer action.
-
getActionType
Gets the serialization type of the lexer action.- Specified by:
getActionType
in interfaceLexerAction
- Returns:
- This method returns the result of calling
getActionType()
on theLexerAction
returned bygetAction()
.
-
isPositionDependent
public boolean isPositionDependent()Gets whether the lexer action is position-dependent. Position-dependent actions may have different semantics depending on theCharStream
index at the time the action is executed.Many lexer commands, including
type
,skip
, andmore
, do not check the input index during their execution. Actions like this are position-independent, and may be stored more efficiently as part of theLexerATNConfig.lexerActionExecutor
.- Specified by:
isPositionDependent
in interfaceLexerAction
- Returns:
- This method returns
true
.
-
execute
Execute the lexer action in the context of the specifiedLexer
.For position-dependent actions, the input stream must already be positioned correctly prior to calling this method.
This method calls
execute(org.antlr.v4.runtime.Lexer)
on the result ofgetAction()
using the providedlexer
.- Specified by:
execute
in interfaceLexerAction
- Parameters:
lexer
- The lexer instance.
-
hashCode
public int hashCode() -
equals
-