quartz: On flushing, always signal blocked event handle.
[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
25 #ifdef HAVE_LIBXML2
26
27 #include "xslpattern.h"
28 #include "xslpattern.tab.h"
29
30 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
31
32 #define SCAN    xslpattern_get_extra(yyscanner)
33
34 #define YY_INPUT(tok_buf, tok_len, max) \
35         do { \
36             if (SCAN->pos <= SCAN->len) \
37             { \
38                 tok_len = SCAN->len - SCAN->pos; \
39                 if (tok_len > max) tok_len = max; \
40                 memcpy(tok_buf, SCAN->in + SCAN->pos, tok_len); \
41                 SCAN->pos += tok_len; \
42             } \
43             else \
44             { \
45                 tok_len = YY_NULL; \
46             } \
47         } while (0);
48
49 #define TOK(tok)    TRACE("token: %s : %s\n", #tok, yytext); return tok
50 #define OP(tok)     *yylval=NULL; TOK(tok)
51 #define SYM(tok)    *yylval=NULL; TOK(tok)
52 #define STR(tok)    *yylval=xmlStrdup(BAD_CAST yytext); TOK(tok)
53
54
55 %}
56
57 %option reentrant bison-bridge
58 %option noyywrap
59 %option prefix="xslpattern_"
60 %option noinput nounput
61
62 /* From the w3c XML standard
63  * <http://www.w3.org/TR/REC-xml/> */
64
65     /* [2.3] Common Syntactic Constructs */
66 WSpace          ([[:space:]])
67
68 NCNameStartChar ([A-Za-z_]|[\xc0-\xd6\xd8-\xf6\xf8-\xff])
69
70 NameCharEx      ([0-9]|[-._\xb7])
71
72 NCNameChar      ({NCNameStartChar}|{NameCharEx})
73
74 /* From the w3c XML Namespace standard
75  * <http://www.w3.org/TR/REC-xml-names/> */
76
77     /* [3] Declaring Namespaces*/
78 NCName          ({NCNameStartChar}{NCNameChar}*)
79
80 /* Mostly verbatim from the w3c XPath standard.
81  * <http://www.w3.org/TR/xpath/> */
82
83
84     /* [3.4] Booleans
85      * ||, &&, $foo$ are XSLPattern only */
86
87 OP_Or           ("or"|"||"|"$or$")
88 OP_And          ("and"|"&&"|"$and$")
89 OP_Eq           ("="|"$eq$")
90 OP_IEq          ("$ieq$")
91 OP_NEq          ("!="|"$ne$")
92 OP_INEq         ("$ine$")
93 OP_Lt           ("<"|"$lt$")
94 OP_ILt          ("$ilt$")
95 OP_Gt           (">"|"$gt$")
96 OP_IGt          ("$igt$")
97 OP_LEq          ("<="|"$le$")
98 OP_ILEq         ("$ile$")
99 OP_GEq          (">="|"$ge$")
100 OP_IGEq         ("$ige$")
101 OP_Not          ("$not$")
102 OP_All          ("$all$")
103 OP_Any          ("$any$")
104
105     /* [3.7] Lexical Structure */
106 Literal             (([\x22]([^\x22]*)[\x22])|([\x27]([^\x27]*)[\x27]))
107 Number              ({Digits}("."{Digits}?)?|"."{Digits})
108 Digits              ([0-9]+)
109
110 ANY                 (.)
111
112 %%
113
114 {WSpace}+                   { /* ignored */ }
115 {Literal}                   { STR(TOK_Literal); }
116 "//"                        { SYM(TOK_DblFSlash); }
117 "/"                         { SYM(TOK_FSlash); }
118 ".."                        { SYM(TOK_Parent); }
119 "."                         { SYM(TOK_Self); }
120 "::"                        { SYM(TOK_Axis); }
121 ":"                         { SYM(TOK_Colon); }
122 "("                         { SYM('('); }
123 ")"                         { SYM(')'); }
124 "["                         { SYM('['); }
125 "]"                         { SYM(']'); }
126 "@"                         { SYM('@'); }
127 ","                         { SYM(','); }
128 "*"                         { SYM('*'); }
129 {OP_And}                    { OP(TOK_OpAnd); }
130 {OP_Or}                     { OP(TOK_OpOr); }
131 {OP_Not}                    { OP(TOK_OpNot); }
132 {OP_Eq}                     { OP(TOK_OpEq); }
133 {OP_IEq}                    { OP(TOK_OpIEq); }
134 {OP_NEq}                    { OP(TOK_OpNEq); }
135 {OP_INEq}                   { OP(TOK_OpINEq); }
136 {OP_Lt}                     { OP(TOK_OpLt); }
137 {OP_ILt}                    { OP(TOK_OpILt); }
138 {OP_Gt}                     { OP(TOK_OpGt); }
139 {OP_IGt}                    { OP(TOK_OpIGt); }
140 {OP_LEq}                    { OP(TOK_OpLEq); }
141 {OP_ILEq}                   { OP(TOK_OpILEq); }
142 {OP_GEq}                    { OP(TOK_OpGEq); }
143 {OP_IGEq}                   { OP(TOK_OpIGEq); }
144 {OP_All}                    { OP(TOK_OpAll); }
145 {OP_Any}                    { OP(TOK_OpAny); }
146 "|"                         { SYM('|'); }
147 "!"                         { SYM('!'); }
148 {NCName}                    { STR(TOK_NCName); }
149 {Number}                    { STR(TOK_Number); }
150 {ANY}                       { FIXME("Unexpected character '%s'.\n",yytext); }
151
152 %%
153
154 xmlChar* XSLPattern_to_XPath(xmlXPathContextPtr ctxt, xmlChar const* xslpat_str)
155 {
156     parser_param p;
157     TRACE("(%s)\n", wine_dbgstr_a((char const*)xslpat_str));
158     memset(&p, 0, sizeof(parser_param));
159     p.ctx = ctxt;
160     p.in = xslpat_str;
161     p.len = xmlStrlen(xslpat_str);
162
163     xslpattern_lex_init(&p.yyscanner);
164     xslpattern_set_extra(&p, p.yyscanner);
165
166     xslpattern_parse(&p, p.yyscanner);
167
168     TRACE("=> %s\n", wine_dbgstr_a((char const*)p.out));
169     xslpattern_lex_destroy(p.yyscanner);
170
171     if (p.err)
172     {
173         xmlFree(p.out);
174         return xmlStrdup(xslpat_str);
175     }
176     else
177     {
178         return p.out;
179     }
180
181 }
182
183 #endif /* HAVE_LIBXML2 */