github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/opt/optgen/lang/testdata/parser (about) 1 # 2 # Define without tags. 3 # 4 parse 5 # This is a file header, and shouldn't be part of Lt's comment. 6 7 # This is a comment about Lt. 8 # And another information-packed line about it as well. 9 # 10 define Lt { 11 # This is a field comment. 12 # 13 Left Expr 14 15 # And another field comment. 16 Right Expr 17 } 18 ---- 19 (Root 20 Defines=(DefineSet 21 (Define 22 Comments=(Comments # This is a comment about Lt. # And another information-packed line about it as well. #) 23 Tags=(Tags) 24 Name="Lt" 25 Fields=(DefineFields 26 (DefineField 27 Comments=(Comments # This is a field comment. #) 28 Name="Left" 29 Type="Expr" 30 Src=<test.opt:9:5> 31 ) 32 (DefineField 33 Comments=(Comments # And another field comment.) 34 Name="Right" 35 Type="Expr" 36 Src=<test.opt:12:5> 37 ) 38 ) 39 Src=<test.opt:6:1> 40 ) 41 ) 42 Rules=(RuleSet) 43 ) 44 45 # 46 # Define with tags. 47 # 48 parse 49 # Comment on definition with a tag. 50 [Tag1, Tag2] 51 define Not { 52 Input Expr 53 } 54 ---- 55 (Root 56 Defines=(DefineSet 57 (Define 58 Comments=(Comments # Comment on definition with a tag. ) 59 Tags=(Tags Tag1 Tag2) 60 Name="Not" 61 Fields=(DefineFields 62 (DefineField Comments=(Comments) Name="Input" Type="Expr" Src=<test.opt:4:5>) 63 ) 64 Src=<test.opt:2:1> 65 ) 66 ) 67 Rules=(RuleSet) 68 ) 69 70 # 71 # Define error cases + recovery cases. 72 # 73 parse 74 # Expected tag name 75 [...] 76 define Not {} 77 78 # Expected comma 79 [Tag1 Tag2] 80 define Not {} 81 82 # Expected define statement 83 [Tag1] 84 def Not {} 85 86 # Expected define name 87 define {} 88 89 # Expected '{' 90 } 91 define Not Unknown 92 93 # Expected field name 94 define Not { 95 () 96 } 97 98 # Expected field type 99 define Not { 100 Input 123 101 } 102 ---- 103 test.opt:2:2: expected tag name, found '...' 104 test.opt:6:7: expected comma, found 'Tag2' 105 test.opt:11:1: expected define statement, found 'def' 106 test.opt:14:8: expected define name, found '{' 107 test.opt:18:12: expected '{', found 'Unknown' 108 test.opt:22:5: expected define field name, found '(' 109 test.opt:27:11: expected define field type, found '123' 110 111 # 112 # Multiple rules with comments. 113 # 114 parse 115 # This is the One rule. 116 [One] 117 (One) => (One) 118 119 # This is an intermediate comment that shouldn't be included. 120 121 # This is the Two rule. 122 [Two] 123 (Two) => (Two) 124 ---- 125 (Root 126 Defines=(DefineSet) 127 Rules=(RuleSet 128 (Rule 129 Comments=(Comments # This is the One rule.) 130 Name="One" 131 Tags=(Tags) 132 Match=(Func 133 Name=(Names One) 134 Args=(Slice) 135 Src=<test.opt:3:1> 136 ) 137 Replace=(Func 138 Name=(Names One) 139 Args=(Slice) 140 Src=<test.opt:3:10> 141 ) 142 Src=<test.opt:2:1> 143 ) 144 (Rule 145 Comments=(Comments # This is the Two rule.) 146 Name="Two" 147 Tags=(Tags) 148 Match=(Func 149 Name=(Names Two) 150 Args=(Slice) 151 Src=<test.opt:9:1> 152 ) 153 Replace=(Func 154 Name=(Names Two) 155 Args=(Slice) 156 Src=<test.opt:9:10> 157 ) 158 Src=<test.opt:8:1> 159 ) 160 ) 161 ) 162 163 # 164 # Match multiple op names. 165 # 166 parse 167 [Tag] 168 (One | Two) => (One) 169 ---- 170 (Root 171 Defines=(DefineSet) 172 Rules=(RuleSet 173 (Rule 174 Comments=(Comments) 175 Name="Tag" 176 Tags=(Tags) 177 Match=(Func 178 Name=(Names One Two) 179 Args=(Slice) 180 Src=<test.opt:2:1> 181 ) 182 Replace=(Func 183 Name=(Names One) 184 Args=(Slice) 185 Src=<test.opt:2:16> 186 ) 187 Src=<test.opt:1:1> 188 ) 189 ) 190 ) 191 192 # 193 # Use various match operators. 194 # 195 parse 196 [Tag] 197 (Op 198 (SubOp *) # Nested match 199 "hello" # String 200 10 # Number 201 ^(SubOp) # Negation 202 * # Any 203 [ ... * ... ] # List 204 [ * ... ] 205 [ ... * ] 206 [ * ] 207 [] 208 ) 209 => 210 (Op) 211 ---- 212 (Root 213 Defines=(DefineSet) 214 Rules=(RuleSet 215 (Rule 216 Comments=(Comments) 217 Name="Tag" 218 Tags=(Tags) 219 Match=(Func 220 Name=(Names Op) 221 Args=(Slice 222 (Func 223 Name=(Names SubOp) 224 Args=(Slice (Any)) 225 Src=<test.opt:3:5> 226 ) 227 "hello" 228 10 229 (Not 230 Input=(Func 231 Name=(Names SubOp) 232 Args=(Slice) 233 Src=<test.opt:6:6> 234 ) 235 Src=<test.opt:6:5> 236 ) 237 (Any) 238 (List 239 Items=(Slice (ListAny) (Any) (ListAny)) 240 Src=<test.opt:8:5> 241 ) 242 (List 243 Items=(Slice (Any) (ListAny)) 244 Src=<test.opt:9:5> 245 ) 246 (List 247 Items=(Slice (ListAny) (Any)) 248 Src=<test.opt:10:5> 249 ) 250 (List 251 Items=(Slice (Any)) 252 Src=<test.opt:11:5> 253 ) 254 (List Items=(Slice) Src=<test.opt:12:5>) 255 ) 256 Src=<test.opt:2:1> 257 ) 258 Replace=(Func 259 Name=(Names Op) 260 Args=(Slice) 261 Src=<test.opt:15:1> 262 ) 263 Src=<test.opt:1:1> 264 ) 265 ) 266 ) 267 268 # 269 # Bind different kinds of expressions. 270 # 271 parse 272 [Bind] 273 (Op 274 $match:(SubOp *) 275 $string:"hello" 276 $not:^(SubOp) 277 $any:* 278 $list:[... * ...] 279 ) 280 => 281 (Op) 282 ---- 283 (Root 284 Defines=(DefineSet) 285 Rules=(RuleSet 286 (Rule 287 Comments=(Comments) 288 Name="Bind" 289 Tags=(Tags) 290 Match=(Func 291 Name=(Names Op) 292 Args=(Slice 293 (Bind 294 Label="match" 295 Target=(Func 296 Name=(Names SubOp) 297 Args=(Slice (Any)) 298 Src=<test.opt:3:12> 299 ) 300 Src=<test.opt:3:5> 301 ) 302 (Bind Label="string" Target="hello" Src=<test.opt:4:5>) 303 (Bind 304 Label="not" 305 Target=(Not 306 Input=(Func 307 Name=(Names SubOp) 308 Args=(Slice) 309 Src=<test.opt:5:11> 310 ) 311 Src=<test.opt:5:10> 312 ) 313 Src=<test.opt:5:5> 314 ) 315 (Bind Label="any" Target=(Any) Src=<test.opt:6:5>) 316 (Bind 317 Label="list" 318 Target=(List 319 Items=(Slice (ListAny) (Any) (ListAny)) 320 Src=<test.opt:7:11> 321 ) 322 Src=<test.opt:7:5> 323 ) 324 ) 325 Src=<test.opt:2:1> 326 ) 327 Replace=(Func 328 Name=(Names Op) 329 Args=(Slice) 330 Src=<test.opt:10:1> 331 ) 332 Src=<test.opt:1:1> 333 ) 334 ) 335 ) 336 337 # 338 # Match boolean expressions. 339 # 340 parse 341 [boolean] 342 (op * & ^^(func) & (func2)) => (op) 343 ---- 344 (Root 345 Defines=(DefineSet) 346 Rules=(RuleSet 347 (Rule 348 Comments=(Comments) 349 Name="boolean" 350 Tags=(Tags) 351 Match=(Func 352 Name=(Names op) 353 Args=(Slice 354 (And 355 Left=(Any) 356 Right=(And 357 Left=(Not 358 Input=(Not 359 Input=(Func 360 Name=(Names func) 361 Args=(Slice) 362 Src=<test.opt:2:11> 363 ) 364 Src=<test.opt:2:10> 365 ) 366 Src=<test.opt:2:9> 367 ) 368 Right=(Func 369 Name=(Names func2) 370 Args=(Slice) 371 Src=<test.opt:2:20> 372 ) 373 Src=<test.opt:2:9> 374 ) 375 Src=<test.opt:2:5> 376 ) 377 ) 378 Src=<test.opt:2:1> 379 ) 380 Replace=(Func 381 Name=(Names op) 382 Args=(Slice) 383 Src=<test.opt:2:32> 384 ) 385 Src=<test.opt:1:1> 386 ) 387 ) 388 ) 389 390 # 391 # Match nested custom functions with literal name argument. 392 # 393 parse 394 [Invoke] 395 (Op $left:* $right:* & (Invoke $right (Invoke2 $left SomeOp))) => (Op) 396 ---- 397 (Root 398 Defines=(DefineSet) 399 Rules=(RuleSet 400 (Rule 401 Comments=(Comments) 402 Name="Invoke" 403 Tags=(Tags) 404 Match=(Func 405 Name=(Names Op) 406 Args=(Slice 407 (Bind Label="left" Target=(Any) Src=<test.opt:2:5>) 408 (Bind 409 Label="right" 410 Target=(And 411 Left=(Any) 412 Right=(Func 413 Name=(Names Invoke) 414 Args=(Slice 415 (Ref Label="right" Src=<test.opt:2:32>) 416 (Func 417 Name=(Names Invoke2) 418 Args=(Slice 419 (Ref Label="left" Src=<test.opt:2:48>) 420 SomeOp 421 ) 422 Src=<test.opt:2:39> 423 ) 424 ) 425 Src=<test.opt:2:24> 426 ) 427 Src=<test.opt:2:20> 428 ) 429 Src=<test.opt:2:13> 430 ) 431 ) 432 Src=<test.opt:2:1> 433 ) 434 Replace=(Func 435 Name=(Names Op) 436 Args=(Slice) 437 Src=<test.opt:2:67> 438 ) 439 Src=<test.opt:1:1> 440 ) 441 ) 442 ) 443 444 # 445 # Match list expressions. 446 # 447 parse 448 [List] 449 (Op 450 $any:[ ... $first:[ $item:(SubOp) ... ] & (Func $first $item) ... ] 451 $last:[ ... $item:* & ^(Func $item) ] 452 $single:[ $item:(SubOp) & (Func $item) ] 453 $empty:[] 454 ) 455 => 456 (Op) 457 ---- 458 (Root 459 Defines=(DefineSet) 460 Rules=(RuleSet 461 (Rule 462 Comments=(Comments) 463 Name="List" 464 Tags=(Tags) 465 Match=(Func 466 Name=(Names Op) 467 Args=(Slice 468 (Bind 469 Label="any" 470 Target=(List 471 Items=(Slice 472 (ListAny) 473 (Bind 474 Label="first" 475 Target=(And 476 Left=(List 477 Items=(Slice 478 (Bind 479 Label="item" 480 Target=(Func 481 Name=(Names SubOp) 482 Args=(Slice) 483 Src=<test.opt:3:31> 484 ) 485 Src=<test.opt:3:25> 486 ) 487 (ListAny) 488 ) 489 Src=<test.opt:3:23> 490 ) 491 Right=(Func 492 Name=(Names Func) 493 Args=(Slice 494 (Ref Label="first" Src=<test.opt:3:53>) 495 (Ref Label="item" Src=<test.opt:3:60>) 496 ) 497 Src=<test.opt:3:47> 498 ) 499 Src=<test.opt:3:23> 500 ) 501 Src=<test.opt:3:16> 502 ) 503 (ListAny) 504 ) 505 Src=<test.opt:3:10> 506 ) 507 Src=<test.opt:3:5> 508 ) 509 (Bind 510 Label="last" 511 Target=(List 512 Items=(Slice 513 (ListAny) 514 (Bind 515 Label="item" 516 Target=(And 517 Left=(Any) 518 Right=(Not 519 Input=(Func 520 Name=(Names Func) 521 Args=(Slice 522 (Ref Label="item" Src=<test.opt:4:34>) 523 ) 524 Src=<test.opt:4:28> 525 ) 526 Src=<test.opt:4:27> 527 ) 528 Src=<test.opt:4:23> 529 ) 530 Src=<test.opt:4:17> 531 ) 532 ) 533 Src=<test.opt:4:11> 534 ) 535 Src=<test.opt:4:5> 536 ) 537 (Bind 538 Label="single" 539 Target=(List 540 Items=(Slice 541 (Bind 542 Label="item" 543 Target=(And 544 Left=(Func 545 Name=(Names SubOp) 546 Args=(Slice) 547 Src=<test.opt:5:21> 548 ) 549 Right=(Func 550 Name=(Names Func) 551 Args=(Slice 552 (Ref Label="item" Src=<test.opt:5:37>) 553 ) 554 Src=<test.opt:5:31> 555 ) 556 Src=<test.opt:5:21> 557 ) 558 Src=<test.opt:5:15> 559 ) 560 ) 561 Src=<test.opt:5:13> 562 ) 563 Src=<test.opt:5:5> 564 ) 565 (Bind 566 Label="empty" 567 Target=(List Items=(Slice) Src=<test.opt:6:12>) 568 Src=<test.opt:6:5> 569 ) 570 ) 571 Src=<test.opt:2:1> 572 ) 573 Replace=(Func 574 Name=(Names Op) 575 Args=(Slice) 576 Src=<test.opt:9:1> 577 ) 578 Src=<test.opt:1:1> 579 ) 580 ) 581 ) 582 583 # 584 # Replace with bound expression. 585 # 586 parse 587 [ConstructBound] 588 (Op $input:*) => $input 589 ---- 590 (Root 591 Defines=(DefineSet) 592 Rules=(RuleSet 593 (Rule 594 Comments=(Comments) 595 Name="ConstructBound" 596 Tags=(Tags) 597 Match=(Func 598 Name=(Names Op) 599 Args=(Slice 600 (Bind Label="input" Target=(Any) Src=<test.opt:2:5>) 601 ) 602 Src=<test.opt:2:1> 603 ) 604 Replace=(Ref Label="input" Src=<test.opt:2:18>) 605 Src=<test.opt:1:1> 606 ) 607 ) 608 ) 609 610 # 611 # Replace with construct expression. 612 # 613 parse 614 [Construct] 615 (Op $input:*) => (Op $input (SubOp "foo" AnotherOp)) 616 ---- 617 (Root 618 Defines=(DefineSet) 619 Rules=(RuleSet 620 (Rule 621 Comments=(Comments) 622 Name="Construct" 623 Tags=(Tags) 624 Match=(Func 625 Name=(Names Op) 626 Args=(Slice 627 (Bind Label="input" Target=(Any) Src=<test.opt:2:5>) 628 ) 629 Src=<test.opt:2:1> 630 ) 631 Replace=(Func 632 Name=(Names Op) 633 Args=(Slice 634 (Ref Label="input" Src=<test.opt:2:22>) 635 (Func 636 Name=(Names SubOp) 637 Args=(Slice "foo" AnotherOp) 638 Src=<test.opt:2:29> 639 ) 640 ) 641 Src=<test.opt:2:18> 642 ) 643 Src=<test.opt:1:1> 644 ) 645 ) 646 ) 647 648 # 649 # Replace with construct list expression. 650 # 651 parse 652 [ConstructList] 653 (Op $left:* $right:*) 654 => 655 (Op [$left "foo" [] [$right] AnotherOp]) 656 ---- 657 (Root 658 Defines=(DefineSet) 659 Rules=(RuleSet 660 (Rule 661 Comments=(Comments) 662 Name="ConstructList" 663 Tags=(Tags) 664 Match=(Func 665 Name=(Names Op) 666 Args=(Slice 667 (Bind Label="left" Target=(Any) Src=<test.opt:2:5>) 668 (Bind Label="right" Target=(Any) Src=<test.opt:2:13>) 669 ) 670 Src=<test.opt:2:1> 671 ) 672 Replace=(Func 673 Name=(Names Op) 674 Args=(Slice 675 (List 676 Items=(Slice 677 (Ref Label="left" Src=<test.opt:4:6>) 678 "foo" 679 (List Items=(Slice) Src=<test.opt:4:18>) 680 (List 681 Items=(Slice 682 (Ref Label="right" Src=<test.opt:4:22>) 683 ) 684 Src=<test.opt:4:21> 685 ) 686 AnotherOp 687 ) 688 Src=<test.opt:4:5> 689 ) 690 ) 691 Src=<test.opt:4:1> 692 ) 693 Src=<test.opt:1:1> 694 ) 695 ) 696 ) 697 698 # 699 # Use dynamic construct name. 700 # 701 parse 702 [Construct] 703 (Op $input:*) => ((MakeOpName $input) (SubOp $input)) 704 ---- 705 (Root 706 Defines=(DefineSet) 707 Rules=(RuleSet 708 (Rule 709 Comments=(Comments) 710 Name="Construct" 711 Tags=(Tags) 712 Match=(Func 713 Name=(Names Op) 714 Args=(Slice 715 (Bind Label="input" Target=(Any) Src=<test.opt:2:5>) 716 ) 717 Src=<test.opt:2:1> 718 ) 719 Replace=(Func 720 Name=(Func 721 Name=(Names MakeOpName) 722 Args=(Slice 723 (Ref Label="input" Src=<test.opt:2:31>) 724 ) 725 Src=<test.opt:2:19> 726 ) 727 Args=(Slice 728 (Func 729 Name=(Names SubOp) 730 Args=(Slice 731 (Ref Label="input" Src=<test.opt:2:46>) 732 ) 733 Src=<test.opt:2:39> 734 ) 735 ) 736 Src=<test.opt:2:18> 737 ) 738 Src=<test.opt:1:1> 739 ) 740 ) 741 ) 742 743 # 744 # Match error cases + recovery cases. 745 # 746 parse 747 # Expected define statement or rule 748 (Op) => (Op) 749 750 # Expected op name 751 [Tag] 752 (Op | *) => (Op) 753 754 # Expected bind label 755 [Tag] 756 (Op $*) => (Op) 757 758 # Expected match pattern 759 [Tag] 760 (Op 1.1) => (Op) 761 762 # Expected match pattern 763 [Tag] 764 (Op * & $foo:*) => (Op) 765 766 # Expected operator name 767 [Tag] 768 (Op * & ^(*)) => (Op) 769 770 # Expected match pattern in list 771 [Tag] 772 (Op [ ... 10.1 ... ]) => (Op) 773 774 # Expected list end bracket (any case) 775 [Tag] 776 (Op [ ... * ...) => (Op) 777 778 # Expected list end bracket (last case) 779 [Tag] 780 (Op [ ... * ) => (Op) 781 782 # Expected list end bracket (empty case) 783 [Tag] 784 (Op [ ) => (Op) 785 786 # Numeric value out of range 787 [Tag] 788 (Op 1000000000000000000000000000) => (Op) 789 ---- 790 test.opt:2:1: expected define statement or rule, found '(' 791 test.opt:6:7: expected name, found '*' 792 test.opt:10:6: expected label, found '*' 793 test.opt:14:6: expected expression, found '.' 794 test.opt:18:9: expected expression, found '$' 795 test.opt:22:11: expected name, found '*' 796 test.opt:26:13: expected expression, found '.' 797 test.opt:30:16: expected expression, found ')' 798 test.opt:34:13: expected expression, found ')' 799 test.opt:38:7: expected expression, found ')' 800 test.opt:42:5: strconv.ParseInt: parsing "1000000000000000000000000000": value out of range 801 802 # 803 # Replace error cases + recovery cases. 804 # 805 parse 806 # Expected replace expression 807 [Tag] 808 (Op) => 123 809 810 # Expected construct name 811 [Tag] 812 (Op) => (*) 813 814 # Expected replace expression (nested) 815 [Tag] 816 (Op) => (Op .123) 817 818 # Expected construct name (nested) 819 [Tag] 820 (Op) => ((123)) 821 822 # Expected replace pattern, found name 823 [Tag] 824 (Op) => Op 825 826 # Replace with string expression. 827 [Tag] 828 (Op) => "foo" 829 ---- 830 test.opt:3:9: expected replace pattern, found '123' 831 test.opt:7:10: expected name, found '*' 832 test.opt:11:13: expected expression, found '.' 833 test.opt:15:11: expected name, found '123' 834 test.opt:19:9: expected replace pattern, found 'Op' 835 test.opt:23:9: expected replace pattern, found '"foo"' 836 837 # 838 # Replace EOF error case 839 # 840 parse 841 [Name] 842 (Op) 843 ---- 844 test.opt:2:5: expected '=>', found EOF 845 846 # 847 # Error opening file. Ensure that file error is last error, with no recovery 848 # attempted. 849 # 850 parse unknown.opt 851 define Empty {} 852 ---- 853 unknown file 'unknown.opt'