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 calling Recognizer.action(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(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
  • Field Details

    • ruleIndex

      private final int ruleIndex
    • actionIndex

      private final int actionIndex
  • Constructor Details

  • Method Details

    • getRuleIndex

      public int getRuleIndex()
      Gets the rule index to use for calls to Recognizer.action(RuleContext, int, int).
      Returns:
      The rule index for the custom action.
    • getActionIndex

      public int getActionIndex()
      Gets the action index to use for calls to Recognizer.action(RuleContext, int, int).
      Returns:
      The action index for the custom action.
    • getActionType

      public LexerActionType getActionType()
      Gets the serialization type of the lexer action.
      Specified by:
      getActionType in interface LexerAction
      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 the 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().

      Specified by:
      isPositionDependent in interface LexerAction
      Returns:
      This method returns true.
    • execute

      public void execute(Lexer lexer)
      Execute the lexer action in the context of the specified 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(RuleContext, int, int) with the appropriate rule and action indexes.

      Specified by:
      execute in interface LexerAction
      Parameters:
      lexer - The lexer instance.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object