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,
LexerActionExecutor lexerActionExecutor,
int startIndex,
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) |
void |
clearDFA()
Clear the DFA cache used by the current instance.
|
protected boolean |
closure(CharStream input,
LexerATNConfig 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 |
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,
boolean treatEofAsEpsilon) |
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 final Lexer recog
protected int startIndex
protected int line
protected int charPositionInLine
public final DFA[] decisionToDFA
protected int mode
protected final LexerATNSimulator.SimState prevAccept
public static int match_calls
public LexerATNSimulator(ATN atn, DFA[] decisionToDFA, PredictionContextCache sharedContextCache)
public LexerATNSimulator(Lexer recog, ATN atn, DFA[] decisionToDFA, PredictionContextCache sharedContextCache)
public void copyState(LexerATNSimulator simulator)
public int match(CharStream input, int mode)
public void reset()
reset
in class ATNSimulator
public void clearDFA()
ATNSimulator
clearDFA
in class ATNSimulator
protected int matchATN(CharStream input)
protected int execATN(CharStream input, DFAState ds0)
protected DFAState getExistingTargetState(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 cachedprotected DFAState computeTargetState(CharStream input, 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(CharStream input, ATNConfigSet closure, ATNConfigSet reach, int t)
t
. Parameter reach
is a return
parameter.protected void accept(CharStream input, LexerActionExecutor lexerActionExecutor, int startIndex, int index, int line, int charPos)
protected ATNState getReachableTarget(Transition trans, int t)
protected ATNConfigSet computeStartState(CharStream input, ATNState p)
protected boolean closure(CharStream input, LexerATNConfig config, ATNConfigSet configs, boolean currentAltReachedAcceptState, boolean speculative, boolean treatEofAsEpsilon)
config
, all other (potentially reachable) states for
this rule would have a lower priority.true
if an accept state is reached, otherwise
false
.protected LexerATNConfig getEpsilonTarget(CharStream input, LexerATNConfig config, Transition t, ATNConfigSet configs, boolean speculative, boolean treatEofAsEpsilon)
protected boolean evaluatePredicate(CharStream input, int ruleIndex, int predIndex, boolean speculative)
If 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(LexerATNSimulator.SimState settings, CharStream input, DFAState dfaState)
protected DFAState addDFAEdge(DFAState from, int t, ATNConfigSet q)
protected DFAState addDFAState(ATNConfigSet configs)
public final DFA getDFA(int mode)
public String getText(CharStream input)
public int getLine()
public void setLine(int line)
public int getCharPositionInLine()
public void setCharPositionInLine(int charPositionInLine)
public void consume(CharStream input)
public String getTokenName(int t)
Copyright © 1992–2018 ANTLR. All rights reserved.