Code

change API: separate functions creating a blur filter, one for a given item, another...
[inkscape.git] / src / dom / xpathparser.h
index 32127f89b0411dae90588a1958556fd8d97aa856..ce565622807996d4e48f7033ea09520e2ef1402b 100644 (file)
-#ifndef __XPATHPARSER_H__\r
-#define __XPATHPARSER_H__\r
-\r
-/**\r
- * Phoebe DOM Implementation.\r
- *\r
- * This is a C++ approximation of the W3C DOM model, which follows\r
- * fairly closely the specifications in the various .idl files, copies of\r
- * which are provided for reference.  Most important is this one:\r
- *\r
- * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html\r
- *\r
- * Authors:\r
- *   Bob Jamison\r
- *\r
- * Copyright (C) 2005 Bob Jamison\r
- *\r
- *  This library is free software; you can redistribute it and/or\r
- *  modify it under the terms of the GNU Lesser General Public\r
- *  License as published by the Free Software Foundation; either\r
- *  version 2.1 of the License, or (at your option) any later version.\r
- *\r
- *  This library is distributed in the hope that it will be useful,\r
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
- *  Lesser General Public License for more details.\r
- *\r
- *  You should have received a copy of the GNU Lesser General Public\r
- *  License along with this library; if not, write to the Free Software\r
- *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r
- */\r
-\r
-\r
-#include <stdio.h>\r
-#include <stdarg.h>\r
-\r
-#include <string>\r
-#include <vector>\r
-\r
-#include "dom.h"\r
-#include "xpathtoken.h"\r
-\r
-namespace org\r
-{\r
-namespace w3c\r
-{\r
-namespace dom\r
-{\r
-namespace xpath\r
-{\r
-\r
-typedef dom::DOMString DOMString;\r
-typedef dom::Node Node;\r
-typedef dom::NodeList  NodeList;\r
-\r
-\r
-\r
-//########################################################################\r
-//# L E X I C A L    D E F I N I T I O N S\r
-//########################################################################\r
-\r
-\r
-typedef struct\r
-{\r
-   int   ival;\r
-   char *sval;\r
-} LookupEntry;\r
-\r
-\r
-\r
-//Note:  in the following definitions, where the starts of\r
-//strings are similar, put the longer definitions first\r
-\r
-/**\r
- *\r
- */\r
-typedef enum\r
-{\r
-    COMMENT,\r
-    TEXT,\r
-    PROCESSING_INSTRUCTION,\r
-    NODE\r
-} NodeType;\r
-\r
-\r
-static LookupEntry nodeTypeTable [] =\r
-{\r
-    {  COMMENT,                "comment"                },\r
-    {  TEXT,                   "text"                   },\r
-    {  PROCESSING_INSTRUCTION, "processing-instruction" },\r
-    {  NODE,                   "node"                   },\r
-    { -1,                      NULL                     }\r
-};\r
-\r
-\r
-/**\r
- *\r
- */\r
-typedef enum\r
-{\r
-    ANCESTOR_OR_SELF,\r
-    ANCESTOR,\r
-    ATTRIBUTE,\r
-    CHILD,\r
-    DESCENDANT_OR_SELF,\r
-    DESCENDANT,\r
-    FOLLOWING_SIBLING,\r
-    FOLLOWING,\r
-    NAMESPACE,\r
-    PARENT,\r
-    PRECEDING_SIBLING,\r
-    PRECEDING,\r
-    SELF\r
-} AxisNameType;\r
-\r
-\r
-static LookupEntry axisNameTable [] =\r
-{\r
-    {  ANCESTOR_OR_SELF,    "ancestor-or-self"  },\r
-    {  ANCESTOR,            "ancestor"          },\r
-    {  ATTRIBUTE,           "attribute"         },\r
-    {  CHILD,               "child"             },\r
-    {  DESCENDANT_OR_SELF,  "descendant-or-self"},\r
-    {  DESCENDANT,          "descendant"        },\r
-    {  FOLLOWING_SIBLING,   "following-sibling" },\r
-    {  FOLLOWING,           "following"         },\r
-    {  NAMESPACE,           "namespace"         },\r
-    {  PARENT,              "parent"            },\r
-    {  PRECEDING_SIBLING,   "preceding-sibling" },\r
-    {  PRECEDING,           "preceding"         },\r
-    {  SELF,                "self"              },\r
-    { -1,                   NULL                }\r
-};\r
-\r
-\r
-/**\r
- *\r
- */\r
-typedef enum\r
-{\r
-    NONE = 0,\r
-    CHAR, //default if none of the below\r
-    //Expr tokens\r
-    LPAREN,\r
-    RPAREN,\r
-    LBRACKET,\r
-    RBRACKET,\r
-    DOUBLE_DOT,\r
-    DOT,\r
-    AMPR,\r
-    COMMA,\r
-    DOUBLE_COLON,\r
-    NAME_TEST,\r
-    NODE_TYPE,\r
-    OPERATOR,\r
-    FUNCTION_NAME,\r
-    AXIS_NAME,\r
-    LITERAL,\r
-    NUMBER,\r
-    VARIABLE_REFERENCE,\r
-    //Operator tokens\r
-    AND,\r
-    OR,\r
-    MOD,\r
-    DIV,\r
-    MULTIPLY,\r
-    DOUBLE_SLASH,\r
-    SLASH,\r
-    PIPE,\r
-    PLUS,\r
-    MINUS,\r
-    EQUALS,\r
-    NOT_EQUALS,\r
-    LESS_THAN_EQUALS,\r
-    LESS_THAN,\r
-    GREATER_THAN_EQUALS,\r
-    GREATER_THAN\r
-} LexTokType;\r
-\r
-\r
-/*\r
-* Be VERY careful that this table matches the LexicalTokenType enum\r
-* declaration above.\r
-*/\r
-static LookupEntry exprTokenTable [] =\r
-{\r
-    {  NONE,                "xxNONExx"          },\r
-    {  CHAR,                "CHAR"              },\r
-    //Expr tokens\r
-    {  LPAREN,              "("                 },\r
-    {  RPAREN,              ")"                 },\r
-    {  LBRACKET,            "["                 },\r
-    {  RBRACKET,            "]"                 },\r
-    {  DOUBLE_DOT,          ".."                },\r
-    {  DOT,                 "."                 },\r
-    {  AMPR,                "@"                 },\r
-    {  COMMA,               ","                 },\r
-    {  DOUBLE_COLON,        "::"                },\r
-    {  NAME_TEST,           "NameTest"          },\r
-    {  NODE_TYPE,           "NodeType"          },\r
-    {  OPERATOR,            "Operator"          },\r
-    {  FUNCTION_NAME,       "FunctionName"      },\r
-    {  AXIS_NAME,           "AxisName"          },\r
-    {  LITERAL,             "Literal"           },\r
-    {  NUMBER,              "Number"            },\r
-    {  VARIABLE_REFERENCE,  "VariableReference" },\r
-    { -1,                   NULL                }\r
-};\r
-\r
-static LookupEntry operatorTable [] =\r
-{\r
-    {  NONE,                "xxNONExx"          },\r
-    //Operator tokens\r
-    {  AND,                 "and"               },\r
-    {  OR,                  "or"                },\r
-    {  MOD,                 "mod"               },\r
-    {  DIV,                 "div"               },\r
-    {  MULTIPLY,            "*"                 },\r
-    {  DOUBLE_SLASH,        "//"                },\r
-    {  SLASH,               "/"                 },\r
-    {  PIPE,                "|"                 },\r
-    {  PLUS,                "+"                 },\r
-    {  MINUS,               "-"                 },\r
-    {  EQUALS,              "="                 },\r
-    {  NOT_EQUALS,          "!="                },\r
-    {  LESS_THAN_EQUALS,    "<="                },\r
-    {  LESS_THAN,           "<"                 },\r
-    {  GREATER_THAN_EQUALS, ">="                },\r
-    {  GREATER_THAN,        ">"                 },\r
-    { -1,                   NULL                }\r
-};\r
-\r
-\r
-/**\r
- *\r
- */\r
-class LexTok\r
-{\r
-public:\r
-    LexTok(const LexTok &tok)\r
-        {\r
-        type     = tok.type;\r
-        location = tok.location;\r
-        sval     = tok.sval;\r
-        dval     = tok.dval;\r
-        ival     = tok.ival;\r
-        }\r
-    LexTok()\r
-        { init(); }\r
-    LexTok(int theType, int loc)\r
-        { init(); type = theType; location = loc;}\r
-    LexTok(int theType, int loc, const DOMString &val)\r
-        { init(); type = theType; location = loc; sval = val; }\r
-    LexTok(int theType, int loc, double val)\r
-        { init(); type = theType; location = loc; dval = val; }\r
-    LexTok(int theType, int loc, long val)\r
-        { init(); type = theType; location = loc; ival = val; }\r
-\r
-    void print()\r
-        {\r
-        if (type == OPERATOR)\r
-            {\r
-            char *tokenStr = "unknown";\r
-            for (LookupEntry *entry = operatorTable; entry->sval ; entry++)\r
-                {\r
-                if (entry->ival == ival)\r
-                    {\r
-                    tokenStr = entry->sval;\r
-                    break;\r
-                    }\r
-                }\r
-            printf("(%s)\n", tokenStr);\r
-            }\r
-        else if (type == NODE_TYPE)\r
-            {\r
-            char *tokenStr = "unknown";\r
-            for (LookupEntry *entry = nodeTypeTable; entry->sval ; entry++)\r
-                {\r
-                if (entry->ival == ival)\r
-                    {\r
-                    tokenStr = entry->sval;\r
-                    break;\r
-                    }\r
-                }\r
-            printf("{{%s}}\n", tokenStr);\r
-            }\r
-        else if (type == AXIS_NAME)\r
-            {\r
-            char *tokenStr = "unknown";\r
-            for (LookupEntry *entry = axisNameTable; entry->sval ; entry++)\r
-                {\r
-                if (entry->ival == ival)\r
-                    {\r
-                    tokenStr = entry->sval;\r
-                    break;\r
-                    }\r
-                }\r
-            printf("{%s}\n", tokenStr);\r
-            }\r
-        else if (type == CHAR)\r
-            printf("'%c'\n", (char)ival);\r
-        else if (type == NAME_TEST)\r
-            printf("\"%s\"\n", sval.c_str());\r
-        else if (type == LITERAL)\r
-            printf("L'%s'\n", sval.c_str());\r
-        else if (type == FUNCTION_NAME)\r
-            printf("%s()\n", sval.c_str());\r
-        else if (type == NUMBER)\r
-            printf("#%f\n", dval);\r
-        else\r
-            {\r
-            char *tokenStr = "unknown";\r
-            for (LookupEntry *entry = exprTokenTable; entry->sval ; entry++)\r
-                {\r
-                if (entry->ival == type)\r
-                    {\r
-                    tokenStr = entry->sval;\r
-                    break;\r
-                    }\r
-                }\r
-            printf("%s\n", tokenStr);\r
-            //printf("%s [%s/%f/%ld]\n", tokenStr, sval.c_str(), dval, ival);\r
-            }\r
-        }\r
-\r
-    int getType()\r
-       { return type; }\r
-    int getLocation()\r
-        { return location; }\r
-    DOMString &getStringValue()\r
-        { return sval; }\r
-    double getDoubleValue()\r
-        { return dval; }\r
-    long getIntValue()\r
-        { return ival; }\r
-\r
-private:\r
-    void  init()\r
-        {\r
-        type     = NONE;\r
-        location = 0;\r
-        dval     = 0.0;\r
-        ival     = 0;\r
-        }\r
-\r
-    int       type;\r
-    int       location;\r
-    DOMString sval;\r
-    double    dval;\r
-    long      ival;\r
-};\r
-\r
-\r
-\r
-\r
-\r
-//########################################################################\r
-//# P A R S E R\r
-//########################################################################\r
-\r
-class XPathParser\r
-{\r
-public:\r
-\r
-    //#################################\r
-    //# CONSTRUCTOR\r
-    //#################################\r
-\r
-    /**\r
-     *\r
-     */\r
-    XPathParser()\r
-        {\r
-        debug = false;\r
-        }\r
-\r
-    /**\r
-     *\r
-     */\r
-    ~XPathParser() {}\r
-\r
-    /**\r
-     *\r
-     */\r
-    bool getDebug()\r
-        { return debug; }\r
-\r
-    /**\r
-     *\r
-     */\r
-    void setDebug(bool val)\r
-        { debug = val; }\r
-\r
-\r
-\r
-    /**\r
-     *  Normally not called directly unless for string parsing testing\r
-     */\r
-    bool parse(const DOMString &str);\r
-\r
-    /**\r
-     * This is the big one. Called by the xpath-dom api to fetch\r
-     * nodes from a DOM tree.\r
-     */\r
-    NodeList evaluate(const Node *root, const DOMString &str);\r
-\r
-\r
-\r
-private:\r
-\r
-    //#################################\r
-    //# MESSAGES\r
-    //#################################\r
-\r
-    /**\r
-     *\r
-     */\r
-    void trace(const char *fmt, ...);\r
-\r
-    /**\r
-     *\r
-     */\r
-    void traceStack(const char *name, int pos, int depth);\r
-\r
-    /**\r
-     *\r
-     */\r
-    void error(const char *fmt, ...);\r
-\r
-    //#################################\r
-    //# LEXICAL  SCANNING\r
-    //#################################\r
-\r
-    /**\r
-     *  Add a lexical token of a given type to the list\r
-     */\r
-    void lexTokAdd(int type, int loc);\r
-    void lexTokAdd(int type, int loc, const DOMString &val);\r
-    void lexTokAdd(int type, int loc, double val);\r
-    void lexTokAdd(int type, int loc, long   val);\r
-\r
-    /**\r
-     *\r
-     */\r
-    void lexicalTokenDump();\r
-\r
-    /**\r
-     *\r
-     */\r
-    LexTok lexTok(int p);\r
-\r
-    /**\r
-     *\r
-     */\r
-    int lexTokType(int p);\r
-\r
-    /**\r
-     *\r
-     */\r
-    int peek(int p);\r
-\r
-    /**\r
-     *\r
-     */\r
-    int get(int p);\r
-\r
-    /**\r
-     *\r
-     */\r
-    int getword(int p, DOMString &str);\r
-\r
-    /**\r
-     *\r
-     */\r
-    int match(int p, const char *str);\r
-\r
-    /**\r
-     *\r
-     */\r
-    int skipwhite(int p);\r
-\r
-    /**\r
-     *\r
-     */\r
-    int getNumber(int p, double &dresult);\r
-\r
-    /**\r
-     *\r
-     */\r
-    int getLiteral(int p, DOMString &result);\r
-\r
-    /**\r
-     *\r
-     */\r
-    int getNameTest(int p0, DOMString &result);\r
-\r
-    /**\r
-     *\r
-     */\r
-    int getNCName(int p0, DOMString &result);\r
-\r
-\r
-\r
-\r
-    /**\r
-     *\r
-     */\r
-    int lexicalScan();\r
-\r
-\r
-    //#################################\r
-    //# GRAMMAR  PARSING\r
-    //#################################\r
-\r
-    /**\r
-     * The grammar definitions marked [1]-[39] are directly\r
-     * from the W3C XPath grammar spacification.\r
-     */\r
-\r
-    /**\r
-     * [1]\r
-     */\r
-    int getLocationPath(int p0, int depth);\r
-\r
-    /**\r
-     * [2]\r
-     */\r
-    int getAbsoluteLocationPath(int p0, int depth);\r
-\r
-    /**\r
-     * [3]\r
-     */\r
-    int getRelativeLocationPath(int p0, int depth);\r
-\r
-    /**\r
-     * [4]\r
-     */\r
-    int getStep(int p0, int depth);\r
-\r
-    /**\r
-     * [5]\r
-     */\r
-    int getAxisSpecifier(int p0, int depth);\r
-\r
-    /**\r
-     * [6]\r
-     */\r
-    int getAxisName(int p0, int depth);\r
-\r
-    /**\r
-     * [7]\r
-     */\r
-    int getNodeTest(int p0, int depth);\r
-\r
-    /**\r
-     * [8]\r
-     */\r
-    int getPredicate(int p0, int depth);\r
-\r
-    /**\r
-     * [9]\r
-     */\r
-    int getPredicateExpr(int p0, int depth);\r
-\r
-    /**\r
-     * [10]\r
-     */\r
-    int getAbbreviatedAbsoluteLocationPath(int p0, int depth);\r
-    /**\r
-     * [11]\r
-     */\r
-    int getAbbreviatedRelativeLocationPath(int p0, int depth);\r
-    /**\r
-     * [12]\r
-     */\r
-    int getAbbreviatedStep(int p0, int depth);\r
-\r
-    /**\r
-     * [13]\r
-     */\r
-    int getAbbreviatedAxisSpecifier(int p0, int depth);\r
-\r
-    /**\r
-     * [14]\r
-     */\r
-    int getExpr(int p0, int depth);\r
-\r
-    /**\r
-     * [15]\r
-     */\r
-    int getPrimaryExpr(int p0, int depth);\r
-\r
-    /**\r
-     * [16]\r
-     */\r
-    int getFunctionCall(int p0, int depth);\r
-\r
-    /**\r
-     * [17]\r
-     */\r
-    int getArgument(int p0, int depth);\r
-\r
-    /**\r
-     * [18]\r
-     */\r
-    int getUnionExpr(int p0, int depth);\r
-\r
-    /**\r
-     * [19]\r
-     */\r
-    int getPathExpr(int p0, int depth);\r
-\r
-    /**\r
-     * [20]\r
-     */\r
-    int getFilterExpr(int p0, int depth);\r
-\r
-    /**\r
-     * [21]\r
-     */\r
-    int getOrExpr(int p0, int depth);\r
-\r
-    /**\r
-     * [22]\r
-     */\r
-    int getAndExpr(int p0, int depth);\r
-\r
-    /**\r
-     * [23]\r
-     */\r
-    int getEqualityExpr(int p0, int depth);\r
-\r
-    /**\r
-     * [24]\r
-     */\r
-    int getRelationalExpr(int p0, int depth);\r
-\r
-    /**\r
-     * [25]\r
-     */\r
-    int getAdditiveExpr(int p0, int depth);\r
-\r
-    /**\r
-     * [26]\r
-     */\r
-    int getMultiplicativeExpr(int p0, int depth);\r
-\r
-    /**\r
-     * [27]\r
-     */\r
-    int getUnaryExpr(int p0, int depth);\r
-\r
-    /**\r
-     * [28]\r
-     */\r
-    int getExprToken(int p0, int depth);\r
-\r
-    /**\r
-     * [29]\r
-     */\r
-    int getLiteral(int p0, int depth);\r
-\r
-    /**\r
-     * [30]\r
-     */\r
-    int getNumber(int p0, int depth);\r
-\r
-    /**\r
-     * [31]\r
-     */\r
-    int getDigits(int p0, int depth);\r
-\r
-    /**\r
-     * [32]\r
-     */\r
-    int getOperator(int p0, int depth);\r
-\r
-    /**\r
-     * [33]\r
-     */\r
-    int getOperatorName(int p0, int depth);\r
-\r
-    /**\r
-     * [34]\r
-     */\r
-    int getMultiplyOperator(int p0, int depth);\r
-\r
-    /**\r
-     * [35]\r
-     */\r
-    int getFunctionName(int p0, int depth);\r
-\r
-    /**\r
-     * [36]\r
-     */\r
-    int getVariableReference(int p0, int depth);\r
-\r
-    /**\r
-     * [37]\r
-     */\r
-    int getNameTest(int p0, int depth);\r
-\r
-    /**\r
-     * [38]\r
-     */\r
-    int getNodeType(int p0, int depth);\r
-\r
-    /**\r
-     * [39]\r
-     */\r
-    int getExprWhitespace(int p0, int depth);\r
-\r
-\r
-\r
-    //#################################\r
-    //# DATA ITEMS\r
-    //#################################\r
-\r
-    /**\r
-     *\r
-     */\r
-    bool debug;\r
-\r
-    /**\r
-     *\r
-     */\r
-    char *parsebuf;\r
-\r
-    /**\r
-     *\r
-     */\r
-    int parselen;\r
-\r
-    /**\r
-     *\r
-     */\r
-    int position;\r
-\r
-    /**\r
-     *\r
-     */\r
-    DOMString numberString;\r
-\r
-    /**\r
-     *\r
-     */\r
-    double number;\r
-\r
-\r
-    /**\r
-     *  The result of the first lexical scan\r
-     */\r
-    std::vector<LexTok> lexicalTokens;\r
-\r
-    /**\r
-     *  The result of parsing.  If parsing was successful, then\r
-     *  this is executable via execute()\r
-     */\r
-    TokenList tokens;\r
-\r
-\r
-\r
-\r
-};\r
-\r
-\r
-\r
-\r
-\r
-\r
-} // namespace xpath\r
-} // namespace dom\r
-} // namespace w3c\r
-} // namespace org\r
-#endif /* __XPATHPARSER_H__ */\r
-//#########################################################################\r
-//# E N D    O F    F I L E\r
-//#########################################################################\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
+#ifndef __XPATHPARSER_H__
+#define __XPATHPARSER_H__
+
+/**
+ * Phoebe DOM Implementation.
+ *
+ * This is a C++ approximation of the W3C DOM model, which follows
+ * fairly closely the specifications in the various .idl files, copies of
+ * which are provided for reference.  Most important is this one:
+ *
+ * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html
+ *
+ * Authors:
+ *   Bob Jamison
+ *
+ * Copyright (C) 2005 Bob Jamison
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library 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 the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+
+#include <stdio.h>
+#include <stdarg.h>
+
+#include <string>
+#include <vector>
+
+#include "dom.h"
+#include "xpathtoken.h"
+
+namespace org
+{
+namespace w3c
+{
+namespace dom
+{
+namespace xpath
+{
+
+typedef dom::DOMString DOMString;
+typedef dom::Node Node;
+typedef dom::NodeList  NodeList;
+
+
+
+//########################################################################
+//# L E X I C A L    D E F I N I T I O N S
+//########################################################################
+
+
+typedef struct
+{
+   int   ival;
+   char *sval;
+} LookupEntry;
+
+
+
+//Note:  in the following definitions, where the starts of
+//strings are similar, put the longer definitions first
+
+/**
+ *
+ */
+typedef enum
+{
+    COMMENT,
+    TEXT,
+    PROCESSING_INSTRUCTION,
+    NODE
+} NodeType;
+
+
+static LookupEntry nodeTypeTable [] =
+{
+    {  COMMENT,                "comment"                },
+    {  TEXT,                   "text"                   },
+    {  PROCESSING_INSTRUCTION, "processing-instruction" },
+    {  NODE,                   "node"                   },
+    { -1,                      NULL                     }
+};
+
+
+/**
+ *
+ */
+typedef enum
+{
+    ANCESTOR_OR_SELF,
+    ANCESTOR,
+    ATTRIBUTE,
+    CHILD,
+    DESCENDANT_OR_SELF,
+    DESCENDANT,
+    FOLLOWING_SIBLING,
+    FOLLOWING,
+    NAMESPACE,
+    PARENT,
+    PRECEDING_SIBLING,
+    PRECEDING,
+    SELF
+} AxisNameType;
+
+
+static LookupEntry axisNameTable [] =
+{
+    {  ANCESTOR_OR_SELF,    "ancestor-or-self"  },
+    {  ANCESTOR,            "ancestor"          },
+    {  ATTRIBUTE,           "attribute"         },
+    {  CHILD,               "child"             },
+    {  DESCENDANT_OR_SELF,  "descendant-or-self"},
+    {  DESCENDANT,          "descendant"        },
+    {  FOLLOWING_SIBLING,   "following-sibling" },
+    {  FOLLOWING,           "following"         },
+    {  NAMESPACE,           "namespace"         },
+    {  PARENT,              "parent"            },
+    {  PRECEDING_SIBLING,   "preceding-sibling" },
+    {  PRECEDING,           "preceding"         },
+    {  SELF,                "self"              },
+    { -1,                   NULL                }
+};
+
+
+/**
+ *
+ */
+typedef enum
+{
+    NONE = 0,
+    CHAR, //default if none of the below
+    //Expr tokens
+    LPAREN,
+    RPAREN,
+    LBRACKET,
+    RBRACKET,
+    DOUBLE_DOT,
+    DOT,
+    AMPR,
+    COMMA,
+    DOUBLE_COLON,
+    NAME_TEST,
+    NODE_TYPE,
+    OPERATOR,
+    FUNCTION_NAME,
+    AXIS_NAME,
+    LITERAL,
+    NUMBER,
+    VARIABLE_REFERENCE,
+    //Operator tokens
+    AND,
+    OR,
+    MOD,
+    DIV,
+    MULTIPLY,
+    DOUBLE_SLASH,
+    SLASH,
+    PIPE,
+    PLUS,
+    MINUS,
+    EQUALS,
+    NOT_EQUALS,
+    LESS_THAN_EQUALS,
+    LESS_THAN,
+    GREATER_THAN_EQUALS,
+    GREATER_THAN
+} LexTokType;
+
+
+/*
+* Be VERY careful that this table matches the LexicalTokenType enum
+* declaration above.
+*/
+static LookupEntry exprTokenTable [] =
+{
+    {  NONE,                "xxNONExx"          },
+    {  CHAR,                "CHAR"              },
+    //Expr tokens
+    {  LPAREN,              "("                 },
+    {  RPAREN,              ")"                 },
+    {  LBRACKET,            "["                 },
+    {  RBRACKET,            "]"                 },
+    {  DOUBLE_DOT,          ".."                },
+    {  DOT,                 "."                 },
+    {  AMPR,                "@"                 },
+    {  COMMA,               ","                 },
+    {  DOUBLE_COLON,        "::"                },
+    {  NAME_TEST,           "NameTest"          },
+    {  NODE_TYPE,           "NodeType"          },
+    {  OPERATOR,            "Operator"          },
+    {  FUNCTION_NAME,       "FunctionName"      },
+    {  AXIS_NAME,           "AxisName"          },
+    {  LITERAL,             "Literal"           },
+    {  NUMBER,              "Number"            },
+    {  VARIABLE_REFERENCE,  "VariableReference" },
+    { -1,                   NULL                }
+};
+
+static LookupEntry operatorTable [] =
+{
+    {  NONE,                "xxNONExx"          },
+    //Operator tokens
+    {  AND,                 "and"               },
+    {  OR,                  "or"                },
+    {  MOD,                 "mod"               },
+    {  DIV,                 "div"               },
+    {  MULTIPLY,            "*"                 },
+    {  DOUBLE_SLASH,        "//"                },
+    {  SLASH,               "/"                 },
+    {  PIPE,                "|"                 },
+    {  PLUS,                "+"                 },
+    {  MINUS,               "-"                 },
+    {  EQUALS,              "="                 },
+    {  NOT_EQUALS,          "!="                },
+    {  LESS_THAN_EQUALS,    "<="                },
+    {  LESS_THAN,           "<"                 },
+    {  GREATER_THAN_EQUALS, ">="                },
+    {  GREATER_THAN,        ">"                 },
+    { -1,                   NULL                }
+};
+
+
+/**
+ *
+ */
+class LexTok
+{
+public:
+    LexTok(const LexTok &tok)
+        {
+        type     = tok.type;
+        location = tok.location;
+        sval     = tok.sval;
+        dval     = tok.dval;
+        ival     = tok.ival;
+        }
+    LexTok()
+        { init(); }
+    LexTok(int theType, int loc)
+        { init(); type = theType; location = loc;}
+    LexTok(int theType, int loc, const DOMString &val)
+        { init(); type = theType; location = loc; sval = val; }
+    LexTok(int theType, int loc, double val)
+        { init(); type = theType; location = loc; dval = val; }
+    LexTok(int theType, int loc, long val)
+        { init(); type = theType; location = loc; ival = val; }
+
+    void print()
+        {
+        if (type == OPERATOR)
+            {
+            char *tokenStr = "unknown";
+            for (LookupEntry *entry = operatorTable; entry->sval ; entry++)
+                {
+                if (entry->ival == ival)
+                    {
+                    tokenStr = entry->sval;
+                    break;
+                    }
+                }
+            printf("(%s)\n", tokenStr);
+            }
+        else if (type == NODE_TYPE)
+            {
+            char *tokenStr = "unknown";
+            for (LookupEntry *entry = nodeTypeTable; entry->sval ; entry++)
+                {
+                if (entry->ival == ival)
+                    {
+                    tokenStr = entry->sval;
+                    break;
+                    }
+                }
+            printf("{{%s}}\n", tokenStr);
+            }
+        else if (type == AXIS_NAME)
+            {
+            char *tokenStr = "unknown";
+            for (LookupEntry *entry = axisNameTable; entry->sval ; entry++)
+                {
+                if (entry->ival == ival)
+                    {
+                    tokenStr = entry->sval;
+                    break;
+                    }
+                }
+            printf("{%s}\n", tokenStr);
+            }
+        else if (type == CHAR)
+            printf("'%c'\n", (char)ival);
+        else if (type == NAME_TEST)
+            printf("\"%s\"\n", sval.c_str());
+        else if (type == LITERAL)
+            printf("L'%s'\n", sval.c_str());
+        else if (type == FUNCTION_NAME)
+            printf("%s()\n", sval.c_str());
+        else if (type == NUMBER)
+            printf("#%f\n", dval);
+        else
+            {
+            char *tokenStr = "unknown";
+            for (LookupEntry *entry = exprTokenTable; entry->sval ; entry++)
+                {
+                if (entry->ival == type)
+                    {
+                    tokenStr = entry->sval;
+                    break;
+                    }
+                }
+            printf("%s\n", tokenStr);
+            //printf("%s [%s/%f/%ld]\n", tokenStr, sval.c_str(), dval, ival);
+            }
+        }
+
+    int getType()
+       { return type; }
+    int getLocation()
+        { return location; }
+    DOMString &getStringValue()
+        { return sval; }
+    double getDoubleValue()
+        { return dval; }
+    long getIntValue()
+        { return ival; }
+
+private:
+    void  init()
+        {
+        type     = NONE;
+        location = 0;
+        dval     = 0.0;
+        ival     = 0;
+        }
+
+    int       type;
+    int       location;
+    DOMString sval;
+    double    dval;
+    long      ival;
+};
+
+
+
+
+
+//########################################################################
+//# P A R S E R
+//########################################################################
+
+class XPathParser
+{
+public:
+
+    //#################################
+    //# CONSTRUCTOR
+    //#################################
+
+    /**
+     *
+     */
+    XPathParser()
+        {
+        debug = false;
+        }
+
+    /**
+     *
+     */
+    ~XPathParser() {}
+
+    /**
+     *
+     */
+    bool getDebug()
+        { return debug; }
+
+    /**
+     *
+     */
+    void setDebug(bool val)
+        { debug = val; }
+
+
+
+    /**
+     *  Normally not called directly unless for string parsing testing
+     */
+    bool parse(const DOMString &str);
+
+    /**
+     * This is the big one. Called by the xpath-dom api to fetch
+     * nodes from a DOM tree.
+     */
+    NodeList evaluate(const NodePtr root, const DOMString &str);
+
+
+
+private:
+
+    //#################################
+    //# MESSAGES
+    //#################################
+
+    /**
+     *
+     */
+    void trace(const char *fmt, ...);
+
+    /**
+     *
+     */
+    void traceStack(const char *name, int pos, int depth);
+
+    /**
+     *
+     */
+    void error(const char *fmt, ...);
+
+    //#################################
+    //# LEXICAL  SCANNING
+    //#################################
+
+    /**
+     *  Add a lexical token of a given type to the list
+     */
+    void lexTokAdd(int type, int loc);
+    void lexTokAdd(int type, int loc, const DOMString &val);
+    void lexTokAdd(int type, int loc, double val);
+    void lexTokAdd(int type, int loc, long   val);
+
+    /**
+     *
+     */
+    void lexicalTokenDump();
+
+    /**
+     *
+     */
+    LexTok lexTok(int p);
+
+    /**
+     *
+     */
+    int lexTokType(int p);
+
+    /**
+     *
+     */
+    int peek(int p);
+
+    /**
+     *
+     */
+    int get(int p);
+
+    /**
+     *
+     */
+    int getword(int p, DOMString &str);
+
+    /**
+     *
+     */
+    int match(int p, const char *str);
+
+    /**
+     *
+     */
+    int skipwhite(int p);
+
+    /**
+     *
+     */
+    int getNumber(int p, double &dresult);
+
+    /**
+     *
+     */
+    int getLiteral(int p, DOMString &result);
+
+    /**
+     *
+     */
+    int getNameTest(int p0, DOMString &result);
+
+    /**
+     *
+     */
+    int getNCName(int p0, DOMString &result);
+
+
+
+
+    /**
+     *
+     */
+    int lexicalScan();
+
+
+    //#################################
+    //# GRAMMAR  PARSING
+    //#################################
+
+    /**
+     * Add a newly derived token to the token list;
+     */
+    void tokAdd(const Token &token);
+
+    void tokAdd(int type);
+
+    void tokAdd(int type, long val);
+
+    void tokAdd(int type, double val);
+
+    void tokAdd(int type, const DOMString &val);
+
+
+    /**
+     * The grammar definitions marked [1]-[39] are directly
+     * from the W3C XPath grammar spacification.
+     */
+
+    /**
+     * [1]
+     */
+    int getLocationPath(int p0, int depth);
+
+    /**
+     * [2]
+     */
+    int getAbsoluteLocationPath(int p0, int depth);
+
+    /**
+     * [3]
+     */
+    int getRelativeLocationPath(int p0, int depth);
+
+    /**
+     * [4]
+     */
+    int getStep(int p0, int depth);
+
+    /**
+     * [5]
+     */
+    int getAxisSpecifier(int p0, int depth);
+
+    /**
+     * [6]
+     */
+    int getAxisName(int p0, int depth);
+
+    /**
+     * [7]
+     */
+    int getNodeTest(int p0, int depth);
+
+    /**
+     * [8]
+     */
+    int getPredicate(int p0, int depth);
+
+    /**
+     * [9]
+     */
+    int getPredicateExpr(int p0, int depth);
+
+    /**
+     * [10]
+     */
+    int getAbbreviatedAbsoluteLocationPath(int p0, int depth);
+    /**
+     * [11]
+     */
+    int getAbbreviatedRelativeLocationPath(int p0, int depth);
+    /**
+     * [12]
+     */
+    int getAbbreviatedStep(int p0, int depth);
+
+    /**
+     * [13]
+     */
+    int getAbbreviatedAxisSpecifier(int p0, int depth);
+
+    /**
+     * [14]
+     */
+    int getExpr(int p0, int depth);
+
+    /**
+     * [15]
+     */
+    int getPrimaryExpr(int p0, int depth);
+
+    /**
+     * [16]
+     */
+    int getFunctionCall(int p0, int depth);
+
+    /**
+     * [17]
+     */
+    int getArgument(int p0, int depth);
+
+    /**
+     * [18]
+     */
+    int getUnionExpr(int p0, int depth);
+
+    /**
+     * [19]
+     */
+    int getPathExpr(int p0, int depth);
+
+    /**
+     * [20]
+     */
+    int getFilterExpr(int p0, int depth);
+
+    /**
+     * [21]
+     */
+    int getOrExpr(int p0, int depth);
+
+    /**
+     * [22]
+     */
+    int getAndExpr(int p0, int depth);
+
+    /**
+     * [23]
+     */
+    int getEqualityExpr(int p0, int depth);
+
+    /**
+     * [24]
+     */
+    int getRelationalExpr(int p0, int depth);
+
+    /**
+     * [25]
+     */
+    int getAdditiveExpr(int p0, int depth);
+
+    /**
+     * [26]
+     */
+    int getMultiplicativeExpr(int p0, int depth);
+
+    /**
+     * [27]
+     */
+    int getUnaryExpr(int p0, int depth);
+
+    /**
+     * [28]
+     */
+    int getExprToken(int p0, int depth);
+
+    /**
+     * [29]
+     */
+    int getLiteral(int p0, int depth);
+
+    /**
+     * [30]
+     */
+    int getNumber(int p0, int depth);
+
+    /**
+     * [31]
+     */
+    int getDigits(int p0, int depth);
+
+    /**
+     * [32]
+     */
+    int getOperator(int p0, int depth);
+
+    /**
+     * [33]
+     */
+    int getOperatorName(int p0, int depth);
+
+    /**
+     * [34]
+     */
+    int getMultiplyOperator(int p0, int depth);
+
+    /**
+     * [35]
+     */
+    int getFunctionName(int p0, int depth);
+
+    /**
+     * [36]
+     */
+    int getVariableReference(int p0, int depth);
+
+    /**
+     * [37]
+     */
+    int getNameTest(int p0, int depth);
+
+    /**
+     * [38]
+     */
+    int getNodeType(int p0, int depth);
+
+    /**
+     * [39]
+     */
+    int getExprWhitespace(int p0, int depth);
+
+
+
+    //#################################
+    //# DATA ITEMS
+    //#################################
+
+    /**
+     *
+     */
+    bool debug;
+
+    /**
+     *
+     */
+    char *parsebuf;
+
+    /**
+     *
+     */
+    int parselen;
+
+    /**
+     *
+     */
+    int position;
+
+    /**
+     *
+     */
+    DOMString numberString;
+
+    /**
+     *
+     */
+    double number;
+
+
+    /**
+     *  The result of the first lexical scan
+     */
+    std::vector<LexTok> lexicalTokens;
+
+    /**
+     *  The result of parsing.  If parsing was successful, then
+     *  this is executable via execute()
+     */
+    TokenList tokens;
+
+
+
+
+};
+
+
+
+
+
+
+} // namespace xpath
+} // namespace dom
+} // namespace w3c
+} // namespace org
+#endif /* __XPATHPARSER_H__ */
+//#########################################################################
+//# E N D    O F    F I L E
+//#########################################################################
+
+
+
+
+
+
+
+