File: xslpattern.l

package info (click to toggle)
wine-development 4.2-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 209,180 kB
  • sloc: ansic: 2,917,742; perl: 18,943; yacc: 15,637; makefile: 9,182; objc: 6,548; lex: 4,315; python: 1,786; cpp: 1,042; sh: 771; java: 742; xml: 557; awk: 69; cs: 17
file content (185 lines) | stat: -rw-r--r-- 5,653 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
 *    XSLPattern lexer
 *
 * Copyright 2010 Adam Martinson for CodeWeavers
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

%{
#include "config.h"
#include "wine/port.h"

#ifdef HAVE_LIBXML2

#include "xslpattern.h"
#include "xslpattern.tab.h"
#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(msxml);

#define SCAN    xslpattern_get_extra(yyscanner)

#define YY_INPUT(tok_buf, tok_len, max) \
        do { \
            if (SCAN->pos <= SCAN->len) \
            { \
                tok_len = SCAN->len - SCAN->pos; \
                if (tok_len > max) tok_len = max; \
                memcpy(tok_buf, SCAN->in + SCAN->pos, tok_len); \
                SCAN->pos += tok_len; \
            } \
            else \
            { \
                tok_len = YY_NULL; \
            } \
        } while (0);

#define TOK(tok)    TRACE("token: %s : %s\n", #tok, yytext); return tok
#define OP(tok)     *yylval=NULL; TOK(tok)
#define SYM(tok)    *yylval=NULL; TOK(tok)
#define STR(tok)    *yylval=xmlStrdup(BAD_CAST yytext); TOK(tok)


%}

%option reentrant bison-bridge
%option noyywrap
%option prefix="xslpattern_"
%option noinput nounput never-interactive

/* From the w3c XML standard
 * <http://www.w3.org/TR/REC-xml/> */

    /* [2.3] Common Syntactic Constructs */
WSpace          ([[:space:]])

NCNameStartChar ([A-Za-z_]|[\xc0-\xd6\xd8-\xf6\xf8-\xff])

NameCharEx      ([0-9]|[-._\xb7])

NCNameChar      ({NCNameStartChar}|{NameCharEx})

/* From the w3c XML Namespace standard
 * <http://www.w3.org/TR/REC-xml-names/> */

    /* [3] Declaring Namespaces*/
NCName          ({NCNameStartChar}{NCNameChar}*)

/* Mostly verbatim from the w3c XPath standard.
 * <http://www.w3.org/TR/xpath/> */


    /* [3.4] Booleans
     * ||, &&, $foo$ are XSLPattern only */

OP_Or           ("or"|"||"|"$or$")
OP_And          ("and"|"&&"|"$and$")
OP_Eq           ("="|"$eq$")
OP_IEq          ("$ieq$")
OP_NEq          ("!="|"$ne$")
OP_INEq         ("$ine$")
OP_Lt           ("<"|"$lt$")
OP_ILt          ("$ilt$")
OP_Gt           (">"|"$gt$")
OP_IGt          ("$igt$")
OP_LEq          ("<="|"$le$")
OP_ILEq         ("$ile$")
OP_GEq          (">="|"$ge$")
OP_IGEq         ("$ige$")
OP_Not          ("$not$")
OP_All          ("$all$")
OP_Any          ("$any$")

    /* [3.7] Lexical Structure */
Literal             (([\x22]([^\x22]*)[\x22])|([\x27]([^\x27]*)[\x27]))
Number              ({Digits}("."{Digits}?)?|"."{Digits})
Digits              ([0-9]+)

ANY                 (.)

%%

{WSpace}+                   { /* ignored */ }
{Literal}                   { STR(TOK_Literal); }
"//"                        { SYM(TOK_DblFSlash); }
"/"                         { SYM(TOK_FSlash); }
".."                        { SYM(TOK_Parent); }
"."                         { SYM(TOK_Self); }
"::"                        { SYM(TOK_Axis); }
":"                         { SYM(TOK_Colon); }
"("                         { SYM('('); }
")"                         { SYM(')'); }
"["                         { SYM('['); }
"]"                         { SYM(']'); }
"@"                         { SYM('@'); }
","                         { SYM(','); }
"*"                         { SYM('*'); }
{OP_And}                    { OP(TOK_OpAnd); }
{OP_Or}                     { OP(TOK_OpOr); }
{OP_Not}                    { OP(TOK_OpNot); }
{OP_Eq}                     { OP(TOK_OpEq); }
{OP_IEq}                    { OP(TOK_OpIEq); }
{OP_NEq}                    { OP(TOK_OpNEq); }
{OP_INEq}                   { OP(TOK_OpINEq); }
{OP_Lt}                     { OP(TOK_OpLt); }
{OP_ILt}                    { OP(TOK_OpILt); }
{OP_Gt}                     { OP(TOK_OpGt); }
{OP_IGt}                    { OP(TOK_OpIGt); }
{OP_LEq}                    { OP(TOK_OpLEq); }
{OP_ILEq}                   { OP(TOK_OpILEq); }
{OP_GEq}                    { OP(TOK_OpGEq); }
{OP_IGEq}                   { OP(TOK_OpIGEq); }
{OP_All}                    { OP(TOK_OpAll); }
{OP_Any}                    { OP(TOK_OpAny); }
"|"                         { SYM('|'); }
"!"                         { SYM('!'); }
{NCName}                    { STR(TOK_NCName); }
{Number}                    { STR(TOK_Number); }
{ANY}                       { FIXME("Unexpected character '%s'.\n",yytext); }

%%

xmlChar* XSLPattern_to_XPath(xmlXPathContextPtr, xmlChar const*) DECLSPEC_HIDDEN;
xmlChar* XSLPattern_to_XPath(xmlXPathContextPtr ctxt, xmlChar const* xslpat_str)
{
    parser_param p;
    TRACE("(%s)\n", debugstr_a((char const*)xslpat_str));
    memset(&p, 0, sizeof(parser_param));
    p.ctx = ctxt;
    p.in = xslpat_str;
    p.len = xmlStrlen(xslpat_str);

    xslpattern_lex_init(&p.yyscanner);
    xslpattern_set_extra(&p, p.yyscanner);

    xslpattern_parse(&p, p.yyscanner);

    TRACE("=> %s\n", debugstr_a((char const*)p.out));
    xslpattern_lex_destroy(p.yyscanner);

    if (p.err)
    {
        xmlFree(p.out);
        return xmlStrdup(xslpat_str);
    }
    else
    {
        return p.out;
    }

}

#endif /* HAVE_LIBXML2 */