📄 xpathparser.java
字号:
// created by jay 0.8 (c) 1998 Axel.Schreiner@informatik.uni-osnabrueck.de // line 2 "XPathParser.y"/* XPathParser.y - An XPath 1.0 parser. Copyright (C) 2004 The Free Software FoundationThis file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. */package gnu.xml.xpath;import java.util.ArrayList;import java.util.Collections;import java.util.List;import java.util.Map;import javax.xml.namespace.NamespaceContext;import javax.xml.namespace.QName;import javax.xml.xpath.XPathFunctionResolver;import javax.xml.xpath.XPathVariableResolver;import org.w3c.dom.Node;/** * An XPath 1.0 parser. * * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> */public class XPathParser{ NamespaceContext namespaceContext; XPathVariableResolver variableResolver; XPathFunctionResolver functionResolver; QName getQName(String name) { QName qName = QName.valueOf(name); if (namespaceContext != null) { String prefix = qName.getPrefix(); String uri = qName.getNamespaceURI(); if (prefix != null && (uri == null || uri.length() == 0)) { uri = namespaceContext.getNamespaceURI(prefix); String localName = qName.getLocalPart(); qName = new QName(uri, localName, prefix); } } return qName; } Expr lookupFunction(String name, List args) { int arity = args.size(); if ("position".equals(name) && arity == 0) { return new PositionFunction(); } else if ("last".equals(name) && arity == 0) { return new LastFunction(); } else if ("string".equals(name) && (arity == 1 || arity == 0)) { return new StringFunction(args); } else if ("number".equals(name) && (arity == 1 || arity == 0)) { return new NumberFunction(args); } else if ("boolean".equals(name) && arity == 1) { return new BooleanFunction(args); } else if ("count".equals(name) && arity == 1) { return new CountFunction(args); } else if ("not".equals(name) && arity == 1) { return new NotFunction(args); } else if ("id".equals(name) && arity == 1) { return new IdFunction(args); } else if ("concat".equals(name) && arity > 1) { return new ConcatFunction(args); } else if ("true".equals(name) && arity == 0) { return new TrueFunction(); } else if ("false".equals(name) && arity == 0) { return new FalseFunction(); } else if ("name".equals(name) && (arity == 1 || arity == 0)) { return new NameFunction(args); } else if ("local-name".equals(name) && (arity == 1 || arity == 0)) { return new LocalNameFunction(args); } else if ("namespace-uri".equals(name) && (arity == 1 || arity == 0)) { return new NamespaceUriFunction(args); } else if ("starts-with".equals(name) && arity == 2) { return new StartsWithFunction(args); } else if ("contains".equals(name) && arity == 2) { return new ContainsFunction(args); } else if ("string-length".equals(name) && (arity == 1 || arity == 0)) { return new StringLengthFunction(args); } else if ("translate".equals(name) && arity == 3) { return new TranslateFunction(args); } else if ("normalize-space".equals(name) && (arity == 1 || arity == 0)) { return new NormalizeSpaceFunction(args); } else if ("substring".equals(name) && (arity == 2 || arity == 3)) { return new SubstringFunction(args); } else if ("substring-before".equals(name) && arity == 2) { return new SubstringBeforeFunction(args); } else if ("substring-after".equals(name) && arity == 2) { return new SubstringAfterFunction(args); } else if ("lang".equals(name) && arity == 1) { return new LangFunction(args); } else if ("sum".equals(name) && arity == 1) { return new SumFunction(args); } else if ("floor".equals(name) && arity == 1) { return new FloorFunction(args); } else if ("ceiling".equals(name) && arity == 1) { return new CeilingFunction(args); } else if ("round".equals(name) && arity == 1) { return new RoundFunction(args); } else if (functionResolver != null) { QName qName = QName.valueOf(name); Object function = functionResolver.resolveFunction(qName, arity); if (function != null && function instanceof Function && function instanceof Expr) { Function f = (Function) function; f.setArguments(args); return (Expr) function; } } return new FunctionCall(functionResolver, name, args); } // line 211 "-"// %token constants public static final int LITERAL = 257; public static final int DIGITS = 258; public static final int NAME = 259; public static final int LP = 260; public static final int RP = 261; public static final int LB = 262; public static final int RB = 263; public static final int COMMA = 264; public static final int PIPE = 265; public static final int SLASH = 266; public static final int DOUBLE_SLASH = 267; public static final int EQ = 268; public static final int NE = 269; public static final int GT = 270; public static final int LT = 271; public static final int GTE = 272; public static final int LTE = 273; public static final int PLUS = 274; public static final int MINUS = 275; public static final int AT = 276; public static final int STAR = 277; public static final int DOLLAR = 278; public static final int COLON = 279; public static final int DOUBLE_COLON = 280; public static final int DOT = 281; public static final int DOUBLE_DOT = 282; public static final int ANCESTOR = 283; public static final int ANCESTOR_OR_SELF = 284; public static final int ATTRIBUTE = 285; public static final int CHILD = 286; public static final int DESCENDANT = 287; public static final int DESCENDANT_OR_SELF = 288; public static final int FOLLOWING = 289; public static final int FOLLOWING_SIBLING = 290; public static final int NAMESPACE = 291; public static final int PARENT = 292; public static final int PRECEDING = 293; public static final int PRECEDING_SIBLING = 294; public static final int SELF = 295; public static final int DIV = 296; public static final int MOD = 297; public static final int OR = 298; public static final int AND = 299; public static final int COMMENT = 300; public static final int PROCESSING_INSTRUCTION = 301; public static final int TEXT = 302; public static final int NODE = 303; public static final int UNARY = 304; public static final int yyErrorCode = 256; /** thrown for irrecoverable syntax errors and stack overflow. */ public static class yyException extends java.lang.Exception { public yyException (String message) { super(message); } } /** must be implemented by a scanner object to supply input to the parser. */ public interface yyInput { /** move on to next token. @return false if positioned beyond tokens. @throws IOException on input error. */ boolean advance () throws java.io.IOException; /** classifies current token. Should not be called if advance() returned false. @return current %token or single character. */ int token (); /** associated with current token. Should not be called if advance() returned false. @return value for token(). */ Object value (); } /** simplified error message. @see <a href="#yyerror(java.lang.String, java.lang.String[])">yyerror</a> */ public void yyerror (String message) { yyerror(message, null); } /** (syntax) error message. Can be overwritten to control message format. @param message text to be displayed. @param expected vector of acceptable tokens, if available. */ public void yyerror (String message, String[] expected) { if (expected != null && expected.length > 0) { System.err.print(message+", expecting"); for (int n = 0; n < expected.length; ++ n) System.err.print(" "+expected[n]); System.err.println(); } else System.err.println(message); } /** debugging support, requires the package jay.yydebug. Set to null to suppress debugging messages. *///t protected jay.yydebug.yyDebug yydebug; protected static final int yyFinal = 30; /** index-checked interface to yyName[]. @param token single character or %token value. @return token name or [illegal] or [unknown]. *///t public static final String yyname (int token) {//t if (token < 0 || token > YyNameClass.yyName.length) return "[illegal]";//t String name;//t if ((name = YyNameClass.yyName[token]) != null) return name;//t return "[unknown]";//t } /** computes list of expected tokens on error by tracing the tables. @param state for which to compute the list. @return list of token names. */ protected String[] yyExpecting (int state) { int token, n, len = 0; boolean[] ok = new boolean[YyNameClass.yyName.length]; if ((n = YySindexClass.yySindex[state]) != 0) for (token = n < 0 ? -n : 0; token < YyNameClass.yyName.length && n+token < YyTableClass.yyTable.length; ++ token) if (YyCheckClass.yyCheck[n+token] == token && !ok[token] && YyNameClass.yyName[token] != null) { ++ len; ok[token] = true; } if ((n = YyRindexClass.yyRindex[state]) != 0) for (token = n < 0 ? -n : 0; token < YyNameClass.yyName.length && n+token < YyTableClass.yyTable.length; ++ token) if (YyCheckClass.yyCheck[n+token] == token && !ok[token] && YyNameClass.yyName[token] != null) { ++ len; ok[token] = true; } String result[] = new String[len]; for (n = token = 0; n < len; ++ token) if (ok[token]) result[n++] = YyNameClass.yyName[token]; return result; } /** the generated parser, with debugging messages. Maintains a state and a value stack, currently with fixed maximum size. @param yyLex scanner. @param yydebug debug message writer implementing yyDebug, or null. @return result of the last reduction, if any. @throws yyException on irrecoverable parse error. */ public Object yyparse (yyInput yyLex, Object yydebug)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -