htmlparsertokenmanager.java

来自「HTML解释器JAVA源码」· Java 代码 · 共 2,122 行 · 第 1/4 页

JAVA
2,122
字号
         MatchLoop: do         {            switch(jjstateSet[--i])            {               case 1:               case 3:                  if (kind > 43)                     kind = 43;                  jjCheckNAdd(3);                  break;               case 5:                  jjAddStates(9, 10);                  break;               case 8:                  jjAddStates(11, 12);                  break;               default : break;            }         } while(i != startsAt);      }      else      {         int i2 = (curChar & 0xff) >> 6;         long l2 = 1L << (curChar & 077);         MatchLoop: do         {            switch(jjstateSet[--i])            {               case 1:               case 3:                  if ((jjbitVec0[i2] & l2) == 0L)                     break;                  if (kind > 43)                     kind = 43;                  jjCheckNAdd(3);                  break;               case 5:                  if ((jjbitVec0[i2] & l2) != 0L)                     jjAddStates(9, 10);                  break;               case 8:                  if ((jjbitVec0[i2] & l2) != 0L)                     jjAddStates(11, 12);                  break;               default : break;            }         } while(i != startsAt);      }      if (kind != 0x7fffffff)      {         jjmatchedKind = kind;         jjmatchedPos = curPos;         kind = 0x7fffffff;      }      ++curPos;      if ((i = jjnewStateCnt) == (startsAt = 11 - (jjnewStateCnt = startsAt)))         return curPos;      try { curChar = input_stream.readChar(); }      catch(java.io.IOException e) { return curPos; }   }}private final int jjStopStringLiteralDfa_3(int pos, long active0){   switch (pos)   {      default :         return -1;   }}private final int jjStartNfa_3(int pos, long active0){   return jjMoveNfa_3(jjStopStringLiteralDfa_3(pos, active0), pos + 1);}private final int jjStartNfaWithStates_3(int pos, int kind, int state){   jjmatchedKind = kind;   jjmatchedPos = pos;   try { curChar = input_stream.readChar(); }   catch(java.io.IOException e) { return pos + 1; }   return jjMoveNfa_3(state, pos + 1);}private final int jjMoveStringLiteralDfa0_3(){   switch(curChar)   {      case 45:         return jjStartNfaWithStates_3(0, 34, 12);      default :         return jjMoveNfa_3(1, 0);   }}private final int jjMoveNfa_3(int startState, int curPos){   int[] nextStates;   int startsAt = 0;   jjnewStateCnt = 16;   int i = 1;   jjstateSet[0] = startState;   int j, kind = 0x7fffffff;   for (;;)   {      if (++jjround == 0x7fffffff)         ReInitRounds();      if (curChar < 64)      {         long l = 1L << curChar;         MatchLoop: do         {            switch(jjstateSet[--i])            {               case 12:                  if (curChar == 62)                  {                     if (kind > 33)                        kind = 33;                  }                  else if (curChar == 45)                     jjCheckNAddTwoStates(13, 14);                  break;               case 1:                  if ((0xffffdf7bffffdbffL & l) != 0L)                  {                     if (kind > 36)                        kind = 36;                     jjCheckNAdd(3);                  }                  else if ((0x8400000000L & l) != 0L)                  {                     if (kind > 36)                        kind = 36;                  }                  else if ((0x2400L & l) != 0L)                  {                     if (kind > 35)                        kind = 35;                  }                  else if (curChar == 45)                     jjAddStates(18, 19);                  if (curChar == 39)                     jjCheckNAddTwoStates(8, 9);                  else if (curChar == 34)                     jjCheckNAddTwoStates(5, 6);                  else if (curChar == 13)                     jjstateSet[jjnewStateCnt++] = 0;                  break;               case 0:                  if (curChar == 10 && kind > 35)                     kind = 35;                  break;               case 2:                  if ((0x2400L & l) != 0L && kind > 35)                     kind = 35;                  break;               case 3:                  if ((0xffffdf7bffffdbffL & l) == 0L)                     break;                  if (kind > 36)                     kind = 36;                  jjCheckNAdd(3);                  break;               case 4:                  if (curChar == 34)                     jjCheckNAddTwoStates(5, 6);                  break;               case 5:                  if ((0xfffffffbffffdbffL & l) != 0L)                     jjCheckNAddTwoStates(5, 6);                  break;               case 6:                  if (curChar == 34 && kind > 36)                     kind = 36;                  break;               case 7:                  if (curChar == 39)                     jjCheckNAddTwoStates(8, 9);                  break;               case 8:                  if ((0xffffff7fffffdbffL & l) != 0L)                     jjCheckNAddTwoStates(8, 9);                  break;               case 9:                  if (curChar == 39 && kind > 36)                     kind = 36;                  break;               case 10:                  if ((0x8400000000L & l) != 0L && kind > 36)                     kind = 36;                  break;               case 11:                  if (curChar == 45)                     jjAddStates(18, 19);                  break;               case 13:                  if (curChar == 32)                     jjCheckNAddTwoStates(13, 14);                  break;               case 14:                  if (curChar == 62 && kind > 33)                     kind = 33;                  break;               case 15:                  if (curChar == 62 && kind > 33)                     kind = 33;                  break;               default : break;            }         } while(i != startsAt);      }      else if (curChar < 128)      {         long l = 1L << (curChar & 077);         MatchLoop: do         {            switch(jjstateSet[--i])            {               case 1:               case 3:                  if (kind > 36)                     kind = 36;                  jjCheckNAdd(3);                  break;               case 5:                  jjAddStates(9, 10);                  break;               case 8:                  jjAddStates(11, 12);                  break;               default : break;            }         } while(i != startsAt);      }      else      {         int i2 = (curChar & 0xff) >> 6;         long l2 = 1L << (curChar & 077);         MatchLoop: do         {            switch(jjstateSet[--i])            {               case 1:               case 3:                  if ((jjbitVec0[i2] & l2) == 0L)                     break;                  if (kind > 36)                     kind = 36;                  jjCheckNAdd(3);                  break;               case 5:                  if ((jjbitVec0[i2] & l2) != 0L)                     jjAddStates(9, 10);                  break;               case 8:                  if ((jjbitVec0[i2] & l2) != 0L)                     jjAddStates(11, 12);                  break;               default : break;            }         } while(i != startsAt);      }      if (kind != 0x7fffffff)      {         jjmatchedKind = kind;         jjmatchedPos = curPos;         kind = 0x7fffffff;      }      ++curPos;      if ((i = jjnewStateCnt) == (startsAt = 16 - (jjnewStateCnt = startsAt)))         return curPos;      try { curChar = input_stream.readChar(); }      catch(java.io.IOException e) { return curPos; }   }}static final int[] jjnextStates = {   0, 2, 3, 6, 7, 9, 10, 3, 4, 5, 6, 8, 9, 0, 1, 4,    2, 3, 12, 15, };public static final String[] jjstrLiteralImages = {"", null, null, null, null, null, null, null, null, null, null, null, "\74", "\74\57", "\74\41\55\55", "\74\41", null, null, null, null, null, null, null, null, null, "\76", "\57\76", "\75", "\74", null, null, null, null, null, "\55", null, null, null, "\76", null, null, null, "\74", null, };public static final String[] lexStateNames = {   "LexStyle",    "LexScript",    "LexDecl",    "LexComment",    "LexAttrVal",    "LexInTag",    "LexStartTag",    "DEFAULT", };public static final int[] jjnewLexState = {   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 6, 6, 3, 2, -1, -1, -1, 5, 5, 5, 7, -1, -1,    7, 7, 4, 6, -1, -1, 5, -1, 7, -1, -1, -1, -1, 7, 7, 7, -1, -1, -1, };static final long[] jjtoToken = {   0xfffbf7ff801L, };static final long[] jjtoSkip = {   0x40800000L, };static final long[] jjtoSpecial = {   0x40800000L, };private ASCII_CharStream input_stream;private final int[] jjrounds = new int[16];private final int[] jjstateSet = new int[32];StringBuffer image;int jjimageLen;int lengthOfMatch;protected char curChar;public HtmlParserTokenManager(ASCII_CharStream stream){   if (ASCII_CharStream.staticFlag)      throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer.");   input_stream = stream;}public HtmlParserTokenManager(ASCII_CharStream stream, int lexState){   this(stream);   SwitchTo(lexState);}public void ReInit(ASCII_CharStream stream){   jjmatchedPos = jjnewStateCnt = 0;   curLexState = defaultLexState;   input_stream = stream;   ReInitRounds();}private final void ReInitRounds(){   int i;   jjround = 0x80000001;   for (i = 16; i-- > 0;)      jjrounds[i] = 0x80000000;}public void ReInit(ASCII_CharStream stream, int lexState){   ReInit(stream);   SwitchTo(lexState);}public void SwitchTo(int lexState){   if (lexState >= 8 || lexState < 0)      throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE);   else      curLexState = lexState;}private final Token jjFillToken(){   Token t = Token.newToken(jjmatchedKind);   t.kind = jjmatchedKind;   String im = jjstrLiteralImages[jjmatchedKind];   t.image = (im == null) ? input_stream.GetImage() : im;   t.beginLine = input_stream.getBeginLine();   t.beginColumn = input_stream.getBeginColumn();   t.endLine = input_stream.getEndLine();   t.endColumn = input_stream.getEndColumn();   return t;}int curLexState = 7;int defaultLexState = 7;int jjnewStateCnt;int jjround;int jjmatchedPos;int jjmatchedKind;public final 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();      matchedToken.specialToken = specialToken;      return matchedToken;   }   image = null;   jjimageLen = 0;   switch(curLexState)   {     case 0:       jjmatchedKind = 0x7fffffff;       jjmatchedPos = 0;       curPos = jjMoveStringLiteralDfa0_0();       break;     case 1:       jjmatchedKind = 0x7fffffff;       jjmatchedPos = 0;       curPos = jjMoveStringLiteralDfa0_1();       break;     case 2:       jjmatchedKind = 0x7fffffff;       jjmatchedPos = 0;       curPos = jjMoveStringLiteralDfa0_2();       break;     case 3:       jjmatchedKind = 0x7fffffff;       jjmatchedPos = 0;       curPos = jjMoveStringLiteralDfa0_3();       break;     case 4:       jjmatchedKind = 0x7fffffff;       jjmatchedPos = 0;       curPos = jjMoveStringLiteralDfa0_4();       if (jjmatchedPos == 0 && jjmatchedKind > 32)       {          jjmatchedKind = 32;       }       break;     case 5:       jjmatchedKind = 0x7fffffff;       jjmatchedPos = 0;       curPos = jjMoveStringLiteralDfa0_5();       if (jjmatchedPos == 0 && jjmatchedKind > 29)       {          jjmatchedKind = 29;       }       break;     case 6:       jjmatchedKind = 0x7fffffff;       jjmatchedPos = 0;       curPos = jjMoveStringLiteralDfa0_6();       if (jjmatchedPos == 0 && jjmatchedKind > 22)       {          jjmatchedKind = 22;       }       break;     case 7:       jjmatchedKind = 0x7fffffff;       jjmatchedPos = 0;       curPos = jjMoveStringLiteralDfa0_7();       break;   }     if (jjmatchedKind != 0x7fffffff)     {        if (jjmatchedPos + 1 < curPos)           input_stream.backup(curPos - jjmatchedPos - 1);        if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L)        {           matchedToken = jjFillToken();           matchedToken.specialToken = specialToken;           TokenLexicalActions(matchedToken);       if (jjnewLexState[jjmatchedKind] != -1)         curLexState = jjnewLexState[jjmatchedKind];           return matchedToken;        }        else        {           if ((jjtoSpecial[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L)           {              matchedToken = jjFillToken();              if (specialToken == null)                 specialToken = matchedToken;              else              {                 matchedToken.specialToken = specialToken;                 specialToken = (specialToken.next = matchedToken);              }           }         if (jjnewLexState[jjmatchedKind] != -1)           curLexState = jjnewLexState[jjmatchedKind];           continue EOFLoop;        }     }     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);  }}final void TokenLexicalActions(Token matchedToken){   switch(jjmatchedKind)   {      case 28 :        if (image == null)            image = new StringBuffer(jjstrLiteralImages[28]);         else            image.append(jjstrLiteralImages[28]);    Token t = new Token();    t.image       = "<";    t.kind        = TAG_START;    t.next        = matchedToken.next;    t.beginLine   = matchedToken.beginLine;    t.beginColumn = matchedToken.beginColumn;    t.endLine     = matchedToken.endLine;    t.endColumn   = matchedToken.endColumn;    matchedToken.next  = t;    matchedToken.kind  = TAG_END;    matchedToken.image = ">";         break;      default :          break;   }}}

⌨️ 快捷键说明

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