summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a8e9f85)
raw | patch | inline | side by side (parent: a8e9f85)
author | ishmal <ishmal@users.sourceforge.net> | |
Fri, 7 Jul 2006 20:08:35 +0000 (20:08 +0000) | ||
committer | ishmal <ishmal@users.sourceforge.net> | |
Fri, 7 Jul 2006 20:08:35 +0000 (20:08 +0000) |
src/dom/xpathparser.cpp | patch | blob | history | |
src/dom/xpathparser.h | patch | blob | history |
index 2c7c85d83b23443aac7f83d2f43c79ac7774747d..5962b70dc68294b28e5117a87d5dbb8dfec63c66 100644 (file)
--- a/src/dom/xpathparser.cpp
+++ b/src/dom/xpathparser.cpp
//# X P A T H G R A M M A R P A R S I N G
//#########################################################################
-
+//## Various shorthand methods to add a token to the list
void XPathParser::tokAdd(const Token &tok)
{
tokens.add(tok);
}
+void XPathParser::tokAdd(int type)
+{
+ tokens.add(Token::create(type));
+}
+
+void XPathParser::tokAdd(int type, long val)
+{
+ tokens.add(Token::create(type, val));
+}
+
+void XPathParser::tokAdd(int type, double val)
+{
+ tokens.add(Token::create(type, val));
+}
+
+void XPathParser::tokAdd(int type, const DOMString &val)
+{
+ tokens.add(Token::create(type, val));
+}
+
+
+
+
+
+//########################################
+//# Grammar - specific parsing
+//########################################
+
/**
* [1] LocationPath ::=
* RelativeLocationPath
int p2 = getAbsoluteLocationPath(p, depth+1);
if (p2 > p)
{
- tokens.add(Token::create(Token::TOK_ABSOLUTE));
+ tokAdd(Token::TOK_ABSOLUTE);
return p2;
}
p2 = getRelativeLocationPath(p, depth+1);
if (p2 > p)
{
- tokens.add(Token::create(Token::TOK_RELATIVE));
+ tokAdd(Token::TOK_RELATIVE);
return p2;
}
{
p++;
// a '//' is an abbreviation for /descendant-or-self:node()/
- tokAdd(Token::create(Token::TOK_AXIS_DESCENDANT_OR_SELF));
+ tokAdd(Token::TOK_AXIS_DESCENDANT_OR_SELF);
p2 = getRelativeLocationPath(p, depth+1);
if (p2 < 0)
{
switch (axisType)
{
case ANCESTOR_OR_SELF:
- tokAdd(Token::create(Token::TOK_AXIS_ANCESTOR_OR_SELF));
+ tokAdd(Token::TOK_AXIS_ANCESTOR_OR_SELF);
case ANCESTOR:
- tokAdd(Token::create(Token::TOK_AXIS_ANCESTOR));
+ tokAdd(Token::TOK_AXIS_ANCESTOR);
case ATTRIBUTE:
- tokAdd(Token::create(Token::TOK_AXIS_ATTRIBUTE));
+ tokAdd(Token::TOK_AXIS_ATTRIBUTE);
case CHILD:
- tokAdd(Token::create(Token::TOK_AXIS_CHILD));
+ tokAdd(Token::TOK_AXIS_CHILD);
case DESCENDANT_OR_SELF:
- tokAdd(Token::create(Token::TOK_AXIS_DESCENDANT_OR_SELF));
+ tokAdd(Token::TOK_AXIS_DESCENDANT_OR_SELF);
case DESCENDANT:
- tokAdd(Token::create(Token::TOK_AXIS_DESCENDANT));
+ tokAdd(Token::TOK_AXIS_DESCENDANT);
case FOLLOWING_SIBLING:
- tokAdd(Token::create(Token::TOK_AXIS_FOLLOWING_SIBLING));
+ tokAdd(Token::TOK_AXIS_FOLLOWING_SIBLING);
case FOLLOWING:
- tokAdd(Token::create(Token::TOK_AXIS_FOLLOWING));
+ tokAdd(Token::TOK_AXIS_FOLLOWING);
case NAMESPACE:
- tokAdd(Token::create(Token::TOK_AXIS_NAMESPACE));
+ tokAdd(Token::TOK_AXIS_NAMESPACE);
case PARENT:
- tokAdd(Token::create(Token::TOK_AXIS_PARENT));
+ tokAdd(Token::TOK_AXIS_PARENT);
case PRECEDING_SIBLING:
- tokAdd(Token::create(Token::TOK_AXIS_PRECEDING_SIBLING));
+ tokAdd(Token::TOK_AXIS_PRECEDING_SIBLING);
case PRECEDING:
- tokAdd(Token::create(Token::TOK_AXIS_PRECEDING));
+ tokAdd(Token::TOK_AXIS_PRECEDING);
case SELF:
- tokAdd(Token::create(Token::TOK_AXIS_SELF));
+ tokAdd(Token::TOK_AXIS_SELF);
default:
{
error("unknown axis type %d", axisType);
if (t.getType() == NAME_TEST)
{
p++;
- tokAdd(Token::create(Token::TOK_NAME_TEST, t.getStringValue()));
+ tokAdd(Token::TOK_NAME_TEST, t.getStringValue());
return p;
}
if (t.getType() == NODE_TYPE)
if (lexTokType(p) == LITERAL)
{
- tokens.add(Token::create(Token::TOK_STR,
- lexTok(p).getStringValue()));
+ tokAdd(Token::TOK_STR, lexTok(p).getStringValue());
p++;
return p;
}
if (lexTokType(p) == NUMBER)
{
- tokens.add(Token::create(Token::TOK_FLOAT,
- lexTok(p).getDoubleValue()));
+ tokAdd(Token::TOK_FLOAT, lexTok(p).getDoubleValue());
p++;
return p;
}
// Function names from http://www.w3.org/TR/xpath#NT-FunctionName
if (name == "last")
- tokens.add(Token::create(Token::TOK_FUNC_LAST));
+ tokAdd(Token::TOK_FUNC_LAST);
else if (name == "position")
- tokens.add(Token::create(Token::TOK_FUNC_POSITION));
+ tokAdd(Token::TOK_FUNC_POSITION);
else if (name == "count")
- tokens.add(Token::create(Token::TOK_FUNC_COUNT));
+ tokAdd(Token::TOK_FUNC_COUNT);
else if (name == "id")
- tokens.add(Token::create(Token::TOK_FUNC_ID));
+ tokAdd(Token::TOK_FUNC_ID);
else if (name == "local-name")
- tokens.add(Token::create(Token::TOK_FUNC_LOCAL_NAME));
+ tokAdd(Token::TOK_FUNC_LOCAL_NAME);
else if (name == "namespace-uri")
- tokens.add(Token::create(Token::TOK_FUNC_NAMESPACE_URI));
+ tokAdd(Token::TOK_FUNC_NAMESPACE_URI);
else if (name == "name")
- tokens.add(Token::create(Token::TOK_FUNC_NAME));
+ tokAdd(Token::TOK_FUNC_NAME);
else if (name == "string")
- tokens.add(Token::create(Token::TOK_FUNC_STRING));
+ tokAdd(Token::TOK_FUNC_STRING);
else if (name == "concat")
- tokens.add(Token::create(Token::TOK_FUNC_CONCAT));
+ tokAdd(Token::TOK_FUNC_CONCAT);
else if (name == "starts-with")
- tokens.add(Token::create(Token::TOK_FUNC_STARTS_WITH));
+ tokAdd(Token::TOK_FUNC_STARTS_WITH);
else if (name == "contains")
- tokens.add(Token::create(Token::TOK_FUNC_CONTAINS));
+ tokAdd(Token::TOK_FUNC_CONTAINS);
else if (name == "substring-before")
- tokens.add(Token::create(Token::TOK_FUNC_SUBSTRING_BEFORE));
+ tokAdd(Token::TOK_FUNC_SUBSTRING_BEFORE);
else if (name == "substring-after")
- tokens.add(Token::create(Token::TOK_FUNC_SUBSTRING_AFTER));
+ tokAdd(Token::TOK_FUNC_SUBSTRING_AFTER);
else if (name == "substring")
- tokens.add(Token::create(Token::TOK_FUNC_SUBSTRING));
+ tokAdd(Token::TOK_FUNC_SUBSTRING);
else if (name == "string-length")
- tokens.add(Token::create(Token::TOK_FUNC_STRING_LENGTH));
+ tokAdd(Token::TOK_FUNC_STRING_LENGTH);
else if (name == "normalize-space")
- tokens.add(Token::create(Token::TOK_FUNC_NORMALIZE_SPACE));
+ tokAdd(Token::TOK_FUNC_NORMALIZE_SPACE);
else if (name == "translate")
- tokens.add(Token::create(Token::TOK_FUNC_TRANSLATE));
+ tokAdd(Token::TOK_FUNC_TRANSLATE);
else if (name == "boolean")
- tokens.add(Token::create(Token::TOK_FUNC_BOOLEAN));
+ tokAdd(Token::TOK_FUNC_BOOLEAN);
else if (name == "not")
- tokens.add(Token::create(Token::TOK_FUNC_NOT));
+ tokAdd(Token::TOK_FUNC_NOT);
else if (name == "true")
- tokens.add(Token::create(Token::TOK_FUNC_TRUE));
+ tokAdd(Token::TOK_FUNC_TRUE);
else if (name == "false")
- tokens.add(Token::create(Token::TOK_FUNC_FALSE));
+ tokAdd(Token::TOK_FUNC_FALSE);
else if (name == "lang")
- tokens.add(Token::create(Token::TOK_FUNC_LANG));
+ tokAdd(Token::TOK_FUNC_LANG);
else if (name == "number")
- tokens.add(Token::create(Token::TOK_FUNC_NUMBER));
+ tokAdd(Token::TOK_FUNC_NUMBER);
else if (name == "sum")
- tokens.add(Token::create(Token::TOK_FUNC_SUM));
+ tokAdd(Token::TOK_FUNC_SUM);
else if (name == "floor")
- tokens.add(Token::create(Token::TOK_FUNC_FLOOR));
+ tokAdd(Token::TOK_FUNC_FLOOR);
else if (name == "ceiling")
- tokens.add(Token::create(Token::TOK_FUNC_CEILING));
+ tokAdd(Token::TOK_FUNC_CEILING);
else if (name == "round")
- tokens.add(Token::create(Token::TOK_FUNC_ROUND));
+ tokAdd(Token::TOK_FUNC_ROUND);
else
{
error("unknown function name:'%s'", name.c_str());
error("OR (|) requires union expression on the left");
return -1;
}
- tokens.add(Token::create(Token::TOK_UNION));
+ tokAdd(Token::TOK_UNION);
p = p2;
}
return p;
p = p2;
return p;
}
- tokens.add(Token::create(Token::TOK_OR));
+ tokAdd(Token::TOK_OR);
return p;
}
p = p2;
return p;
}
- tokens.add(Token::create(Token::TOK_AND));
+ tokAdd(Token::TOK_AND);
return p;
}
error("Equality expression expected after ==");
return -1;
}
- tokens.add(Token::create(Token::TOK_EQUALS));
+ tokAdd(Token::TOK_EQUALS);
p = p2;
return p;
}
error("Equality expression expected after !=");
return -1;
}
- tokens.add(Token::create(Token::TOK_NOT_EQUALS));
+ tokAdd(Token::TOK_NOT_EQUALS);
p = p2;
return p;
}
error("Relational expression after '>'");
return -1;
}
- tokens.add(Token::create(Token::TOK_GREATER_THAN));
+ tokAdd(Token::TOK_GREATER_THAN);
p = p2;
return p;
}
error("Relational expression after '<'");
return -1;
}
- tokens.add(Token::create(Token::TOK_LESS_THAN));
+ tokAdd(Token::TOK_LESS_THAN);
p = p2;
return p;
}
error("Relational expression after '>='");
return -1;
}
- tokens.add(Token::create(Token::TOK_GREATER_THAN_EQUALS));
+ tokAdd(Token::TOK_GREATER_THAN_EQUALS);
p = p2;
return p;
}
error("Relational expression after '<='");
return -1;
}
- tokens.add(Token::create(Token::TOK_LESS_THAN_EQUALS));
+ tokAdd(Token::TOK_LESS_THAN_EQUALS);
p = p2;
return p;
}
error("Additive expression after '+'");
return -1;
}
- tokens.add(Token::create(Token::TOK_PLUS));
+ tokAdd(Token::TOK_MINUS);
p = p2;
return p;
}
error("Additive expression after '-'");
return -1;
}
- tokens.add(Token::create(Token::TOK_MINUS));
+ tokAdd(Token::TOK_MINUS);
p = p2;
return p;
}
error("Multiplicative expression after '*'");
return -1;
}
- tokens.add(Token::create(Token::TOK_MUL));
+ tokAdd(Token::TOK_MUL);
p = p2;
return p;
}
error("Multiplicative expression after 'div'");
return -1;
}
- tokens.add(Token::create(Token::TOK_DIV));
+ tokAdd(Token::TOK_DIV);
p = p2;
return p;
}
error("Multiplicative expression after 'mod'");
return -1;
}
- tokens.add(Token::create(Token::TOK_MOD));
+ tokAdd(Token::TOK_MOD);
p = p2;
return p;
}
error("Unary expression after '-'");
return -1;
}
- tokens.add(Token::create(Token::TOK_NEG));
+ tokAdd(Token::TOK_NEG);
p = p2;
return p;
}
diff --git a/src/dom/xpathparser.h b/src/dom/xpathparser.h
index 4bf19b72fc79fa92741bbadcc965b977338e119e..70ad2f6c67f07cc66f552e0c2c33075bed17cdca 100644 (file)
--- a/src/dom/xpathparser.h
+++ b/src/dom/xpathparser.h
*/
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.