jsonlexer.java

来自「resetful样式的ws样例,一种面向资源的webservices服务」· Java 代码 · 共 721 行 · 第 1/2 页

JAVA
721
字号
  /**   * Closes the input stream.   */  public final void yyclose() throws java.io.IOException {    zzAtEOF = true;            /* indicate end of file */    zzEndRead = zzStartRead;  /* invalidate buffer    */    if (zzReader != null)      zzReader.close();  }  /**   * Resets the scanner to read from a new input stream.   * Does not close the old reader.   *   * All internal variables are reset, the old input stream    * <b>cannot</b> be reused (internal buffer is discarded and lost).   * Lexical state is set to <tt>ZZ_INITIAL</tt>.   *   * @param reader   the new input stream    */  public final void yyreset(java.io.Reader reader) {    zzReader = reader;    zzAtBOL  = true;    zzAtEOF  = false;    zzEndRead = zzStartRead = 0;    zzCurrentPos = zzMarkedPos = zzPushbackPos = 0;    yyline = yychar = yycolumn = 0;    zzLexicalState = YYINITIAL;  }  /**   * Returns the current lexical state.   */  public final int yystate() {    return zzLexicalState;  }  /**   * Enters a new lexical state   *   * @param newState the new lexical state   */  public final void yybegin(int newState) {    zzLexicalState = newState;  }  /**   * Returns the text matched by the current regular expression.   */  public final String yytext() {    return new String( zzBuffer, zzStartRead, zzMarkedPos-zzStartRead );  }  /**   * Returns the character at position <tt>pos</tt> from the    * matched text.    *    * It is equivalent to yytext().charAt(pos), but faster   *   * @param pos the position of the character to fetch.    *            A value from 0 to yylength()-1.   *   * @return the character at position pos   */  public final char yycharat(int pos) {    return zzBuffer[zzStartRead+pos];  }  /**   * Returns the length of the matched text region.   */  public final int yylength() {    return zzMarkedPos-zzStartRead;  }  /**   * Reports an error that occured while scanning.   *   * In a wellformed scanner (no or only correct usage of    * yypushback(int) and a match-all fallback rule) this method    * will only be called with things that "Can't Possibly Happen".   * If this method is called, something is seriously wrong   * (e.g. a JFlex bug producing a faulty scanner etc.).   *   * Usual syntax/scanner level error handling should be done   * in error fallback rules.   *   * @param   errorCode  the code of the errormessage to display   */  private void zzScanError(int errorCode) {    String message;    try {      message = ZZ_ERROR_MSG[errorCode];    }    catch (ArrayIndexOutOfBoundsException e) {      message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];    }    throw new Error(message);  }   /**   * Pushes the specified amount of characters back into the input stream.   *   * They will be read again by then next call of the scanning method   *   * @param number  the number of characters to be read again.   *                This number must not be greater than yylength()!   */  public void yypushback(int number)  {    if ( number > yylength() )      zzScanError(ZZ_PUSHBACK_2BIG);    zzMarkedPos -= number;  }  /**   * Resumes scanning until the next regular expression is matched,   * the end of input is encountered or an I/O-Error occurs.   *   * @return      the next token   * @exception   java.io.IOException  if any I/O-Error occurs   */  public JsonToken yylex() throws java.io.IOException {    int zzInput;    int zzAction;    // cached fields:    int zzCurrentPosL;    int zzMarkedPosL;    int zzEndReadL = zzEndRead;    char [] zzBufferL = zzBuffer;    char [] zzCMapL = ZZ_CMAP;    int [] zzTransL = ZZ_TRANS;    int [] zzRowMapL = ZZ_ROWMAP;    int [] zzAttrL = ZZ_ATTRIBUTE;    while (true) {      zzMarkedPosL = zzMarkedPos;      yychar+= zzMarkedPosL-zzStartRead;      boolean zzR = false;      for (zzCurrentPosL = zzStartRead; zzCurrentPosL < zzMarkedPosL;                                                             zzCurrentPosL++) {        switch (zzBufferL[zzCurrentPosL]) {        case '\u000B':        case '\u000C':        case '\u0085':        case '\u2028':        case '\u2029':          yyline++;          zzR = false;          break;        case '\r':          yyline++;          zzR = true;          break;        case '\n':          if (zzR)            zzR = false;          else {            yyline++;          }          break;        default:          zzR = false;        }      }      if (zzR) {        // peek one character ahead if it is \n (if we have counted one line too much)        boolean zzPeek;        if (zzMarkedPosL < zzEndReadL)          zzPeek = zzBufferL[zzMarkedPosL] == '\n';        else if (zzAtEOF)          zzPeek = false;        else {          boolean eof = zzRefill();          zzEndReadL = zzEndRead;          zzMarkedPosL = zzMarkedPos;          zzBufferL = zzBuffer;          if (eof)             zzPeek = false;          else             zzPeek = zzBufferL[zzMarkedPosL] == '\n';        }        if (zzPeek) yyline--;      }      zzAction = -1;      zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;        zzState = zzLexicalState;      zzForAction: {        while (true) {              if (zzCurrentPosL < zzEndReadL)            zzInput = zzBufferL[zzCurrentPosL++];          else if (zzAtEOF) {            zzInput = YYEOF;            break zzForAction;          }          else {            // store back cached positions            zzCurrentPos  = zzCurrentPosL;            zzMarkedPos   = zzMarkedPosL;            boolean eof = zzRefill();            // get translated positions and possibly new buffer            zzCurrentPosL  = zzCurrentPos;            zzMarkedPosL   = zzMarkedPos;            zzBufferL      = zzBuffer;            zzEndReadL     = zzEndRead;            if (eof) {              zzInput = YYEOF;              break zzForAction;            }            else {              zzInput = zzBufferL[zzCurrentPosL++];            }          }          int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ];          if (zzNext == -1) break zzForAction;          zzState = zzNext;          int zzAttributes = zzAttrL[zzState];          if ( (zzAttributes & 1) == 1 ) {            zzAction = zzState;            zzMarkedPosL = zzCurrentPosL;            if ( (zzAttributes & 8) == 8 ) break zzForAction;          }        }      }      // store back cached position      zzMarkedPos = zzMarkedPosL;      switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {        case 23:           { string.append(Character.toChars(Integer.parseInt(yytext().substring(2),16)));          }        case 24: break;        case 15:           { string.append('\n');          }        case 25: break;        case 6:           { return (new JsonToken(JsonToken.END_ARRAY, yytext(), yyline, yychar, yychar+1));          }        case 26: break;        case 7:           { return (new JsonToken(JsonToken.START_OBJECT, yytext(), yyline, yychar, yychar+1));          }        case 27: break;        case 3:           { return (new JsonToken(JsonToken.COMMA, yytext(), yyline, yychar, yychar+1));          }        case 28: break;        case 4:           { return (new JsonToken(JsonToken.COLON, yytext(), yyline, yychar, yychar+1));          }        case 29: break;        case 19:           { string.append('\b');          }        case 30: break;        case 8:           { return (new JsonToken(JsonToken.END_OBJECT, yytext(), yyline, yychar, yychar+1));          }        case 31: break;        case 21:           { return (new JsonToken(JsonToken.NULL, yytext(), yyline, yychar, yychar+yylength()));          }        case 32: break;        case 18:           { string.append('/');          }        case 33: break;        case 17:           { string.append('\\');          }        case 34: break;        case 22:           { return (new JsonToken(JsonToken.FALSE, yytext(), yyline, yychar, yychar+yylength()));          }        case 35: break;        case 9:           { string.setLength(0); yybegin(STRING);          }        case 36: break;        case 11:           { yybegin(YYINITIAL);        return (new JsonToken(JsonToken.STRING, string.toString(), yyline, yychar, yychar+string.length()));          }        case 37: break;        case 2:           { return (new JsonToken(JsonToken.NUMBER, yytext(), yyline, yychar, yychar+yylength()));          }        case 38: break;        case 20:           { return (new JsonToken(JsonToken.TRUE, yytext(), yyline, yychar, yychar+yylength()));          }        case 39: break;        case 13:           { string.append('\r');          }        case 40: break;        case 10:           { string.append(yytext());          }        case 41: break;        case 16:           { string.append('\"');          }        case 42: break;        case 14:           { string.append('\f');          }        case 43: break;        case 5:           { return (new JsonToken(JsonToken.START_ARRAY, yytext(), yyline, yychar, yychar+1));          }        case 44: break;        case 12:           { string.append('\t');          }        case 45: break;        case 1:           {           }        case 46: break;        default:           if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {            zzAtEOF = true;            return null;          }           else {            zzScanError(ZZ_NO_MATCH);          }      }    }  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?