Class LexerCustomAction
java.lang.Object
org.graalvm.shadowed.org.antlr.v4.runtime.atn.LexerCustomAction
- All Implemented Interfaces:
LexerAction
Executes a custom lexer action by calling
Recognizer.action(org.graalvm.shadowed.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.graalvm.shadowed.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.
- Since:
- 4.2
-
Constructor Summary
ConstructorsConstructorDescriptionLexerCustomAction(int ruleIndex, int actionIndex) Constructs a custom lexer action with the specified rule and action indexes. -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoidExecute the lexer action in the context of the specifiedLexer.intGets the action index to use for calls toRecognizer.action(org.graalvm.shadowed.org.antlr.v4.runtime.RuleContext, int, int).Gets the serialization type of the lexer action.intGets the rule index to use for calls toRecognizer.action(org.graalvm.shadowed.org.antlr.v4.runtime.RuleContext, int, int).inthashCode()booleanGets whether the lexer action is position-dependent.
-
Constructor Details
-
LexerCustomAction
public LexerCustomAction(int ruleIndex, int actionIndex) Constructs a custom lexer action with the specified rule and action indexes.- Parameters:
ruleIndex- The rule index to use for calls toRecognizer.action(org.graalvm.shadowed.org.antlr.v4.runtime.RuleContext, int, int).actionIndex- The action index to use for calls toRecognizer.action(org.graalvm.shadowed.org.antlr.v4.runtime.RuleContext, int, int).
-
-
Method Details
-
getRuleIndex
public int getRuleIndex()Gets the rule index to use for calls toRecognizer.action(org.graalvm.shadowed.org.antlr.v4.runtime.RuleContext, int, int).- Returns:
- The rule index for the custom action.
-
getActionIndex
public int getActionIndex()Gets the action index to use for calls toRecognizer.action(org.graalvm.shadowed.org.antlr.v4.runtime.RuleContext, int, int).- Returns:
- The action index for the custom action.
-
getActionType
Gets the serialization type of the lexer action.- Specified by:
getActionTypein interfaceLexerAction- Returns:
- This method returns
LexerActionType.CUSTOM.
-
isPositionDependent
public boolean isPositionDependent()Gets whether the lexer action is position-dependent. Position-dependent actions may have different semantics depending on theCharStreamindex 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().- Specified by:
isPositionDependentin 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.
Custom actions are implemented by calling
Recognizer.action(org.graalvm.shadowed.org.antlr.v4.runtime.RuleContext, int, int)with the appropriate rule and action indexes.- Specified by:
executein interfaceLexerAction- Parameters:
lexer- The lexer instance.
-
hashCode
-
equals
-