xpathparser.java

来自「JXPath」· Java 代码 · 共 2,233 行 · 第 1/5 页

JAVA
2,233
字号
    case AXIS_SELF:
    case AXIS_CHILD:
    case AXIS_PARENT:
    case AXIS_ANCESTOR:
    case AXIS_ATTRIBUTE:
    case AXIS_NAMESPACE:
    case AXIS_PRECEDING:
    case AXIS_FOLLOWING:
    case AXIS_DESCENDANT:
    case AXIS_ANCESTOR_OR_SELF:
    case AXIS_FOLLOWING_SIBLING:
    case AXIS_PRECEDING_SIBLING:
    case AXIS_DESCENDANT_OR_SELF:
    case FUNCTION_LAST:
    case FUNCTION_POSITION:
    case FUNCTION_COUNT:
    case FUNCTION_ID:
    case FUNCTION_KEY:
    case FUNCTION_LOCAL_NAME:
    case FUNCTION_NAMESPACE_URI:
    case FUNCTION_NAME:
    case FUNCTION_STRING:
    case FUNCTION_CONCAT:
    case FUNCTION_STARTS_WITH:
    case FUNCTION_CONTAINS:
    case FUNCTION_SUBSTRING_BEFORE:
    case FUNCTION_SUBSTRING_AFTER:
    case FUNCTION_SUBSTRING:
    case FUNCTION_STRING_LENGTH:
    case FUNCTION_NORMALIZE_SPACE:
    case FUNCTION_TRANSLATE:
    case FUNCTION_BOOLEAN:
    case FUNCTION_NOT:
    case FUNCTION_TRUE:
    case FUNCTION_FALSE:
    case FUNCTION_NULL:
    case FUNCTION_LANG:
    case FUNCTION_NUMBER:
    case FUNCTION_SUM:
    case FUNCTION_FLOOR:
    case FUNCTION_CEILING:
    case FUNCTION_ROUND:
    case FUNCTION_FORMAT_NUMBER:
    case NCName:
    case 82:
    case 83:
    case 86:
    case 88:
      ex = RelativeLocationPath();
      break;
    case SLASH:
    case SLASHSLASH:
      ex = AbsoluteLocationPath();
      break;
    default:
      jj_la1[5] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
        {if (true) return ex;}
    throw new Error("Missing return statement in function");
  }

/* [2] AbsoluteLocationPath ::= '/' RelativeLocationPath? | AbbreviatedAbsoluteLocationPath  */
/* [10]    AbbreviatedAbsoluteLocationPath    ::=    '//' RelativeLocationPath  */
  final public Object AbsoluteLocationPath() throws ParseException {
    ArrayList steps = new ArrayList();
    if (jj_2_2(2147483647)) {
      LocationStep(steps);
      label_1:
      while (true) {
        switch (jj_nt.kind) {
        case SLASH:
        case SLASHSLASH:
          ;
          break;
        default:
          jj_la1[6] = jj_gen;
          break label_1;
        }
        LocationStep(steps);
      }
    } else {
      switch (jj_nt.kind) {
      case SLASH:
        jj_consume_token(SLASH);
        break;
      default:
        jj_la1[7] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
    }
        {if (true) return compiler.locationPath(true, steps.toArray());}
    throw new Error("Missing return statement in function");
  }

/* [3] RelativeLocationPath ::= Step | RelativeLocationPath '/' Step | AbbreviatedRelativeLocationPath */
  final public Object RelativeLocationPath() throws ParseException {
    ArrayList steps = new ArrayList();
    NodeTest(steps);
    label_2:
    while (true) {
      switch (jj_nt.kind) {
      case SLASH:
      case SLASHSLASH:
        ;
        break;
      default:
        jj_la1[8] = jj_gen;
        break label_2;
      }
      LocationStep(steps);
    }
        {if (true) return compiler.locationPath(false, steps.toArray());}
    throw new Error("Missing return statement in function");
  }

/* [3] RelativeLocationPath ::= Step | RelativeLocationPath '/' Step | AbbreviatedRelativeLocationPath */
/* [11]    AbbreviatedRelativeLocationPath    ::=    RelativeLocationPath '//' Step  */


/*--------------------*/
/* 2.1 Location Steps */
/*--------------------*/

/* [4] Step ::= AxisSpecifier NodeTest Predicate*   | AbbreviatedStep  */
  final public void LocationStep(ArrayList steps) throws ParseException {
    Object t;
    Object s;
    switch (jj_nt.kind) {
    case SLASH:
      jj_consume_token(SLASH);
      break;
    case SLASHSLASH:
      jj_consume_token(SLASHSLASH);
            // Abbreviated step: descendant-or-self::node()
            t = compiler.nodeTypeTest(Compiler.NODE_TYPE_NODE);
            steps.add(compiler.step(Compiler.AXIS_DESCENDANT_OR_SELF, t, null));
      break;
    default:
      jj_la1[9] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
    NodeTest(steps);
  }

/* [7] NodeTest ::= WildcardName | NodeType '(' ')' | 'processing-instruction' '(' Literal ')' */
  final public void NodeTest(ArrayList steps) throws ParseException {
    int axis;
    int type = -1;
    String instruction = null;
    Object name = null;
    Object s;
    Object p;
    ArrayList ps = new ArrayList();
    switch (jj_nt.kind) {
    case OR:
    case AND:
    case MOD:
    case DIV:
    case NODE:
    case TEXT:
    case COMMENT:
    case PI:
    case AXIS_SELF:
    case AXIS_CHILD:
    case AXIS_PARENT:
    case AXIS_ANCESTOR:
    case AXIS_ATTRIBUTE:
    case AXIS_NAMESPACE:
    case AXIS_PRECEDING:
    case AXIS_FOLLOWING:
    case AXIS_DESCENDANT:
    case AXIS_ANCESTOR_OR_SELF:
    case AXIS_FOLLOWING_SIBLING:
    case AXIS_PRECEDING_SIBLING:
    case AXIS_DESCENDANT_OR_SELF:
    case FUNCTION_LAST:
    case FUNCTION_POSITION:
    case FUNCTION_COUNT:
    case FUNCTION_ID:
    case FUNCTION_KEY:
    case FUNCTION_LOCAL_NAME:
    case FUNCTION_NAMESPACE_URI:
    case FUNCTION_NAME:
    case FUNCTION_STRING:
    case FUNCTION_CONCAT:
    case FUNCTION_STARTS_WITH:
    case FUNCTION_CONTAINS:
    case FUNCTION_SUBSTRING_BEFORE:
    case FUNCTION_SUBSTRING_AFTER:
    case FUNCTION_SUBSTRING:
    case FUNCTION_STRING_LENGTH:
    case FUNCTION_NORMALIZE_SPACE:
    case FUNCTION_TRANSLATE:
    case FUNCTION_BOOLEAN:
    case FUNCTION_NOT:
    case FUNCTION_TRUE:
    case FUNCTION_FALSE:
    case FUNCTION_NULL:
    case FUNCTION_LANG:
    case FUNCTION_NUMBER:
    case FUNCTION_SUM:
    case FUNCTION_FLOOR:
    case FUNCTION_CEILING:
    case FUNCTION_ROUND:
    case FUNCTION_FORMAT_NUMBER:
    case NCName:
    case 86:
    case 88:
      axis = AxisSpecifier();
      if (jj_2_3(2147483647)) {
        type = NodeType();
        jj_consume_token(80);
        jj_consume_token(81);
      } else if (jj_2_4(2147483647)) {
        jj_consume_token(PI);
        jj_consume_token(80);
        jj_consume_token(Literal);
                    instruction = unescape(token.image.substring(1, token.image.length() - 1));
        jj_consume_token(81);
      } else {
        switch (jj_nt.kind) {
        case OR:
        case AND:
        case MOD:
        case DIV:
        case NODE:
        case TEXT:
        case COMMENT:
        case PI:
        case FUNCTION_LAST:
        case FUNCTION_POSITION:
        case FUNCTION_COUNT:
        case FUNCTION_ID:
        case FUNCTION_KEY:
        case FUNCTION_LOCAL_NAME:
        case FUNCTION_NAMESPACE_URI:
        case FUNCTION_NAME:
        case FUNCTION_STRING:
        case FUNCTION_CONCAT:
        case FUNCTION_STARTS_WITH:
        case FUNCTION_CONTAINS:
        case FUNCTION_SUBSTRING_BEFORE:
        case FUNCTION_SUBSTRING_AFTER:
        case FUNCTION_SUBSTRING:
        case FUNCTION_STRING_LENGTH:
        case FUNCTION_NORMALIZE_SPACE:
        case FUNCTION_TRANSLATE:
        case FUNCTION_BOOLEAN:
        case FUNCTION_NOT:
        case FUNCTION_TRUE:
        case FUNCTION_FALSE:
        case FUNCTION_NULL:
        case FUNCTION_LANG:
        case FUNCTION_NUMBER:
        case FUNCTION_SUM:
        case FUNCTION_FLOOR:
        case FUNCTION_CEILING:
        case FUNCTION_ROUND:
        case FUNCTION_FORMAT_NUMBER:
        case NCName:
        case 88:
          name = WildcardName();
          break;
        default:
          jj_la1[10] = jj_gen;
          jj_consume_token(-1);
          throw new ParseException();
        }
      }
      break;
    case 82:
      jj_consume_token(82);
                    axis = Compiler.AXIS_SELF;
                    type = Compiler.NODE_TYPE_NODE;
      break;
    case 83:
      jj_consume_token(83);
                    axis = Compiler.AXIS_PARENT;
                    type = Compiler.NODE_TYPE_NODE;
      break;
    default:
      jj_la1[11] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
    label_3:
    while (true) {
      switch (jj_nt.kind) {
      case 84:
        ;
        break;
      default:
        jj_la1[12] = jj_gen;
        break label_3;
      }
      p = Predicate();
                ps.add(p);
    }
        if (name != null){
            s = compiler.nodeNameTest(name);
        }
        else if (instruction != null){
            s = compiler.processingInstructionTest(instruction);
        }
        else {
            s = compiler.nodeTypeTest(type);
        }
        steps.add(compiler.step(axis, s, ps.toArray()));
  }

/* [5] AxisSpecifier ::=    AxisName '::' | AbbreviatedAxisSpecifier  */
  final public int AxisSpecifier() throws ParseException {
    int axis;
    switch (jj_nt.kind) {
    case AXIS_SELF:
    case AXIS_CHILD:
    case AXIS_PARENT:
    case AXIS_ANCESTOR:
    case AXIS_ATTRIBUTE:
    case AXIS_NAMESPACE:
    case AXIS_PRECEDING:
    case AXIS_FOLLOWING:
    case AXIS_DESCENDANT:
    case AXIS_ANCESTOR_OR_SELF:
    case AXIS_FOLLOWING_SIBLING:
    case AXIS_PRECEDING_SIBLING:
    case AXIS_DESCENDANT_OR_SELF:
      axis = AxisName();
      break;
    default:
      jj_la1[13] = jj_gen;
      axis = AbbreviatedAxisSpecifier();
    }
        {if (true) return axis;}
    throw new Error("Missing return statement in function");
  }

/*----------*/
/* 2.2 Axes */
/*----------*/

/* [6] AxisName ::= 'ancestor' | 'ancestor-or-self' | 'attribute'  | 'child' | 'descendant'
                    | 'descendant-or-self' | 'following' | 'following-sibling' | 'namespace'
                       | 'parent' | 'preceding' | 'preceding-sibling' | 'self'
*/
  final public int AxisName() throws ParseException {
    int axis = 0;
    switch (jj_nt.kind) {
    case AXIS_SELF:
      jj_consume_token(AXIS_SELF);
                                          axis = Compiler.AXIS_SELF;
      break;
    case AXIS_CHILD:
      jj_consume_token(AXIS_CHILD);
                                          axis = Compiler.AXIS_CHILD;
      break;
    case AXIS_PARENT:
      jj_consume_token(AXIS_PARENT);
                                          axis = Compiler.AXIS_PARENT;
      break;
    case AXIS_ANCESTOR:
      jj_consume_token(AXIS_ANCESTOR);
                                          axis = Compiler.AXIS_ANCESTOR;
      break;
    case AXIS_ATTRIBUTE:
      jj_consume_token(AXIS_ATTRIBUTE);
                                          axis = Compiler.AXIS_ATTRIBUTE;
      break;
    case AXIS_NAMESPACE:
      jj_consume_token(AXIS_NAMESPACE);
                                          axis = Compiler.AXIS_NAMESPACE;
      break;
    case AXIS_PRECEDING:
      jj_consume_token(AXIS_PRECEDING);
                                          axis = Compiler.AXIS_PRECEDING;
      break;
    case AXIS_FOLLOWING:
      jj_consume_token(AXIS_FOLLOWING);
                                          axis = Compiler.AXIS_FOLLOWING;
      break;
    case AXIS_DESCENDANT:
      jj_consume_token(AXIS_DESCENDANT);
                                          axis = Compiler.AXIS_DESCENDANT;
      break;
    case AXIS_ANCESTOR_OR_SELF:
      jj_consume_token(AXIS_ANCESTOR_OR_SELF);
                                          axis = Compiler.AXIS_ANCESTOR_OR_SELF;
      break;
    case AXIS_FOLLOWING_SIBLING:
      jj_consume_token(AXIS_FOLLOWING_SIBLING);
                                          axis = Compiler.AXIS_FOLLOWING_SIBLING;
      break;
    case AXIS_PRECEDING_SIBLING:
      jj_consume_token(AXIS_PRECEDING_SIBLING);
                                          axis = Compiler.AXIS_PRECEDING_SIBLING;
      break;
    case AXIS_DESCENDANT_OR_SELF:
      jj_consume_token(AXIS_DESCENDANT_OR_SELF);
                                          axis = Compiler.AXIS_DESCENDANT_OR_SELF;
      break;
    default:
      jj_la1[14] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
        {if (true) return axis;}
    throw new Error("Missing return statement in function");
  }

/*----------------*/
/* 2.3 Node Tests */
/*----------------*/

/*----------------*/
/* 2.4 Predicates */
/*----------------*/

/* [8] Predicate ::= '[' PredicateExpr ']'  */
/* [9] PredicateExpr ::=  Expr  */
  final public Object Predicate() throws ParseException {
    Object ex;
    jj_consume_token(84);
    ex = Expression();
    jj_consume_token(85);
        {if (true) return ex;}
    throw new Error("Missing return statement in function");
  }

/* [12]    AbbreviatedStep    ::=    '.'  | '..'  */

/* [13]    AbbreviatedAxisSpecifier    ::=    '@'? */
  final public int AbbreviatedAxisSpecifier() throws ParseException {
    int axis = Compiler.AXIS_CHILD;
    switch (jj_nt.kind) {
    case 86:
      jj_consume_token(86);
           axis = Compiler.AXIS_ATTRIBUTE;
      break;
    default:
      jj_la1[15] = jj_gen;
      ;
    }
        {if (true) return axis;}

⌨️ 快捷键说明

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