/*
 * Copyright (C) 2009 JavaRosa
 *
 * Licensed 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.
 */

package org.javarosa.xpath;

import org.javarosa.xpath.expr.XPathExpression;
import org.javarosa.xpath.parser.Lexer;
import org.javarosa.xpath.parser.Parser;
import org.javarosa.xpath.parser.XPathSyntaxException;

public class XPathParseTool {
    public static final String[] xpathClasses = {
            "org.javarosa.xpath.expr.XPathArithExpr",
            "org.javarosa.xpath.expr.XPathBoolExpr",
            "org.javarosa.xpath.expr.XPathCmpExpr",
            "org.javarosa.xpath.expr.XPathEqExpr",
            "org.javarosa.xpath.expr.XPathFilterExpr",
            "org.javarosa.xpath.expr.XPathFuncExpr",
            "org.javarosa.xpath.expr.XPathNumericLiteral",
            "org.javarosa.xpath.expr.XPathNumNegExpr",
            "org.javarosa.xpath.expr.XPathPathExpr",
            "org.javarosa.xpath.expr.XPathStringLiteral",
            "org.javarosa.xpath.expr.XPathUnionExpr",
            "org.javarosa.xpath.expr.XPathVariableReference"
    };

    public static XPathExpression parseXPath(String xpath) throws XPathSyntaxException {
        return Parser.parse(Lexer.lex(xpath));
    }

    //for running from command line
//    public static void main (String[] args) {
//        String expr = args[0];
//        Vector tokens;
//        ASTNode root;
//
//        System.out.println(expr + " ...");
//
//        try {
//            tokens = Lexer.lex(expr);
//            root = Parser.buildParseTree(tokens);
//        } catch (XPathSyntaxException xpse) {
//            System.out.println("   ...syntax error");
//            return;
//        }
//
//        System.out.print("   [");
//        for (int i = 0; i < tokens.size(); i++) {
//            System.out.print(((Token)tokens.elementAt(i)).toString());
//            if (i < tokens.size() - 1)
//                System.out.print(" ");
//        }
//        System.out.println("]");
//
//        root.print();
//    }

}

@@ -1,597 +1,4 @@
-/*%0A * Copyright (C) 2009 JavaRosa%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22); you may not%0A * use this file except in compliance with the License. You may obtain a copy of%0A * the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS, WITHOUT%0A * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the%0A * License for the specific language governing permissions and limitations under%0A * the License.%0A */%0A%0A
 pack
@@ -1099,799 +1099,6 @@
   %7D%0A
-%0A    //for running from command line%0A//    public static void main (String%5B%5D args) %7B%0A//        String expr = args%5B0%5D;%0A//        Vector tokens;%0A//        ASTNode root;%0A//%0A//        System.out.println(expr + %22 ...%22);%0A//%0A//        try %7B%0A//            tokens = Lexer.lex(expr);%0A//            root = Parser.buildParseTree(tokens);%0A//        %7D catch (XPathSyntaxException xpse) %7B%0A//            System.out.println(%22   ...syntax error%22);%0A//            return;%0A//        %7D%0A//%0A//        System.out.print(%22   %5B%22);%0A//        for (int i = 0; i %3C tokens.size(); i++) %7B%0A//            System.out.print(((Token)tokens.elementAt(i)).toString());%0A//            if (i %3C tokens.size() - 1)%0A//                System.out.print(%22 %22);%0A//        %7D%0A//        System.out.println(%22%5D%22);%0A//%0A//        root.print();%0A//    %7D%0A%0A
 %7D%0A

remove commented out code