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

public Class LexerATNSimulator

extends ATNSimulator
Class Inheritance
Imports
org.antlr.v4.runtime.CharStream, .IntStream, .Lexer, .LexerNoViableAltException, .Token, org.antlr.v4.runtime.dfa.AcceptStateInfo, .DFA, .DFAState, org.antlr.v4.runtime.misc.Interval, .NotNull, .Nullable, java.util.Locale

"dup" of ParserInterpreter

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
LexerATNSimulator.SimState

When we hit an accept state in either the DFA or the ATN, we have to notify the character stream to start buffering characters via IntStream#mark and record the current state.

Field Summary

Modifier and TypeField and Description
protected int
charPositionInLine

The index of the character relative to the beginning of the line 0..n-1

public static final boolean
public static final boolean
protected int
line

line number 1..n within the input

public static int
match_calls

Deprecated This field is no longer used.
public static final int
public static final int
protected int
public boolean
protected final LexerATNSimulator.SimState
prevAccept

Used during DFA/ATN exec to record the most recent accept configuration info

protected final Lexer
protected int
startIndex

The current token's starting index into the character stream.

Inherited from org.antlr.v4.runtime.atn.ATNSimulator:
atnERRORRULE_LF_VARIANT_MARKERRULE_NOLF_VARIANT_MARKERRULE_VARIANT_DELIMITERSERIALIZED_UUIDSERIALIZED_VERSION

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
protected void
accept(CharStream input, LexerActionExecutor lexerActionExecutor, int startIndex, int index, int line, int charPos)

protected DFAState
protected void
protected DFAState
addDFAState(ATNConfigSet configs)

Add a new DFA state if there isn't one with this set of configurations already.

protected void
protected boolean

Returns:

true if an accept state is reached, otherwise false.
closure
(CharStream input, ATNConfig config, ATNConfigSet configs, boolean currentAltReachedAcceptState, boolean speculative, boolean treatEofAsEpsilon)

Since the alternatives within any lexer decision are ordered by preference, this method stops pursuing the closure as soon as an accept state is reached.

protected ATNConfigSet
protected DFAState

Returns:

The computed target DFA state for the given input symbol t. If t does not lead to a valid DFA state, this method returns ERROR.
computeTargetState
(CharStream
The input stream
input
,
DFAState
The current DFA state
s
,
int
The next input symbol
t
)

Compute a target state for an edge in the DFA, and attempt to add the computed state and corresponding edge to the DFA.

public void
public void
protected boolean

Returns:

true if the specified predicate evaluates to true.
evaluatePredicate
(CharStream
The input stream.
input
,
int
The rule containing the predicate.
ruleIndex
,
int
The index of the predicate within the rule.
predIndex
,
boolean
true if the current index in input is one character before the predicate's location.
speculative
)

Evaluate a predicate specified in the lexer.

protected int
protected int
public int
public final DFA
getDFA(int mode)

protected ATNConfig
getEpsilonTarget(CharStream input, ATNConfig config, Transition t, ATNConfigSet configs, boolean speculative, boolean treatEofAsEpsilon)

protected DFAState

Returns:

The existing target DFA state for the given input symbol t, or null if the target state for this edge is not already cached
getExistingTargetState
(DFAState
The current DFA state
s
,
int
The next input symbol
t
)

Get an existing target state for an edge in the DFA.

public int
protected void
getReachableConfigSet(CharStream input, ATNConfigSet closure, ATNConfigSet reach, int t)

Given a starting configuration set, figure out all ATN configurations we can reach upon input t.

protected ATNState
public String
getText(CharStream input)

Get the text matched so far for the current token.

public String
getTokenName(int t)

public int
match(CharStream input, int mode)

protected int
public void
public void
setCharPositionInLine(int charPositionInLine)

public void
setLine(int line)

Inherited from org.antlr.v4.runtime.atn.ATNSimulator:
checkConditioncheckConditionclearDFAdeserializeedgeFactorystateFactorytoInttoInt32toLongtoUUID

Field Detail

charPositionInLineback to summary
protected int charPositionInLine

The index of the character relative to the beginning of the line 0..n-1

debugback to summary
public static final boolean debug
dfa_debugback to summary
public static final boolean dfa_debug
lineback to summary
protected int line

line number 1..n within the input

match_callsback to summary
public static int match_calls

Deprecated

This field is no longer used.

Annotations
@Deprecated
MAX_DFA_EDGEback to summary
public static final int MAX_DFA_EDGE
MIN_DFA_EDGEback to summary
public static final int MIN_DFA_EDGE
modeback to summary
protected int mode
optimize_tail_callsback to summary
public boolean optimize_tail_calls
prevAcceptback to summary
protected final LexerATNSimulator.SimState prevAccept

Used during DFA/ATN exec to record the most recent accept configuration info

Annotations
@NotNull
recogback to summary
protected final Lexer recog
Annotations
@Nullable
startIndexback to summary
protected int startIndex

The current token's starting index into the character stream. Shared across DFA to ATN simulation in case the ATN fails and the DFA did not have a previous accept state. In this case, we use the ATN-generated exception object.

Constructor Detail

LexerATNSimulatorback to summary
public LexerATNSimulator(ATN atn)
LexerATNSimulatorback to summary
public LexerATNSimulator(Lexer recog, ATN atn)

Method Detail

acceptback to summary
protected void accept(CharStream input, LexerActionExecutor lexerActionExecutor, int startIndex, int index, int line, int charPos)
addDFAEdgeback to summary
protected DFAState addDFAEdge(DFAState from, int t, ATNConfigSet q)
Annotations
@NotNull
addDFAEdgeback to summary
protected void addDFAEdge(DFAState p, int t, DFAState q)
addDFAStateback to summary
protected DFAState addDFAState(ATNConfigSet configs)

Add a new DFA state if there isn't one with this set of configurations already. This method also detects the first configuration containing an ATN rule stop state. Later, when traversing the DFA, we will know which rule to accept.

Annotations
@NotNull
captureSimStateback to summary
protected void captureSimState(LexerATNSimulator.SimState settings, CharStream input, DFAState dfaState)
closureback to summary
protected boolean closure(CharStream input, ATNConfig config, ATNConfigSet configs, boolean currentAltReachedAcceptState, boolean speculative, boolean treatEofAsEpsilon)

Since the alternatives within any lexer decision are ordered by preference, this method stops pursuing the closure as soon as an accept state is reached. After the first accept state is reached by depth-first search from config, all other (potentially reachable) states for this rule would have a lower priority.

Returns:boolean

true if an accept state is reached, otherwise false.

computeStartStateback to summary
protected ATNConfigSet computeStartState(CharStream input, ATNState p)
Annotations
@NotNull
computeTargetStateback to summary
protected DFAState computeTargetState(CharStream input, DFAState s, int t)

Compute a target state for an edge in the DFA, and attempt to add the computed state and corresponding edge to the DFA.

Parameters
input:CharStream

The input stream

s:DFAState

The current DFA state

t:int

The next input symbol

Returns:DFAState

The computed target DFA state for the given input symbol t. If t does not lead to a valid DFA state, this method returns ERROR.

Annotations
@NotNull
consumeback to summary
public void consume(CharStream input)
copyStateback to summary
public void copyState(LexerATNSimulator simulator)
evaluatePredicateback to summary
protected boolean evaluatePredicate(CharStream input, int ruleIndex, int predIndex, boolean speculative)

Evaluate a predicate specified in the lexer.

If speculative is true, this method was called before consume for the matched character. This method should call consume before evaluating the predicate to ensure position sensitive values, including Lexer#getText, Lexer#getLine, and Lexer#getCharPositionInLine, properly reflect the current lexer state. This method should restore input and the simulator to the original state before returning (i.e. undo the actions made by the call to consume.

Parameters
input:CharStream

The input stream.

ruleIndex:int

The rule containing the predicate.

predIndex:int

The index of the predicate within the rule.

speculative:boolean

true if the current index in input is one character before the predicate's location.

Returns:boolean

true if the specified predicate evaluates to true.

execATNback to summary
protected int execATN(CharStream input, DFAState ds0)
failOrAcceptback to summary
protected int failOrAccept(LexerATNSimulator.SimState prevAccept, CharStream input, ATNConfigSet reach, int t)
getCharPositionInLineback to summary
public int getCharPositionInLine()
getDFAback to summary
public final DFA getDFA(int mode)
Annotations
@NotNull
getEpsilonTargetback to summary
protected ATNConfig getEpsilonTarget(CharStream input, ATNConfig config, Transition t, ATNConfigSet configs, boolean speculative, boolean treatEofAsEpsilon)
Annotations
@Nullable
getExistingTargetStateback to summary
protected DFAState getExistingTargetState(DFAState s, int t)

Get an existing target state for an edge in the DFA. If the target state for the edge has not yet been computed or is otherwise not available, this method returns null.

Parameters
s:DFAState

The current DFA state

t:int

The next input symbol

Returns:DFAState

The existing target DFA state for the given input symbol t, or null if the target state for this edge is not already cached

Annotations
@Nullable
getLineback to summary
public int getLine()
getReachableConfigSetback to summary
protected void getReachableConfigSet(CharStream input, ATNConfigSet closure, ATNConfigSet reach, int t)

Given a starting configuration set, figure out all ATN configurations we can reach upon input t. Parameter reach is a return parameter.

getReachableTargetback to summary
protected ATNState getReachableTarget(Transition trans, int t)
Annotations
@Nullable
getTextback to summary
public String getText(CharStream input)

Get the text matched so far for the current token.

Annotations
@NotNull
getTokenNameback to summary
public String getTokenName(int t)
Annotations
@NotNull
matchback to summary
public int match(CharStream input, int mode)
matchATNback to summary
protected int matchATN(CharStream input)
resetback to summary
public void reset()

Implements abstract org.antlr.v4.runtime.atn.ATNSimulator.reset.

Annotations
@Override
setCharPositionInLineback to summary
public void setCharPositionInLine(int charPositionInLine)
setLineback to summary
public void setLine(int line)
org.antlr.v4.runtime.atn back to summary

protected Class LexerATNSimulator.SimState

extends Object
Class Inheritance

When we hit an accept state in either the DFA or the ATN, we have to notify the character stream to start buffering characters via IntStream#mark and record the current state. The current sim state includes the current index into the input, the current line, and current character position in that line. Note that the Lexer is tracking the starting line and characterization of the token. These variables track the "state" of the simulator when it hits an accept state.

We track these variables separately for the DFA and ATN simulation because the DFA simulation often has to fail over to the ATN simulation. If the ATN simulation fails, we need the DFA to fall back to its previously accepted state, if any. If the ATN succeeds, then the ATN does the accept and the DFA simulator that invoked it can simply return the predicted token type.

Field Summary

Modifier and TypeField and Description
protected int
protected DFAState
protected int
protected int

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
protected void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

charPosback to summary
protected int charPos
dfaStateback to summary
protected DFAState dfaState
indexback to summary
protected int index
lineback to summary
protected int line

Constructor Detail

SimStateback to summary
protected SimState()

Method Detail

resetback to summary
protected void reset()