xpathparser.h revision 6cd2e86330e1049942b9ce57d4f10bbe2542067d
#ifndef SEEN_XPATHPARSER_H
#define SEEN_XPATHPARSER_H
/**
* @file
* 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:
*
*/
/*
* Authors:
* Bob Jamison
*
* Copyright (C) 2005-2007 Bob Jamison
*
* 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"
{
{
{
{
//########################################################################
//# L E X I C A L D E F I N I T I O N S
//########################################################################
typedef struct
{
int ival;
char const *sval;
} LookupEntry;
//Note: in the following definitions, where the starts of
//strings are similar, put the longer definitions first
/**
*
*/
typedef enum
{
TEXT,
} NodeType;
static LookupEntry nodeTypeTable [] =
{
{ COMMENT, "comment" },
{ TEXT, "text" },
{ PROCESSING_INSTRUCTION, "processing-instruction" },
{ NODE, "node" },
{ -1, NULL }
};
/**
*
*/
typedef enum
{
} 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
DOT,
AMPR,
//Operator tokens
AND,
OR,
MOD,
DIV,
PIPE,
PLUS,
} 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 }
};
/**
*
*/
{
{
}
LexTok()
{ init(); }
void print()
{
{
char const *tokenStr = "unknown";
{
{
break;
}
}
}
{
char const *tokenStr = "unknown";
{
{
break;
}
}
}
{
char const *tokenStr = "unknown";
{
{
break;
}
}
}
else if (type == FUNCTION_NAME)
else
{
char const *tokenStr = "unknown";
{
{
break;
}
}
//printf("%s [%s/%f/%ld]\n", tokenStr, sval.c_str(), dval, ival);
}
}
int getType()
{ return type; }
int getLocation()
{ return location; }
{ return sval; }
double getDoubleValue()
{ return dval; }
long getIntValue()
{ return ival; }
void init()
{
location = 0;
dval = 0.0;
ival = 0;
}
int type;
int location;
double dval;
long ival;
};
//########################################################################
//# P A R S E R
//########################################################################
{
//#################################
//# CONSTRUCTOR
//#################################
/**
*
*/
XPathParser() :
debug(false),
parsebuf(0),
parselen(0),
position(0),
numberString(),
number(0),
tokens()
{
}
/**
*
*/
virtual ~XPathParser() {}
/**
*
*/
bool getDebug()
{ return debug; }
/**
*
*/
/**
* Normally not called directly unless for string parsing testing
*/
/**
* This is the big one. Called by the xpath-dom api to fetch
* nodes from a DOM tree.
*/
//#################################
//# MESSAGES
//#################################
/**
*
*/
#ifdef G_GNUC_PRINTF
#endif
;
/**
*
*/
/**
*
*/
#ifdef G_GNUC_PRINTF
#endif
;
//#################################
//# LEXICAL SCANNING
//#################################
/**
* Add a lexical token of a given type to the list
*/
/**
*
*/
void lexicalTokenDump();
/**
*
*/
/**
*
*/
int lexTokType(int p);
/**
*
*/
int peek(int p);
/**
*
*/
int get(int p);
/**
*
*/
/**
*
*/
/**
*
*/
int skipwhite(int p);
/**
*
*/
/**
*
*/
/**
*
*/
/**
*
*/
/**
*
*/
int lexicalScan();
//#################################
//# GRAMMAR PARSING
//#################################
/**
* Add a newly derived token to the token list;
*/
/**
* The grammar definitions marked [1]-[39] are directly
* from the W3C XPath grammar spacification.
*/
/**
* [1]
*/
/**
* [2]
*/
/**
* [3]
*/
/**
* [4]
*/
/**
* [5]
*/
/**
* [6]
*/
/**
* [7]
*/
/**
* [8]
*/
/**
* [9]
*/
/**
* [10]
*/
/**
* [11]
*/
/**
* [12]
*/
/**
* [13]
*/
/**
* [14]
*/
/**
* [15]
*/
/**
* [16]
*/
/**
* [17]
*/
/**
* [18]
*/
/**
* [19]
*/
/**
* [20]
*/
/**
* [21]
*/
/**
* [22]
*/
/**
* [23]
*/
/**
* [24]
*/
/**
* [25]
*/
/**
* [26]
*/
/**
* [27]
*/
/**
* [28]
*/
/**
* [29]
*/
/**
* [30]
*/
/**
* [31]
*/
/**
* [32]
*/
/**
* [33]
*/
/**
* [34]
*/
/**
* [35]
*/
/**
* [36]
*/
/**
* [37]
*/
/**
* [38]
*/
/**
* [39]
*/
//#################################
//# DATA ITEMS
//#################################
/**
*
*/
bool debug;
/**
*
*/
char *parsebuf;
/**
*
*/
int parselen;
/**
*
*/
int position;
/**
*
*/
/**
*
*/
double number;
/**
* The result of the first lexical scan
*/
/**
* The result of parsing. If parsing was successful, then
* this is executable via execute()
*/
};
} // namespace xpath
} // namespace dom
} // namespace w3c
} // namespace org
#endif // SEEN_XPATHPARSER_H
//#########################################################################
//# E N D O F F I L E
//#########################################################################