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 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 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 379 380 381 382 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 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 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 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915
|
/*
** Parser for the mapserver
*/
%{
/* C declarations */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include "mapserver.h" /* for TRUE/FALSE and REGEX includes */
#include "maptime.h" /* for time comparison routines */
#include "mapprimitive.h" /* for shapeObj */
#include "mapparser.h" /* for YYSTYPE in the function prototype for yylex() */
int yylex(YYSTYPE *, parseObj *); /* prototype functions, defined after the grammar */
int yyerror(parseObj *, const char *);
%}
/* Bison/Yacc declarations */
/* %define api.pure */
%pure_parser
%parse-param {parseObj *p}
%lex-param {parseObj *p}
%union {
double dblval;
int intval;
char *strval;
struct tm tmval;
shapeObj *shpval;
}
%token <intval> BOOLEAN
%token <dblval> NUMBER
%token <strval> STRING
%token <tmval> TIME
%token <shpval> SHAPE
%left OR
%left AND
%left NOT
%left RE EQ NE LT GT LE GE IN IEQ IRE
%left INTERSECTS DISJOINT TOUCHES OVERLAPS CROSSES WITHIN CONTAINS EQUALS BEYOND DWITHIN
%left AREA LENGTH COMMIFY ROUND
%left UPPER LOWER INITCAP FIRSTCAP
%left TOSTRING
%left YYBUFFER DIFFERENCE SIMPLIFY SIMPLIFYPT GENERALIZE SMOOTHSIA JAVASCRIPT
%left '+' '-'
%left '*' '/' '%'
%left NEG
%right '^'
%type <intval> logical_exp
%type <dblval> math_exp
%type <strval> string_exp
%type <tmval> time_exp
%type <shpval> shape_exp
/* Bison/Yacc grammar */
%%
input: /* empty string */
| logical_exp {
switch(p->type) {
case(MS_PARSE_TYPE_BOOLEAN):
p->result.intval = $1;
break;
case(MS_PARSE_TYPE_STRING):
if($1)
p->result.strval = msStrdup("true");
else
p->result.strval = msStrdup("false");
break;
}
}
| math_exp {
switch(p->type) {
case(MS_PARSE_TYPE_BOOLEAN):
if($1 != 0)
p->result.intval = MS_TRUE;
else
p->result.intval = MS_FALSE;
break;
case(MS_PARSE_TYPE_STRING):
p->result.strval = (char *)malloc(64); /* large enough for a double */
snprintf(p->result.strval, 64, "%g", $1);
break;
}
}
| string_exp {
switch(p->type) {
case(MS_PARSE_TYPE_BOOLEAN):
if($1) /* string is not NULL */
p->result.intval = MS_TRUE;
else
p->result.intval = MS_FALSE;
break;
case(MS_PARSE_TYPE_STRING):
p->result.strval = $1; // msStrdup($1);
break;
}
}
| shape_exp {
switch(p->type) {
case(MS_PARSE_TYPE_SHAPE):
p->result.shpval = $1;
p->result.shpval->scratch = MS_FALSE;
break;
}
}
;
logical_exp: BOOLEAN
| '(' logical_exp ')' { $$ = $2; }
| logical_exp EQ logical_exp {
$$ = MS_FALSE;
if($1 == $3) $$ = MS_TRUE;
}
| logical_exp OR logical_exp {
if($1 == MS_TRUE)
$$ = MS_TRUE;
else if($3 == MS_TRUE)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
}
| logical_exp AND logical_exp {
if($1 == MS_TRUE) {
if($3 == MS_TRUE)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
} else
$$ = MS_FALSE;
}
| logical_exp OR math_exp {
if($1 == MS_TRUE)
$$ = MS_TRUE;
else if($3 != 0)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
}
| logical_exp AND math_exp {
if($1 == MS_TRUE) {
if($3 != 0)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
} else
$$ = MS_FALSE;
}
| math_exp OR logical_exp {
if($1 != 0)
$$ = MS_TRUE;
else if($3 == MS_TRUE)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
}
| math_exp AND logical_exp {
if($1 != 0) {
if($3 == MS_TRUE)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
} else
$$ = MS_FALSE;
}
| math_exp OR math_exp {
if($1 != 0)
$$ = MS_TRUE;
else if($3 != 0)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
}
| math_exp AND math_exp {
if($1 != 0) {
if($3 != 0)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
} else
$$ = MS_FALSE;
}
| NOT logical_exp { $$ = !$2; }
| NOT math_exp { $$ = !$2; }
| string_exp RE string_exp {
ms_regex_t re;
if(MS_STRING_IS_NULL_OR_EMPTY($1) == MS_TRUE) {
$$ = MS_FALSE;
} else {
if(ms_regcomp(&re, $3, MS_REG_EXTENDED|MS_REG_NOSUB) != 0) {
$$ = MS_FALSE;
} else {
if(ms_regexec(&re, $1, 0, NULL, 0) == 0)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
ms_regfree(&re);
}
}
free($1);
free($3);
}
| string_exp IRE string_exp {
ms_regex_t re;
if(MS_STRING_IS_NULL_OR_EMPTY($1) == MS_TRUE) {
$$ = MS_FALSE;
} else {
if(ms_regcomp(&re, $3, MS_REG_EXTENDED|MS_REG_NOSUB|MS_REG_ICASE) != 0) {
$$ = MS_FALSE;
} else {
if(ms_regexec(&re, $1, 0, NULL, 0) == 0)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
ms_regfree(&re);
}
}
free($1);
free($3);
}
| math_exp EQ math_exp {
if($1 == $3)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
}
| math_exp NE math_exp {
if($1 != $3)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
}
| math_exp GT math_exp {
if($1 > $3)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
}
| math_exp LT math_exp {
if($1 < $3)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
}
| math_exp GE math_exp {
if($1 >= $3)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
}
| math_exp LE math_exp {
if($1 <= $3)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
}
| string_exp EQ string_exp {
if(strcmp($1, $3) == 0)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
free($1);
free($3);
}
| string_exp NE string_exp {
if(strcmp($1, $3) != 0)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
free($1);
free($3);
}
| string_exp GT string_exp {
if(strcmp($1, $3) > 0)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
free($1);
free($3);
}
| string_exp LT string_exp {
if(strcmp($1, $3) < 0)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
free($1);
free($3);
}
| string_exp GE string_exp {
if(strcmp($1, $3) >= 0)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
free($1);
free($3);
}
| string_exp LE string_exp {
if(strcmp($1, $3) <= 0)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
free($1);
free($3);
}
| time_exp EQ time_exp {
if(msTimeCompare(&($1), &($3)) == 0)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
}
| time_exp NE time_exp {
if(msTimeCompare(&($1), &($3)) != 0)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
}
| time_exp GT time_exp {
if(msTimeCompare(&($1), &($3)) > 0)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
}
| time_exp LT time_exp {
if(msTimeCompare(&($1), &($3)) < 0)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
}
| time_exp GE time_exp {
if(msTimeCompare(&($1), &($3)) >= 0)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
}
| time_exp LE time_exp {
if(msTimeCompare(&($1), &($3)) <= 0)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
}
| string_exp IN string_exp {
char *delim, *bufferp;
$$ = MS_FALSE;
bufferp=$3;
while((delim=strchr(bufferp,',')) != NULL) {
*delim='\0';
if(strcmp($1,bufferp) == 0) {
$$ = MS_TRUE;
break;
}
*delim=',';
bufferp=delim+1;
}
if($$ == MS_FALSE && strcmp($1,bufferp) == 0) // test for last (or only) item
$$ = MS_TRUE;
free($1);
free($3);
}
| math_exp IN string_exp {
char *delim,*bufferp;
$$ = MS_FALSE;
bufferp=$3;
while((delim=strchr(bufferp,',')) != NULL) {
*delim='\0';
if($1 == atof(bufferp)) {
$$ = MS_TRUE;
break;
}
*delim=',';
bufferp=delim+1;
}
if($1 == atof(bufferp)) // is this test necessary?
$$ = MS_TRUE;
free($3);
}
| math_exp IEQ math_exp {
if($1 == $3)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
}
| string_exp IEQ string_exp {
if(strcasecmp($1, $3) == 0)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
free($1);
free($3);
}
| time_exp IEQ time_exp {
if(msTimeCompare(&($1), &($3)) == 0)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
}
| shape_exp EQ shape_exp {
int rval;
rval = msGEOSEquals($1, $3);
if($1->scratch == MS_TRUE) msFreeShape($1);
if($3->scratch == MS_TRUE) msFreeShape($3);
if(rval == -1) {
yyerror(p, "Equals (EQ or ==) operator failed.");
return(-1);
} else
$$ = rval;
}
| EQUALS '(' shape_exp ',' shape_exp ')' {
int rval;
rval = msGEOSEquals($3, $5);
if($3->scratch == MS_TRUE) msFreeShape($3);
if($5->scratch == MS_TRUE) msFreeShape($5);
if(rval == -1) {
yyerror(p, "Equals function failed.");
return(-1);
} else
$$ = rval;
}
| INTERSECTS '(' shape_exp ',' shape_exp ')' {
int rval;
rval = msGEOSIntersects($3, $5);
if($3->scratch == MS_TRUE) msFreeShape($3);
if($5->scratch == MS_TRUE) msFreeShape($5);
if(rval == -1) {
yyerror(p, "Intersects function failed.");
return(-1);
} else
$$ = rval;
}
| shape_exp INTERSECTS shape_exp {
int rval;
rval = msGEOSIntersects($1, $3);
if($1->scratch == MS_TRUE) msFreeShape($1);
if($3->scratch == MS_TRUE) msFreeShape($3);
if(rval == -1) {
yyerror(p, "Intersects operator failed.");
return(-1);
} else
$$ = rval;
}
| DISJOINT '(' shape_exp ',' shape_exp ')' {
int rval;
rval = msGEOSDisjoint($3, $5);
if($3->scratch == MS_TRUE) msFreeShape($3);
if($5->scratch == MS_TRUE) msFreeShape($5);
if(rval == -1) {
yyerror(p, "Disjoint function failed.");
return(-1);
} else
$$ = rval;
}
| shape_exp DISJOINT shape_exp {
int rval;
rval = msGEOSDisjoint($1, $3);
if($1->scratch == MS_TRUE) msFreeShape($1);
if($3->scratch == MS_TRUE) msFreeShape($3);
if(rval == -1) {
yyerror(p, "Disjoint operator failed.");
return(-1);
} else
$$ = rval;
}
| TOUCHES '(' shape_exp ',' shape_exp ')' {
int rval;
rval = msGEOSTouches($3, $5);
if($3->scratch == MS_TRUE) msFreeShape($3);
if($5->scratch == MS_TRUE) msFreeShape($5);
if(rval == -1) {
yyerror(p, "Touches function failed.");
return(-1);
} else
$$ = rval;
}
| shape_exp TOUCHES shape_exp {
int rval;
rval = msGEOSTouches($1, $3);
if($1->scratch == MS_TRUE) msFreeShape($1);
if($3->scratch == MS_TRUE) msFreeShape($3);
if(rval == -1) {
yyerror(p, "Touches operator failed.");
return(-1);
} else
$$ = rval;
}
| OVERLAPS '(' shape_exp ',' shape_exp ')' {
int rval;
rval = msGEOSOverlaps($3, $5);
if($3->scratch == MS_TRUE) msFreeShape($3);
if($5->scratch == MS_TRUE) msFreeShape($5);
if(rval == -1) {
yyerror(p, "Overlaps function failed.");
return(-1);
} else
$$ = rval;
}
| shape_exp OVERLAPS shape_exp {
int rval;
rval = msGEOSOverlaps($1, $3);
if($1->scratch == MS_TRUE) msFreeShape($1);
if($3->scratch == MS_TRUE) msFreeShape($3);
if(rval == -1) {
yyerror(p, "Overlaps operator failed.");
return(-1);
} else
$$ = rval;
}
| CROSSES '(' shape_exp ',' shape_exp ')' {
int rval;
rval = msGEOSCrosses($3, $5);
if($3->scratch == MS_TRUE) msFreeShape($3);
if($5->scratch == MS_TRUE) msFreeShape($5);
if(rval == -1) {
yyerror(p, "Crosses function failed.");
return(-1);
} else
$$ = rval;
}
| shape_exp CROSSES shape_exp {
int rval;
rval = msGEOSCrosses($1, $3);
if($1->scratch == MS_TRUE) msFreeShape($1);
if($3->scratch == MS_TRUE) msFreeShape($3);
if(rval == -1) {
yyerror(p, "Crosses operator failed.");
return(-1);
} else
$$ = rval;
}
| WITHIN '(' shape_exp ',' shape_exp ')' {
int rval;
rval = msGEOSWithin($3, $5);
if($3->scratch == MS_TRUE) msFreeShape($3);
if($5->scratch == MS_TRUE) msFreeShape($5);
if(rval == -1) {
yyerror(p, "Within function failed.");
return(-1);
} else
$$ = rval;
}
| shape_exp WITHIN shape_exp {
int rval;
rval = msGEOSWithin($1, $3);
if($1->scratch == MS_TRUE) msFreeShape($1);
if($3->scratch == MS_TRUE) msFreeShape($3);
if(rval == -1) {
yyerror(p, "Within operator failed.");
return(-1);
} else
$$ = rval;
}
| CONTAINS '(' shape_exp ',' shape_exp ')' {
int rval;
rval = msGEOSContains($3, $5);
if($3->scratch == MS_TRUE) msFreeShape($3);
if($5->scratch == MS_TRUE) msFreeShape($5);
if(rval == -1) {
yyerror(p, "Contains function failed.");
return(-1);
} else
$$ = rval;
}
| shape_exp CONTAINS shape_exp {
int rval;
rval = msGEOSContains($1, $3);
if($1->scratch == MS_TRUE) msFreeShape($1);
if($3->scratch == MS_TRUE) msFreeShape($3);
if(rval == -1) {
yyerror(p, "Contains operator failed.");
return(-1);
} else
$$ = rval;
}
| DWITHIN '(' shape_exp ',' shape_exp ',' math_exp ')' {
double d;
d = msGEOSDistance($3, $5);
if($3->scratch == MS_TRUE) msFreeShape($3);
if($5->scratch == MS_TRUE) msFreeShape($5);
if(d <= $7)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
}
| BEYOND '(' shape_exp ',' shape_exp ',' math_exp ')' {
double d;
d = msGEOSDistance($3, $5);
if($3->scratch == MS_TRUE) msFreeShape($3);
if($5->scratch == MS_TRUE) msFreeShape($5);
if(d > $7)
$$ = MS_TRUE;
else
$$ = MS_FALSE;
}
;
math_exp: NUMBER
| '(' math_exp ')' { $$ = $2; }
| math_exp '+' math_exp { $$ = $1 + $3; }
| math_exp '-' math_exp { $$ = $1 - $3; }
| math_exp '*' math_exp { $$ = $1 * $3; }
| math_exp '%' math_exp { $$ = (int)$1 % (int)$3; }
| math_exp '/' math_exp {
if($3 == 0.0) {
yyerror(p, "Division by zero.");
return(-1);
} else
$$ = $1 / $3;
}
| '-' math_exp %prec NEG { $$ = $2; }
| math_exp '^' math_exp { $$ = pow($1, $3); }
| LENGTH '(' string_exp ')' { $$ = strlen($3); }
| AREA '(' shape_exp ')' {
if($3->type != MS_SHAPE_POLYGON) {
yyerror(p, "Area can only be computed for polygon shapes.");
return(-1);
}
$$ = msGetPolygonArea($3);
if($3->scratch == MS_TRUE) msFreeShape($3);
}
| ROUND '(' math_exp ',' math_exp ')' { $$ = (MS_NINT($3/$5))*$5; }
;
shape_exp: SHAPE
| '(' shape_exp ')' { $$ = $2; }
| YYBUFFER '(' shape_exp ',' math_exp ')' {
shapeObj *s;
s = msGEOSBuffer($3, $5);
if(!s) {
yyerror(p, "Executing buffer failed.");
return(-1);
}
s->scratch = MS_TRUE;
$$ = s;
}
| DIFFERENCE '(' shape_exp ',' shape_exp ')' {
shapeObj *s;
s = msGEOSDifference($3, $5);
if(!s) {
yyerror(p, "Executing difference failed.");
return(-1);
}
s->scratch = MS_TRUE;
$$ = s;
}
| SIMPLIFY '(' shape_exp ',' math_exp ')' {
shapeObj *s;
s = msGEOSSimplify($3, $5);
if(!s) {
yyerror(p, "Executing simplify failed.");
return(-1);
}
s->scratch = MS_TRUE;
$$ = s;
}
| SIMPLIFYPT '(' shape_exp ',' math_exp ')' {
shapeObj *s;
s = msGEOSTopologyPreservingSimplify($3, $5);
if(!s) {
yyerror(p, "Executing simplifypt failed.");
return(-1);
}
s->scratch = MS_TRUE;
$$ = s;
}
| GENERALIZE '(' shape_exp ',' math_exp ')' {
shapeObj *s;
s = msGeneralize($3, $5);
if(!s) {
yyerror(p, "Executing generalize failed.");
return(-1);
}
s->scratch = MS_TRUE;
$$ = s;
}
| SMOOTHSIA '(' shape_exp ')' {
shapeObj *s;
s = msSmoothShapeSIA($3, 3, 1, NULL);
if(!s) {
yyerror(p, "Executing smoothsia failed.");
return(-1);
}
s->scratch = MS_TRUE;
$$ = s;
}
| SMOOTHSIA '(' shape_exp ',' math_exp ')' {
shapeObj *s;
s = msSmoothShapeSIA($3, $5, 1, NULL);
if(!s) {
yyerror(p, "Executing smoothsia failed.");
return(-1);
}
s->scratch = MS_TRUE;
$$ = s;
}
| SMOOTHSIA '(' shape_exp ',' math_exp ',' math_exp ')' {
shapeObj *s;
s = msSmoothShapeSIA($3, $5, $7, NULL);
if(!s) {
yyerror(p, "Executing smoothsia failed.");
return(-1);
}
s->scratch = MS_TRUE;
$$ = s;
}
| SMOOTHSIA '(' shape_exp ',' math_exp ',' math_exp ',' string_exp ')' {
shapeObj *s;
s = msSmoothShapeSIA($3, $5, $7, $9);
free($9);
if(!s) {
yyerror(p, "Executing smoothsia failed.");
return(-1);
}
s->scratch = MS_TRUE;
$$ = s;
}
| JAVASCRIPT '(' shape_exp ',' string_exp ')' {
#ifdef USE_V8_MAPSCRIPT
shapeObj *s;
s = msV8TransformShape($3, $5);
free($5);
if(!s) {
yyerror(p, "Executing javascript failed.");
return(-1);
}
s->scratch = MS_TRUE;
$$ = s;
#else
yyerror(p, "Javascript support not compiled in");
return(-1);
#endif
}
;
string_exp: STRING
| '(' string_exp ')' { $$ = $2; }
| string_exp '+' string_exp {
$$ = (char *)malloc(strlen($1) + strlen($3) + 1);
sprintf($$, "%s%s", $1, $3); free($1); free($3);
}
| TOSTRING '(' math_exp ',' string_exp ')' {
$$ = (char *) malloc(strlen($5) + 64); /* Plenty big? Should use snprintf below... */
sprintf($$, $5, $3);
free($5);
}
| COMMIFY '(' string_exp ')' {
$3 = msCommifyString($3);
$$ = $3;
}
| UPPER '(' string_exp ')' {
msStringToUpper($3);
$$ = $3;
}
| LOWER '(' string_exp ')' {
msStringToLower($3);
$$ = $3;
}
| INITCAP '(' string_exp ')' {
msStringInitCap($3);
$$ = $3;
}
| FIRSTCAP '(' string_exp ')' {
msStringFirstCap($3);
$$ = $3;
}
;
time_exp: TIME
| '(' time_exp ')' { $$ = $2; }
;
%%
/*
** Any extra C functions
*/
int yylex(YYSTYPE *lvalp, parseObj *p)
{
int token;
if(p->expr->curtoken == NULL) return(0); /* done */
// fprintf(stderr, "in yylex() - curtoken=%d...\n", p->expr->curtoken->token);
token = p->expr->curtoken->token; /* may override */
switch(p->expr->curtoken->token) {
case MS_TOKEN_LITERAL_BOOLEAN:
token = BOOLEAN;
(*lvalp).intval = p->expr->curtoken->tokenval.dblval;
break;
case MS_TOKEN_LITERAL_NUMBER:
token = NUMBER;
(*lvalp).dblval = p->expr->curtoken->tokenval.dblval;
break;
case MS_TOKEN_LITERAL_SHAPE:
token = SHAPE;
// fprintf(stderr, "token value = %s\n", msShapeToWKT(p->expr->curtoken->tokenval.shpval));
(*lvalp).shpval = p->expr->curtoken->tokenval.shpval;
break;
case MS_TOKEN_LITERAL_STRING:
// printf("token value = %s\n", p->expr->curtoken->tokenval.strval);
token = STRING;
(*lvalp).strval = msStrdup(p->expr->curtoken->tokenval.strval);
break;
case MS_TOKEN_LITERAL_TIME:
token = TIME;
(*lvalp).tmval = p->expr->curtoken->tokenval.tmval;
break;
case MS_TOKEN_COMPARISON_EQ: token = EQ; break;
case MS_TOKEN_COMPARISON_IEQ: token = IEQ; break;
case MS_TOKEN_COMPARISON_NE: token = NE; break;
case MS_TOKEN_COMPARISON_LT: token = LT; break;
case MS_TOKEN_COMPARISON_GT: token = GT; break;
case MS_TOKEN_COMPARISON_LE: token = LE; break;
case MS_TOKEN_COMPARISON_GE: token = GE; break;
case MS_TOKEN_COMPARISON_RE: token = RE; break;
case MS_TOKEN_COMPARISON_IRE: token = IRE; break;
case MS_TOKEN_COMPARISON_IN: token = IN; break;
case MS_TOKEN_COMPARISON_INTERSECTS: token = INTERSECTS; break;
case MS_TOKEN_COMPARISON_DISJOINT: token = DISJOINT; break;
case MS_TOKEN_COMPARISON_TOUCHES: token = TOUCHES; break;
case MS_TOKEN_COMPARISON_OVERLAPS: token = OVERLAPS; break;
case MS_TOKEN_COMPARISON_CROSSES: token = CROSSES; break;
case MS_TOKEN_COMPARISON_WITHIN: token = WITHIN; break;
case MS_TOKEN_COMPARISON_CONTAINS: token = CONTAINS; break;
case MS_TOKEN_COMPARISON_EQUALS: token = EQUALS; break;
case MS_TOKEN_COMPARISON_BEYOND: token = BEYOND; break;
case MS_TOKEN_COMPARISON_DWITHIN: token = DWITHIN; break;
case MS_TOKEN_LOGICAL_AND: token = AND; break;
case MS_TOKEN_LOGICAL_OR: token = OR; break;
case MS_TOKEN_LOGICAL_NOT: token = NOT; break;
case MS_TOKEN_BINDING_DOUBLE:
case MS_TOKEN_BINDING_INTEGER:
token = NUMBER;
(*lvalp).dblval = atof(p->shape->values[p->expr->curtoken->tokenval.bindval.index]);
break;
case MS_TOKEN_BINDING_STRING:
token = STRING;
(*lvalp).strval = msStrdup(p->shape->values[p->expr->curtoken->tokenval.bindval.index]);
break;
case MS_TOKEN_BINDING_SHAPE:
token = SHAPE;
// fprintf(stderr, "token value = %s\n", msShapeToWKT(p->shape));
(*lvalp).shpval = p->shape;
break;
case MS_TOKEN_BINDING_MAP_CELLSIZE:
token = NUMBER;
(*lvalp).dblval = p->dblval;
break;
case MS_TOKEN_BINDING_DATA_CELLSIZE:
token = NUMBER;
(*lvalp).dblval = p->dblval2;
break;
case MS_TOKEN_BINDING_TIME:
token = TIME;
msTimeInit(&((*lvalp).tmval));
if(msParseTime(p->shape->values[p->expr->curtoken->tokenval.bindval.index], &((*lvalp).tmval)) != MS_TRUE) {
yyerror(p, "Parsing time value failed.");
return(-1);
}
break;
case MS_TOKEN_FUNCTION_AREA: token = AREA; break;
case MS_TOKEN_FUNCTION_LENGTH: token = LENGTH; break;
case MS_TOKEN_FUNCTION_TOSTRING: token = TOSTRING; break;
case MS_TOKEN_FUNCTION_COMMIFY: token = COMMIFY; break;
case MS_TOKEN_FUNCTION_UPPER: token = UPPER; break;
case MS_TOKEN_FUNCTION_LOWER: token = LOWER; break;
case MS_TOKEN_FUNCTION_INITCAP: token = INITCAP; break;
case MS_TOKEN_FUNCTION_FIRSTCAP: token = FIRSTCAP; break;
case MS_TOKEN_FUNCTION_ROUND: token = ROUND; break;
case MS_TOKEN_FUNCTION_BUFFER: token = YYBUFFER; break;
case MS_TOKEN_FUNCTION_DIFFERENCE: token = DIFFERENCE; break;
case MS_TOKEN_FUNCTION_SIMPLIFY: token = SIMPLIFY; break;
case MS_TOKEN_FUNCTION_SIMPLIFYPT: token = SIMPLIFYPT; break;
case MS_TOKEN_FUNCTION_GENERALIZE: token = GENERALIZE; break;
case MS_TOKEN_FUNCTION_SMOOTHSIA: token = SMOOTHSIA; break;
case MS_TOKEN_FUNCTION_JAVASCRIPT: token = JAVASCRIPT; break;
default:
break;
}
p->expr->curtoken = p->expr->curtoken->next; /* re-position */
return(token);
}
int yyerror(parseObj *p, const char *s) {
msSetError(MS_PARSEERR, "%s", "yyparse()", s);
return(0);
}
|