xslpattern.y 31.8 KB
Newer Older
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
/*
 *    XSLPattern parser (XSLPattern => XPath)
 *
 * 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"
27
#include <libxml/xpathInternals.h>
28
#include "wine/debug.h"
29 30 31 32

WINE_DEFAULT_DEBUG_CHANNEL(msxml);


33
static const xmlChar NameTest_mod_pre[] = "*[name()='";
34 35 36
static const xmlChar NameTest_mod_post[] = "']";

#define U(str) BAD_CAST str
37

38 39 40 41 42 43 44
static inline BOOL is_literal(xmlChar const* tok)
{
    return (tok && tok[0] && tok[1] &&
            tok[0]== tok[xmlStrlen(tok)-1] &&
            (tok[0] == '\'' || tok[0] == '"'));
}

45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
static void xslpattern_error(parser_param* param, void const* scanner, char const* msg)
{
    FIXME("%s:\n"
          "  param {\n"
          "    yyscanner=%p\n"
          "    ctx=%p\n"
          "    in=\"%s\"\n"
          "    pos=%i\n"
          "    len=%i\n"
          "    out=\"%s\"\n"
          "    err=%i\n"
          "  }\n"
          "  scanner=%p\n",
          msg, param->yyscanner, param->ctx, param->in, param->pos,
          param->len, param->out, ++param->err, scanner);
}

62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
%}

%token TOK_Parent TOK_Self TOK_DblFSlash TOK_FSlash TOK_Axis TOK_Colon
%token TOK_OpAnd TOK_OpOr TOK_OpNot
%token TOK_OpEq TOK_OpIEq TOK_OpNEq TOK_OpINEq
%token TOK_OpLt TOK_OpILt TOK_OpGt TOK_OpIGt TOK_OpLEq TOK_OpILEq TOK_OpGEq TOK_OpIGEq
%token TOK_OpAll TOK_OpAny
%token TOK_NCName TOK_Literal TOK_Number

%start XSLPattern

%pure_parser
%parse-param {parser_param* p}
%parse-param {void* scanner}
%lex-param {yyscan_t* scanner}

%left TOK_OpAnd TOK_OpOr
%left TOK_OpEq TOK_OpIEq TOK_OpNEq TOK_OpINEq
%left TOK_OpLt TOK_OpILt TOK_OpGt TOK_OpIGt TOK_OpLEq TOK_OpILEq TOK_OpGEq TOK_OpIGEq

82 83
%expect 14

84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
%%

    XSLPattern              : Expr
                            {
                                p->out = $1;
                            }
    ;

/* Mostly verbatim from the w3c XML Namespaces standard.
 * <http://www.w3.org/TR/REC-xml-names/> */

    /* [4] Qualified Names */
    QName                   : PrefixedName
                            | UnprefixedName
    ;
    PrefixedName            : TOK_NCName TOK_Colon TOK_NCName
                            {
101
                                TRACE("Got PrefixedName: \"%s:%s\"\n", $1, $3);
102
                                $$=$1;
103
                                $$=xmlStrcat($$,U(":"));
104 105 106 107 108 109
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                            }
    ;
    UnprefixedName          : TOK_NCName
                            {
110
                                TRACE("Got UnprefixedName: \"%s\"\n", $1);
111 112 113 114 115 116 117 118 119 120 121 122 123
                                $$=$1;
                            }
    ;

/* Based on the w3c XPath standard, adapted where needed.
 * <http://www.w3.org/TR/xpath/> */

    /* [2] Location Paths */
    LocationPath            : RelativeLocationPath
                            | AbsoluteLocationPath
    ;
    AbsoluteLocationPath    : TOK_FSlash RelativeLocationPath
                            {
124
                                TRACE("Got AbsoluteLocationPath: \"/%s\"\n", $2);
125 126 127 128 129 130
                                $$=xmlStrdup(U("/"));
                                $$=xmlStrcat($$,$2);
                                xmlFree($2);
                            }
                            | TOK_FSlash
                            {
131
                                TRACE("Got AbsoluteLocationPath: \"/\"\n");
132 133 134 135 136 137 138
                                $$=xmlStrdup(U("/"));
                            }
                            | AbbreviatedAbsoluteLocationPath
    ;
    RelativeLocationPath    : Step
                            | RelativeLocationPath TOK_FSlash Step
                            {
139
                                TRACE("Got RelativeLocationPath: \"%s/%s\"\n", $1, $3);
140 141 142 143 144 145 146 147
                                $$=$1;
                                $$=xmlStrcat($$,U("/"));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                            }
                            | AbbreviatedRelativeLocationPath
    ;
    /* [2.1] Location Steps */
148
    Step                    : AxisSpecifier NodeTest Predicates
149
                            {
150
                                TRACE("Got Step: \"%s%s%s\"\n", $1, $2, $3);
151 152 153 154 155 156
                                $$=$1;
                                $$=xmlStrcat($$,$2);
                                xmlFree($2);
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                            }
157
                            | NodeTest Predicates
158
                            {
159
                                TRACE("Got Step: \"%s%s\"\n", $1, $2);
160 161 162 163
                                $$=$1;
                                $$=xmlStrcat($$,$2);
                                xmlFree($2);
                            }
164
                            | AxisSpecifier NodeTest
165
                            {
166
                                TRACE("Got Step: \"%s%s\"\n", $1, $2);
167 168 169 170
                                $$=$1;
                                $$=xmlStrcat($$,$2);
                                xmlFree($2);
                            }
171
                            | NodeTest
172 173 174 175 176
                            | Attribute
                            | AbbreviatedStep
    ;
    AxisSpecifier           : TOK_NCName TOK_Axis
                            {
177
                                TRACE("Got AxisSpecifier: \"%s::\"\n", $1);
178 179 180 181
                                $$=$1;
                                $$=xmlStrcat($$,U("::"));
                            }
    ;
182
    Attribute               : '@' QName
183
                            {
184
                                TRACE("Got Attribute: \"@%s\"\n", $2);
185 186 187 188 189 190 191
                                $$=xmlStrdup(U("@"));
                                $$=xmlStrcat($$,$2);
                                xmlFree($2);
                            }
    ;

    /* [2.3] Node Tests */
192 193 194
    NodeTest                : NameTest
                            | FunctionCall
    ;
195 196
    NameTest                : '*'
                            {
197
                                TRACE("Got NameTest: \"*\"\n");
198 199 200 201
                                $$=xmlStrdup(U("*"));
                            }
                            | TOK_NCName TOK_Colon '*'
                            {
202
                                TRACE("Got NameTest: \"%s:*\"\n", $1);
203 204 205
                                $$=$1;
                                $$=xmlStrcat($$,U(":*"));
                            }
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
                            | TOK_NCName TOK_Colon TOK_NCName
                            { /* PrefixedName */
                                xmlChar const* registeredNsURI = xmlXPathNsLookup(p->ctx, $1);
                                TRACE("Got PrefixedName: \"%s:%s\"\n", $1, $3);

                                if (registeredNsURI)
                                    $$=xmlStrdup(U(""));
                                else
                                    $$=xmlStrdup(NameTest_mod_pre);

                                $$=xmlStrcat($$,$1);
                                xmlFree($1);
                                $$=xmlStrcat($$,U(":"));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);

                                if (!registeredNsURI)
                                    $$=xmlStrcat($$,NameTest_mod_post);
                            }
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
                            | UnprefixedName
                            {
                                $$=xmlStrdup(NameTest_mod_pre);
                                $$=xmlStrcat($$,$1);
                                xmlFree($1);
                                $$=xmlStrcat($$,NameTest_mod_post);
                            }
    /* [2.4] Predicates */
    Predicates              : Predicates Predicate
                            {
                                $$=$1;
                                $$=xmlStrcat($$,$2);
                                xmlFree($2);
                            }
                            | Predicate
    ;
    Predicate               : '[' PredicateExpr ']'
                            {
243
                                TRACE("Got Predicate: \"[%s]\"\n", $2);
244 245 246 247 248 249 250 251 252 253 254 255 256 257
                                $$=xmlStrdup(U("["));
                                $$=xmlStrcat($$,$2);
                                xmlFree($2);
                                $$=xmlStrcat($$,U("]"));
                            }
    ;
    PredicateExpr           : TOK_Number
                            {
                                $$=xmlStrdup(U("index()="));
                                $$=xmlStrcat($$,$1);
                                xmlFree($1);
                            }
                            | BoolExpr
                            | Attribute
258
                            | TOK_NCName
259 260 261 262
    ;
    /* [2.5] Abbreviated Syntax */
    AbbreviatedAbsoluteLocationPath : TOK_DblFSlash RelativeLocationPath
                            {
263
                                TRACE("Got AbbreviatedAbsoluteLocationPath: \"//%s\"\n", $2);
264 265 266 267 268 269 270
                                $$=xmlStrdup(U("//"));
                                $$=xmlStrcat($$,$2);
                                xmlFree($2);
                            }
    ;
    AbbreviatedRelativeLocationPath : RelativeLocationPath TOK_DblFSlash Step
                            {
271
                                TRACE("Got AbbreviatedRelativeLocationPath: \"%s//%s\"\n", $1, $3);
272 273 274 275 276 277 278 279
                                $$=$1;
                                $$=xmlStrcat($$,U("//"));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                            }
    ;
    AbbreviatedStep         : TOK_Parent
                            {
280
                                TRACE("Got AbbreviatedStep: \"..\"\n");
281 282 283 284
                                $$=xmlStrdup(U(".."));
                            }
                            | TOK_Self
                            {
285
                                TRACE("Got AbbreviatedStep: \".\"\n");
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
                                $$=xmlStrdup(U("."));
                            }
    ;

    /* [3] Expressions */
    /* [3.1] Basics */
    Expr                    : OrExpr
    ;
    BoolExpr                : FunctionCall
                            | BoolUnaryExpr
                            | BoolRelationalExpr
                            | BoolEqualityExpr
                            | BoolAndExpr
                            | BoolOrExpr
    ;
    PrimaryExpr             : '(' Expr ')'
                            {
303
                                TRACE("Got PrimaryExpr: \"(%s)\"\n", $1);
304 305 306 307 308 309 310
                                $$=xmlStrdup(U("("));
                                $$=xmlStrcat($$,$2);
                                xmlFree($2);
                                $$=xmlStrcat($$,U(")"));
                            }
                            | PathExpr '!' FunctionCall
                            {
311
                                TRACE("Got PrimaryExpr: \"%s!%s\"\n", $1, $3);
312 313 314 315 316 317 318 319 320 321 322
                                $$=$1;
                                $$=xmlStrcat($$,U("/"));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                            }
                            | TOK_Literal
                            | TOK_Number
    ;
    /* [3.2] Function Calls */
    FunctionCall            : QName '(' Arguments ')'
                            {
323
                                TRACE("Got FunctionCall: \"%s(%s)\"\n", $1, $3);
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
                                if (xmlStrEqual($1,U("ancestor")))
                                {
                                    $$=$1;
                                    $$=xmlStrcat($$,U("::"));
                                    $$=xmlStrcat($$,$3);
                                    xmlFree($3);
                                }
                                else if (xmlStrEqual($1,U("attribute")))
                                {
                                    if (is_literal($3))
                                    {
                                        $$=xmlStrdup(U("@*[name()="));
                                        xmlFree($1);
                                        $$=xmlStrcat($$,$3);
                                        xmlFree($3);
                                        $$=xmlStrcat($$,U("]"));
                                    }
                                    else
                                    {
                                        /* XML_XPATH_INVALID_TYPE */
                                        $$=xmlStrdup(U("error(1211, 'Error: attribute("));
                                        xmlFree($1);
                                        $$=xmlStrcat($$,$3);
                                        xmlFree($3);
                                        $$=xmlStrcat($$,U("): invalid argument')"));
                                    }
                                }
                                else if (xmlStrEqual($1,U("element")))
                                {
                                    if (is_literal($3))
                                    {
                                        $$=xmlStrdup(U("node()[nodeType()=1][name()="));
                                        xmlFree($1);
                                        $$=xmlStrcat($$,$3);
                                        xmlFree($3);
                                        $$=xmlStrcat($$,U("]"));
                                    }
                                    else
                                    {
                                        /* XML_XPATH_INVALID_TYPE */
                                        $$=xmlStrdup(U("error(1211, 'Error: element("));
                                        xmlFree($1);
                                        $$=xmlStrcat($$,$3);
                                        xmlFree($3);
                                        $$=xmlStrcat($$,U("): invalid argument')"));
                                    }
                                }
                                else
                                {
                                    $$=$1;
                                    $$=xmlStrcat($$,U("("));
                                    $$=xmlStrcat($$,$3);
                                    xmlFree($3);
                                    $$=xmlStrcat($$,U(")"));
                                }
379 380 381
                            }
                            | QName '(' ')'
                            {
382
                                TRACE("Got FunctionCall: \"%s()\"\n", $1);
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
                                /* comment() & node() work the same in XPath */
                                if (xmlStrEqual($1,U("attribute")))
                                {
                                    $$=xmlStrdup(U("@*"));
                                    xmlFree($1);
                                }
                                else if (xmlStrEqual($1,U("element")))
                                {
                                    $$=xmlStrdup(U("node()[nodeType()=1]"));
                                    xmlFree($1);
                                }
                                else if (xmlStrEqual($1,U("pi")))
                                {
                                    $$=xmlStrdup(U("processing-instruction()"));
                                    xmlFree($1);
                                }
                                else if (xmlStrEqual($1,U("textnode")))
                                {
                                    $$=xmlStrdup(U("text()"));
                                    xmlFree($1);
                                }
                                else
                                {
                                    $$=$1;
                                    $$=xmlStrcat($$,U("()"));
                                }
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
                            }
    ;
    Arguments               : Argument ',' Arguments
                            {
                                $$=$1;
                                $$=xmlStrcat($$,U(","));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                            }
                            | Argument
    ;
    Argument                : Expr
    ;
    /* [3.3] Node-sets */
    UnionExpr               : PathExpr
                            | UnionExpr '|' PathExpr
                            {
426
                                TRACE("Got UnionExpr: \"%s|%s\"\n", $1, $3);
427 428 429 430 431 432 433 434 435
                                $$=$1;
                                $$=xmlStrcat($$,U("|"));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                            }
    ;
    PathExpr                : LocationPath
                            | FilterExpr TOK_FSlash RelativeLocationPath
                            {
436
                                TRACE("Got PathExpr: \"%s/%s\"\n", $1, $3);
437 438 439 440 441 442 443
                                $$=$1;
                                $$=xmlStrcat($$,U("/"));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                            }
                            | FilterExpr TOK_DblFSlash RelativeLocationPath
                            {
444
                                TRACE("Got PathExpr: \"%s//%s\"\n", $1, $3);
445 446 447 448 449 450 451 452 453 454
                                $$=$1;
                                $$=xmlStrcat($$,U("//"));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                            }
                            | FilterExpr
    ;
    FilterExpr              : PrimaryExpr
                            | FilterExpr Predicate
                            {
455
                                TRACE("Got FilterExpr: \"%s%s\"\n", $1, $2);
456 457 458 459 460 461 462 463 464 465 466
                                $$=$1;
                                $$=xmlStrcat($$,$2);
                                xmlFree($2);
                            }
    ;
    /* [3.4] Booleans */
    OrExpr                  : AndExpr
                            | BoolOrExpr
    ;
    BoolOrExpr              : OrExpr TOK_OpOr AndExpr
                            {
467
                                TRACE("Got OrExpr: \"%s $or$ %s\"\n", $1, $3);
468 469 470 471 472 473 474 475 476 477 478
                                $$=$1;
                                $$=xmlStrcat($$,U(" or "));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                            }
    ;
    AndExpr                 : EqualityExpr
                            | BoolAndExpr
    ;
    BoolAndExpr             : AndExpr TOK_OpAnd EqualityExpr
                            {
479
                                TRACE("Got AndExpr: \"%s $and$ %s\"\n", $1, $3);
480 481 482 483 484 485 486 487 488 489 490
                                $$=$1;
                                $$=xmlStrcat($$,U(" and "));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                            }
    ;
    EqualityExpr            : RelationalExpr
                            | BoolEqualityExpr
    ;
    BoolEqualityExpr        : EqualityExpr TOK_OpEq RelationalExpr
                            {
491
                                TRACE("Got EqualityExpr: \"%s $eq$ %s\"\n", $1, $3);
492 493 494 495 496 497 498
                                $$=$1;
                                $$=xmlStrcat($$,U("="));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                            }
                            | EqualityExpr TOK_OpIEq RelationalExpr
                            {
499
                                TRACE("Got EqualityExpr: \"%s $ieq$ %s\"\n", $1, $3);
500 501 502 503 504 505 506 507 508 509
                                $$=xmlStrdup(U("OP_IEq("));
                                $$=xmlStrcat($$,$1);
                                xmlFree($1);
                                $$=xmlStrcat($$,U(","));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                                $$=xmlStrcat($$,U(")"));
                            }
                            | EqualityExpr TOK_OpNEq RelationalExpr
                            {
510
                                TRACE("Got EqualityExpr: \"%s $ne$ %s\"\n", $1, $3);
511 512 513 514 515 516 517
                                $$=$1;
                                $$=xmlStrcat($$,U("!="));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                            }
                            | EqualityExpr TOK_OpINEq RelationalExpr
                            {
518
                                TRACE("Got EqualityExpr: \"%s $ine$ %s\"\n", $1, $3);
519 520 521 522 523 524 525 526 527 528 529 530 531 532
                                $$=xmlStrdup(U("OP_INEq("));
                                $$=xmlStrcat($$,$1);
                                xmlFree($1);
                                $$=xmlStrcat($$,U(","));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                                $$=xmlStrcat($$,U(")"));
                            }
    ;
    RelationalExpr          : UnaryExpr
                            | BoolRelationalExpr
    ;
    BoolRelationalExpr      : RelationalExpr TOK_OpLt UnaryExpr
                            {
533
                                TRACE("Got RelationalExpr: \"%s $lt$ %s\"\n", $1, $3);
534 535 536 537 538 539 540
                                $$=$1;
                                $$=xmlStrcat($$,U("<"));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                            }
                            | RelationalExpr TOK_OpILt UnaryExpr
                            {
541
                                TRACE("Got RelationalExpr: \"%s $ilt$ %s\"\n", $1, $3);
542 543 544 545 546 547 548 549 550 551
                                $$=xmlStrdup(U("OP_ILt("));
                                $$=xmlStrcat($$,$1);
                                xmlFree($1);
                                $$=xmlStrcat($$,U(","));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                                $$=xmlStrcat($$,U(")"));
                            }
                            | RelationalExpr TOK_OpGt UnaryExpr
                            {
552
                                TRACE("Got RelationalExpr: \"%s $gt$ %s\"\n", $1, $3);
553 554 555 556 557 558 559
                                $$=$1;
                                $$=xmlStrcat($$,U(">"));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                            }
                            | RelationalExpr TOK_OpIGt UnaryExpr
                            {
560
                                TRACE("Got RelationalExpr: \"%s $igt$ %s\"\n", $1, $3);
561 562 563 564 565 566 567 568 569 570
                                $$=xmlStrdup(U("OP_IGt("));
                                $$=xmlStrcat($$,$1);
                                xmlFree($1);
                                $$=xmlStrcat($$,U(","));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                                $$=xmlStrcat($$,U(")"));
                            }
                            | RelationalExpr TOK_OpLEq UnaryExpr
                            {
571
                                TRACE("Got RelationalExpr: \"%s $le$ %s\"\n", $1, $3);
572 573 574 575 576 577 578
                                $$=$1;
                                $$=xmlStrcat($$,U("<="));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                            }
                            | RelationalExpr TOK_OpILEq UnaryExpr
                            {
579
                                TRACE("Got RelationalExpr: \"%s $ile$ %s\"\n", $1, $3);
580 581 582 583 584 585 586 587 588 589
                                $$=xmlStrdup(U("OP_ILEq("));
                                $$=xmlStrcat($$,$1);
                                xmlFree($1);
                                $$=xmlStrcat($$,U(","));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                                $$=xmlStrcat($$,U(")"));
                            }
                            | RelationalExpr TOK_OpGEq UnaryExpr
                            {
590
                                TRACE("Got RelationalExpr: \"%s $ge$ %s\"\n", $1, $3);
591 592 593 594 595 596 597
                                $$=$1;
                                $$=xmlStrcat($$,U(">="));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                            }
                            | RelationalExpr TOK_OpIGEq UnaryExpr
                            {
598
                                TRACE("Got RelationalExpr: \"%s $ige$ %s\"\n", $1, $3);
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614
                                $$=xmlStrdup(U("OP_IGEq("));
                                $$=xmlStrcat($$,$1);
                                xmlFree($1);
                                $$=xmlStrcat($$,U(","));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                                $$=xmlStrcat($$,U(")"));
                            }
    ;

    /* [3.5] Numbers */
    UnaryExpr               : UnionExpr
                            | BoolUnaryExpr
    ;
    BoolUnaryExpr           : TOK_OpNot UnaryExpr
                            {
615
                                TRACE("Got UnaryExpr: \"$not$ %s\"\n", $2);
616 617 618 619 620 621 622
                                $$=xmlStrdup(U(" not("));
                                $$=xmlStrcat($$,$2);
                                xmlFree($2);
                                $$=xmlStrcat($$,U(")"));
                            }
                            | TOK_OpAny Expr
                            {
623
                                TRACE("Got UnaryExpr: \"$any$ %s\"\n", $2);
624 625 626 627 628 629 630
                                $$=xmlStrdup(U("boolean("));
                                $$=xmlStrcat($$,$2);
                                xmlFree($2);
                                $$=xmlStrcat($$,U(")"));
                            }
                            | TOK_OpAll AllExpr
                            {
631
                                TRACE("Got UnaryExpr: \"$all$ %s\"\n", $2);
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749
                                $$=xmlStrdup(U("not("));
                                $$=xmlStrcat($$,$2);
                                xmlFree($2);
                                $$=xmlStrcat($$,U(")"));
                            }
                            | TOK_OpAll
                            {
                                FIXME("Unrecognized $all$ expression - ignoring\n");
                                $$=xmlStrdup(U(""));
                            }
    ;
    AllExpr                 : PathExpr TOK_OpEq PathExpr
                            {
                                $$=$1;
                                $$=xmlStrcat($$,U("!="));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                            }
                            | PathExpr TOK_OpNEq PathExpr
                            {
                                $$=$1;
                                $$=xmlStrcat($$,U("="));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                            }
                            | PathExpr TOK_OpLt PathExpr
                            {
                                $$=$1;
                                $$=xmlStrcat($$,U(">="));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                            }
                            | PathExpr TOK_OpLEq PathExpr
                            {
                                $$=$1;
                                $$=xmlStrcat($$,U(">"));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                            }
                            | PathExpr TOK_OpGt PathExpr
                            {
                                $$=$1;
                                $$=xmlStrcat($$,U("<="));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                            }
                            | PathExpr TOK_OpGEq PathExpr
                            {
                                $$=$1;
                                $$=xmlStrcat($$,U("<"));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                            }
                            | PathExpr TOK_OpIEq PathExpr
                            {
                                $$=xmlStrdup(U("OP_INEq("));
                                $$=xmlStrcat($$,$1);
                                xmlFree($1);
                                $$=xmlStrcat($$,U(","));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                                $$=xmlStrcat($$,U(")"));
                            }
                            | PathExpr TOK_OpINEq PathExpr
                            {
                                $$=xmlStrdup(U("OP_IEq("));
                                $$=xmlStrcat($$,$1);
                                xmlFree($1);
                                $$=xmlStrcat($$,U(","));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                                $$=xmlStrcat($$,U(")"));
                            }
                            | PathExpr TOK_OpILt PathExpr
                            {
                                $$=xmlStrdup(U("OP_IGEq("));
                                $$=xmlStrcat($$,$1);
                                xmlFree($1);
                                $$=xmlStrcat($$,U(","));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                                $$=xmlStrcat($$,U(")"));
                            }
                            | PathExpr TOK_OpILEq PathExpr
                            {
                                $$=xmlStrdup(U("OP_IGt("));
                                $$=xmlStrcat($$,$1);
                                xmlFree($1);
                                $$=xmlStrcat($$,U(","));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                                $$=xmlStrcat($$,U(")"));
                            }
                            | PathExpr TOK_OpIGt PathExpr
                            {
                                $$=xmlStrdup(U("OP_ILEq("));
                                $$=xmlStrcat($$,$1);
                                xmlFree($1);
                                $$=xmlStrcat($$,U(","));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                                $$=xmlStrcat($$,U(")"));
                            }
                            | PathExpr TOK_OpIGEq PathExpr
                            {
                                $$=xmlStrdup(U("OP_ILt("));
                                $$=xmlStrcat($$,$1);
                                xmlFree($1);
                                $$=xmlStrcat($$,U(","));
                                $$=xmlStrcat($$,$3);
                                xmlFree($3);
                                $$=xmlStrcat($$,U(")"));
                            }
    ;

%%

#endif  /* HAVE_LIBXML2 */