xpath.jjt
来自「jsr170接口的java实现。是个apache的开源项目。」· JJT 代码 · 共 2,736 行 · 第 1/5 页
JJT
2,736 行
/* * Generated using "maven jackrabbit:generage-xpath-parser-jjt" from the * the following files with the following copyright and license notices: * * javacc.xsl, jjtree.xsl, and strip.xsl: * -------------------------------------- * Copyright (c) 2002 World Wide Web Consortium, * (Massachusetts Institute of Technology, Institut National de * Recherche en Informatique et en Automatique, Keio University). All * Rights Reserved. This program is distributed under the W3C's Software * Intellectual Property License. This program is distributed in the * hope that it will be useful, but WITHOUT ANY WARRANTY; without even * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. * See W3C License http://www.w3.org/Consortium/Legal/ for more details. * * jjtree-jackrabbit.xsl: * ---------------------- * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * xpath-grammar.xml: * ------------------ * Copyright (c) 2002 W3C(r) (http://www.w3.org/) (MIT (http://www.lcs.mit.edu/), * INRIA (http://www.inria.fr/), Keio (http://www.keio.ac.jp/)), * All Rights Reserved. * See http://www.w3.org/Consortium/Legal/ipr-notice-20000612#Copyright. * W3C liability * (http://www.w3.org/Consortium/Legal/ipr-notice-20000612#Legal_Disclaimer), * trademark * (http://www.w3.org/Consortium/Legal/ipr-notice-20000612#W3C_Trademarks), * document use * (http://www.w3.org/Consortium/Legal/copyright-documents-19990405), * and software licensing rules * (http://www.w3.org/Consortium/Legal/copyright-software-19980720) * apply. */options { STATIC = false; MULTI=false; VISITOR=true ; // invokes the JJTree Visitor support NODE_SCOPE_HOOK=false; NODE_USES_PARSER=true; } PARSER_BEGIN(XPath) package org.apache.jackrabbit.core.query.xpath; import java.io.*; import java.util.Stack;import java.util.Vector;public class XPath { boolean m_isMatchPattern = false; boolean isStep = false; Stack binaryTokenStack = new Stack(); public Node createNode(int id) { return null; } public static void main(String args[]) throws Exception { int numberArgsLeft = args.length; int argsStart = 0; boolean isMatchParser = false; if(numberArgsLeft > 0) { if(args[argsStart].equals("-match")) { isMatchParser = true; System.out.println("Match Pattern Parser"); argsStart++; numberArgsLeft--; } } if(numberArgsLeft > 0) { try { final boolean dumpTree = true; if(args[0].endsWith(".xquery")) { System.out.println("Running test for: "+args[0]); File file = new File(args[0]); FileInputStream fis = new FileInputStream(file); XPath parser = new XPath(fis); SimpleNode tree = parser.XPath2(); if(dumpTree) tree.dump("|") ; } else { for(int i = argsStart; i < args.length; i++) { System.out.println(); System.out.println("Test["+i+"]: "+args[i]); XPath parser = new XPath(new java.io.StringBufferInputStream(args[i])); SimpleNode tree; if(isMatchParser) { tree = parser.XPath2(); } else { tree = parser.XPath2(); } ((SimpleNode)tree.jjtGetChild(0)).dump("|") ; } System.out.println("Success!!!!"); } } catch(ParseException pe) { System.err.println(pe.getMessage()); } return; } java.io.DataInputStream dinput = new java.io.DataInputStream(System.in); while(true) { try { System.err.println("Type Expression: "); String input = dinput.readLine(); if(null == input || input.trim().length() == 0) break; XPath parser = new XPath(new java.io.StringBufferInputStream(input)); SimpleNode tree; if(isMatchParser) { tree = parser.XPath2(); } else { tree = parser.XPath2(); } ((SimpleNode)tree.jjtGetChild(0)).dump("|") ; } catch(ParseException pe) { System.err.println(pe.getMessage()); } catch(Exception e) { System.err.println(e.getMessage()); } } } } PARSER_END(XPath) TOKEN_MGR_DECLS : { private Stack stateStack = new Stack(); // private Vector persistentLexStates = new Vector(); static final int PARENMARKER = 2000; /** * Push the current state onto the state stack. */ private void pushState() { // System.err.println("pushing: "+curLexState); printLinePos(); stateStack.addElement(new Integer(curLexState)); } /** * Push the given state onto the state stack. * @param state Must be a valid state. */ private void pushState(int state) { stateStack.push(new Integer(state)); } /** * Pop the state on the state stack, and switch to that state. */ private void popState() { if (stateStack.size() == 0) { printLinePos(); } int nextState = ((Integer) stateStack.pop()).intValue(); // System.err.println("pop "+nextState); printLinePos(); if(nextState == PARENMARKER) printLinePos(); SwitchTo(nextState); } /** * Push the given state onto the state stack. * @param state Must be a valid state. */ private boolean isState(int state) { for (int i = 0; i < stateStack.size(); i++) { if(((Integer) stateStack.elementAt(i)).intValue() == state) { return true; } } return false; } /** * Push a parenthesis state. This pushes, in addition to the * lexical state value, a special marker that lets * resetParenStateOrSwitch(int state) * know if it should pop and switch. Used for the comma operator. */ private void pushParenState(int commaState, int rparState) { stateStack.push(new Integer(rparState)); stateStack.push(new Integer(commaState)); stateStack.push(new Integer(PARENMARKER)); SwitchTo(commaState); } /** * Print the current line position. */ public void printLinePos() { System.err.println("Line: " + input_stream.getEndLine()); }} SimpleNode XPath2() : {} { QueryList()<EOF> { return jjtThis ; } } <DEFAULT>TOKEN :{ < IntegerLiteral : <Digits> > : OPERATOR}<DEFAULT>TOKEN :{ < DecimalLiteral : (("." <Digits>) | (<Digits> "." (["0" - "9"])*)) > : OPERATOR}<DEFAULT>TOKEN :{ < DoubleLiteral : (("." <Digits>) | (<Digits> ("." (["0" - "9"])*)?)) ["e", "E"] (["+", "-"])? <Digits> > : OPERATOR}<DEFAULT, OPERATOR>TOKEN :{ < StringLiteral : (("\"" ((("\"" "\"") | ~["\""]))* "\"") | ("'" ((("'" "'") | ~["'"]))* "'")) > : OPERATOR}<KINDTESTFORPI>TOKEN :{ < StringLiteralForKindTest : (("\"" ((("\"" "\"") | ~["\""]))* "\"") | ("'" ((("'" "'") | ~["'"]))* "'")) > : KINDTESTFORPI}<DEFAULT>TOKEN :{ < XQueryVersion : "xquery" (<skip_>)* "version" > : XQUERYVERSION}<XQUERYVERSION>TOKEN :{ < StringLiteralForVersion : (("\"" ((("\"" "\"") | ~["\""]))* "\"") | ("'" ((("'" "'") | ~["'"]))* "'")) > : XQUERYVERSION}<XQUERYVERSION>TOKEN :{ < XQueryEncoding : "encoding" > : XQUERYVERSION}<DEFAULT, ITEMTYPE>TOKEN :{ < AtStringLiteral : "at" (<skip_>)* <URLLiteral> > : DEFAULT}<NAMESPACEDECL, NAMESPACEKEYWORD>TOKEN :{ < URLLiteral : (("\"" ((("\"" "\"") | ~["\""]))* "\"") | ("'" ((("'" "'") | ~["'"]))* "'")) > : DEFAULT}<DEFAULT>TOKEN :{ < ModuleNamespace : "module" (<skip_>)* "namespace" > : NAMESPACEDECL}<DEFAULT, OPERATOR, KINDTEST, NAMESPACEDECL, XMLSPACE_DECL, SINGLETYPE, ITEMTYPE, NAMESPACEKEYWORD, VARNAME, OCCURRENCEINDICATOR, CLOSEKINDTEST, XQUERYVERSION>SKIP:{ < <skip_>>}TOKEN :{ < #skip_ : (((<WhitespaceChar>)+ )) >}<OCCURRENCEINDICATOR>SKIP :{ < NotOccurrenceIndicator : ~["*", "?", "+"] > { input_stream.backup(1); } : OPERATOR}<DEFAULT>TOKEN :{ < ProcessingInstructionStart : "<?" > { pushState(OPERATOR); } : PROCESSING_INSTRUCTION}<ELEMENT_CONTENT>TOKEN :{ < ProcessingInstructionStartForElementContent : "<?" > { pushState(); } : PROCESSING_INSTRUCTION}<PROCESSING_INSTRUCTION, PROCESSING_INSTRUCTION_CONTENT>TOKEN :{ < ProcessingInstructionEnd : "?>" > { popState(); }}<DEFAULT>TOKEN :{ < AxisChild : "child" (<skip_>)* "::" > : DEFAULT}<DEFAULT>TOKEN :{ < AxisDescendant : "descendant" (<skip_>)* "::" > : DEFAULT}<DEFAULT>TOKEN :{ < AxisParent : "parent" (<skip_>)* "::" > : DEFAULT}<DEFAULT>TOKEN :{ < AxisAttribute : "attribute" (<skip_>)* "::" > : DEFAULT}<DEFAULT>TOKEN :{ < AxisSelf : "self" (<skip_>)* "::" > : DEFAULT}<DEFAULT>TOKEN :{ < AxisDescendantOrSelf : "descendant-or-self" (<skip_>)* "::" > : DEFAULT}<DEFAULT>TOKEN :{ < AxisAncestor : "ancestor" (<skip_>)* "::" > : DEFAULT}<DEFAULT>TOKEN :{ < AxisFollowingSibling : "following-sibling" (<skip_>)* "::" > : DEFAULT}<DEFAULT>TOKEN :{ < AxisPrecedingSibling : "preceding-sibling" (<skip_>)* "::" > : DEFAULT}<DEFAULT>TOKEN :{ < AxisFollowing : "following" (<skip_>)* "::" > : DEFAULT}<DEFAULT>TOKEN :{ < AxisPreceding : "preceding" (<skip_>)* "::" > : DEFAULT}<DEFAULT>TOKEN :{ < AxisAncestorOrSelf : "ancestor-or-self" (<skip_>)* "::" > : DEFAULT}<DEFAULT>TOKEN :{ < DefineFunction : "declare" (<skip_>)+ "function" > : DEFAULT}<DEFAULT>TOKEN :{ < DeclareOrdering : "declare" (<skip_>)+ "ordering" > : OPERATOR}<OPERATOR>TOKEN :{ < Ordered : "ordered" > : DEFAULT}<OPERATOR>TOKEN :{ < Unordered : "unordered" > : DEFAULT}<DEFAULT>TOKEN :{ < DeclareDefaultOrderingEmpty : "declare" (<skip_>)+ "default" (<skip_>)+ "order" > : OPERATOR}<DEFAULT>TOKEN :{ < DeclareInheritNamespaces : "declare" (<skip_>)+ "inherit-namespaces" > : OPERATOR}<OPERATOR>TOKEN :{ < Yes : "yes" > : DEFAULT}<OPERATOR>TOKEN :{ < No : "no" > : DEFAULT}<OPERATOR, ITEMTYPE>TOKEN :{ < External : "external" > : DEFAULT}<OPERATOR, ITEMTYPE>TOKEN :{ < Or : "or" > : DEFAULT}<OPERATOR, ITEMTYPE>TOKEN :{ < And : "and" > : DEFAULT}<OPERATOR, ITEMTYPE>TOKEN :{ < Div : "div" > : DEFAULT}<OPERATOR, ITEMTYPE>TOKEN :{ < Idiv : "idiv" > : DEFAULT}<OPERATOR, ITEMTYPE>TOKEN :{ < Mod : "mod" > : DEFAULT}<OPERATOR>TOKEN :{ < Multiply : "*" > : DEFAULT}<OPERATOR, ITEMTYPE>TOKEN :{ < In : "in" > : DEFAULT}<PROCESSING_INSTRUCTION>TOKEN :{ < PITarget : <NCName> > : PROCESSING_INSTRUCTION}TOKEN :{ < #Prefix : <NCName> >}TOKEN :{
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?