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