Commit 4f78c04e authored by Adam Martinson's avatar Adam Martinson Committed by Alexandre Julliard

msxml3: XSLPattern support.

Parse XSLPattern queries and translate them into equivalent XPath queries. XSLPattern built-in functions/operators are translated to their XPath counterparts where applicable. If no direct XPath counterpart exists, they are registered as custom XPath functions for the sake of speed where possible. As a last resort, they are translated into compound XPath expressions to accomplish the task, if more slowly. If the parser encounters an error, the original XSLPattern query is returned, as this is more likely to work than a mangled one.
parent 0d27b740
......@@ -91,6 +91,9 @@ dlls/msi/sql.tab.h
dlls/mstask/mstask_local.h
dlls/mstask/mstask_local_i.c
dlls/msxml3/msxml3_v1.tlb
dlls/msxml3/xslpattern.tab.c
dlls/msxml3/xslpattern.tab.h
dlls/msxml3/xslpattern.yy.c
dlls/ole32/dcom.h
dlls/ole32/dcom_p.c
dlls/ole32/irot.h
......
......@@ -32,6 +32,10 @@ C_SRCS = \
xmldoc.c \
xmlelem.c
LEX_SRCS = xslpattern.l
BISON_SRCS = xslpattern.y
RC_SRCS = version.rc
IDL_TLB_SRCS = msxml3_v1.idl
......
......@@ -156,7 +156,7 @@ static inline domdoc_properties * properties_from_xmlDocPtr(xmlDocPtr doc)
return priv_from_xmlDocPtr(doc)->properties;
}
static inline BOOL is_xpathmode(const xmlDocPtr doc)
BOOL is_xpathmode(const xmlDocPtr doc)
{
return properties_from_xmlDocPtr(doc)->XPath;
}
......
/*
* XPath query result node list implementation (TODO: XSLPattern support)
* XPath/XSLPattern query result node list implementation
*
* Copyright 2005 Mike McCormack
* Copyright 2007 Mikolaj Zalewski
* 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
......@@ -41,7 +42,6 @@
* execution of the query
* - supports IXMLDOMSelection (TODO)
*
* TODO: XSLPattern support
*/
WINE_DEFAULT_DEBUG_CHANNEL(msxml);
......@@ -49,8 +49,11 @@ WINE_DEFAULT_DEBUG_CHANNEL(msxml);
#ifdef HAVE_LIBXML2
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
int registerNamespaces(xmlXPathContextPtr ctxt);
BOOL is_xpathmode(const xmlDocPtr doc);
xmlChar* XSLPattern_to_XPath(xmlChar const* xslpat_str);
typedef struct _queryresult
{
......@@ -374,6 +377,120 @@ static dispex_static_data_t queryresult_dispex = {
queryresult_iface_tids
};
void XSLPattern_invalid(xmlXPathParserContextPtr pctx, int nargs)
{
xmlXPathObjectPtr obj;
for (; nargs > 0; --nargs)
{
obj = valuePop(pctx);
xmlXPathFreeObject(obj);
}
obj = xmlMalloc(sizeof(xmlXPathObject));
obj->type = XPATH_UNDEFINED;
valuePush(pctx,obj);
}
#define XSLPATTERN_CHECK_ARGS(n) \
if (nargs != n) { \
FIXME("XSLPattern syntax error: Expected 0 arguments, got %i\n", nargs); \
XSLPattern_invalid(pctx, nargs); \
return; \
}
void XSLPattern_index(xmlXPathParserContextPtr pctx, int nargs)
{
XSLPATTERN_CHECK_ARGS(0);
xmlXPathPositionFunction(pctx, 0);
valuePush(pctx, xmlXPathNewFloat(xmlXPathPopNumber(pctx) - 1.0));
}
void XSLPattern_end(xmlXPathParserContextPtr pctx, int nargs)
{
double pos, last;
XSLPATTERN_CHECK_ARGS(0);
xmlXPathPositionFunction(pctx, 0);
pos = xmlXPathPopNumber(pctx);
xmlXPathLastFunction(pctx, 0);
last = xmlXPathPopNumber(pctx);
valuePush(pctx, xmlXPathNewBoolean(pos == last));
}
void XSLPattern_OP_IEq(xmlXPathParserContextPtr pctx, int nargs)
{
xmlChar *arg1, *arg2;
XSLPATTERN_CHECK_ARGS(2);
arg2 = xmlXPathPopString(pctx);
arg1 = xmlXPathPopString(pctx);
valuePush(pctx, xmlXPathNewBoolean(xmlStrcasecmp(arg1, arg2) == 0));
xmlFree(arg1);
xmlFree(arg2);
}
void XSLPattern_OP_INEq(xmlXPathParserContextPtr pctx, int nargs)
{
xmlChar *arg1, *arg2;
XSLPATTERN_CHECK_ARGS(2);
arg2 = xmlXPathPopString(pctx);
arg1 = xmlXPathPopString(pctx);
valuePush(pctx, xmlXPathNewBoolean(xmlStrcasecmp(arg1, arg2) != 0));
xmlFree(arg1);
xmlFree(arg2);
}
void XSLPattern_OP_ILt(xmlXPathParserContextPtr pctx, int nargs)
{
xmlChar *arg1, *arg2;
XSLPATTERN_CHECK_ARGS(2);
arg2 = xmlXPathPopString(pctx);
arg1 = xmlXPathPopString(pctx);
valuePush(pctx, xmlXPathNewBoolean(xmlStrcasecmp(arg1, arg2) < 0));
xmlFree(arg1);
xmlFree(arg2);
}
void XSLPattern_OP_ILEq(xmlXPathParserContextPtr pctx, int nargs)
{
xmlChar *arg1, *arg2;
XSLPATTERN_CHECK_ARGS(2);
arg2 = xmlXPathPopString(pctx);
arg1 = xmlXPathPopString(pctx);
valuePush(pctx, xmlXPathNewBoolean(xmlStrcasecmp(arg1, arg2) <= 0));
xmlFree(arg1);
xmlFree(arg2);
}
void XSLPattern_OP_IGt(xmlXPathParserContextPtr pctx, int nargs)
{
xmlChar *arg1, *arg2;
XSLPATTERN_CHECK_ARGS(2);
arg2 = xmlXPathPopString(pctx);
arg1 = xmlXPathPopString(pctx);
valuePush(pctx, xmlXPathNewBoolean(xmlStrcasecmp(arg1, arg2) > 0));
xmlFree(arg1);
xmlFree(arg2);
}
void XSLPattern_OP_IGEq(xmlXPathParserContextPtr pctx, int nargs)
{
xmlChar *arg1, *arg2;
XSLPATTERN_CHECK_ARGS(2);
arg2 = xmlXPathPopString(pctx);
arg1 = xmlXPathPopString(pctx);
valuePush(pctx, xmlXPathNewBoolean(xmlStrcasecmp(arg1, arg2) >= 0));
xmlFree(arg1);
xmlFree(arg2);
}
HRESULT queryresult_create(xmlNodePtr node, LPCWSTR szQuery, IXMLDOMNodeList **out)
{
queryresult *This = heap_alloc_zero(sizeof(queryresult));
......@@ -399,6 +516,35 @@ HRESULT queryresult_create(xmlNodePtr node, LPCWSTR szQuery, IXMLDOMNodeList **o
ctxt->node = node;
registerNamespaces(ctxt);
if (is_xpathmode(This->node->doc))
{
xmlXPathRegisterAllFunctions(ctxt);
}
else
{
xmlChar* tmp;
int len;
WARN("Attempting XSLPattern emulation (experimental).\n");
tmp = XSLPattern_to_XPath(str);
len = (xmlStrlen(tmp)+1)*sizeof(xmlChar);
str = heap_realloc(str, len);
memcpy(str, tmp, len);
xmlFree(tmp);
xmlXPathRegisterFunc(ctxt, (xmlChar const*)"not", xmlXPathNotFunction);
xmlXPathRegisterFunc(ctxt, (xmlChar const*)"boolean", xmlXPathBooleanFunction);
xmlXPathRegisterFunc(ctxt, (xmlChar const*)"index", XSLPattern_index);
xmlXPathRegisterFunc(ctxt, (xmlChar const*)"end", XSLPattern_end);
xmlXPathRegisterFunc(ctxt, (xmlChar const*)"OP_IEq", XSLPattern_OP_IEq);
xmlXPathRegisterFunc(ctxt, (xmlChar const*)"OP_INEq", XSLPattern_OP_INEq);
xmlXPathRegisterFunc(ctxt, (xmlChar const*)"OP_ILt", XSLPattern_OP_ILt);
xmlXPathRegisterFunc(ctxt, (xmlChar const*)"OP_ILEq", XSLPattern_OP_ILEq);
xmlXPathRegisterFunc(ctxt, (xmlChar const*)"OP_IGt", XSLPattern_OP_IGt);
xmlXPathRegisterFunc(ctxt, (xmlChar const*)"OP_IGEq", XSLPattern_OP_IGEq);
}
This->result = xmlXPathEval(str, ctxt);
if (!This->result || This->result->type != XPATH_NODESET)
{
......
......@@ -3,6 +3,7 @@
*
* Copyright 2005 Mike McCormack for CodeWeavers
* Copyright 2007-2008 Alistair Leslie-Hughes
* 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
......@@ -6052,16 +6053,223 @@ static void test_XSLPattern(void)
len = 0;
ole_check(IXMLDOMNodeList_get_length(list, &len));
/* should select <elem><c> and <elem xmlns='...'><c> but not <elem><foo:c> */
todo_wine ok(len == 3, "expected 3 entries in list, got %d\n", len);
ok(len == 3, "expected 3 entries in list, got %d\n", len);
IXMLDOMNodeList_Release(list);
/* for XSLPattern start index is 0, for XPath it's 1 */
ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[0]"), &list));
len = 0;
ole_check(IXMLDOMNodeList_get_length(list, &len));
todo_wine ok(len != 0, "expected filled list\n");
ok(len != 0, "expected filled list\n");
if (len)
todo_wine expect_list_and_release(list, "E1.E2.D1");
expect_list_and_release(list, "E1.E2.D1");
/* index() */
ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()=1]"), &list));
len = 0;
ole_check(IXMLDOMNodeList_get_length(list, &len));
ok(len != 0, "expected filled list\n");
if (len)
expect_list_and_release(list, "E2.E2.D1");
/* $eq$ */
ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $eq$ 1]"), &list));
len = 0;
ole_check(IXMLDOMNodeList_get_length(list, &len));
ok(len != 0, "expected filled list\n");
if (len)
expect_list_and_release(list, "E2.E2.D1");
/* end() */
ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[end()]"), &list));
len = 0;
ole_check(IXMLDOMNodeList_get_length(list, &len));
ok(len != 0, "expected filled list\n");
if (len)
expect_list_and_release(list, "E4.E2.D1");
/* $not$ */
ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[$not$ end()]"), &list));
len = 0;
ole_check(IXMLDOMNodeList_get_length(list, &len));
ok(len != 0, "expected filled list\n");
if (len)
expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1");
/* !=/$ne$ */
ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() != 0]"), &list));
len = 0;
ole_check(IXMLDOMNodeList_get_length(list, &len));
ok(len != 0, "expected filled list\n");
if (len)
expect_list_and_release(list, "E2.E2.D1 E3.E2.D1 E4.E2.D1");
ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $ne$ 0]"), &list));
len = 0;
ole_check(IXMLDOMNodeList_get_length(list, &len));
ok(len != 0, "expected filled list\n");
if (len)
expect_list_and_release(list, "E2.E2.D1 E3.E2.D1 E4.E2.D1");
/* </$lt$ */
ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() < 2]"), &list));
len = 0;
ole_check(IXMLDOMNodeList_get_length(list, &len));
ok(len != 0, "expected filled list\n");
if (len)
expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $lt$ 2]"), &list));
len = 0;
ole_check(IXMLDOMNodeList_get_length(list, &len));
ok(len != 0, "expected filled list\n");
if (len)
expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
/* <=/$le$ */
ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() <= 1]"), &list));
len = 0;
ole_check(IXMLDOMNodeList_get_length(list, &len));
ok(len != 0, "expected filled list\n");
if (len)
expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $le$ 1]"), &list));
len = 0;
ole_check(IXMLDOMNodeList_get_length(list, &len));
ok(len != 0, "expected filled list\n");
if (len)
expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
/* >/$gt$ */
ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() > 1]"), &list));
len = 0;
ole_check(IXMLDOMNodeList_get_length(list, &len));
ok(len != 0, "expected filled list\n");
if (len)
expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $gt$ 1]"), &list));
len = 0;
ole_check(IXMLDOMNodeList_get_length(list, &len));
ok(len != 0, "expected filled list\n");
if (len)
expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
/* >=/$ge$ */
ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() >= 2]"), &list));
len = 0;
ole_check(IXMLDOMNodeList_get_length(list, &len));
ok(len != 0, "expected filled list\n");
if (len)
expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $ge$ 2]"), &list));
len = 0;
ole_check(IXMLDOMNodeList_get_length(list, &len));
ok(len != 0, "expected filled list\n");
if (len)
expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
/* $ieq$ */
ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $ieq$ 'a2 field']"), &list));
len = 0;
ole_check(IXMLDOMNodeList_get_length(list, &len));
ok(len != 0, "expected filled list\n");
if (len)
expect_list_and_release(list, "E2.E2.D1");
/* $ine$ */
ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $ine$ 'a2 field']"), &list));
len = 0;
ole_check(IXMLDOMNodeList_get_length(list, &len));
ok(len != 0, "expected filled list\n");
if (len)
expect_list_and_release(list, "E1.E2.D1 E3.E2.D1 E4.E2.D1");
/* $ilt$ */
ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $ilt$ 'a3 field']"), &list));
len = 0;
ole_check(IXMLDOMNodeList_get_length(list, &len));
ok(len != 0, "expected filled list\n");
if (len)
expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
/* $ile$ */
ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $ile$ 'a2 field']"), &list));
len = 0;
ole_check(IXMLDOMNodeList_get_length(list, &len));
ok(len != 0, "expected filled list\n");
if (len)
expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
/* $igt$ */
ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $igt$ 'a2 field']"), &list));
len = 0;
ole_check(IXMLDOMNodeList_get_length(list, &len));
ok(len != 0, "expected filled list\n");
if (len)
expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
/* $ige$ */
ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $ige$ 'a3 field']"), &list));
len = 0;
ole_check(IXMLDOMNodeList_get_length(list, &len));
ok(len != 0, "expected filled list\n");
if (len)
expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
/* $any$ */
ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[$any$ *='B2 field']"), &list));
len = 0;
ole_check(IXMLDOMNodeList_get_length(list, &len));
ok(len != 0, "expected filled list\n");
if (len)
expect_list_and_release(list, "E2.E2.D1");
/* $all$ */
ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[$all$ *!='B2 field']"), &list));
len = 0;
ole_check(IXMLDOMNodeList_get_length(list, &len));
ok(len != 0, "expected filled list\n");
if (len)
expect_list_and_release(list, "E1.E2.D1 E3.E2.D1 E4.E2.D1");
/* or/$or$/|| */
ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()=0 or end()]"), &list));
len = 0;
ole_check(IXMLDOMNodeList_get_length(list, &len));
ok(len != 0, "expected filled list\n");
if (len)
expect_list_and_release(list, "E1.E2.D1 E4.E2.D1");
ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()=0 $or$ end()]"), &list));
len = 0;
ole_check(IXMLDOMNodeList_get_length(list, &len));
ok(len != 0, "expected filled list\n");
if (len)
expect_list_and_release(list, "E1.E2.D1 E4.E2.D1");
ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()=0 || end()]"), &list));
len = 0;
ole_check(IXMLDOMNodeList_get_length(list, &len));
ok(len != 0, "expected filled list\n");
if (len)
expect_list_and_release(list, "E1.E2.D1 E4.E2.D1");
/* and/$and$/&& */
ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()>0 and $not$ end()]"), &list));
len = 0;
ole_check(IXMLDOMNodeList_get_length(list, &len));
ok(len != 0, "expected filled list\n");
if (len)
expect_list_and_release(list, "E2.E2.D1 E3.E2.D1");
ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()>0 $and$ $not$ end()]"), &list));
len = 0;
ole_check(IXMLDOMNodeList_get_length(list, &len));
ok(len != 0, "expected filled list\n");
if (len)
expect_list_and_release(list, "E2.E2.D1 E3.E2.D1");
ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()>0 && $not$ end()]"), &list));
len = 0;
ole_check(IXMLDOMNodeList_get_length(list, &len));
ok(len != 0, "expected filled list\n");
if (len)
expect_list_and_release(list, "E2.E2.D1 E3.E2.D1");
IXMLDOMDocument2_Release(doc);
free_bstrs();
......
/*
* XSLPattern lexer/parser shared internals
*
* 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
*/
#ifndef __XSLPATTERN__
#define __XSLPATTERN__
#ifndef __WINE_CONFIG_H
#error You must include config.h to use this header
#endif
#include "wine/debug.h"
#ifndef HAVE_LIBXML2
#error You must have libxml2 to use this header
#endif
#include <libxml/tree.h>
#include <libxml/xmlstring.h>
typedef struct _parser_param {
void* yyscanner;
xmlChar const* in;
int pos;
int len;
xmlChar* out;
int err;
} parser_param;
#define YYSTYPE xmlChar*
#define YY_EXTRA_TYPE parser_param*
int xslpattern_lex(xmlChar**, void*);
int xslpattern_lex_init(void**);
int xslpattern_lex_destroy(void*);
void xslpattern_set_extra(parser_param*, void*);
int xslpattern_parse(parser_param*, void*);
void xslpattern_error(parser_param* param, void const* scanner, char const* msg);
#endif /* __XSLPATTERN__ */
/*
* XSLPattern lexer
*
* 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"
#include "xslpattern.tab.h"
WINE_DEFAULT_DEBUG_CHANNEL(msxml);
#define SCAN xslpattern_get_extra(yyscanner)
#define YY_INPUT(tok_buf, tok_len, max) \
do { \
if (SCAN->pos <= SCAN->len) \
{ \
tok_len = SCAN->len - SCAN->pos; \
if (tok_len > max) tok_len = max; \
memcpy(tok_buf, SCAN->in + SCAN->pos, tok_len); \
SCAN->pos += tok_len; \
} \
else \
{ \
tok_len = YY_NULL; \
} \
} while (0);
#define TOK(tok) TRACE("token: %s : %s\n", #tok, yytext); return tok
#define OP(tok) *yylval=NULL; TOK(tok)
#define SYM(tok) *yylval=NULL; TOK(tok)
#define STR(tok) *yylval=xmlStrdup(BAD_CAST yytext); TOK(tok)
%}
%option reentrant bison-bridge
%option noyywrap
%option prefix="xslpattern_"
%option noinput nounput
/* From the w3c XML standard
* <http://www.w3.org/TR/REC-xml/> */
/* [2.3] Common Syntactic Constructs */
WSpace ([[:space:]])
NCNameStartChar ([A-Za-z_]|[\xc0-\xd6\xd8-\xf6\xf8-\xff])
NameCharEx ([0-9]|[-._\xb7])
NCNameChar ({NCNameStartChar}|{NameCharEx})
/* From the w3c XML Namespace standard
* <http://www.w3.org/TR/REC-xml-names/> */
/* [3] Declaring Namespaces*/
NCName ({NCNameStartChar}{NCNameChar}*)
/* Mostly verbatim from the w3c XPath standard.
* <http://www.w3.org/TR/xpath/> */
/* [3.4] Booleans
* ||, &&, $foo$ are XSLPattern only */
OP_Or ("or"|"||"|"$or$")
OP_And ("and"|"&&"|"$and$")
OP_Eq ("="|"$eq$")
OP_IEq ("$ieq$")
OP_NEq ("!="|"$ne$")
OP_INEq ("$ine$")
OP_Lt ("<"|"$lt$")
OP_ILt ("$ilt$")
OP_Gt (">"|"$gt$")
OP_IGt ("$igt$")
OP_LEq ("<="|"$le$")
OP_ILEq ("$ile$")
OP_GEq (">="|"$ge$")
OP_IGEq ("$ige$")
OP_Not ("$not$")
OP_All ("$all$")
OP_Any ("$any$")
/* [3.7] Lexical Structure */
Literal (([\x22]([^\x22]*)[\x22])|([\x27]([^\x27]*)[\x27]))
Number ({Digits}("."{Digits}?)?|"."{Digits})
Digits ([0-9]+)
ANY (.)
%%
{WSpace}+ { /* ignored */ }
{Literal} { STR(TOK_Literal); }
"//" { SYM(TOK_DblFSlash); }
"/" { SYM(TOK_FSlash); }
".." { SYM(TOK_Parent); }
"." { SYM(TOK_Self); }
"::" { SYM(TOK_Axis); }
":" { SYM(TOK_Colon); }
"(" { SYM('('); }
")" { SYM(')'); }
"[" { SYM('['); }
"]" { SYM(']'); }
"@" { SYM('@'); }
"," { SYM(','); }
"*" { SYM('*'); }
{OP_And} { OP(TOK_OpAnd); }
{OP_Or} { OP(TOK_OpOr); }
{OP_Not} { OP(TOK_OpNot); }
{OP_Eq} { OP(TOK_OpEq); }
{OP_IEq} { OP(TOK_OpIEq); }
{OP_NEq} { OP(TOK_OpNEq); }
{OP_INEq} { OP(TOK_OpINEq); }
{OP_Lt} { OP(TOK_OpLt); }
{OP_ILt} { OP(TOK_OpILt); }
{OP_Gt} { OP(TOK_OpGt); }
{OP_IGt} { OP(TOK_OpIGt); }
{OP_LEq} { OP(TOK_OpLEq); }
{OP_ILEq} { OP(TOK_OpILEq); }
{OP_GEq} { OP(TOK_OpGEq); }
{OP_IGEq} { OP(TOK_OpIGEq); }
{OP_All} { OP(TOK_OpAll); }
{OP_Any} { OP(TOK_OpAny); }
"|" { SYM('|'); }
"!" { SYM('!'); }
{NCName} { STR(TOK_NCName); }
{Number} { STR(TOK_Number); }
{ANY} { FIXME("Unexpected character '%s'.",yytext); }
%%
xmlChar* XSLPattern_to_XPath(xmlChar const* xslpat_str)
{
parser_param p;
TRACE("(%s)\n", wine_dbgstr_a((char const*)xslpat_str));
memset(&p, 0, sizeof(parser_param));
p.in = xslpat_str;
p.len = xmlStrlen(xslpat_str);
xslpattern_lex_init(&p.yyscanner);
xslpattern_set_extra(&p, p.yyscanner);
xslpattern_parse(&p, p.yyscanner);
TRACE("=> %s\n", wine_dbgstr_a((char const*)p.out));
xslpattern_lex_destroy(p.yyscanner);
if (p.err)
{
xmlFree(p.out);
return xmlStrdup(xslpat_str);
}
else
{
return p.out;
}
}
#endif /* HAVE_LIBXML2 */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment