xpathparser.java

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

JAVA
2,233
字号
/* Generated By:JavaCC: Do not edit this line. XPathParser.java */
    package org.apache.commons.jxpath.ri.parser;

    import org.apache.commons.jxpath.ri.Compiler;
    import java.util.ArrayList;

    public class XPathParser implements XPathParserConstants {
        private Compiler compiler;

        public void setCompiler(Compiler compiler){
            this.compiler = compiler;
        }

        private String unescape(String string){
            int index = string.indexOf("'");
            while (index != -1){
                string = string.substring(0, index) + "\'" + string.substring(index + 6);
                index = string.indexOf("'");
            }
            index = string.indexOf(""");
            while (index != -1){
                string = string.substring(0, index) + "\"" + string.substring(index + 6);
                index = string.indexOf(""");
            }
            return string;
        }

// Note: XPath does not have reserved words, so we have to include all these terminals
  final public String NCName() throws ParseException {
    switch (jj_nt.kind) {
    case OR:
    case AND:
    case MOD:
    case DIV:
    case NCName:
      NCName_Without_CoreFunctions();
      break;
    case NODE:
      jj_consume_token(NODE);
      break;
    case TEXT:
      jj_consume_token(TEXT);
      break;
    case COMMENT:
      jj_consume_token(COMMENT);
      break;
    case PI:
      jj_consume_token(PI);
      break;
    case FUNCTION_LAST:
      jj_consume_token(FUNCTION_LAST);
      break;
    case FUNCTION_POSITION:
      jj_consume_token(FUNCTION_POSITION);
      break;
    case FUNCTION_COUNT:
      jj_consume_token(FUNCTION_COUNT);
      break;
    case FUNCTION_ID:
      jj_consume_token(FUNCTION_ID);
      break;
    case FUNCTION_LOCAL_NAME:
      jj_consume_token(FUNCTION_LOCAL_NAME);
      break;
    case FUNCTION_NAMESPACE_URI:
      jj_consume_token(FUNCTION_NAMESPACE_URI);
      break;
    case FUNCTION_NAME:
      jj_consume_token(FUNCTION_NAME);
      break;
    case FUNCTION_STRING:
      jj_consume_token(FUNCTION_STRING);
      break;
    case FUNCTION_CONCAT:
      jj_consume_token(FUNCTION_CONCAT);
      break;
    case FUNCTION_STARTS_WITH:
      jj_consume_token(FUNCTION_STARTS_WITH);
      break;
    case FUNCTION_CONTAINS:
      jj_consume_token(FUNCTION_CONTAINS);
      break;
    case FUNCTION_SUBSTRING_BEFORE:
      jj_consume_token(FUNCTION_SUBSTRING_BEFORE);
      break;
    case FUNCTION_SUBSTRING_AFTER:
      jj_consume_token(FUNCTION_SUBSTRING_AFTER);
      break;
    case FUNCTION_SUBSTRING:
      jj_consume_token(FUNCTION_SUBSTRING);
      break;
    case FUNCTION_STRING_LENGTH:
      jj_consume_token(FUNCTION_STRING_LENGTH);
      break;
    case FUNCTION_NORMALIZE_SPACE:
      jj_consume_token(FUNCTION_NORMALIZE_SPACE);
      break;
    case FUNCTION_TRANSLATE:
      jj_consume_token(FUNCTION_TRANSLATE);
      break;
    case FUNCTION_BOOLEAN:
      jj_consume_token(FUNCTION_BOOLEAN);
      break;
    case FUNCTION_NOT:
      jj_consume_token(FUNCTION_NOT);
      break;
    case FUNCTION_TRUE:
      jj_consume_token(FUNCTION_TRUE);
      break;
    case FUNCTION_FALSE:
      jj_consume_token(FUNCTION_FALSE);
      break;
    case FUNCTION_NULL:
      jj_consume_token(FUNCTION_NULL);
      break;
    case FUNCTION_LANG:
      jj_consume_token(FUNCTION_LANG);
      break;
    case FUNCTION_NUMBER:
      jj_consume_token(FUNCTION_NUMBER);
      break;
    case FUNCTION_SUM:
      jj_consume_token(FUNCTION_SUM);
      break;
    case FUNCTION_FLOOR:
      jj_consume_token(FUNCTION_FLOOR);
      break;
    case FUNCTION_CEILING:
      jj_consume_token(FUNCTION_CEILING);
      break;
    case FUNCTION_ROUND:
      jj_consume_token(FUNCTION_ROUND);
      break;
    case FUNCTION_KEY:
      jj_consume_token(FUNCTION_KEY);
      break;
    case FUNCTION_FORMAT_NUMBER:
      jj_consume_token(FUNCTION_FORMAT_NUMBER);
      break;
    default:
      jj_la1[0] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
        {if (true) return token.image;}
    throw new Error("Missing return statement in function");
  }

  final public String NCName_Without_CoreFunctions() throws ParseException {
    switch (jj_nt.kind) {
    case NCName:
      jj_consume_token(NCName);
      break;
    case OR:
      jj_consume_token(OR);
      break;
    case AND:
      jj_consume_token(AND);
      break;
    case MOD:
      jj_consume_token(MOD);
      break;
    case DIV:
      jj_consume_token(DIV);
      break;
    default:
      jj_la1[1] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
        {if (true) return token.image;}
    throw new Error("Missing return statement in function");
  }

  final public int CoreFunctionName() throws ParseException {
    int code;
    switch (jj_nt.kind) {
    case FUNCTION_LAST:
      jj_consume_token(FUNCTION_LAST);
                                      code = Compiler.FUNCTION_LAST;
      break;
    case FUNCTION_POSITION:
      jj_consume_token(FUNCTION_POSITION);
                                      code = Compiler.FUNCTION_POSITION;
      break;
    case FUNCTION_COUNT:
      jj_consume_token(FUNCTION_COUNT);
                                      code = Compiler.FUNCTION_COUNT;
      break;
    case FUNCTION_ID:
      jj_consume_token(FUNCTION_ID);
                                      code = Compiler.FUNCTION_ID;
      break;
    case FUNCTION_LOCAL_NAME:
      jj_consume_token(FUNCTION_LOCAL_NAME);
                                      code = Compiler.FUNCTION_LOCAL_NAME;
      break;
    case FUNCTION_NAMESPACE_URI:
      jj_consume_token(FUNCTION_NAMESPACE_URI);
                                      code = Compiler.FUNCTION_NAMESPACE_URI;
      break;
    case FUNCTION_NAME:
      jj_consume_token(FUNCTION_NAME);
                                      code = Compiler.FUNCTION_NAME;
      break;
    case FUNCTION_STRING:
      jj_consume_token(FUNCTION_STRING);
                                      code = Compiler.FUNCTION_STRING;
      break;
    case FUNCTION_CONCAT:
      jj_consume_token(FUNCTION_CONCAT);
                                      code = Compiler.FUNCTION_CONCAT;
      break;
    case FUNCTION_STARTS_WITH:
      jj_consume_token(FUNCTION_STARTS_WITH);
                                      code = Compiler.FUNCTION_STARTS_WITH;
      break;
    case FUNCTION_CONTAINS:
      jj_consume_token(FUNCTION_CONTAINS);
                                      code = Compiler.FUNCTION_CONTAINS;
      break;
    case FUNCTION_SUBSTRING_BEFORE:
      jj_consume_token(FUNCTION_SUBSTRING_BEFORE);
                                      code = Compiler.FUNCTION_SUBSTRING_BEFORE;
      break;
    case FUNCTION_SUBSTRING_AFTER:
      jj_consume_token(FUNCTION_SUBSTRING_AFTER);
                                      code = Compiler.FUNCTION_SUBSTRING_AFTER;
      break;
    case FUNCTION_SUBSTRING:
      jj_consume_token(FUNCTION_SUBSTRING);
                                      code = Compiler.FUNCTION_SUBSTRING;
      break;
    case FUNCTION_STRING_LENGTH:
      jj_consume_token(FUNCTION_STRING_LENGTH);
                                      code = Compiler.FUNCTION_STRING_LENGTH;
      break;
    case FUNCTION_NORMALIZE_SPACE:
      jj_consume_token(FUNCTION_NORMALIZE_SPACE);
                                      code = Compiler.FUNCTION_NORMALIZE_SPACE;
      break;
    case FUNCTION_TRANSLATE:
      jj_consume_token(FUNCTION_TRANSLATE);
                                      code = Compiler.FUNCTION_TRANSLATE;
      break;
    case FUNCTION_BOOLEAN:
      jj_consume_token(FUNCTION_BOOLEAN);
                                      code = Compiler.FUNCTION_BOOLEAN;
      break;
    case FUNCTION_NOT:
      jj_consume_token(FUNCTION_NOT);
                                      code = Compiler.FUNCTION_NOT;
      break;
    case FUNCTION_TRUE:
      jj_consume_token(FUNCTION_TRUE);
                                      code = Compiler.FUNCTION_TRUE;
      break;
    case FUNCTION_FALSE:
      jj_consume_token(FUNCTION_FALSE);
                                      code = Compiler.FUNCTION_FALSE;
      break;
    case FUNCTION_NULL:
      jj_consume_token(FUNCTION_NULL);
                                      code = Compiler.FUNCTION_NULL;
      break;
    case FUNCTION_LANG:
      jj_consume_token(FUNCTION_LANG);
                                      code = Compiler.FUNCTION_LANG;
      break;
    case FUNCTION_NUMBER:
      jj_consume_token(FUNCTION_NUMBER);
                                      code = Compiler.FUNCTION_NUMBER;
      break;
    case FUNCTION_SUM:
      jj_consume_token(FUNCTION_SUM);
                                      code = Compiler.FUNCTION_SUM;
      break;
    case FUNCTION_FLOOR:
      jj_consume_token(FUNCTION_FLOOR);
                                      code = Compiler.FUNCTION_FLOOR;
      break;
    case FUNCTION_CEILING:
      jj_consume_token(FUNCTION_CEILING);
                                      code = Compiler.FUNCTION_CEILING;
      break;
    case FUNCTION_ROUND:
      jj_consume_token(FUNCTION_ROUND);
                                      code = Compiler.FUNCTION_ROUND;
      break;
    case FUNCTION_KEY:
      jj_consume_token(FUNCTION_KEY);
                                      code = Compiler.FUNCTION_KEY;
      break;
    case FUNCTION_FORMAT_NUMBER:
      jj_consume_token(FUNCTION_FORMAT_NUMBER);
                                      code = Compiler.FUNCTION_FORMAT_NUMBER;
      break;
    default:
      jj_la1[2] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
        {if (true) return code;}
    throw new Error("Missing return statement in function");
  }

  final public Object QName() throws ParseException {
 String nc1, nc2 = null;
    nc1 = NCName();
    switch (jj_nt.kind) {
    case 79:
      jj_consume_token(79);
      nc2 = NCName();
      break;
    default:
      jj_la1[3] = jj_gen;
      ;
    }
        if (nc2 == null){
            {if (true) return compiler.qname(null, nc1);}
        }
        else {
            {if (true) return compiler.qname(nc1, nc2);}
        }
    throw new Error("Missing return statement in function");
  }

  final public Object QName_Without_CoreFunctions() throws ParseException {
    String nc1, nc2 = null;
    if (jj_2_1(2147483647)) {
      nc1 = NCName();
      jj_consume_token(79);
      nc2 = NCName();
    } else {
      switch (jj_nt.kind) {
      case OR:
      case AND:
      case MOD:
      case DIV:
      case NCName:
        nc1 = NCName_Without_CoreFunctions();
        break;
      default:
        jj_la1[4] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
    }
        if (nc2 == null){
            {if (true) return compiler.qname(null, nc1);}
        }
        else {
            {if (true) return compiler.qname(nc1, nc2);}
        }
    throw new Error("Missing return statement in function");
  }

  final public Object parseExpression() throws ParseException {
    Object ex;
    ex = Expression();
    jj_consume_token(0);
        {if (true) return ex;}
    throw new Error("Missing return statement in function");
  }

/* ################################################################################### */
/* XSLT Patterns (http://www.w3.org/1999/08/WD-xslt-19990813)                          */
/* ################################################################################### */

/* [XSLT1] Pattern ::= LocationPathPattern | Pattern '|' LocationPathPattern  */

//void Pattern() :
//{}
//{
//        LocationPathPattern() ( <UNION> LocationPathPattern() )* <EOF>
//}
//
//
///* [XSLT2] LocationPathPattern ::=
//   '/' RelativePathPattern? | IdKeyPattern (('/' | '//' RelativePathPattern)? | '//'? RelativePathPattern
//*/
//
//void LocationPathPattern() :
//{}
//{
//        <SLASH> ( RelativePathPattern() )?
//    |    (
//        LOOKAHEAD(IdKeyPattern())
//            IdKeyPattern() ( ( <SLASH> | <SLASHSLASH>) RelativePathPattern() )?
//        |    ( <SLASHSLASH> )? RelativePathPattern()
//        )
//}
//
//
//
///* [XSLT3] IdKeyPattern    ::=    'id' '(' Literal ')' | 'key' '(' Literal ',' Literal ')'  */
//
//void IdKeyPattern() :
//{}
//{
//        <ID> "(" <Literal> ")"
//    |    <KEY>  "(" <Literal> "," <Literal> ")"
//}
//
//
///* [XSLT4] RelativePathPattern    ::=    StepPattern | RelativePathPattern '/' StepPattern
//                           | RelativePathPattern '//' StepPattern
//*/
//void RelativePathPattern() :
//{}
//{
//        StepPattern() ( ( <SLASH>| <SLASHSLASH> ) StepPattern()    )*
//}
//
//
///* [XSLT5]    StepPattern    ::=    AbbreviatedAxisSpecifier NodeTest Predicate*   */
//void StepPattern() :
//{}
//{
//        AbbreviatedAxisSpecifier() NodeTest() (Predicate())*
//}



// See XPath Syntax (http://www.w3.org/TR/xpath )


//void XPath() :
//{}
//{
//    LocationPath()
//    <EOF>
//}


/* [1] LocationPath ::= RelativeLocationPath | AbsoluteLocationPath  */
  final public Object LocationPath() throws ParseException {
 Object ex = null;
    switch (jj_nt.kind) {
    case OR:
    case AND:
    case MOD:
    case DIV:
    case NODE:
    case TEXT:
    case COMMENT:
    case PI:

⌨️ 快捷键说明

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