Package org.antlr.v4.runtime.atn
Class LexerCustomAction
- java.lang.Object
- 
- org.antlr.v4.runtime.atn.LexerCustomAction
 
- 
- All Implemented Interfaces:
- LexerAction
 
 public final class LexerCustomAction extends Object implements LexerAction Executes a custom lexer action by callingRecognizer.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 ofRecognizer.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.- Since:
- 4.2
- Author:
- Sam Harwell
 
- 
- 
Constructor SummaryConstructors Constructor Description LexerCustomAction(int ruleIndex, int actionIndex)Constructs a custom lexer action with the specified rule and action indexes.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)voidexecute(Lexer lexer)Execute the lexer action in the context of the specifiedLexer.intgetActionIndex()Gets the action index to use for calls toRecognizer.action(org.antlr.v4.runtime.RuleContext, int, int).LexerActionTypegetActionType()Gets the serialization type of the lexer action.intgetRuleIndex()Gets the rule index to use for calls toRecognizer.action(org.antlr.v4.runtime.RuleContext, int, int).inthashCode()booleanisPositionDependent()Gets whether the lexer action is position-dependent.
 
- 
- 
- 
Constructor Detail- 
LexerCustomActionpublic 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 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).
 
 
- 
 - 
Method Detail- 
getRuleIndexpublic int getRuleIndex() Gets the rule index to use for calls toRecognizer.action(org.antlr.v4.runtime.RuleContext, int, int).- Returns:
- The rule index for the custom action.
 
 - 
getActionIndexpublic int getActionIndex() Gets the action index to use for calls toRecognizer.action(org.antlr.v4.runtime.RuleContext, int, int).- Returns:
- The action index for the custom action.
 
 - 
getActionTypepublic LexerActionType getActionType() Gets the serialization type of the lexer action.- Specified by:
- getActionTypein interface- LexerAction
- Returns:
- This method returns LexerActionType.CUSTOM.
 
 - 
isPositionDependentpublic 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 interface- LexerAction
- Returns:
- This method returns true.
 
 - 
executepublic 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. Custom actions are implemented by calling Recognizer.action(org.antlr.v4.runtime.RuleContext, int, int)with the appropriate rule and action indexes.- Specified by:
- executein interface- LexerAction
- Parameters:
- lexer- The lexer instance.
 
 
- 
 
-