diff --git a/src/dom/xpathparser.h b/src/dom/xpathparser.h
--- a/src/dom/xpathparser.h
+++ b/src/dom/xpathparser.h
* Authors:
* Bob Jamison
*
- * Copyright (C) 2005 Bob Jamison
+ * Copyright (C) 2005-2007 Bob Jamison
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
#include <vector>
#include "dom.h"
+#include "xpathtoken.h"
namespace org
{
typedef struct
{
int ival;
- char *sval;
+ char const *sval;
} LookupEntry;
sval = tok.sval;
dval = tok.dval;
ival = tok.ival;
- }
- LexTok(int theType, int loc)
- { init(); type = theType; location = loc;}
+ }
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)
{
if (type == OPERATOR)
{
- char *tokenStr = "unknown";
- for (LookupEntry *entry = operatorTable; entry->sval ; entry++)
+ char const *tokenStr = "unknown";
+ for (LookupEntry const *entry = operatorTable; entry->sval ; entry++)
{
if (entry->ival == ival)
{
}
else if (type == NODE_TYPE)
{
- char *tokenStr = "unknown";
+ char const *tokenStr = "unknown";
for (LookupEntry *entry = nodeTypeTable; entry->sval ; entry++)
{
if (entry->ival == ival)
}
else if (type == AXIS_NAME)
{
- char *tokenStr = "unknown";
+ char const *tokenStr = "unknown";
for (LookupEntry *entry = axisNameTable; entry->sval ; entry++)
{
if (entry->ival == ival)
printf("#%f\n", dval);
else
{
- char *tokenStr = "unknown";
+ char const *tokenStr = "unknown";
for (LookupEntry *entry = exprTokenTable; entry->sval ; entry++)
{
if (entry->ival == type)
{
type = NONE;
location = 0;
- sval = "";
dval = 0.0;
ival = 0;
}
-
+
int type;
int location;
DOMString sval;
-//########################################################################
-//# G R A M M A T I C A L T O K E N S
-//########################################################################
-
-typedef enum
-{
- TOK_NONE,
- TOK_ABSOLUTE,
- TOK_RELATIVE,
- TOK_STEP,
- TOK_EXPR
-} TokenTypes;
-
-
-/**
- *
- */
-class Token
-{
-public:
- Token()
- { init(); }
-
- Token(const Token &other)
- {
- init();
- type = other.type;
- }
-
- Token(int theType)
- {
- init();
- type = theType;
- }
-
- ~Token() {}
-
-
-private:
-
- void init()
- {
- type = TOK_NONE;
- }
-
- int type;
-
-
-};
-
-
-
-
-
//########################################################################
//# P A R S E R
*/
XPathParser()
{
- debug = false;
+ debug = false;
}
/**
/**
*
*/
- virtual bool getDebug()
+ bool getDebug()
{ return debug; }
/**
*
*/
- virtual void setDebug(bool val)
+ void setDebug(bool val)
{ debug = val; }
/**
* Normally not called directly unless for string parsing testing
*/
- virtual bool parse(const DOMString &str);
-
- /**
- * Normally not called directly except for testing.
- */
- virtual NodeList execute(const Node *root, std::vector<Token> &toks);
+ bool parse(const DOMString &str);
/**
* This is the big one. Called by the xpath-dom api to fetch
* nodes from a DOM tree.
*/
- virtual NodeList evaluate(const Node *root, const DOMString &str);
+ NodeList evaluate(const NodePtr root, const DOMString &str);
/**
*
*/
- virtual void trace(const char *fmt, ...);
+ void trace(const char *fmt, ...)
+ #ifdef G_GNUC_PRINTF
+ G_GNUC_PRINTF(2, 3)
+ #endif
+ ;
/**
*
*/
- virtual void traceStack(const char *name, int pos, int depth);
+ void traceStack(const char *name, int pos, int depth);
/**
*
*/
- virtual void error(const char *fmt, ...);
+ void error(const char *fmt, ...)
+ #ifdef G_GNUC_PRINTF
+ G_GNUC_PRINTF(2, 3)
+ #endif
+ ;
//#################################
//# LEXICAL SCANNING
/**
* Add a lexical token of a given type to the list
*/
- virtual void lexTokAdd(int type, int loc);
- virtual void lexTokAdd(int type, int loc, const DOMString &val);
- virtual void lexTokAdd(int type, int loc, double val);
- virtual void lexTokAdd(int type, int loc, long val);
+ 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);
/**
*
*/
- virtual void lexicalTokenDump();
+ void lexicalTokenDump();
/**
*
*/
- virtual LexTok lexTok(int p);
+ LexTok lexTok(int p);
/**
*
*/
- virtual int lexTokType(int p);
+ int lexTokType(int p);
/**
*
*/
- virtual int peek(int p);
+ int peek(int p);
/**
*
*/
- virtual int get(int p);
+ int get(int p);
/**
*
*/
- virtual int getword(int p, DOMString &str);
+ int getword(int p, DOMString &str);
/**
*
*/
- virtual int match(int p, const char *str);
+ int match(int p, const char *str);
/**
*
*/
- virtual int skipwhite(int p);
+ int skipwhite(int p);
/**
*
*/
- virtual int getNumber(int p, double &dresult);
+ int getNumber(int p, double &dresult);
/**
*
*/
- virtual int getLiteral(int p, DOMString &result);
+ int getLiteral(int p, DOMString &result);
/**
*
*/
- virtual int getNameTest(int p0, DOMString &result);
+ int getNameTest(int p0, DOMString &result);
/**
*
*/
- virtual int getNCName(int p0, DOMString &result);
+ int getNCName(int p0, DOMString &result);
/**
*
*/
- virtual int lexicalScan();
+ 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]
*/
- virtual int getLocationPath(int p0, int depth);
+ int getLocationPath(int p0, int depth);
/**
* [2]
*/
- virtual int getAbsoluteLocationPath(int p0, int depth);
+ int getAbsoluteLocationPath(int p0, int depth);
/**
* [3]
*/
- virtual int getRelativeLocationPath(int p0, int depth);
+ int getRelativeLocationPath(int p0, int depth);
/**
* [4]
*/
- virtual int getStep(int p0, int depth);
+ int getStep(int p0, int depth);
/**
* [5]
*/
- virtual int getAxisSpecifier(int p0, int depth);
+ int getAxisSpecifier(int p0, int depth);
/**
* [6]
*/
- virtual int getAxisName(int p0, int depth);
+ int getAxisName(int p0, int depth);
/**
* [7]
*/
- virtual int getNodeTest(int p0, int depth);
+ int getNodeTest(int p0, int depth);
/**
* [8]
*/
- virtual int getPredicate(int p0, int depth);
+ int getPredicate(int p0, int depth);
/**
* [9]
*/
- virtual int getPredicateExpr(int p0, int depth);
+ int getPredicateExpr(int p0, int depth);
/**
* [10]
*/
- virtual int getAbbreviatedAbsoluteLocationPath(int p0, int depth);
+ int getAbbreviatedAbsoluteLocationPath(int p0, int depth);
/**
* [11]
*/
- virtual int getAbbreviatedRelativeLocationPath(int p0, int depth);
+ int getAbbreviatedRelativeLocationPath(int p0, int depth);
/**
* [12]
*/
- virtual int getAbbreviatedStep(int p0, int depth);
+ int getAbbreviatedStep(int p0, int depth);
/**
* [13]
*/
- virtual int getAbbreviatedAxisSpecifier(int p0, int depth);
+ int getAbbreviatedAxisSpecifier(int p0, int depth);
/**
* [14]
*/
- virtual int getExpr(int p0, int depth);
+ int getExpr(int p0, int depth);
/**
* [15]
*/
- virtual int getPrimaryExpr(int p0, int depth);
+ int getPrimaryExpr(int p0, int depth);
/**
* [16]
*/
- virtual int getFunctionCall(int p0, int depth);
+ int getFunctionCall(int p0, int depth);
/**
* [17]
*/
- virtual int getArgument(int p0, int depth);
+ int getArgument(int p0, int depth);
/**
* [18]
*/
- virtual int getUnionExpr(int p0, int depth);
+ int getUnionExpr(int p0, int depth);
/**
* [19]
*/
- virtual int getPathExpr(int p0, int depth);
+ int getPathExpr(int p0, int depth);
/**
* [20]
*/
- virtual int getFilterExpr(int p0, int depth);
+ int getFilterExpr(int p0, int depth);
/**
* [21]
*/
- virtual int getOrExpr(int p0, int depth);
+ int getOrExpr(int p0, int depth);
/**
* [22]
*/
- virtual int getAndExpr(int p0, int depth);
+ int getAndExpr(int p0, int depth);
/**
* [23]
*/
- virtual int getEqualityExpr(int p0, int depth);
+ int getEqualityExpr(int p0, int depth);
/**
* [24]
*/
- virtual int getRelationalExpr(int p0, int depth);
+ int getRelationalExpr(int p0, int depth);
/**
* [25]
*/
- virtual int getAdditiveExpr(int p0, int depth);
+ int getAdditiveExpr(int p0, int depth);
/**
* [26]
*/
- virtual int getMultiplicativeExpr(int p0, int depth);
+ int getMultiplicativeExpr(int p0, int depth);
/**
* [27]
*/
- virtual int getUnaryExpr(int p0, int depth);
+ int getUnaryExpr(int p0, int depth);
/**
* [28]
*/
- virtual int getExprToken(int p0, int depth);
+ int getExprToken(int p0, int depth);
/**
* [29]
*/
- virtual int getLiteral(int p0, int depth);
+ int getLiteral(int p0, int depth);
/**
* [30]
*/
- virtual int getNumber(int p0, int depth);
+ int getNumber(int p0, int depth);
/**
* [31]
*/
- virtual int getDigits(int p0, int depth);
+ int getDigits(int p0, int depth);
/**
* [32]
*/
- virtual int getOperator(int p0, int depth);
+ int getOperator(int p0, int depth);
/**
* [33]
*/
- virtual int getOperatorName(int p0, int depth);
+ int getOperatorName(int p0, int depth);
/**
* [34]
*/
- virtual int getMultiplyOperator(int p0, int depth);
+ int getMultiplyOperator(int p0, int depth);
/**
* [35]
*/
- virtual int getFunctionName(int p0, int depth);
+ int getFunctionName(int p0, int depth);
/**
* [36]
*/
- virtual int getVariableReference(int p0, int depth);
+ int getVariableReference(int p0, int depth);
/**
* [37]
*/
- virtual int getNameTest(int p0, int depth);
+ int getNameTest(int p0, int depth);
/**
* [38]
*/
- virtual int getNodeType(int p0, int depth);
+ int getNodeType(int p0, int depth);
/**
* [39]
*/
- virtual int getExprWhitespace(int p0, int depth);
+ int getExprWhitespace(int p0, int depth);
* The result of parsing. If parsing was successful, then
* this is executable via execute()
*/
- std::vector<Token> tokens;
+ TokenList tokens;