public class LexerATNSimulator extends ATNSimulator
Modifier and Type | Class 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. |
Modifier and Type | Field and Description |
---|---|
protected int |
charPositionInLine
The index of the character relative to the beginning of the line 0..n-1
|
static boolean |
debug |
DFA[] |
decisionToDFA |
static boolean |
dfa_debug |
protected int |
line
line number 1..n within the input
|
static int |
match_calls |
static int |
MAX_DFA_EDGE |
static int |
MIN_DFA_EDGE |
protected int |
mode |
protected LexerATNSimulator.SimState |
prevAccept
Used during DFA/ATN exec to record the most recent accept configuration info
|
protected Lexer |
recog |
protected int |
startIndex
The current token's starting index into the character stream.
|
atn, ERROR, SERIALIZED_UUID, SERIALIZED_VERSION, sharedContextCache
Constructor and Description |
---|
LexerATNSimulator(ATN atn,
DFA[] decisionToDFA,
PredictionContextCache sharedContextCache) |
LexerATNSimulator(Lexer recog,
ATN atn,
DFA[] decisionToDFA,
PredictionContextCache sharedContextCache) |
Modifier and Type | Method and Description |
---|---|
protected void |
accept(CharStream input,
int ruleIndex,
int actionIndex,
int index,
int line,
int charPos) |
protected DFAState |
addDFAEdge(DFAState from,
int t,
ATNConfigSet q) |
protected void |
addDFAEdge(DFAState p,
int t,
DFAState q) |
protected DFAState |
addDFAState(ATNConfigSet configs)
Add a new DFA state if there isn't one with this set of
configurations already.
|
protected void |
captureSimState(LexerATNSimulator.SimState settings,
CharStream input,
DFAState dfaState) |
protected boolean |
closure(CharStream input,
LexerATNConfig config,
ATNConfigSet configs,
boolean currentAltReachedAcceptState,
boolean speculative)
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 |
computeStartState(CharStream input,
ATNState p) |
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.
|
void |
consume(CharStream input) |
void |
copyState(LexerATNSimulator simulator) |
protected boolean |
evaluatePredicate(CharStream input,
int ruleIndex,
int predIndex,
boolean speculative)
Evaluate a predicate specified in the lexer.
|
protected int |
execATN(CharStream input,
DFAState ds0) |
protected int |
failOrAccept(LexerATNSimulator.SimState prevAccept,
CharStream input,
ATNConfigSet reach,
int t) |
int |
getCharPositionInLine() |
DFA |
getDFA(int mode) |
protected LexerATNConfig |
getEpsilonTarget(CharStream input,
LexerATNConfig config,
Transition t,
ATNConfigSet configs,
boolean speculative) |
protected DFAState |
getExistingTargetState(DFAState s,
int t)
Get an existing target state for an edge in the DFA.
|
int |
getLine() |
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 |
getReachableTarget(Transition trans,
int t) |
String |
getText(CharStream input)
Get the text matched so far for the current token.
|
String |
getTokenName(int t) |
int |
match(CharStream input,
int mode) |
protected int |
matchATN(CharStream input) |
void |
reset() |
void |
setCharPositionInLine(int charPositionInLine) |
void |
setLine(int line) |
checkCondition, checkCondition, deserialize, edgeFactory, getCachedContext, getSharedContextCache, stateFactory, toInt, toInt32, toLong, toUUID
public static final boolean debug
public static final boolean dfa_debug
public static final int MIN_DFA_EDGE
public static final int MAX_DFA_EDGE
protected int startIndex
protected int line
protected int charPositionInLine
protected int mode
@NotNull protected final LexerATNSimulator.SimState prevAccept
public static int match_calls
public LexerATNSimulator(@NotNull ATN atn, @NotNull DFA[] decisionToDFA, @NotNull PredictionContextCache sharedContextCache)
public void copyState(@NotNull LexerATNSimulator simulator)
public int match(@NotNull CharStream input, int mode)
public void reset()
reset
in class ATNSimulator
protected int matchATN(@NotNull CharStream input)
protected int execATN(@NotNull CharStream input, @NotNull DFAState ds0)
@Nullable protected DFAState getExistingTargetState(@NotNull DFAState s, int t)
null
.s
- The current DFA statet
- The next input symbolt
, or null
if the target state for this edge is not
already cached@NotNull protected DFAState computeTargetState(@NotNull CharStream input, @NotNull DFAState s, int t)
input
- The input streams
- The current DFA statet
- The next input symbolt
. If t
does not lead to a valid DFA state, this method
returns ATNSimulator.ERROR
.protected int failOrAccept(LexerATNSimulator.SimState prevAccept, CharStream input, ATNConfigSet reach, int t)
protected void getReachableConfigSet(@NotNull CharStream input, @NotNull ATNConfigSet closure, @NotNull ATNConfigSet reach, int t)
t
. Parameter reach
is a return
parameter.protected void accept(@NotNull CharStream input, int ruleIndex, int actionIndex, int index, int line, int charPos)
@Nullable protected ATNState getReachableTarget(Transition trans, int t)
@NotNull protected ATNConfigSet computeStartState(@NotNull CharStream input, @NotNull ATNState p)
protected boolean closure(@NotNull CharStream input, @NotNull LexerATNConfig config, @NotNull ATNConfigSet configs, boolean currentAltReachedAcceptState, boolean speculative)
config
, all other (potentially reachable) states for
this rule would have a lower priority.true
if an accept state is reached, otherwise
false
.@Nullable protected LexerATNConfig getEpsilonTarget(@NotNull CharStream input, @NotNull LexerATNConfig config, @NotNull Transition t, @NotNull ATNConfigSet configs, boolean speculative)
protected boolean evaluatePredicate(@NotNull CharStream input, int ruleIndex, int predIndex, boolean speculative)
speculative
is true
, this method was called before
consume(org.antlr.v4.runtime.CharStream)
for the matched character. This method should call
consume(org.antlr.v4.runtime.CharStream)
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(org.antlr.v4.runtime.CharStream)
.input
- The input stream.ruleIndex
- The rule containing the predicate.predIndex
- The index of the predicate within the rule.speculative
- true
if the current index in input
is
one character before the predicate's location.true
if the specified predicate evaluates to
true
.protected void captureSimState(@NotNull LexerATNSimulator.SimState settings, @NotNull CharStream input, @NotNull DFAState dfaState)
@NotNull protected DFAState addDFAEdge(@NotNull DFAState from, int t, @NotNull ATNConfigSet q)
@NotNull protected DFAState addDFAState(@NotNull ATNConfigSet configs)
@NotNull public String getText(@NotNull CharStream input)
public int getLine()
public void setLine(int line)
public int getCharPositionInLine()
public void setCharPositionInLine(int charPositionInLine)
public void consume(@NotNull CharStream input)
Copyright © 1992-2013 ANTLR. All Rights Reserved.