Top Description Fields Constructors Methods
org.antlr.v4.runtime.atn

public Class LexerActionExecutor

extends Object
Class Inheritance
Imports
org.antlr.v4.runtime.CharStream, .IntStream, .Lexer, org.antlr.v4.runtime.dfa.DFA, org.antlr.v4.runtime.misc.MurmurHash, java.util.Arrays

Represents an executor for a sequence of lexer actions which traversed during the matching operation of a lexer rule (token).

The executor tracks position information for position-dependent lexer actions efficiently, ensuring that actions appearing only at the end of the rule do not cause bloating of the DFA created for the lexer.

Author
Sam Harwell
Since
4.2

Field Summary

Modifier and TypeField and Description
private final int
hashCode

Caches the result of hashCode since the hash code is an element of the performance-critical LexerATNConfig#hashCode operation.

private final LexerAction[]

Constructor Summary

AccessConstructor and Description
public
LexerActionExecutor(LexerAction[]
The lexer actions to execute.
lexerActions
)

Constructs an executor for a sequence of LexerAction actions.

Method Summary

Modifier and TypeMethod and Description
public static LexerActionExecutor

Returns:

A LexerActionExecutor for executing the combine actions of lexerActionExecutor and lexerAction.
append
(LexerActionExecutor
The executor for actions already traversed by the lexer while matching a token within a particular LexerATNConfig. If this is null, the method behaves as though it were an empty executor.
lexerActionExecutor
,
LexerAction
The lexer action to execute after the actions specified in lexerActionExecutor.
lexerAction
)

Creates a LexerActionExecutor which executes the actions for the input lexerActionExecutor followed by a specified lexerAction.

public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public void
execute(Lexer
The lexer instance.
lexer
,
CharStream
The input stream which is the source for the current token. When this method is called, the current IntStream#index for input should be the start of the following token, i.e. 1 character past the end of the current token.
input
,
int
The token start index. This value may be passed to IntStream#seek to set the input position to the beginning of the token.
startIndex
)

Execute the actions encapsulated by this executor within the context of a particular Lexer.

public LexerActionExecutor

Returns:

A LexerActionExecutor which stores input stream offsets for all position-dependent lexer actions.
fixOffsetBeforeMatch
(int
The current offset to assign to all position-dependent lexer actions which do not already have offsets assigned.
offset
)

Creates a LexerActionExecutor which encodes the current offset for position-dependent lexer actions.

public LexerAction[]

Returns:

The lexer actions to be executed by this executor.
getLexerActions
()

Gets the lexer actions to be executed by this executor.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

hashCodeback to summary
private final int hashCode

Caches the result of hashCode since the hash code is an element of the performance-critical LexerATNConfig#hashCode operation.

lexerActionsback to summary
private final LexerAction[] lexerActions

Constructor Detail

LexerActionExecutorback to summary
public LexerActionExecutor(LexerAction[] lexerActions)

Constructs an executor for a sequence of LexerAction actions.

Parameters
lexerActions:LexerAction[]

The lexer actions to execute.

Method Detail

appendback to summary
public static LexerActionExecutor append(LexerActionExecutor lexerActionExecutor, LexerAction lexerAction)

Creates a LexerActionExecutor which executes the actions for the input lexerActionExecutor followed by a specified lexerAction.

Parameters
lexerActionExecutor:LexerActionExecutor

The executor for actions already traversed by the lexer while matching a token within a particular LexerATNConfig. If this is null, the method behaves as though it were an empty executor.

lexerAction:LexerAction

The lexer action to execute after the actions specified in lexerActionExecutor.

Returns:LexerActionExecutor

A LexerActionExecutor for executing the combine actions of lexerActionExecutor and lexerAction.

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
executeback to summary
public void execute(Lexer lexer, CharStream input, int startIndex)

Execute the actions encapsulated by this executor within the context of a particular Lexer.

This method calls IntStream#seek to set the position of the input CharStream prior to calling LexerAction#execute on a position-dependent action. Before the method returns, the input position will be restored to the same position it was in when the method was invoked.

Parameters
lexer:Lexer

The lexer instance.

input:CharStream

The input stream which is the source for the current token. When this method is called, the current IntStream#index for input should be the start of the following token, i.e. 1 character past the end of the current token.

startIndex:int

The token start index. This value may be passed to IntStream#seek to set the input position to the beginning of the token.

fixOffsetBeforeMatchback to summary
public LexerActionExecutor fixOffsetBeforeMatch(int offset)

Creates a LexerActionExecutor which encodes the current offset for position-dependent lexer actions.

Normally, when the executor encounters lexer actions where LexerAction#isPositionDependent returns true, it calls IntStream#seek on the input CharStream to set the input position to the end of the current token. This behavior provides for efficient DFA representation of lexer actions which appear at the end of a lexer rule, even when the lexer rule matches a variable number of characters.

Prior to traversing a match transition in the ATN, the current offset from the token start index is assigned to all position-dependent lexer actions which have not already been assigned a fixed offset. By storing the offsets relative to the token start index, the DFA representation of lexer actions which appear in the middle of tokens remains efficient due to sharing among tokens of the same length, regardless of their absolute position in the input stream.

If the current executor already has offsets assigned to all position-dependent lexer actions, the method returns this.

Parameters
offset:int

The current offset to assign to all position-dependent lexer actions which do not already have offsets assigned.

Returns:LexerActionExecutor

A LexerActionExecutor which stores input stream offsets for all position-dependent lexer actions.

getLexerActionsback to summary
public LexerAction[] getLexerActions()

Gets the lexer actions to be executed by this executor.

Returns:LexerAction[]

The lexer actions to be executed by this executor.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override