+++ /dev/null
-/*--------------------------------------------------------------------------\r
- * Copyright 2009 Taro L. Saito\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *--------------------------------------------------------------------------*/\r
-//--------------------------------------\r
-// XerialJ\r
-//\r
-// XPathExpr.java\r
-// Since: Sep 29, 2009 2:26:59 PM\r
-//\r
-// $URL$\r
-// $Author$\r
-//--------------------------------------\r
-package org.xerial.lens.relation.lang;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import org.antlr.runtime.ANTLRStringStream;\r
-import org.antlr.runtime.CommonTokenStream;\r
-import org.antlr.runtime.RecognitionException;\r
-import org.antlr.runtime.tree.Tree;\r
-import org.xerial.core.XerialErrorCode;\r
-import org.xerial.core.XerialException;\r
-import org.xerial.lens.Lens;\r
-import org.xerial.lens.relation.query.impl.XPathLexer;\r
-import org.xerial.lens.relation.query.impl.XPathParser;\r
-import org.xerial.lens.relation.query.impl.XPathParser.xpath_return;\r
-import org.xerial.util.antlr.ANTLRUtil;\r
-import org.xerial.util.log.Logger;\r
-\r
-/**\r
- * XPath expression\r
- * \r
- * @author leo\r
- * \r
- */\r
-public class XPathExpr {\r
-\r
- private static Logger _logger = Logger.getLogger(XPathExpr.class);\r
-\r
- public static enum Axis {\r
- Relative, PC, AD\r
- }\r
-\r
- public static class Step {\r
- public String name;\r
- public Axis axis = Axis.Relative;\r
- public List<Step> step = new ArrayList<Step>();\r
- public List<Predicate> predicate = new ArrayList<Predicate>();\r
- }\r
-\r
- public static class Predicate {\r
- public Step step;\r
- }\r
-\r
- public Step step;\r
-\r
- public static XPathExpr parse(String xpathExpr) throws XerialException {\r
- XPathLexer lexer = new XPathLexer(new ANTLRStringStream(xpathExpr));\r
- CommonTokenStream token = new CommonTokenStream(lexer);\r
- XPathParser parser = new XPathParser(token);\r
-\r
- try {\r
- xpath_return r = parser.xpath();\r
-\r
- if (_logger.isDebugEnabled()) {\r
- // _logger.debug(ANTLRUtil.prettyPrintTokenList(token.getTokens(), ANTLRUtil\r
- // .getTokenTable(XPathLexer.class, "XPath.tokens")));\r
- _logger.debug(ANTLRUtil.parseTree((Tree) r.getTree(), XPathParser.tokenNames));\r
- }\r
-\r
- return Lens.loadANTLRParseTree(XPathExpr.class, (Tree) r.getTree(),\r
- XPathParser.tokenNames);\r
- }\r
- catch (RecognitionException e) {\r
- throw new XerialException(XerialErrorCode.PARSE_ERROR, e);\r
- }\r
-\r
- }\r
-}\r