⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xqparser.java

📁 A framework written in Java for implementing high-level and dynamic languages, compiling them into J
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
  static final int ELEMENT_TOKEN = 251; // 'element' followed by '{' or alpha  static final int ATTRIBUTE_TOKEN = 252;// 'attribute' followed by '{' or alpha  static final int TEXT_TOKEN = 253; // 'text' followed by '{'  static final int COMMENT_TOKEN = 254; // 'text' followed by '{'  static final int PI_TOKEN = 255; // 'processing-instruction' followed by '{' or alpha  static final int DOCUMENT_TOKEN = 256; // ;document' followed by '{'    private int saveToken;  private Object saveValue;  public void mark ()    throws java.io.IOException  {    super.mark();    saveToken = curToken;    saveValue = curValue;  }  public void reset()    throws java.io.IOException  {    curToken = saveToken;    curValue = saveValue;    super.reset();  }  private int setToken (int token, int width)  {    curToken = token;    curLine = port.getLineNumber() + 1;    curColumn = port.getColumnNumber() + 1 - width;    return token;  }  void checkSeparator (char ch)  {    if (XName.isNameStart(ch))      error('e', "missing separator", "XPST0003");  }  int getRawToken()      throws java.io.IOException, SyntaxException  {    int next;    for (;;)      {	next = read();	if (next < 0)	  return setToken(EOF_TOKEN, 0);	if (next == '\n' || next == '\r')	  {	    if (nesting <= 0)	      return setToken(EOL_TOKEN, 0);	  }	else if (next == '(')	  {	    if (checkNext(':'))	      skipComment();            else if (checkNext('#'))              return setToken(PRAGMA_START_TOKEN, 2);	    else	      return setToken('(', 1);	  }	else if (next == '{')	  {	    if (! checkNext('-'))	      return setToken('{', 1);	    next = read();	    if (next != '-')	      {		// FIXME backup 2 chars. Can fix using special token for '{-'.		unread();		unread();		return setToken('{', 1);	      }	    skipOldComment();	  }	else if (next != ' ' && next != '\t')	  break;      }    tokenBufferLength = 0;    curLine = port.getLineNumber() + 1;    curColumn = port.getColumnNumber();    char ch = (char) next;    switch (ch)      {      case ')':  case '[':  case ']':  case '}':      case '$':  case '@':  case ',':  case '?':  case ';':	break;      case ':':	if (checkNext('='))	  ch = COLON_EQUAL_TOKEN;	else if (checkNext(':'))	  ch = COLON_COLON_TOKEN;	break;      case '|':	ch = OP_UNION;	break;      case '*':	ch = OP_MUL;	break;      case '+':	ch = OP_ADD;	break;      case '-':	ch = OP_SUB;	break;      case '!':	if (checkNext('='))	  ch = OP_NEQ;	break;      case '/':	if (checkNext('/'))	  ch = SLASHSLASH_TOKEN;	break;      case '=':	if (checkNext('>'))	  ch = ARROW_TOKEN;	ch = OP_EQU;	break;      case '>':	ch = checkNext('=') ? (char) OP_GEQ	  : checkNext('>') ? (char) OP_GRTGRT : (char) OP_GRT;	break;      case '<':	ch = checkNext('=') ? (char) OP_LEQ	  : checkNext('<') ? (char) OP_LSSLSS : (char) OP_LSS;	break;      case '\'':  case '\"':	char saveReadState = pushNesting ((char) next);	for (;;)	  {	    next = read();	    if (next < 0)	      eofError("unexpected end-of-file in string starting here");	    if (next == '&')	      {		parseEntityOrCharRef();		continue;	      }	    else if (ch == next)	      {		next = read ();		if (ch != next)		  {		    unread(next);		    break;		  }	      }	    tokenBufferAppend((char) next);	  }	popNesting(saveReadState);	ch = STRING_TOKEN;	break;      default:	if (Character.isDigit(ch)            || (ch == '.' && Character.isDigit((char) peek())))	  {	    boolean seenDot = ch == '.';	    for (;; )	      {		tokenBufferAppend(ch);		next = read();		if (next < 0)		  break;		ch = (char) next;		if (ch == '.')		  {		    if (seenDot)  break;		    seenDot = true;		  }		else if (! Character.isDigit(ch))		  break;	      }	    if (next == 'e' || next == 'E')	      {		tokenBufferAppend((char) next);		next = read();		if (next == '+' || next == '-')		  {		    tokenBufferAppend((char) next);		    next = read();		  }		int expDigits = 0;		for (;;)		  {		    if (next < 0)		      break;		    ch = (char) next;		    if (! Character.isDigit(ch))		      {                        checkSeparator(ch);			unread();			break;		      }		    tokenBufferAppend(ch);		    next = read();		    expDigits++;		  }		if (expDigits == 0)		  error('e', "no digits following exponent", "XPST0003");		ch = DOUBLE_TOKEN;	      }	    else	      {		ch = seenDot ? DECIMAL_TOKEN : INTEGER_TOKEN;		if (next >= 0)                  {                    checkSeparator((char) next);                    unread(next);                  }	      }	  }        else if (ch == '.')          {            if (checkNext('.'))              ch = DOTDOT_TOKEN;	    break;          }	else if (XName.isNameStart(ch))	  {	    for (;;)	      {		tokenBufferAppend(ch);		next = read();		ch = (char) next;		if (! XName.isNamePart(ch))		  break;	      }	    if (next < 0)	      ch = NCNAME_TOKEN;	    else	      {		if (next != ':')		    ch = NCNAME_TOKEN;		else		  {		    next = read();		    if (next < 0)		      eofError("unexpected end-of-file after NAME ':'");		    ch = (char) next;		    if (XName.isNameStart(ch))		      {			tokenBufferAppend(':');			for (;;)			  {			    tokenBufferAppend(ch);			    next = read();			    ch = (char) next;			    if (! XName.isNamePart(ch))			      break;			  }			ch = QNAME_TOKEN;		      }		    else if (ch == '=')		      {			unread(ch);			ch = NCNAME_TOKEN;		      }		    else		      ch = NCNAME_COLON_TOKEN;		  }		unread(next);	      }	  }	else if (ch >= ' ' && ch < 127)	  syntaxError("invalid character '"+ch+'\'');	else	  syntaxError("invalid character '\\u"+Integer.toHexString(ch)+'\'');      }    curToken = ch;    return ch;  }  /** Scan until a given delimiter.   * On success, text upto the delimiter is in then tokenBuffer (with   * tokenBufferLength marking its length); the delimiter is not included.   */  public void getDelimited(String delimiter)      throws java.io.IOException, SyntaxException  {    tokenBufferLength = 0;    int dlen = delimiter.length();    char last = delimiter.charAt(dlen-1);    for (;;)      {	int ch = read();	if (ch < 0)	  eofError("unexpected end-of-file looking for '"+delimiter+'\'');	int dstart, j;	// Look for a match for the last delimiter character.	if (ch == last	    && (dstart = tokenBufferLength - (j = dlen - 1)) >= 0)	  {	    // Check that the initial part of the delimiter has also been seen.	    do	      {		if (j == 0)		  {		    tokenBufferLength = dstart;		    return;		  }		j--;	      }	    while (tokenBuffer[dstart+j] == delimiter.charAt(j));	  }	tokenBufferAppend((char) ch);      }  }  public void appendNamedEntity(String name)  {    name = name.intern();    char ch = '?';    if (name == "lt")      ch = '<';    else if (name == "gt")      ch = '>';    else if (name == "amp")      ch = '&';    else if (name == "quot")      ch = '"';    else if (name == "apos")      ch = '\'';    else      error("unknown enity reference: '"+name+"'");    tokenBufferAppend(ch);  }  boolean match (String word1, String word2, boolean force)      throws java.io.IOException, SyntaxException  {    if (match(word1))      {        mark();        getRawToken();        if (match(word2))          {            reset();            getRawToken();            return true;          }        reset();        if (force)          {            error('e', "'"+word1+"' must be followed by '"+word2+"'",                  "XPST0003");            return true;          }      }    return false;  }  /** Return the current token, assuming it is in operator context.   * Resolve NCNAME_TOKEN (identifier) to 'and', 'or', 'div', etc.   */  int peekOperator()      throws java.io.IOException, SyntaxException  {    while (curToken == EOL_TOKEN)      {	if (nesting == 0)	  return EOL_TOKEN;	getRawToken();      }    if (curToken == NCNAME_TOKEN)      {	int len = tokenBufferLength;        char c1, c2, c3;        switch (len)          {          case 2:            c1 = tokenBuffer[0];            c2 = tokenBuffer[1];            if (c1 == 'o' && c2 == 'r')              curToken = OP_OR;            else if (c1 == 't' && c2 == 'o')              curToken = OP_RANGE_TO;            else if (c1 == 'i' && c2 == 's')              curToken = OP_IS;            else if (c1 == 'e' && c2 == 'q')              curToken = OP_EQ;            else if (c1 == 'n' && c2 == 'e')              curToken = OP_NE;            else if (c1 == 'g')              {                if (c2 == 'e')  curToken = OP_GE;                else if (c2 == 't')  curToken = OP_GT;              }            else if (c1 == 'l')              {                if (c2 == 'e')  curToken = OP_LE;                else if (c2 == 't')  curToken = OP_LT;              }            break;          case 3:            c1 = tokenBuffer[0];            c2 = tokenBuffer[1];            c3 = tokenBuffer[2];            if (c1 == 'a')              {                if (c2 == 'n' && c3 == 'd')                  curToken = OP_AND;              }            else if (c1 == 'm') {              if (c2 == 'u' && c3 == 'l')                curToken = OP_MUL;              if (c2 == 'o' && c3 == 'd')                curToken = OP_MOD;            }            else if (c1 == 'd') {              if (c2 == 'i' && c3 == 'v')                curToken = OP_DIV;            }            break;          case 4:            if (match("idiv"))              curToken = OP_IDIV;            else if (match("cast", "as", true))              curToken = OP_CAST_AS;            break;          case 5:            if (match("where"))              curToken = OP_WHERE;            else if (match("isnot"))              curToken = OP_ISNOT;            else if (match("union"))              curToken = OP_UNION;            else if (match("treat", "as", true))              curToken = OP_TREAT_AS;            break;          case 6:            if (match("except"))              curToken = OP_EXCEPT;            break;          case 8:            if (match("instance", "of", true))              curToken = OP_INSTANCEOF;            else if (match("castable", "as", true))              curToken = OP_CASTABLE_AS;            break;          case 9:            if (match("intersect"))              curToken = OP_INTERSECT;            break;          case 10:            if (match("instanceof")) // obsolete              {                warnOldVersion("use 'instanceof of' (two words) instead of 'instanceof'");                curToken = OP_INSTANCEOF;              }            break;          default:            break;          }      }    return curToken;

⌨️ 快捷键说明

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