Class LexerIndexedCustomAction
- java.lang.Object
-
- org.antlr.v4.runtime.atn.LexerIndexedCustomAction
-
- All Implemented Interfaces:
LexerAction
public final class LexerIndexedCustomAction extends Object implements LexerAction
This implementation ofLexerAction
is used for tracking input offsets for position-dependent actions within aLexerActionExecutor
.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)
andLexerActionExecutor.fixOffsetBeforeMatch(int)
.- Since:
- 4.2
- Author:
- Sam Harwell
-
-
Constructor Summary
Constructors Constructor Description LexerIndexedCustomAction(int offset, LexerAction action)
Constructs a new indexed custom action by associating a character offset with aLexerAction
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
void
execute(Lexer lexer)
Execute the lexer action in the context of the specifiedLexer
.LexerAction
getAction()
Gets the lexer action to execute.LexerActionType
getActionType()
Gets the serialization type of the lexer action.int
getOffset()
Gets the location in the inputCharStream
at which the lexer action should be executed.int
hashCode()
boolean
isPositionDependent()
Gets whether the lexer action is position-dependent.
-
-
-
Constructor Detail
-
LexerIndexedCustomAction
public LexerIndexedCustomAction(int offset, LexerAction action)
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 Detail
-
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
public LexerAction getAction()
Gets the lexer action to execute.- Returns:
- A
LexerAction
object which executes the lexer action.
-
getActionType
public LexerActionType 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
public void execute(Lexer lexer)
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.
-
-