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 of LexerAction is used for tracking input offsets for position-dependent actions within a LexerActionExecutor.

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) and LexerActionExecutor.fixOffsetBeforeMatch(int).

Since:
4.2
  • Field Details

    • offset

      private final int offset
    • action

      private final LexerAction action
  • Constructor Details

    • LexerIndexedCustomAction

      public LexerIndexedCustomAction(int offset, LexerAction action)
      Constructs a new indexed custom action by associating a character offset with a LexerAction.

      Note: This class is only required for lexer actions for which LexerAction.isPositionDependent() returns true.

      Parameters:
      offset - The offset into the input CharStream, 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 input CharStream.
  • Method Details

    • getOffset

      public int getOffset()
      Gets the location in the input CharStream 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 interface LexerAction
      Returns:
      This method returns the result of calling getActionType() on the LexerAction returned by getAction().
    • 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.

      Many lexer commands, including type, skip, and more, do not check the input index during their execution. Actions like this are position-independent, and may be stored more efficiently as part of the LexerATNConfig.lexerActionExecutor.

      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.

      This method calls execute(org.antlr.v4.runtime.Lexer) on the result of getAction() using the provided lexer.

      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