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