1*c2c66affSColin Finck /*
2*c2c66affSColin Finck * XSLPattern lexer
3*c2c66affSColin Finck *
4*c2c66affSColin Finck * Copyright 2010 Adam Martinson for CodeWeavers
5*c2c66affSColin Finck *
6*c2c66affSColin Finck * This library is free software; you can redistribute it and/or
7*c2c66affSColin Finck * modify it under the terms of the GNU Lesser General Public
8*c2c66affSColin Finck * License as published by the Free Software Foundation; either
9*c2c66affSColin Finck * version 2.1 of the License, or (at your option) any later version.
10*c2c66affSColin Finck *
11*c2c66affSColin Finck * This library is distributed in the hope that it will be useful,
12*c2c66affSColin Finck * but WITHOUT ANY WARRANTY; without even the implied warranty of
13*c2c66affSColin Finck * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14*c2c66affSColin Finck * Lesser General Public License for more details.
15*c2c66affSColin Finck *
16*c2c66affSColin Finck * You should have received a copy of the GNU Lesser General Public
17*c2c66affSColin Finck * License along with this library; if not, write to the Free Software
18*c2c66affSColin Finck * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19*c2c66affSColin Finck */
20*c2c66affSColin Finck
21*c2c66affSColin Finck %{
22*c2c66affSColin Finck #include "config.h"
23*c2c66affSColin Finck #include "wine/port.h"
24*c2c66affSColin Finck
25*c2c66affSColin Finck #ifdef HAVE_LIBXML2
26*c2c66affSColin Finck
27*c2c66affSColin Finck #include "xslpattern.h"
28*c2c66affSColin Finck #include "xslpattern.tab.h"
29*c2c66affSColin Finck #include "wine/debug.h"
30*c2c66affSColin Finck
31*c2c66affSColin Finck WINE_DEFAULT_DEBUG_CHANNEL(msxml);
32*c2c66affSColin Finck
33*c2c66affSColin Finck #define SCAN xslpattern_get_extra(yyscanner)
34*c2c66affSColin Finck
35*c2c66affSColin Finck #define YY_INPUT(tok_buf, tok_len, max) \
36*c2c66affSColin Finck do { \
37*c2c66affSColin Finck if (SCAN->pos <= SCAN->len) \
38*c2c66affSColin Finck { \
39*c2c66affSColin Finck tok_len = SCAN->len - SCAN->pos; \
40*c2c66affSColin Finck if (tok_len > max) tok_len = max; \
41*c2c66affSColin Finck memcpy(tok_buf, SCAN->in + SCAN->pos, tok_len); \
42*c2c66affSColin Finck SCAN->pos += tok_len; \
43*c2c66affSColin Finck } \
44*c2c66affSColin Finck else \
45*c2c66affSColin Finck { \
46*c2c66affSColin Finck tok_len = YY_NULL; \
47*c2c66affSColin Finck } \
48*c2c66affSColin Finck } while (0);
49*c2c66affSColin Finck
50*c2c66affSColin Finck #define TOK(tok) TRACE("token: %s : %s\n", #tok, yytext); return tok
51*c2c66affSColin Finck #define OP(tok) *yylval=NULL; TOK(tok)
52*c2c66affSColin Finck #define SYM(tok) *yylval=NULL; TOK(tok)
53*c2c66affSColin Finck #define STR(tok) *yylval=xmlStrdup(BAD_CAST yytext); TOK(tok)
54*c2c66affSColin Finck
55*c2c66affSColin Finck
56*c2c66affSColin Finck %}
57*c2c66affSColin Finck
58*c2c66affSColin Finck %option reentrant bison-bridge
59*c2c66affSColin Finck %option noyywrap
60*c2c66affSColin Finck %option prefix="xslpattern_"
61*c2c66affSColin Finck %option noinput nounput never-interactive
62*c2c66affSColin Finck
63*c2c66affSColin Finck /* From the w3c XML standard
64*c2c66affSColin Finck * <http://www.w3.org/TR/REC-xml/> */
65*c2c66affSColin Finck
66*c2c66affSColin Finck /* [2.3] Common Syntactic Constructs */
67*c2c66affSColin Finck WSpace ([[:space:]])
68*c2c66affSColin Finck
69*c2c66affSColin Finck NCNameStartChar ([A-Za-z_]|[\xc0-\xd6\xd8-\xf6\xf8-\xff])
70*c2c66affSColin Finck
71*c2c66affSColin Finck NameCharEx ([0-9]|[-._\xb7])
72*c2c66affSColin Finck
73*c2c66affSColin Finck NCNameChar ({NCNameStartChar}|{NameCharEx})
74*c2c66affSColin Finck
75*c2c66affSColin Finck /* From the w3c XML Namespace standard
76*c2c66affSColin Finck * <http://www.w3.org/TR/REC-xml-names/> */
77*c2c66affSColin Finck
78*c2c66affSColin Finck /* [3] Declaring Namespaces*/
79*c2c66affSColin Finck NCName ({NCNameStartChar}{NCNameChar}*)
80*c2c66affSColin Finck
81*c2c66affSColin Finck /* Mostly verbatim from the w3c XPath standard.
82*c2c66affSColin Finck * <http://www.w3.org/TR/xpath/> */
83*c2c66affSColin Finck
84*c2c66affSColin Finck
85*c2c66affSColin Finck /* [3.4] Booleans
86*c2c66affSColin Finck * ||, &&, $foo$ are XSLPattern only */
87*c2c66affSColin Finck
88*c2c66affSColin Finck OP_Or ("or"|"||"|"$or$")
89*c2c66affSColin Finck OP_And ("and"|"&&"|"$and$")
90*c2c66affSColin Finck OP_Eq ("="|"$eq$")
91*c2c66affSColin Finck OP_IEq ("$ieq$")
92*c2c66affSColin Finck OP_NEq ("!="|"$ne$")
93*c2c66affSColin Finck OP_INEq ("$ine$")
94*c2c66affSColin Finck OP_Lt ("<"|"$lt$")
95*c2c66affSColin Finck OP_ILt ("$ilt$")
96*c2c66affSColin Finck OP_Gt (">"|"$gt$")
97*c2c66affSColin Finck OP_IGt ("$igt$")
98*c2c66affSColin Finck OP_LEq ("<="|"$le$")
99*c2c66affSColin Finck OP_ILEq ("$ile$")
100*c2c66affSColin Finck OP_GEq (">="|"$ge$")
101*c2c66affSColin Finck OP_IGEq ("$ige$")
102*c2c66affSColin Finck OP_Not ("$not$")
103*c2c66affSColin Finck OP_All ("$all$")
104*c2c66affSColin Finck OP_Any ("$any$")
105*c2c66affSColin Finck
106*c2c66affSColin Finck /* [3.7] Lexical Structure */
107*c2c66affSColin Finck Literal (([\x22]([^\x22]*)[\x22])|([\x27]([^\x27]*)[\x27]))
108*c2c66affSColin Finck Number ({Digits}("."{Digits}?)?|"."{Digits})
109*c2c66affSColin Finck Digits ([0-9]+)
110*c2c66affSColin Finck
111*c2c66affSColin Finck ANY (.)
112*c2c66affSColin Finck
113*c2c66affSColin Finck %%
114*c2c66affSColin Finck
115*c2c66affSColin Finck {WSpace}+ { /* ignored */ }
116*c2c66affSColin Finck {Literal} { STR(TOK_Literal); }
117*c2c66affSColin Finck "//" { SYM(TOK_DblFSlash); }
118*c2c66affSColin Finck "/" { SYM(TOK_FSlash); }
119*c2c66affSColin Finck ".." { SYM(TOK_Parent); }
120*c2c66affSColin Finck "." { SYM(TOK_Self); }
121*c2c66affSColin Finck "::" { SYM(TOK_Axis); }
122*c2c66affSColin Finck ":" { SYM(TOK_Colon); }
123*c2c66affSColin Finck "(" { SYM('('); }
124*c2c66affSColin Finck ")" { SYM(')'); }
125*c2c66affSColin Finck "[" { SYM('['); }
126*c2c66affSColin Finck "]" { SYM(']'); }
127*c2c66affSColin Finck "@" { SYM('@'); }
128*c2c66affSColin Finck "," { SYM(','); }
129*c2c66affSColin Finck "*" { SYM('*'); }
130*c2c66affSColin Finck {OP_And} { OP(TOK_OpAnd); }
131*c2c66affSColin Finck {OP_Or} { OP(TOK_OpOr); }
132*c2c66affSColin Finck {OP_Not} { OP(TOK_OpNot); }
133*c2c66affSColin Finck {OP_Eq} { OP(TOK_OpEq); }
134*c2c66affSColin Finck {OP_IEq} { OP(TOK_OpIEq); }
135*c2c66affSColin Finck {OP_NEq} { OP(TOK_OpNEq); }
136*c2c66affSColin Finck {OP_INEq} { OP(TOK_OpINEq); }
137*c2c66affSColin Finck {OP_Lt} { OP(TOK_OpLt); }
138*c2c66affSColin Finck {OP_ILt} { OP(TOK_OpILt); }
139*c2c66affSColin Finck {OP_Gt} { OP(TOK_OpGt); }
140*c2c66affSColin Finck {OP_IGt} { OP(TOK_OpIGt); }
141*c2c66affSColin Finck {OP_LEq} { OP(TOK_OpLEq); }
142*c2c66affSColin Finck {OP_ILEq} { OP(TOK_OpILEq); }
143*c2c66affSColin Finck {OP_GEq} { OP(TOK_OpGEq); }
144*c2c66affSColin Finck {OP_IGEq} { OP(TOK_OpIGEq); }
145*c2c66affSColin Finck {OP_All} { OP(TOK_OpAll); }
146*c2c66affSColin Finck {OP_Any} { OP(TOK_OpAny); }
147*c2c66affSColin Finck "|" { SYM('|'); }
148*c2c66affSColin Finck "!" { SYM('!'); }
149*c2c66affSColin Finck {NCName} { STR(TOK_NCName); }
150*c2c66affSColin Finck {Number} { STR(TOK_Number); }
151*c2c66affSColin Finck {ANY} { FIXME("Unexpected character '%s'.\n",yytext); }
152*c2c66affSColin Finck
153*c2c66affSColin Finck %%
154*c2c66affSColin Finck
155*c2c66affSColin Finck xmlChar* XSLPattern_to_XPath(xmlXPathContextPtr, xmlChar const*) DECLSPEC_HIDDEN;
XSLPattern_to_XPath(xmlXPathContextPtr ctxt,xmlChar const * xslpat_str)156*c2c66affSColin Finck xmlChar* XSLPattern_to_XPath(xmlXPathContextPtr ctxt, xmlChar const* xslpat_str)
157*c2c66affSColin Finck {
158*c2c66affSColin Finck parser_param p;
159*c2c66affSColin Finck TRACE("(%s)\n", debugstr_a((char const*)xslpat_str));
160*c2c66affSColin Finck memset(&p, 0, sizeof(parser_param));
161*c2c66affSColin Finck p.ctx = ctxt;
162*c2c66affSColin Finck p.in = xslpat_str;
163*c2c66affSColin Finck p.len = xmlStrlen(xslpat_str);
164*c2c66affSColin Finck
165*c2c66affSColin Finck xslpattern_lex_init(&p.yyscanner);
166*c2c66affSColin Finck xslpattern_set_extra(&p, p.yyscanner);
167*c2c66affSColin Finck
168*c2c66affSColin Finck xslpattern_parse(&p, p.yyscanner);
169*c2c66affSColin Finck
170*c2c66affSColin Finck TRACE("=> %s\n", debugstr_a((char const*)p.out));
171*c2c66affSColin Finck xslpattern_lex_destroy(p.yyscanner);
172*c2c66affSColin Finck
173*c2c66affSColin Finck if (p.err)
174*c2c66affSColin Finck {
175*c2c66affSColin Finck xmlFree(p.out);
176*c2c66affSColin Finck return xmlStrdup(xslpat_str);
177*c2c66affSColin Finck }
178*c2c66affSColin Finck else
179*c2c66affSColin Finck {
180*c2c66affSColin Finck return p.out;
181*c2c66affSColin Finck }
182*c2c66affSColin Finck
183*c2c66affSColin Finck }
184*c2c66affSColin Finck
185*c2c66affSColin Finck #endif /* HAVE_LIBXML2 */
186