/** * Compute a target state for an edge in the DFA, and attempt to add the * computed state and corresponding edge to the DFA. * * @param input The input stream * @param s The current DFA state * @param t The next input symbol * * @return The computed target DFA state for the given input symbol * {@code t}. If {@code t} does not lead to a valid DFA state, this method * returns {@link #ERROR}. */ protected DFAState computeTargetState(CharStream input, DFAState s, int t) { ATNConfigSet reach = new OrderedATNConfigSet(); // if we don't find an existing DFA state // Fill reach starting from closure, following t transitions getReachableConfigSet(input, s.configs, reach, t); if ( reach.isEmpty() ) { // we got nowhere on t from s if (!reach.hasSemanticContext) { // we got nowhere on t, don't throw out this knowledge; it'd // cause a failover from DFA later. addDFAEdge(s, t, ERROR); } // stop when we can't match any more char return ERROR; } // Add an edge from s to target DFA found/created for reach return addDFAEdge(s, t, reach); }

/** 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 {@link 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. * * <p>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.</p> */ protected static class SimState { protected int index = -1; protected int line = 0; protected int charPos = -1; protected DFAState dfaState; protected void reset() { index = -1; line = 0; charPos = -1; dfaState = null; } }

/** * Compute a target state for an edge in the DFA, and attempt to add the * computed state and corresponding edge to the DFA. * * @param input The input stream * @param s The current DFA state * @param t The next input symbol * * @return The computed target DFA state for the given input symbol * {@code t}. If {@code t} does not lead to a valid DFA state, this method * returns {@link #ERROR}. */ protected DFAState computeTargetState(CharStream input, DFAState s, int t) { ATNConfigSet reach = new OrderedATNConfigSet(); // if we don't find an existing DFA state // Fill reach starting from closure, following t transitions getReachableConfigSet(input, s.configs, reach, t); if ( reach.isEmpty() ) { // we got nowhere on t from s if (!reach.hasSemanticContext) { // we got nowhere on t, don't throw out this knowledge; it'd // cause a failover from DFA later. addDFAEdge(s, t, ERROR); } // stop when we can't match any more char return ERROR; } // Add an edge from s to target DFA found/created for reach return addDFAEdge(s, t, reach); }

/** * Compute a target state for an edge in the DFA, and attempt to add the * computed state and corresponding edge to the DFA. * * @param input The input stream * @param s The current DFA state * @param t The next input symbol * * @return The computed target DFA state for the given input symbol * {@code t}. If {@code t} does not lead to a valid DFA state, this method * returns {@link #ERROR}. */ protected DFAState computeTargetState(CharStream input, DFAState s, int t) { ATNConfigSet reach = new OrderedATNConfigSet(); // if we don't find an existing DFA state // Fill reach starting from closure, following t transitions getReachableConfigSet(input, s.configs, reach, t); if ( reach.isEmpty() ) { // we got nowhere on t from s if (!reach.hasSemanticContext) { // we got nowhere on t, don't throw out this knowledge; it'd // cause a failover from DFA later. addDFAEdge(s, t, ERROR); } // stop when we can't match any more char return ERROR; } // Add an edge from s to target DFA found/created for reach return addDFAEdge(s, t, reach); }

/** 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 {@link 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. * * <p>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.</p> */ protected static class SimState { protected int index = -1; protected int line = 0; protected int charPos = -1; protected DFAState dfaState; protected void reset() { index = -1; line = 0; charPos = -1; dfaState = null; } }

/** 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 {@link 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. * * <p>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.</p> */ protected static class SimState { protected int index = -1; protected int line = 0; protected int charPos = -1; protected DFAState dfaState; protected void reset() { index = -1; line = 0; charPos = -1; dfaState = null; } }

/** * Compute a target state for an edge in the DFA, and attempt to add the * computed state and corresponding edge to the DFA. * * @param input The input stream * @param s The current DFA state * @param t The next input symbol * * @return The computed target DFA state for the given input symbol * {@code t}. If {@code t} does not lead to a valid DFA state, this method * returns {@link #ERROR}. */ @NotNull protected DFAState computeTargetState(@NotNull CharStream input, @NotNull DFAState s, int t) { ATNConfigSet reach = new OrderedATNConfigSet(); // if we don't find an existing DFA state // Fill reach starting from closure, following t transitions getReachableConfigSet(input, s.configs, reach, t); if ( reach.isEmpty() ) { // we got nowhere on t from s if (!reach.hasSemanticContext()) { // we got nowhere on t, don't throw out this knowledge; it'd // cause a failover from DFA later. addDFAEdge(s, t, ERROR); } // stop when we can't match any more char return ERROR; } // Add an edge from s to target DFA found/created for reach return addDFAEdge(s, t, reach); }