LexerAction
public final class LexerCustomAction extends Object implements LexerAction
Recognizer.action(org.antlr.v4.runtime.RuleContext, int, int)
with the
rule and action indexes assigned to the custom action. The implementation of
a custom action is added to the generated code for the lexer in an override
of Recognizer.action(org.antlr.v4.runtime.RuleContext, int, int)
when the grammar is compiled.
This class may represent embedded actions created with the {...}
syntax in ANTLR 4, as well as actions created for lexer commands where the
command argument could not be evaluated when the grammar was compiled.
Constructor | Description |
---|---|
LexerCustomAction(int ruleIndex,
int actionIndex) |
Constructs a custom lexer action with the specified rule and action
indexes.
|
Modifier and Type | Method | Description |
---|---|---|
boolean |
equals(Object obj) |
|
void |
execute(Lexer lexer) |
Execute the lexer action in the context of the specified
Lexer . |
int |
getActionIndex() |
Gets the action index to use for calls to
Recognizer.action(org.antlr.v4.runtime.RuleContext, int, int) . |
LexerActionType |
getActionType() |
Gets the serialization type of the lexer action.
|
int |
getRuleIndex() |
Gets the rule index to use for calls to
Recognizer.action(org.antlr.v4.runtime.RuleContext, int, int) . |
int |
hashCode() |
|
boolean |
isPositionDependent() |
Gets whether the lexer action is position-dependent.
|
public LexerCustomAction(int ruleIndex, int actionIndex)
ruleIndex
- The rule index to use for calls to
Recognizer.action(org.antlr.v4.runtime.RuleContext, int, int)
.actionIndex
- The action index to use for calls to
Recognizer.action(org.antlr.v4.runtime.RuleContext, int, int)
.public int getRuleIndex()
Recognizer.action(org.antlr.v4.runtime.RuleContext, int, int)
.public int getActionIndex()
Recognizer.action(org.antlr.v4.runtime.RuleContext, int, int)
.public LexerActionType getActionType()
getActionType
in interface LexerAction
LexerActionType.CUSTOM
.public boolean isPositionDependent()
CharStream
index at the time the action is executed.
Custom actions are position-dependent since they may represent a
user-defined embedded action which makes calls to methods like
Lexer.getText()
.
isPositionDependent
in interface LexerAction
true
.public void execute(Lexer lexer)
Lexer
.
For position-dependent actions, the input stream must already be positioned correctly prior to calling this method.
Custom actions are implemented by calling Recognizer.action(org.antlr.v4.runtime.RuleContext, int, int)
with the
appropriate rule and action indexes.
execute
in interface LexerAction
lexer
- The lexer instance.Copyright © 1992–2019 ANTLR. All rights reserved.