2010-09-30 20:06:01 +00:00
|
|
|
/*
|
|
|
|
* XSLPattern parser (XSLPattern => XPath)
|
|
|
|
*
|
|
|
|
* Copyright 2010 Adam Martinson for CodeWeavers
|
|
|
|
*
|
|
|
|
* 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 "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_LIBXML2
|
|
|
|
#include "xslpattern.h"
|
2010-10-29 01:14:58 +00:00
|
|
|
#include <libxml/xpathInternals.h>
|
2011-02-24 12:11:53 +00:00
|
|
|
#include "wine/debug.h"
|
2010-09-30 20:06:01 +00:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msxml);
|
|
|
|
|
|
|
|
|
2010-10-29 01:14:58 +00:00
|
|
|
static const xmlChar NameTest_mod_pre[] = "*[name()='";
|
2010-09-30 20:06:01 +00:00
|
|
|
static const xmlChar NameTest_mod_post[] = "']";
|
|
|
|
|
|
|
|
#define U(str) BAD_CAST str
|
2010-10-29 01:14:58 +00:00
|
|
|
|
2010-11-02 21:12:21 +00:00
|
|
|
static inline BOOL is_literal(xmlChar const* tok)
|
|
|
|
{
|
|
|
|
return (tok && tok[0] && tok[1] &&
|
|
|
|
tok[0]== tok[xmlStrlen(tok)-1] &&
|
|
|
|
(tok[0] == '\'' || tok[0] == '"'));
|
|
|
|
}
|
|
|
|
|
2011-03-30 14:43:13 +00:00
|
|
|
static void xslpattern_error(parser_param* param, void const* scanner, char const* msg)
|
|
|
|
{
|
|
|
|
FIXME("%s:\n"
|
|
|
|
" param {\n"
|
|
|
|
" yyscanner=%p\n"
|
|
|
|
" ctx=%p\n"
|
|
|
|
" in=\"%s\"\n"
|
|
|
|
" pos=%i\n"
|
|
|
|
" len=%i\n"
|
|
|
|
" out=\"%s\"\n"
|
|
|
|
" err=%i\n"
|
|
|
|
" }\n"
|
|
|
|
" scanner=%p\n",
|
|
|
|
msg, param->yyscanner, param->ctx, param->in, param->pos,
|
|
|
|
param->len, param->out, ++param->err, scanner);
|
|
|
|
}
|
|
|
|
|
2010-09-30 20:06:01 +00:00
|
|
|
%}
|
|
|
|
|
|
|
|
%token TOK_Parent TOK_Self TOK_DblFSlash TOK_FSlash TOK_Axis TOK_Colon
|
|
|
|
%token TOK_OpAnd TOK_OpOr TOK_OpNot
|
|
|
|
%token TOK_OpEq TOK_OpIEq TOK_OpNEq TOK_OpINEq
|
|
|
|
%token TOK_OpLt TOK_OpILt TOK_OpGt TOK_OpIGt TOK_OpLEq TOK_OpILEq TOK_OpGEq TOK_OpIGEq
|
|
|
|
%token TOK_OpAll TOK_OpAny
|
|
|
|
%token TOK_NCName TOK_Literal TOK_Number
|
|
|
|
|
|
|
|
%start XSLPattern
|
|
|
|
|
|
|
|
%pure_parser
|
|
|
|
%parse-param {parser_param* p}
|
|
|
|
%parse-param {void* scanner}
|
|
|
|
%lex-param {yyscan_t* scanner}
|
|
|
|
|
|
|
|
%left TOK_OpAnd TOK_OpOr
|
|
|
|
%left TOK_OpEq TOK_OpIEq TOK_OpNEq TOK_OpINEq
|
|
|
|
%left TOK_OpLt TOK_OpILt TOK_OpGt TOK_OpIGt TOK_OpLEq TOK_OpILEq TOK_OpGEq TOK_OpIGEq
|
|
|
|
|
2010-11-02 21:12:21 +00:00
|
|
|
%expect 14
|
|
|
|
|
2010-09-30 20:06:01 +00:00
|
|
|
%%
|
|
|
|
|
|
|
|
XSLPattern : Expr
|
|
|
|
{
|
|
|
|
p->out = $1;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
/* Mostly verbatim from the w3c XML Namespaces standard.
|
|
|
|
* <http://www.w3.org/TR/REC-xml-names/> */
|
|
|
|
|
|
|
|
/* [4] Qualified Names */
|
|
|
|
QName : PrefixedName
|
|
|
|
| UnprefixedName
|
|
|
|
;
|
|
|
|
PrefixedName : TOK_NCName TOK_Colon TOK_NCName
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got PrefixedName: \"%s:%s\"\n", $1, $3);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=$1;
|
2010-10-29 01:14:58 +00:00
|
|
|
$$=xmlStrcat($$,U(":"));
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
UnprefixedName : TOK_NCName
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got UnprefixedName: \"%s\"\n", $1);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=$1;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
/* Based on the w3c XPath standard, adapted where needed.
|
|
|
|
* <http://www.w3.org/TR/xpath/> */
|
|
|
|
|
|
|
|
/* [2] Location Paths */
|
|
|
|
LocationPath : RelativeLocationPath
|
|
|
|
| AbsoluteLocationPath
|
|
|
|
;
|
|
|
|
AbsoluteLocationPath : TOK_FSlash RelativeLocationPath
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got AbsoluteLocationPath: \"/%s\"\n", $2);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=xmlStrdup(U("/"));
|
|
|
|
$$=xmlStrcat($$,$2);
|
|
|
|
xmlFree($2);
|
|
|
|
}
|
|
|
|
| TOK_FSlash
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got AbsoluteLocationPath: \"/\"\n");
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=xmlStrdup(U("/"));
|
|
|
|
}
|
|
|
|
| AbbreviatedAbsoluteLocationPath
|
|
|
|
;
|
|
|
|
RelativeLocationPath : Step
|
|
|
|
| RelativeLocationPath TOK_FSlash Step
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got RelativeLocationPath: \"%s/%s\"\n", $1, $3);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=$1;
|
|
|
|
$$=xmlStrcat($$,U("/"));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
}
|
|
|
|
| AbbreviatedRelativeLocationPath
|
|
|
|
;
|
|
|
|
/* [2.1] Location Steps */
|
2010-11-02 21:12:21 +00:00
|
|
|
Step : AxisSpecifier NodeTest Predicates
|
2010-09-30 20:06:01 +00:00
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got Step: \"%s%s%s\"\n", $1, $2, $3);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=$1;
|
|
|
|
$$=xmlStrcat($$,$2);
|
|
|
|
xmlFree($2);
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
}
|
2010-11-02 21:12:21 +00:00
|
|
|
| NodeTest Predicates
|
2010-09-30 20:06:01 +00:00
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got Step: \"%s%s\"\n", $1, $2);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=$1;
|
|
|
|
$$=xmlStrcat($$,$2);
|
|
|
|
xmlFree($2);
|
|
|
|
}
|
2010-11-02 21:12:21 +00:00
|
|
|
| AxisSpecifier NodeTest
|
2010-09-30 20:06:01 +00:00
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got Step: \"%s%s\"\n", $1, $2);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=$1;
|
|
|
|
$$=xmlStrcat($$,$2);
|
|
|
|
xmlFree($2);
|
|
|
|
}
|
2010-11-02 21:12:21 +00:00
|
|
|
| NodeTest
|
2010-09-30 20:06:01 +00:00
|
|
|
| Attribute
|
|
|
|
| AbbreviatedStep
|
|
|
|
;
|
|
|
|
AxisSpecifier : TOK_NCName TOK_Axis
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got AxisSpecifier: \"%s::\"\n", $1);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=$1;
|
|
|
|
$$=xmlStrcat($$,U("::"));
|
|
|
|
}
|
|
|
|
;
|
2011-12-05 20:27:20 +00:00
|
|
|
Attribute : '@' QName
|
2010-09-30 20:06:01 +00:00
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got Attribute: \"@%s\"\n", $2);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=xmlStrdup(U("@"));
|
|
|
|
$$=xmlStrcat($$,$2);
|
|
|
|
xmlFree($2);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
/* [2.3] Node Tests */
|
2010-11-02 21:12:21 +00:00
|
|
|
NodeTest : NameTest
|
|
|
|
| FunctionCall
|
|
|
|
;
|
2010-09-30 20:06:01 +00:00
|
|
|
NameTest : '*'
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got NameTest: \"*\"\n");
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=xmlStrdup(U("*"));
|
|
|
|
}
|
|
|
|
| TOK_NCName TOK_Colon '*'
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got NameTest: \"%s:*\"\n", $1);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=$1;
|
|
|
|
$$=xmlStrcat($$,U(":*"));
|
|
|
|
}
|
2010-10-29 01:14:58 +00:00
|
|
|
| TOK_NCName TOK_Colon TOK_NCName
|
|
|
|
{ /* PrefixedName */
|
|
|
|
xmlChar const* registeredNsURI = xmlXPathNsLookup(p->ctx, $1);
|
|
|
|
TRACE("Got PrefixedName: \"%s:%s\"\n", $1, $3);
|
|
|
|
|
|
|
|
if (registeredNsURI)
|
|
|
|
$$=xmlStrdup(U(""));
|
|
|
|
else
|
|
|
|
$$=xmlStrdup(NameTest_mod_pre);
|
|
|
|
|
|
|
|
$$=xmlStrcat($$,$1);
|
|
|
|
xmlFree($1);
|
|
|
|
$$=xmlStrcat($$,U(":"));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
|
|
|
|
if (!registeredNsURI)
|
|
|
|
$$=xmlStrcat($$,NameTest_mod_post);
|
|
|
|
}
|
2010-09-30 20:06:01 +00:00
|
|
|
| UnprefixedName
|
|
|
|
{
|
|
|
|
$$=xmlStrdup(NameTest_mod_pre);
|
|
|
|
$$=xmlStrcat($$,$1);
|
|
|
|
xmlFree($1);
|
|
|
|
$$=xmlStrcat($$,NameTest_mod_post);
|
|
|
|
}
|
|
|
|
/* [2.4] Predicates */
|
|
|
|
Predicates : Predicates Predicate
|
|
|
|
{
|
|
|
|
$$=$1;
|
|
|
|
$$=xmlStrcat($$,$2);
|
|
|
|
xmlFree($2);
|
|
|
|
}
|
|
|
|
| Predicate
|
|
|
|
;
|
|
|
|
Predicate : '[' PredicateExpr ']'
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got Predicate: \"[%s]\"\n", $2);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=xmlStrdup(U("["));
|
|
|
|
$$=xmlStrcat($$,$2);
|
|
|
|
xmlFree($2);
|
|
|
|
$$=xmlStrcat($$,U("]"));
|
|
|
|
}
|
|
|
|
;
|
|
|
|
PredicateExpr : TOK_Number
|
|
|
|
{
|
|
|
|
$$=xmlStrdup(U("index()="));
|
|
|
|
$$=xmlStrcat($$,$1);
|
|
|
|
xmlFree($1);
|
|
|
|
}
|
|
|
|
| BoolExpr
|
|
|
|
| Attribute
|
|
|
|
;
|
|
|
|
/* [2.5] Abbreviated Syntax */
|
|
|
|
AbbreviatedAbsoluteLocationPath : TOK_DblFSlash RelativeLocationPath
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got AbbreviatedAbsoluteLocationPath: \"//%s\"\n", $2);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=xmlStrdup(U("//"));
|
|
|
|
$$=xmlStrcat($$,$2);
|
|
|
|
xmlFree($2);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
AbbreviatedRelativeLocationPath : RelativeLocationPath TOK_DblFSlash Step
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got AbbreviatedRelativeLocationPath: \"%s//%s\"\n", $1, $3);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=$1;
|
|
|
|
$$=xmlStrcat($$,U("//"));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
AbbreviatedStep : TOK_Parent
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got AbbreviatedStep: \"..\"\n");
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=xmlStrdup(U(".."));
|
|
|
|
}
|
|
|
|
| TOK_Self
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got AbbreviatedStep: \".\"\n");
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=xmlStrdup(U("."));
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
/* [3] Expressions */
|
|
|
|
/* [3.1] Basics */
|
|
|
|
Expr : OrExpr
|
|
|
|
;
|
|
|
|
BoolExpr : FunctionCall
|
|
|
|
| BoolUnaryExpr
|
|
|
|
| BoolRelationalExpr
|
|
|
|
| BoolEqualityExpr
|
|
|
|
| BoolAndExpr
|
|
|
|
| BoolOrExpr
|
|
|
|
;
|
|
|
|
PrimaryExpr : '(' Expr ')'
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got PrimaryExpr: \"(%s)\"\n", $1);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=xmlStrdup(U("("));
|
|
|
|
$$=xmlStrcat($$,$2);
|
|
|
|
xmlFree($2);
|
|
|
|
$$=xmlStrcat($$,U(")"));
|
|
|
|
}
|
|
|
|
| PathExpr '!' FunctionCall
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got PrimaryExpr: \"%s!%s\"\n", $1, $3);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=$1;
|
|
|
|
$$=xmlStrcat($$,U("/"));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
}
|
|
|
|
| TOK_Literal
|
|
|
|
| TOK_Number
|
|
|
|
;
|
|
|
|
/* [3.2] Function Calls */
|
|
|
|
FunctionCall : QName '(' Arguments ')'
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got FunctionCall: \"%s(%s)\"\n", $1, $3);
|
2010-11-02 21:12:21 +00:00
|
|
|
if (xmlStrEqual($1,U("ancestor")))
|
|
|
|
{
|
|
|
|
$$=$1;
|
|
|
|
$$=xmlStrcat($$,U("::"));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
}
|
|
|
|
else if (xmlStrEqual($1,U("attribute")))
|
|
|
|
{
|
|
|
|
if (is_literal($3))
|
|
|
|
{
|
|
|
|
$$=xmlStrdup(U("@*[name()="));
|
|
|
|
xmlFree($1);
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
$$=xmlStrcat($$,U("]"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* XML_XPATH_INVALID_TYPE */
|
|
|
|
$$=xmlStrdup(U("error(1211, 'Error: attribute("));
|
|
|
|
xmlFree($1);
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
$$=xmlStrcat($$,U("): invalid argument')"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (xmlStrEqual($1,U("element")))
|
|
|
|
{
|
|
|
|
if (is_literal($3))
|
|
|
|
{
|
|
|
|
$$=xmlStrdup(U("node()[nodeType()=1][name()="));
|
|
|
|
xmlFree($1);
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
$$=xmlStrcat($$,U("]"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* XML_XPATH_INVALID_TYPE */
|
|
|
|
$$=xmlStrdup(U("error(1211, 'Error: element("));
|
|
|
|
xmlFree($1);
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
$$=xmlStrcat($$,U("): invalid argument')"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$$=$1;
|
|
|
|
$$=xmlStrcat($$,U("("));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
$$=xmlStrcat($$,U(")"));
|
|
|
|
}
|
2010-09-30 20:06:01 +00:00
|
|
|
}
|
|
|
|
| QName '(' ')'
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got FunctionCall: \"%s()\"\n", $1);
|
2010-11-02 21:12:21 +00:00
|
|
|
/* comment() & node() work the same in XPath */
|
|
|
|
if (xmlStrEqual($1,U("attribute")))
|
|
|
|
{
|
|
|
|
$$=xmlStrdup(U("@*"));
|
|
|
|
xmlFree($1);
|
|
|
|
}
|
|
|
|
else if (xmlStrEqual($1,U("element")))
|
|
|
|
{
|
|
|
|
$$=xmlStrdup(U("node()[nodeType()=1]"));
|
|
|
|
xmlFree($1);
|
|
|
|
}
|
|
|
|
else if (xmlStrEqual($1,U("pi")))
|
|
|
|
{
|
|
|
|
$$=xmlStrdup(U("processing-instruction()"));
|
|
|
|
xmlFree($1);
|
|
|
|
}
|
|
|
|
else if (xmlStrEqual($1,U("textnode")))
|
|
|
|
{
|
|
|
|
$$=xmlStrdup(U("text()"));
|
|
|
|
xmlFree($1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$$=$1;
|
|
|
|
$$=xmlStrcat($$,U("()"));
|
|
|
|
}
|
2010-09-30 20:06:01 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
Arguments : Argument ',' Arguments
|
|
|
|
{
|
|
|
|
$$=$1;
|
|
|
|
$$=xmlStrcat($$,U(","));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
}
|
|
|
|
| Argument
|
|
|
|
;
|
|
|
|
Argument : Expr
|
|
|
|
;
|
|
|
|
/* [3.3] Node-sets */
|
|
|
|
UnionExpr : PathExpr
|
|
|
|
| UnionExpr '|' PathExpr
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got UnionExpr: \"%s|%s\"\n", $1, $3);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=$1;
|
|
|
|
$$=xmlStrcat($$,U("|"));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
PathExpr : LocationPath
|
|
|
|
| FilterExpr TOK_FSlash RelativeLocationPath
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got PathExpr: \"%s/%s\"\n", $1, $3);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=$1;
|
|
|
|
$$=xmlStrcat($$,U("/"));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
}
|
|
|
|
| FilterExpr TOK_DblFSlash RelativeLocationPath
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got PathExpr: \"%s//%s\"\n", $1, $3);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=$1;
|
|
|
|
$$=xmlStrcat($$,U("//"));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
}
|
|
|
|
| FilterExpr
|
|
|
|
;
|
|
|
|
FilterExpr : PrimaryExpr
|
|
|
|
| FilterExpr Predicate
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got FilterExpr: \"%s%s\"\n", $1, $2);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=$1;
|
|
|
|
$$=xmlStrcat($$,$2);
|
|
|
|
xmlFree($2);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
/* [3.4] Booleans */
|
|
|
|
OrExpr : AndExpr
|
|
|
|
| BoolOrExpr
|
|
|
|
;
|
|
|
|
BoolOrExpr : OrExpr TOK_OpOr AndExpr
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got OrExpr: \"%s $or$ %s\"\n", $1, $3);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=$1;
|
|
|
|
$$=xmlStrcat($$,U(" or "));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
AndExpr : EqualityExpr
|
|
|
|
| BoolAndExpr
|
|
|
|
;
|
|
|
|
BoolAndExpr : AndExpr TOK_OpAnd EqualityExpr
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got AndExpr: \"%s $and$ %s\"\n", $1, $3);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=$1;
|
|
|
|
$$=xmlStrcat($$,U(" and "));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
EqualityExpr : RelationalExpr
|
|
|
|
| BoolEqualityExpr
|
|
|
|
;
|
|
|
|
BoolEqualityExpr : EqualityExpr TOK_OpEq RelationalExpr
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got EqualityExpr: \"%s $eq$ %s\"\n", $1, $3);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=$1;
|
|
|
|
$$=xmlStrcat($$,U("="));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
}
|
|
|
|
| EqualityExpr TOK_OpIEq RelationalExpr
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got EqualityExpr: \"%s $ieq$ %s\"\n", $1, $3);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=xmlStrdup(U("OP_IEq("));
|
|
|
|
$$=xmlStrcat($$,$1);
|
|
|
|
xmlFree($1);
|
|
|
|
$$=xmlStrcat($$,U(","));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
$$=xmlStrcat($$,U(")"));
|
|
|
|
}
|
|
|
|
| EqualityExpr TOK_OpNEq RelationalExpr
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got EqualityExpr: \"%s $ne$ %s\"\n", $1, $3);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=$1;
|
|
|
|
$$=xmlStrcat($$,U("!="));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
}
|
|
|
|
| EqualityExpr TOK_OpINEq RelationalExpr
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got EqualityExpr: \"%s $ine$ %s\"\n", $1, $3);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=xmlStrdup(U("OP_INEq("));
|
|
|
|
$$=xmlStrcat($$,$1);
|
|
|
|
xmlFree($1);
|
|
|
|
$$=xmlStrcat($$,U(","));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
$$=xmlStrcat($$,U(")"));
|
|
|
|
}
|
|
|
|
;
|
|
|
|
RelationalExpr : UnaryExpr
|
|
|
|
| BoolRelationalExpr
|
|
|
|
;
|
|
|
|
BoolRelationalExpr : RelationalExpr TOK_OpLt UnaryExpr
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got RelationalExpr: \"%s $lt$ %s\"\n", $1, $3);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=$1;
|
|
|
|
$$=xmlStrcat($$,U("<"));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
}
|
|
|
|
| RelationalExpr TOK_OpILt UnaryExpr
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got RelationalExpr: \"%s $ilt$ %s\"\n", $1, $3);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=xmlStrdup(U("OP_ILt("));
|
|
|
|
$$=xmlStrcat($$,$1);
|
|
|
|
xmlFree($1);
|
|
|
|
$$=xmlStrcat($$,U(","));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
$$=xmlStrcat($$,U(")"));
|
|
|
|
}
|
|
|
|
| RelationalExpr TOK_OpGt UnaryExpr
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got RelationalExpr: \"%s $gt$ %s\"\n", $1, $3);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=$1;
|
|
|
|
$$=xmlStrcat($$,U(">"));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
}
|
|
|
|
| RelationalExpr TOK_OpIGt UnaryExpr
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got RelationalExpr: \"%s $igt$ %s\"\n", $1, $3);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=xmlStrdup(U("OP_IGt("));
|
|
|
|
$$=xmlStrcat($$,$1);
|
|
|
|
xmlFree($1);
|
|
|
|
$$=xmlStrcat($$,U(","));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
$$=xmlStrcat($$,U(")"));
|
|
|
|
}
|
|
|
|
| RelationalExpr TOK_OpLEq UnaryExpr
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got RelationalExpr: \"%s $le$ %s\"\n", $1, $3);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=$1;
|
|
|
|
$$=xmlStrcat($$,U("<="));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
}
|
|
|
|
| RelationalExpr TOK_OpILEq UnaryExpr
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got RelationalExpr: \"%s $ile$ %s\"\n", $1, $3);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=xmlStrdup(U("OP_ILEq("));
|
|
|
|
$$=xmlStrcat($$,$1);
|
|
|
|
xmlFree($1);
|
|
|
|
$$=xmlStrcat($$,U(","));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
$$=xmlStrcat($$,U(")"));
|
|
|
|
}
|
|
|
|
| RelationalExpr TOK_OpGEq UnaryExpr
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got RelationalExpr: \"%s $ge$ %s\"\n", $1, $3);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=$1;
|
|
|
|
$$=xmlStrcat($$,U(">="));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
}
|
|
|
|
| RelationalExpr TOK_OpIGEq UnaryExpr
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got RelationalExpr: \"%s $ige$ %s\"\n", $1, $3);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=xmlStrdup(U("OP_IGEq("));
|
|
|
|
$$=xmlStrcat($$,$1);
|
|
|
|
xmlFree($1);
|
|
|
|
$$=xmlStrcat($$,U(","));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
$$=xmlStrcat($$,U(")"));
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
/* [3.5] Numbers */
|
|
|
|
UnaryExpr : UnionExpr
|
|
|
|
| BoolUnaryExpr
|
|
|
|
;
|
|
|
|
BoolUnaryExpr : TOK_OpNot UnaryExpr
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got UnaryExpr: \"$not$ %s\"\n", $2);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=xmlStrdup(U(" not("));
|
|
|
|
$$=xmlStrcat($$,$2);
|
|
|
|
xmlFree($2);
|
|
|
|
$$=xmlStrcat($$,U(")"));
|
|
|
|
}
|
|
|
|
| TOK_OpAny Expr
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got UnaryExpr: \"$any$ %s\"\n", $2);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=xmlStrdup(U("boolean("));
|
|
|
|
$$=xmlStrcat($$,$2);
|
|
|
|
xmlFree($2);
|
|
|
|
$$=xmlStrcat($$,U(")"));
|
|
|
|
}
|
|
|
|
| TOK_OpAll AllExpr
|
|
|
|
{
|
2010-10-29 01:14:58 +00:00
|
|
|
TRACE("Got UnaryExpr: \"$all$ %s\"\n", $2);
|
2010-09-30 20:06:01 +00:00
|
|
|
$$=xmlStrdup(U("not("));
|
|
|
|
$$=xmlStrcat($$,$2);
|
|
|
|
xmlFree($2);
|
|
|
|
$$=xmlStrcat($$,U(")"));
|
|
|
|
}
|
|
|
|
| TOK_OpAll
|
|
|
|
{
|
|
|
|
FIXME("Unrecognized $all$ expression - ignoring\n");
|
|
|
|
$$=xmlStrdup(U(""));
|
|
|
|
}
|
|
|
|
;
|
|
|
|
AllExpr : PathExpr TOK_OpEq PathExpr
|
|
|
|
{
|
|
|
|
$$=$1;
|
|
|
|
$$=xmlStrcat($$,U("!="));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
}
|
|
|
|
| PathExpr TOK_OpNEq PathExpr
|
|
|
|
{
|
|
|
|
$$=$1;
|
|
|
|
$$=xmlStrcat($$,U("="));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
}
|
|
|
|
| PathExpr TOK_OpLt PathExpr
|
|
|
|
{
|
|
|
|
$$=$1;
|
|
|
|
$$=xmlStrcat($$,U(">="));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
}
|
|
|
|
| PathExpr TOK_OpLEq PathExpr
|
|
|
|
{
|
|
|
|
$$=$1;
|
|
|
|
$$=xmlStrcat($$,U(">"));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
}
|
|
|
|
| PathExpr TOK_OpGt PathExpr
|
|
|
|
{
|
|
|
|
$$=$1;
|
|
|
|
$$=xmlStrcat($$,U("<="));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
}
|
|
|
|
| PathExpr TOK_OpGEq PathExpr
|
|
|
|
{
|
|
|
|
$$=$1;
|
|
|
|
$$=xmlStrcat($$,U("<"));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
}
|
|
|
|
| PathExpr TOK_OpIEq PathExpr
|
|
|
|
{
|
|
|
|
$$=xmlStrdup(U("OP_INEq("));
|
|
|
|
$$=xmlStrcat($$,$1);
|
|
|
|
xmlFree($1);
|
|
|
|
$$=xmlStrcat($$,U(","));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
$$=xmlStrcat($$,U(")"));
|
|
|
|
}
|
|
|
|
| PathExpr TOK_OpINEq PathExpr
|
|
|
|
{
|
|
|
|
$$=xmlStrdup(U("OP_IEq("));
|
|
|
|
$$=xmlStrcat($$,$1);
|
|
|
|
xmlFree($1);
|
|
|
|
$$=xmlStrcat($$,U(","));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
$$=xmlStrcat($$,U(")"));
|
|
|
|
}
|
|
|
|
| PathExpr TOK_OpILt PathExpr
|
|
|
|
{
|
|
|
|
$$=xmlStrdup(U("OP_IGEq("));
|
|
|
|
$$=xmlStrcat($$,$1);
|
|
|
|
xmlFree($1);
|
|
|
|
$$=xmlStrcat($$,U(","));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
$$=xmlStrcat($$,U(")"));
|
|
|
|
}
|
|
|
|
| PathExpr TOK_OpILEq PathExpr
|
|
|
|
{
|
|
|
|
$$=xmlStrdup(U("OP_IGt("));
|
|
|
|
$$=xmlStrcat($$,$1);
|
|
|
|
xmlFree($1);
|
|
|
|
$$=xmlStrcat($$,U(","));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
$$=xmlStrcat($$,U(")"));
|
|
|
|
}
|
|
|
|
| PathExpr TOK_OpIGt PathExpr
|
|
|
|
{
|
|
|
|
$$=xmlStrdup(U("OP_ILEq("));
|
|
|
|
$$=xmlStrcat($$,$1);
|
|
|
|
xmlFree($1);
|
|
|
|
$$=xmlStrcat($$,U(","));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
$$=xmlStrcat($$,U(")"));
|
|
|
|
}
|
|
|
|
| PathExpr TOK_OpIGEq PathExpr
|
|
|
|
{
|
|
|
|
$$=xmlStrdup(U("OP_ILt("));
|
|
|
|
$$=xmlStrcat($$,$1);
|
|
|
|
xmlFree($1);
|
|
|
|
$$=xmlStrcat($$,U(","));
|
|
|
|
$$=xmlStrcat($$,$3);
|
|
|
|
xmlFree($3);
|
|
|
|
$$=xmlStrcat($$,U(")"));
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
#endif /* HAVE_LIBXML2 */
|