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