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

📄 xqparser.java

📁 A framework written in Java for implementing high-level and dynamic languages, compiling them into J
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
  }  /**   * Internal method to match against double-lexeme tokens.   * @param word0 expected previous word   * @param word1 expected next word   */  private boolean lookingAt (String word0, String word1)      throws java.io.IOException, SyntaxException  {    if (! word0.equals(curValue))      return false;    int i = 0;    int len = word1.length();    for (;; )      {	int ch = read();	if (i == len)	  {	    if (ch < 0)	      return true;	    if ( ! XName.isNamePart((char) ch))	      {		unread();		return true;	      }	    i++;	    break;	  }	if (ch < 0 || ch != word1.charAt(i++))	  break;      }    port.skip(-i);    return false;  }  int getAxis ()  {    // match axis name    String name = new String(tokenBuffer, 0, tokenBufferLength).intern();    int i;    for (i = COUNT_OP_AXIS;  --i >= 0; )      if (axisNames[i] == name)	break;    if (i < 0        || i == AXIS_NAMESPACE) // The namespace-axis is XSLT/XPath-only.      {	error('e', "unknown axis name '" + name + '\'', "XPST0003");	i = AXIS_CHILD;      }    return (char) (OP_AXIS_FIRST + i);  }  /** Process token, assuming we are in operand context.   */  int peekOperand()      throws java.io.IOException, SyntaxException  {    while (curToken == EOL_TOKEN)      getRawToken();    if (curToken == NCNAME_TOKEN || curToken == QNAME_TOKEN)      {	int next = skipSpace(nesting != 0);        switch (tokenBuffer[0])          {          case 'a':            if (match("attribute"))              {                if (next == '(')                  return curToken = OP_ATTRIBUTE;                if (next == '{' || XName.isNameStart((char) next))                  {                    unread();                    return curToken = ATTRIBUTE_TOKEN;                  }                break;              }            break;          case 'c':            if (match("comment"))              {                if (next == '(')                  return curToken = OP_COMMENT;                if (next == '{')                  {                    unread();                    return curToken = COMMENT_TOKEN;                  }              }            break;          case 'd':            if (next == '{' && match("document"))              {                unread();                return curToken = DOCUMENT_TOKEN;              }            if (next == '(' && match("document-node"))              return curToken = OP_DOCUMENT;            break;          case 'e':            if (match("element"))              {                if (next == '(')                  return curToken = OP_ELEMENT;                if (next == '{' || XName.isNameStart((char) next))                  {                    unread();                    return curToken = ELEMENT_TOKEN;                  }                break;              }            if (match("empty-sequence"))              return curToken = OP_EMPTY_SEQUENCE;            if (next == '$' && match("every"))              return curToken = EVERY_DOLLAR_TOKEN;            break;          case 'f':            if (next == '$' && match("for"))              return curToken = FOR_DOLLAR_TOKEN;            break;          case 'i':            if (next == '(' && match("if"))              return curToken = IF_LPAREN_TOKEN;            if (next == '(' && match("item"))              return curToken = OP_ITEM;            break;          case 'l':            if (next == '$' && match("let"))              return curToken = LET_DOLLAR_TOKEN;            break;          case 'n':            if (next == '(' && match("node"))              return curToken = OP_NODE;            break;          case 'o':            if (next == '{' && match("ordered"))              return curToken = ORDERED_LBRACE_TOKEN;            break;           case 'p':            if (match("processing-instruction"))              {                if (next == '(')                  return curToken = OP_PI;                if (next == '{' || XName.isNameStart((char) next))                  {                    unread();                    return curToken = PI_TOKEN;                  }                break;              }            break;          case 's':            if (next == '$' && match("some"))              return curToken = SOME_DOLLAR_TOKEN;            if (next == '(' && match("schema-attribute"))              return curToken = OP_SCHEMA_ATTRIBUTE;            if (next == '(' && match("schema-element"))              return curToken = OP_SCHEMA_ELEMENT;            break;          case 't':            if (match("text"))              {                if (next == '(')                  return curToken = OP_TEXT;                if (next == '{')                  {                    unread();                    return curToken = TEXT_TOKEN;                  }              }            if (next == '(' && match("typeswitch"))              return curToken = TYPESWITCH_LPAREN_TOKEN;            break;          case 'u':            if (next == '{' && match("unordered"))              return curToken = UNORDERED_LBRACE_TOKEN;            break;           case 'v':            if (next == '{' && match("validate"))              return curToken = VALIDATE_LBRACE_TOKEN;            break;          }	if (next == '(' && peek() != ':')	  {	    return curToken = FNAME_TOKEN;	  }	if (next == ':' && peek() == ':')	  return curToken = getAxis();	String name = new String(tokenBuffer, 0, tokenBufferLength);	curValue = name;	switch (next)	  {          case 'b':	    if (lookingAt("declare", /*"b"+*/ "ase-uri"))              return curToken = DECLARE_BASE_URI_TOKEN;	    if (lookingAt("declare", /*"b"+*/ "oundary-space"))              return curToken = DECLARE_BOUNDARY_SPACE_TOKEN;            break;          case 'c':	    if (lookingAt("declare", /*"c"+*/ "onstruction"))              return curToken = DECLARE_CONSTRUCTION_TOKEN;	    if (lookingAt("declare", /*"c"+*/ "opy-namespaces"))              return curToken = DECLARE_COPY_NAMESPACES_TOKEN;            break;	  case 'd':	    if (lookingAt("declare", /*"d"+*/ "efault"))	      {		getRawToken();		if (match("function"))		  return curToken = DEFAULT_FUNCTION_TOKEN;		if (match("element"))		  return curToken = DEFAULT_ELEMENT_TOKEN;		if (match("collation"))		  return curToken = DEFAULT_COLLATION_TOKEN;		if (match("order"))		  return curToken = DEFAULT_ORDER_TOKEN;		error("unrecognized/unimplemented 'declare default'");		skipToSemicolon();		return peekOperand();	      }	  case 'e':	    if (lookingAt("default", /*"e"+*/ "lement"))	      {		warnOldVersion("replace 'default element' by 'declare default element namespace'");		return curToken = DEFAULT_ELEMENT_TOKEN;	      }	    break;	  case 'f':	    if (lookingAt("declare", /*"f"+*/ "unction"))	      return curToken = DECLARE_FUNCTION_TOKEN;	    if (lookingAt("define", /*"f"+*/ "unction"))	      {                warnOldVersion("replace 'define function' by 'declare function'");		return curToken = DECLARE_FUNCTION_TOKEN;	      }	    if (lookingAt("default", /*"f"+*/ "unction"))	      {		warnOldVersion("replace 'default function' by 'declare default function namespace'");		return curToken = DEFAULT_FUNCTION_TOKEN;	      }	    break;	  case 'm':	    if (lookingAt("import", /*"m"+*/ "odule"))	      return curToken = IMPORT_MODULE_TOKEN;	    break;	  case 'n':	    if (lookingAt("declare", /*"n"+*/ "amespace"))	      return curToken = DECLARE_NAMESPACE_TOKEN;	    if (lookingAt("default", /*"n"+*/ "amespace"))	      {		warnOldVersion("replace 'default namespace' by 'declare default element namespace'");		return curToken = DEFAULT_ELEMENT_TOKEN;	      }	    if (lookingAt("module", /*"n"+*/ "amespace"))	      return curToken = MODULE_NAMESPACE_TOKEN;	    break;	  case 'o':	    if (lookingAt("declare", /*"o"+*/ "rdering"))	      return curToken = DECLARE_ORDERING_TOKEN;	    if (lookingAt("declare", /*"o"+*/ "ption"))	      return curToken = DECLARE_OPTION_TOKEN;	    break;	  case 's':	    if (lookingAt("import", /*"s"+*/ "chema"))	      return curToken = IMPORT_SCHEMA_TOKEN;	    break;	  case 'v':	    if (lookingAt("declare", /*"v"+*/ "ariable"))	      return curToken = DECLARE_VARIABLE_TOKEN;	    if (lookingAt("define", /*"v"+*/ "ariable"))	      {                warnOldVersion("replace 'define variable' by 'declare variable'");		return curToken = DECLARE_VARIABLE_TOKEN;	      }            if (lookingAt("xquery", /*"v"+*/ "ersion"))              return curToken = XQUERY_VERSION_TOKEN;	    break;	  case 'x':	    if (lookingAt("declare", /*"x"+*/ "mlspace"))              {		warnOldVersion("replace 'define xmlspace' by 'declare boundary-space'");                return curToken = DECLARE_BOUNDARY_SPACE_TOKEN;              }	    break;	  }	if (next >= 0)	  {	    unread();	    if (XName.isNameStart((char) next) && curValue.equals("define"))	      {		getRawToken();		curToken = DEFINE_QNAME_TOKEN;	      }	  }	return curToken;      }    if (curToken == NCNAME_COLON_TOKEN)      {	int next = read();	if (next == ':') // We've seen an Axis specifier.	  curToken = getAxis();	else	  unread(next);      }    return curToken;  }  void checkAllowedNamespaceDeclaration (String prefix, String uri,                                         boolean inConstructor)  {    boolean xmlPrefix = "xml".equals(prefix);    if (NamespaceBinding.XML_NAMESPACE.equals(uri))      {        if (! xmlPrefix || ! inConstructor)          error('e', "namespace uri cannot be the same as the prefined xml namespace",                "XQST0070");      }    else if (xmlPrefix || "xmlns".equals(prefix))      error('e', "namespace prefix cannot be 'xml' or 'xmlns'",            "XQST0070");  }  void pushNamespace(String prefix, String uri)  {    if (uri.length() == 0)      uri = null;    prologNamespaces = new NamespaceBinding(prefix, uri, prologNamespaces);  }  public XQParser(InPort port, SourceMessages messages, XQuery interp)  {    super(port, messages);    interpreter = interp;    lexical = new NameLookup(interp);    nesting = 1;    // Push standard namespaces into lexical scope.    NamespaceBinding ns = builtinNamespaces;    prologNamespaces = ns;  }  public void setInteractive(boolean v)  {    if (interactive != v)      if (v) nesting--; else nesting++;    interactive = v;  }    private static final int priority(int opcode)  {    switch (opcode)      {      case OP_OR:	return 1;      case OP_AND:        return 2;      case OP_EQU:  case OP_NEQ:      case OP_LSS:  case OP_GRT:  case OP_LEQ:  case OP_GEQ:      case OP_EQ:  case OP_NE:      case OP_LT:  case OP_GT:  case OP_LE:  case OP_GE:      case OP_IS:  case OP_ISNOT:      case OP_GRTGRT:  case OP_LSSLSS:        return 3;      case OP_RANGE_TO:        return 4;      case OP_ADD:  case OP_SUB:	return 5;      case OP_MUL: case OP_DIV:  case OP_IDIV: case OP_MOD:        return 6;      case OP_UNION:        return 7;      case OP_INTERSECT:  case OP_EXCEPT:        return 8;      case OP_INSTANCEOF:	return 9;      case OP_TREAT_AS:        return 10;      case OP_CASTABLE_AS:        return 11;      case OP_CAST_AS:        return 12;      default:	return 0;      }  }  static Expression makeBinary(Expression func,			       Expression exp1, Expression exp2)  {    Expression[] args = new Expression[2];    args[0] = exp1;    args[1] = exp2;    return new ApplyExp(func, args);  }  static Expression makeExprSequence(Expression exp1, Expression exp2)  {    return makeBinary(makeFunctionExp		      ("gnu.kawa.functions.AppendValues", "appendValues"),		      exp1, exp2);  }  Expression makeBinary(int op, Expression exp1, Expression exp2)      throws java.io.IOException, SyntaxException  {    Expression func;    switch (op)      {      case OP_ADD: 	func = makeFunctionExp("gnu.xquery.util.ArithOp", "add", "+");	break;      case OP_SUB:	func = makeFunctionExp("gnu.xquery.util.ArithOp", "sub", "-");	break;      case OP_MUL:	func = makeFunctionExp("gnu.xquery.util.ArithOp", "mul", "*");	break;      case OP_DIV:	func = makeFunctionExp("gnu.xquery.util.ArithOp", "div", "div");	break;      case OP_IDIV:	func = makeFunctionExp("gnu.xquery.util.ArithOp", "idiv", "idiv");	break;      case OP_MOD:	func = makeFunctionExp("gnu.xquery.util.ArithOp", "mod", "mod");	break;      case OP_EQ:	func = makeFunctionExp("gnu.xquery.util.Compare", "valEq", "eq");	break;      case OP_NE:	func = makeFunctionExp("gnu.xquery.util.Compare", "valNe", "ne");	break;      case OP_LT:	func = makeFunctionExp("gnu.xquery.util.Compare", "valLt", "lt");	break;      case OP_LE:	func = makeFunctionExp("gnu.xquery.util.Compare", "valLe", "le");	break;      case OP_GT:	func = makeFunctionExp("gnu.xquery.util.Compare", "valGt", "gt");	break;      case OP_GE:	func = makeFunctionExp("gnu.xquery.util.Compare", "valGe", "ge");	break;      case OP_EQU:	func = makeFunctionExp("gnu.xquery.util.Compare", "=");	break;      case OP_NEQ:	func = makeFunctionExp("gnu.xquery.util.Compare", "!=");	break;      case OP_LSS:	func = makeFunctionExp("gnu.xquery.util.Compare", "<");	break;      case OP_LEQ:	func = makeFunctionExp("gnu.xquery.util.Compare", "<=");	break;      case OP_GRT:

⌨️ 快捷键说明

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