addDFAEdge method

DFAState? addDFAEdge(
  1. DFA dfa,
  2. DFAState? from,
  3. int t,
  4. DFAState to,
)

Add an edge to the DFA, if possible. This method calls {@link #addDFAState} to ensure the to state is present in the DFA. If from is null, or if t is outside the range of edges that can be represented in the DFA tables, this method returns without adding the edge to the DFA.

If [to] is null, this method returns null. Otherwise, this method returns the [DFAState] returned by calling {@link #addDFAState} for the [to] state.

@param dfa The DFA @param from The source state for the edge @param t The input symbol @param to The target state for the edge

@return If to is null, this method returns null; otherwise this method returns the result of calling {@link #addDFAState} on to

Implementation

DFAState? addDFAEdge(DFA dfa, DFAState? from, int t, DFAState to) {
  if (debug) {
    log('EDGE $from -> $to upon ' + getTokenName(t));
  }

  to = addDFAState(dfa, to); // used existing if possible not incoming
  if (from == null || t < -1 || t > atn.maxTokenType) {
    return to;
  }

  from.edges ??= List.filled(atn.maxTokenType + 1 + 1, null);

  from.edges![t + 1] = to; // connect

  if (debug) {
    log('DFA=\n' + dfa.toString(parser.vocabulary));
  }

  return to;
}