xpathparser.java

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

JAVA
2,233
字号
    throw new Error("Missing return statement in function");
  }

/*---------------*/
/* 3 Expressions */
/*---------------*/

/*------------*/
/* 3.1 Basics */
/*------------*/

/*
The effect of the grammar is that the order of precedence is (lowest precedence first):
    or
    and
    =, !=
    <=, <, >=, >
and all operators are left associative.
For example, 3 > 2 > 1 is equivalent to (3 > 2) > 1, which evaluates to false.
*/

/* [14] Expr ::= OrExpr */
  final public Object Expression() throws ParseException {
 Object ex;
    ex = OrExpr();
        {if (true) return ex;}
    throw new Error("Missing return statement in function");
  }

/* [15] PrimaryExpr ::= VariableReference | '(' Expr ')' | Literal | Number | FunctionCall */
  final public Object PrimaryExpr() throws ParseException {
    Object ex = null;
    switch (jj_nt.kind) {
    case VARIABLE:
      ex = VariableReference();
      break;
    case 80:
      jj_consume_token(80);
      ex = Expression();
      jj_consume_token(81);
      break;
    case Literal:
      jj_consume_token(Literal);
                      ex = compiler.literal(unescape(token.image.substring(1, token.image.length() - 1)));
      break;
    case Number:
      jj_consume_token(Number);
                      ex = compiler.number(token.image);
      break;
    default:
      jj_la1[16] = jj_gen;
      if (jj_2_5(2147483647)) {
        ex = CoreFunctionCall();
      } 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:
          ex = FunctionCall();
          break;
        default:
          jj_la1[17] = jj_gen;
          jj_consume_token(-1);
          throw new ParseException();
        }
      }
    }
        {if (true) return ex;}
    throw new Error("Missing return statement in function");
  }

/*--------------------*/
/* 3.2 Function Calls */
/*--------------------*/

/* [16]    FunctionCall    ::=    FunctionName '(' ( Argument ( ',' Argument)*)? ')'  */
  final public Object FunctionCall() throws ParseException {
    Object name;
    ArrayList args;
    name = FunctionName();
    args = ArgumentList();
        if (args == null){
            {if (true) return compiler.function(name, null);}
        }
        else {
            {if (true) return compiler.function(name, args.toArray());}
        }
    throw new Error("Missing return statement in function");
  }

  final public Object CoreFunctionCall() throws ParseException {
    int code = 0;
    ArrayList args;
    code = CoreFunctionName();
    args = ArgumentList();
        if (args == null){
            {if (true) return compiler.function(code, null);}
        }
        else {
            {if (true) return compiler.function(code, args.toArray());}
        }
    throw new Error("Missing return statement in function");
  }

  final public ArrayList ArgumentList() throws ParseException {
    ArrayList args = null;
    Object arg;
    jj_consume_token(80);
    switch (jj_nt.kind) {
    case SLASH:
    case SLASHSLASH:
    case MINUS:
    case VARIABLE:
    case Literal:
    case Number:
    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 80:
    case 82:
    case 83:
    case 86:
    case 88:
      arg = Argument();
                                args = new ArrayList(); args.add(arg);
      label_4:
      while (true) {
        switch (jj_nt.kind) {
        case 87:
          ;
          break;
        default:
          jj_la1[18] = jj_gen;
          break label_4;
        }
        jj_consume_token(87);
        arg = Argument();
                                       args.add(arg);
      }
      break;
    default:
      jj_la1[19] = jj_gen;
      ;
    }
    jj_consume_token(81);
        {if (true) return args;}
    throw new Error("Missing return statement in function");
  }

/* [17]    Argument    ::=    Expr */
  final public Object Argument() throws ParseException {
    Object ex;
    ex = Expression();
        {if (true) return ex;}
    throw new Error("Missing return statement in function");
  }

/*---------------*/
/* 3.3 Node-sets */
/*---------------*/

/* [18] UnionExpr    ::=    PathExpr | UnionExpr '|' PathExpr */
  final public Object UnionExpr() throws ParseException {
    Object ex, r;
    ArrayList list = null;
    ex = PathExpr();
    label_5:
    while (true) {
      switch (jj_nt.kind) {
      case UNION:
        ;
        break;
      default:
        jj_la1[20] = jj_gen;
        break label_5;
      }
      jj_consume_token(UNION);
      r = PathExpr();
                if (list == null){
                    list = new ArrayList();
                    list.add(ex);
                }
                list.add(r);
    }
        if (list != null){
            ex = compiler.union(list.toArray());
        }
        {if (true) return ex;}
    throw new Error("Missing return statement in function");
  }

/* [19] PathExpr ::= LocationPath | FilterExpr | FilterExpr '/' RelativeLocationPath | FilterExpr '//' RelativeLocationPath  */
  final public Object PathExpr() throws ParseException {
    Object ex = null;
    Object[] steps;
    if (jj_2_6(2147483647)) {
      ex = FilterExpr();
    } else {
      switch (jj_nt.kind) {
      case SLASH:
      case SLASHSLASH:
      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 82:
      case 83:
      case 86:
      case 88:
        ex = LocationPath();
        break;
      default:
        jj_la1[21] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
    }
        {if (true) return ex;}
    throw new Error("Missing return statement in function");
  }

/* [20]    FilterExpr    ::=    PrimaryExpr    | FilterExpr Predicate */
  final public Object FilterExpr() throws ParseException {
    Object ex, p;
    ArrayList ps = new ArrayList();
    boolean path = false;
    ArrayList steps = new ArrayList();
    ex = PrimaryExpr();
    label_6:
    while (true) {
      switch (jj_nt.kind) {
      case 84:
        ;
        break;
      default:
        jj_la1[22] = jj_gen;
        break label_6;
      }
      p = Predicate();
                path = true;
                ps.add(p);
    }
    label_7:
    while (true) {
      switch (jj_nt.kind) {
      case SLASH:
      case SLASHSLASH:
        ;
        break;
      default:
        jj_la1[23] = jj_gen;
        break label_7;
      }
      LocationStep(steps);
                path = true;
    }
        if (path){
            {if (true) return compiler.expressionPath(ex, ps.toArray(), steps.toArray());}
        }
        else {
            {if (true) return ex;}
        }
    throw new Error("Missing return statement in function");
  }

/*--------------*/
/* 3.4 Booleans */
/*--------------*/

/* [21] OrExpr    ::=    AndExpr | OrExpr 'or' AndExpr */
  final public Object OrExpr() throws ParseException {
    Object ex, r;
    ArrayList list = null;
    ex = AndExpr();
    label_8:
    while (true) {
      switch (jj_nt.kind) {
      case OR:
        ;
        break;
      default:
        jj_la1[24] = jj_gen;
        break label_8;
      }
      jj_consume_token(OR);
      r = AndExpr();
                if (list == null){
                    list = new ArrayList();
                    list.add(ex);
                }
                list.add(r);
    }
        if (list != null){
            ex = compiler.or(list.toArray());
        }
        {if (true) return ex;}
    throw new Error("Missing return statement in function");
  }

/* [22] AndExpr    ::=    EqualityExpr  | AndExpr 'and' EqualityExpr  */
  final public Object AndExpr() throws ParseException {
    Object ex, r;
    ArrayList list = null;
    ex = EqualityExpr();
    label_9:
    while (true) {
      switch (jj_nt.kind) {
      case AND:
        ;
        break;
      default:
        jj_la1[25] = jj_gen;
        break label_9;
      }

⌨️ 快捷键说明

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