/* Generated By:JavaCC: Do not edit this line. SqlNormalizerTokenManager.java */
package datadog.trace.instrumentation.jdbc.normalizer;

/** Token Manager. */
public class SqlNormalizerTokenManager implements SqlNormalizerConstants {

  /** Debug output. */
  public java.io.PrintStream debugStream = System.out;
  /** Set debug output. */
  public void setDebugStream(java.io.PrintStream ds) {
    debugStream = ds;
  }

  private int jjMoveStringLiteralDfa0_0() {
    return jjMoveNfa_0(0, 0);
  }

  static final long[] jjbitVec0 = {
    0xfff0000040220002L, 0xffffffffffffdfffL, 0xfffff02f7fffffffL, 0x12000000007fffffL
  };
  static final long[] jjbitVec2 = {0x0L, 0x0L, 0x420040000000000L, 0xff7fffffff7fffffL};
  static final long[] jjbitVec3 = {
    0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0x501f0003ffc3L
  };
  static final long[] jjbitVec4 = {
    0x0L, 0x3cdf000000000000L, 0xfffffffbffffd740L, 0xffbfffffffffffffL
  };
  static final long[] jjbitVec5 = {
    0xffffffffffffffffL, 0xffffffffffffffffL, 0xfffffffffffffc03L, 0xffffffffffffffffL
  };
  static final long[] jjbitVec6 = {
    0xfffe00ffffffffffL, 0xfffffffe027fffffL, 0xffL, 0x707ffffff0000L
  };
  static final long[] jjbitVec7 = {
    0xffffffff00000000L, 0xfffec000000007ffL, 0xffffffffffffffffL, 0x9c00c060002fffffL
  };
  static final long[] jjbitVec8 = {
    0xfffffffd0000L, 0xffffffffffffe000L, 0x2003fffffffffL, 0x43007fffffffc00L
  };
  static final long[] jjbitVec9 = {0x110043fffffL, 0x1ffffffL, 0x1ffd00000000L, 0x0L};
  static final long[] jjbitVec10 = {
    0x23fffffffffffff0L, 0xfefe0003ff010000L, 0x23c5fdfffff99fe0L, 0x30003b0004000L
  };
  static final long[] jjbitVec11 = {
    0x36dfdfffff987e0L, 0x1c00005e000000L, 0x23edfdfffffbbfe0L, 0x300010000L
  };
  static final long[] jjbitVec12 = {
    0x23edfdfffff99fe0L, 0x20003b0000000L, 0x3ffc718d63dc7e8L, 0x10000L
  };
  static final long[] jjbitVec13 = {
    0x23effdfffffddfe0L, 0x303000000L, 0x23effdfffffddfe0L, 0x6000340000000L
  };
  static final long[] jjbitVec14 = {
    0x27fffffffffddfe0L, 0xfc00000300004000L, 0x2ffbfffffc7fffe0L, 0x7fL
  };
  static final long[] jjbitVec15 = {0xdfffffffffffeL, 0x7fL, 0x200decaefef02596L, 0xf000005fL};
  static final long[] jjbitVec16 = {0x1L, 0x1ffffffffeffL, 0x1f00L, 0x0L};
  static final long[] jjbitVec17 = {
    0x800007ffffffffffL, 0xffe1c0623c3f0000L, 0xffffffff00004003L, 0xf7ffffffffff20bfL
  };
  static final long[] jjbitVec18 = {
    0xffffffffffffffffL, 0xffffffff3d7f3dffL, 0x7f3dffffffff3dffL, 0xffffffffff7fff3dL
  };
  static final long[] jjbitVec19 = {
    0xffffffffff3dffffL, 0x7ffffffL, 0xffffffff0000ffffL, 0x1fffffffffffffL
  };
  static final long[] jjbitVec20 = {
    0xfffffffffffffffeL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL
  };
  static final long[] jjbitVec21 = {
    0xffffffffffffffffL, 0xffff9fffffffffffL, 0xffffffff07fffffeL, 0x7ffffffffffL
  };
  static final long[] jjbitVec22 = {
    0x3ffff0003dfffL, 0x1dfff0003ffffL, 0xfffffffffffffL, 0x10800000L
  };
  static final long[] jjbitVec23 = {
    0xffffffff00000000L, 0xffffffffffffffL, 0xffff05ffffffffffL, 0x3fffffffffffffL
  };
  static final long[] jjbitVec24 = {0x1fffffffL, 0x1f3fffffff0000L, 0xfffffffffffL, 0xfeL};
  static final long[] jjbitVec25 = {0xffffffff007fffffL, 0x1fffffL, 0x8000000000L, 0x0L};
  static final long[] jjbitVec26 = {0xfffffffffffe0L, 0xfe0L, 0xfc00c001fffffff8L, 0x3fffffffffL};
  static final long[] jjbitVec27 = {0xfffffffffL, 0x3ffffffffc00e000L, 0x0L, 0x63de0000000000L};
  static final long[] jjbitVec28 = {
    0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0x0L
  };
  static final long[] jjbitVec29 = {
    0xffffffff3f3fffffL, 0x3fffffffaaff3f3fL, 0x5fdfffffffffffffL, 0x1fdc1fff0fcf1fdcL
  };
  static final long[] jjbitVec30 = {0x0L, 0x8002000000000000L, 0x1fff0000L, 0x0L};
  static final long[] jjbitVec31 = {0xf3ffbd503e2ffc84L, 0x43e0L, 0x18L, 0x0L};
  static final long[] jjbitVec32 = {
    0xffff7fffffffffffL, 0xffffffff7fffffffL, 0xffffffffffffffffL, 0xc781fffffffffL
  };
  static final long[] jjbitVec33 = {
    0xffff20bfffffffffL, 0x80ffffffffffL, 0x7f7f7f7f007fffffL, 0x7f7f7f7fL
  };
  static final long[] jjbitVec34 = {0x800000000000L, 0x0L, 0x0L, 0x0L};
  static final long[] jjbitVec35 = {
    0x183e000000000060L, 0xfffffffffffffffeL, 0xfffffffee07fffffL, 0xf7ffffffffffffffL
  };
  static final long[] jjbitVec36 = {
    0xfffe3fffffffffe0L, 0xffffffffffffffffL, 0x7ffffff00007fffL, 0xffff000000000000L
  };
  static final long[] jjbitVec37 = {
    0xffffffffffffffffL, 0xffffffffffffffffL, 0x3fffffffffffffL, 0x0L
  };
  static final long[] jjbitVec38 = {
    0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0x1fffL
  };
  static final long[] jjbitVec39 = {
    0xffffffffffffffffL, 0xffffffffffffffffL, 0x1fffL, 0x3fffffffffff0000L
  };
  static final long[] jjbitVec40 = {
    0xc00ffff1fffL, 0x80007fffffffffffL, 0xffffffff00ffffffL, 0x3fffffffffL
  };
  static final long[] jjbitVec41 = {
    0xfffffffcff800000L, 0xffffffffffffffffL, 0x7ff000f79ffL, 0xff00000000000000L
  };
  static final long[] jjbitVec42 = {
    0x7fffff7bbL, 0xfffffffffffffL, 0xffffffffffffcL, 0x8fc000000000000L
  };
  static final long[] jjbitVec43 = {
    0xffff003ffffffc00L, 0x1fffffff0000007fL, 0x7fffffffffff0L, 0x8000L
  };
  static final long[] jjbitVec44 = {
    0x1ffffffffffL, 0x47fffff00000ff7L, 0x3e62ffffffffffffL, 0x1c07ff38000005L
  };
  static final long[] jjbitVec45 = {0x7f7f007e7e7eL, 0x0L, 0x0L, 0x7ffffffffL};
  static final long[] jjbitVec46 = {
    0xffffffffffffffffL, 0xffffffffffffffffL, 0xffff000fffffffffL, 0xffffffffffff87fL
  };
  static final long[] jjbitVec47 = {
    0xffffffffffffffffL, 0xffff3fffffffffffL, 0xffffffffffffffffL, 0x3ffffffL
  };
  static final long[] jjbitVec48 = {
    0x5f7ffdffa0f8007fL, 0xffffffffffffffdbL, 0x3ffffffffffffL, 0xfffffffffff80000L
  };
  static final long[] jjbitVec49 = {
    0x3fffffffffffffffL, 0xffffffffffff0000L, 0xfffffffffffcffffL, 0xfff0000000000ffL
  };
  static final long[] jjbitVec50 = {
    0x0L, 0xffdf000000000000L, 0xffffffffffffffffL, 0x1fffffffffffffffL
  };
  static final long[] jjbitVec51 = {
    0x7fffffe00000000L, 0xffffffc007fffffeL, 0x7fffffffffffffffL, 0x1cfcfcfcL
  };
  static final long[] jjbitVec52 = {0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL};

  private int jjMoveNfa_0(int startState, int curPos) {
    // int[] nextStates; // not used
    int startsAt = 0;
    jjnewStateCnt = 19;
    int i = 1;
    jjstateSet[0] = startState;
    // int j; // not used
    int kind = 0x7fffffff;
    for (; ; ) {
      if (++jjround == 0x7fffffff) ReInitRounds();
      if (curChar < 64) {
        long l = 1L << curChar;
        do {
          switch (jjstateSet[--i]) {
            case 0:
              if ((0x3ff000000000000L & l) != 0L) {
                if (kind > 2) kind = 2;
                jjCheckNAdd(4);
              } else if ((0x100002600L & l) != 0L) {
                if (kind > 6) kind = 6;
                jjCheckNAdd(18);
              } else if ((0x680000000000L & l) != 0L) jjCheckNAddTwoStates(2, 3);
              else if (curChar == 34) jjCheckNAddStates(0, 2);
              else if (curChar == 39) jjCheckNAddStates(3, 5);
              if (curChar == 48) jjstateSet[jjnewStateCnt++] = 5;
              break;
            case 1:
              if ((0x3ff000000000000L & l) == 0L) break;
              if (kind > 1) kind = 1;
              jjstateSet[jjnewStateCnt++] = 1;
              break;
            case 2:
              if ((0x680000000000L & l) != 0L) jjCheckNAddTwoStates(2, 3);
              break;
            case 3:
              if ((0x3ff000000000000L & l) == 0L) break;
              if (kind > 2) kind = 2;
              jjCheckNAdd(4);
              break;
            case 4:
              if ((0x3ff680000000000L & l) == 0L) break;
              if (kind > 2) kind = 2;
              jjCheckNAdd(4);
              break;
            case 6:
              if ((0x3ff000000000000L & l) == 0L) break;
              if (kind > 3) kind = 3;
              jjstateSet[jjnewStateCnt++] = 6;
              break;
            case 7:
              if (curChar == 48) jjstateSet[jjnewStateCnt++] = 5;
              break;
            case 8:
            case 9:
              if (curChar == 39) jjCheckNAddStates(3, 5);
              break;
            case 10:
              if (curChar == 39) jjstateSet[jjnewStateCnt++] = 9;
              break;
            case 11:
              if ((0xffffff7fffffffffL & l) != 0L) jjCheckNAddStates(3, 5);
              break;
            case 12:
              if (curChar == 39 && kind > 4) kind = 4;
              break;
            case 13:
            case 14:
              if (curChar == 34) jjCheckNAddStates(0, 2);
              break;
            case 15:
              if (curChar == 34) jjstateSet[jjnewStateCnt++] = 14;
              break;
            case 16:
              if ((0xfffffffbffffffffL & l) != 0L) jjCheckNAddStates(0, 2);
              break;
            case 17:
              if (curChar == 34 && kind > 5) kind = 5;
              break;
            case 18:
              if ((0x100002600L & l) == 0L) break;
              if (kind > 6) kind = 6;
              jjCheckNAdd(18);
              break;
            default:
              break;
          }
        } while (i != startsAt);
      } else if (curChar < 128) {
        long l = 1L << (curChar & 077);
        do {
          switch (jjstateSet[--i]) {
            case 0:
            case 1:
              if ((0x7fffffe87fffffeL & l) == 0L) break;
              if (kind > 1) kind = 1;
              jjCheckNAdd(1);
              break;
            case 4:
              if ((0x2000000020L & l) == 0L) break;
              if (kind > 2) kind = 2;
              jjstateSet[jjnewStateCnt++] = 4;
              break;
            case 5:
              if ((0x100000001000000L & l) != 0L) jjCheckNAdd(6);
              break;
            case 6:
              if ((0x7e0000007eL & l) == 0L) break;
              if (kind > 3) kind = 3;
              jjCheckNAdd(6);
              break;
            case 11:
              jjAddStates(3, 5);
              break;
            case 16:
              jjAddStates(0, 2);
              break;
            default:
              break;
          }
        } while (i != startsAt);
      } else {
        int hiByte = (int) (curChar >> 8);
        int i1 = hiByte >> 6;
        long l1 = 1L << (hiByte & 077);
        int i2 = (curChar & 0xff) >> 6;
        long l2 = 1L << (curChar & 077);
        do {
          switch (jjstateSet[--i]) {
            case 0:
            case 1:
              if (!jjCanMove_0(hiByte, i1, i2, l1, l2)) break;
              if (kind > 1) kind = 1;
              jjCheckNAdd(1);
              break;
            case 11:
              if (jjCanMove_1(hiByte, i1, i2, l1, l2)) jjAddStates(3, 5);
              break;
            case 16:
              if (jjCanMove_1(hiByte, i1, i2, l1, l2)) jjAddStates(0, 2);
              break;
            default:
              break;
          }
        } while (i != startsAt);
      }
      if (kind != 0x7fffffff) {
        jjmatchedKind = kind;
        jjmatchedPos = curPos;
        kind = 0x7fffffff;
      }
      ++curPos;
      if ((i = jjnewStateCnt) == (startsAt = 19 - (jjnewStateCnt = startsAt))) return curPos;
      try {
        curChar = input_stream.readChar();
      } catch (java.io.IOException e) {
        return curPos;
      }
    }
  }

  static final int[] jjnextStates = {
    15, 16, 17, 10, 11, 12,
  };

  private static final boolean jjCanMove_0(int hiByte, int i1, int i2, long l1, long l2) {
    switch (hiByte) {
      case 0:
        return ((jjbitVec2[i2] & l2) != 0L);
      case 2:
        return ((jjbitVec3[i2] & l2) != 0L);
      case 3:
        return ((jjbitVec4[i2] & l2) != 0L);
      case 4:
        return ((jjbitVec5[i2] & l2) != 0L);
      case 5:
        return ((jjbitVec6[i2] & l2) != 0L);
      case 6:
        return ((jjbitVec7[i2] & l2) != 0L);
      case 7:
        return ((jjbitVec8[i2] & l2) != 0L);
      case 8:
        return ((jjbitVec9[i2] & l2) != 0L);
      case 9:
        return ((jjbitVec10[i2] & l2) != 0L);
      case 10:
        return ((jjbitVec11[i2] & l2) != 0L);
      case 11:
        return ((jjbitVec12[i2] & l2) != 0L);
      case 12:
        return ((jjbitVec13[i2] & l2) != 0L);
      case 13:
        return ((jjbitVec14[i2] & l2) != 0L);
      case 14:
        return ((jjbitVec15[i2] & l2) != 0L);
      case 15:
        return ((jjbitVec16[i2] & l2) != 0L);
      case 16:
        return ((jjbitVec17[i2] & l2) != 0L);
      case 18:
        return ((jjbitVec18[i2] & l2) != 0L);
      case 19:
        return ((jjbitVec19[i2] & l2) != 0L);
      case 20:
        return ((jjbitVec20[i2] & l2) != 0L);
      case 22:
        return ((jjbitVec21[i2] & l2) != 0L);
      case 23:
        return ((jjbitVec22[i2] & l2) != 0L);
      case 24:
        return ((jjbitVec23[i2] & l2) != 0L);
      case 25:
        return ((jjbitVec24[i2] & l2) != 0L);
      case 26:
        return ((jjbitVec25[i2] & l2) != 0L);
      case 27:
        return ((jjbitVec26[i2] & l2) != 0L);
      case 28:
        return ((jjbitVec27[i2] & l2) != 0L);
      case 29:
        return ((jjbitVec28[i2] & l2) != 0L);
      case 31:
        return ((jjbitVec29[i2] & l2) != 0L);
      case 32:
        return ((jjbitVec30[i2] & l2) != 0L);
      case 33:
        return ((jjbitVec31[i2] & l2) != 0L);
      case 44:
        return ((jjbitVec32[i2] & l2) != 0L);
      case 45:
        return ((jjbitVec33[i2] & l2) != 0L);
      case 46:
        return ((jjbitVec34[i2] & l2) != 0L);
      case 48:
        return ((jjbitVec35[i2] & l2) != 0L);
      case 49:
        return ((jjbitVec36[i2] & l2) != 0L);
      case 77:
        return ((jjbitVec37[i2] & l2) != 0L);
      case 159:
        return ((jjbitVec38[i2] & l2) != 0L);
      case 164:
        return ((jjbitVec39[i2] & l2) != 0L);
      case 166:
        return ((jjbitVec40[i2] & l2) != 0L);
      case 167:
        return ((jjbitVec41[i2] & l2) != 0L);
      case 168:
        return ((jjbitVec42[i2] & l2) != 0L);
      case 169:
        return ((jjbitVec43[i2] & l2) != 0L);
      case 170:
        return ((jjbitVec44[i2] & l2) != 0L);
      case 171:
        return ((jjbitVec45[i2] & l2) != 0L);
      case 215:
        return ((jjbitVec46[i2] & l2) != 0L);
      case 250:
        return ((jjbitVec47[i2] & l2) != 0L);
      case 251:
        return ((jjbitVec48[i2] & l2) != 0L);
      case 253:
        return ((jjbitVec49[i2] & l2) != 0L);
      case 254:
        return ((jjbitVec50[i2] & l2) != 0L);
      case 255:
        return ((jjbitVec51[i2] & l2) != 0L);
      default:
        if ((jjbitVec0[i1] & l1) != 0L) return true;
        return false;
    }
  }

  private static final boolean jjCanMove_1(int hiByte, int i1, int i2, long l1, long l2) {
    switch (hiByte) {
      case 0:
        return ((jjbitVec52[i2] & l2) != 0L);
      default:
        if ((jjbitVec20[i1] & l1) != 0L) return true;
        return false;
    }
  }

  /** Token literal values. */
  public static final String[] jjstrLiteralImages = {
    "", null, null, null, null, null, null, null,
  };

  /** Lexer state names. */
  public static final String[] lexStateNames = {
    "DEFAULT",
  };

  protected SimpleCharStream input_stream;
  private final int[] jjrounds = new int[19];
  private final int[] jjstateSet = new int[38];
  protected char curChar;
  /** Constructor. */
  public SqlNormalizerTokenManager(SimpleCharStream stream) {
    if (SimpleCharStream.staticFlag)
      throw new Error(
          "ERROR: Cannot use a static CharStream class with a non-static lexical analyzer.");
    input_stream = stream;
  }

  /** Constructor. */
  public SqlNormalizerTokenManager(SimpleCharStream stream, int lexState) {
    this(stream);
    SwitchTo(lexState);
  }

  /** Reinitialise parser. */
  public void ReInit(SimpleCharStream stream) {
    jjmatchedPos = jjnewStateCnt = 0;
    curLexState = defaultLexState;
    input_stream = stream;
    ReInitRounds();
  }

  private void ReInitRounds() {
    int i;
    jjround = 0x80000001;
    for (i = 19; i-- > 0; ) jjrounds[i] = 0x80000000;
  }

  /** Reinitialise parser. */
  public void ReInit(SimpleCharStream stream, int lexState) {
    ReInit(stream);
    SwitchTo(lexState);
  }

  /** Switch to specified lex state. */
  public void SwitchTo(int lexState) {
    if (lexState >= 1 || lexState < 0)
      throw new TokenMgrError(
          "Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.",
          TokenMgrError.INVALID_LEXICAL_STATE);
    else curLexState = lexState;
  }

  protected Token jjFillToken() {
    final Token t;
    final String tokenImage;
    final int beginLine;
    final int endLine;
    final int beginColumn;
    final int endColumn;
    String im = jjstrLiteralImages[jjmatchedKind];
    tokenImage = (im == null) ? input_stream.GetImage() : im;
    beginLine = input_stream.getBeginLine();
    beginColumn = input_stream.getBeginColumn();
    endLine = input_stream.getEndLine();
    endColumn = input_stream.getEndColumn();
    t = Token.newToken(jjmatchedKind, tokenImage);

    t.beginLine = beginLine;
    t.endLine = endLine;
    t.beginColumn = beginColumn;
    t.endColumn = endColumn;

    return t;
  }

  int curLexState = 0;
  int defaultLexState = 0;
  int jjnewStateCnt;
  int jjround;
  int jjmatchedPos;
  int jjmatchedKind;

  /** Get the next Token. */
  public Token getNextToken() {
    // int kind;
    Token specialToken = null;
    Token matchedToken;
    int curPos = 0;

    EOFLoop:
    for (; ; ) {
      try {
        curChar = input_stream.BeginToken();
      } catch (java.io.IOException e) {
        jjmatchedKind = 0;
        matchedToken = jjFillToken();
        return matchedToken;
      }

      jjmatchedKind = 0x7fffffff;
      jjmatchedPos = 0;
      curPos = jjMoveStringLiteralDfa0_0();
      if (jjmatchedPos == 0 && jjmatchedKind > 7) {
        jjmatchedKind = 7;
      }
      if (jjmatchedKind != 0x7fffffff) {
        if (jjmatchedPos + 1 < curPos) input_stream.backup(curPos - jjmatchedPos - 1);
        matchedToken = jjFillToken();
        return matchedToken;
      }
      int error_line = input_stream.getEndLine();
      int error_column = input_stream.getEndColumn();
      String error_after = null;
      boolean EOFSeen = false;
      try {
        input_stream.readChar();
        input_stream.backup(1);
      } catch (java.io.IOException e1) {
        EOFSeen = true;
        error_after = curPos <= 1 ? "" : input_stream.GetImage();
        if (curChar == '\n' || curChar == '\r') {
          error_line++;
          error_column = 0;
        } else error_column++;
      }
      if (!EOFSeen) {
        input_stream.backup(1);
        error_after = curPos <= 1 ? "" : input_stream.GetImage();
      }
      throw new TokenMgrError(
          EOFSeen,
          curLexState,
          error_line,
          error_column,
          error_after,
          curChar,
          TokenMgrError.LEXICAL_ERROR);
    }
  }

  private void jjCheckNAdd(int state) {
    if (jjrounds[state] != jjround) {
      jjstateSet[jjnewStateCnt++] = state;
      jjrounds[state] = jjround;
    }
  }

  private void jjAddStates(int start, int end) {
    do {
      jjstateSet[jjnewStateCnt++] = jjnextStates[start];
    } while (start++ != end);
  }

  private void jjCheckNAddTwoStates(int state1, int state2) {
    jjCheckNAdd(state1);
    jjCheckNAdd(state2);
  }

  private void jjCheckNAddStates(int start, int end) {
    do {
      jjCheckNAdd(jjnextStates[start]);
    } while (start++ != end);
  }
}
