modernc.org/ql@v1.4.7/ql.y (about) 1 %{ 2 3 //TODO Put your favorite license here 4 5 // yacc source generated by ebnf2y[1] 6 // at 2019-04-12 12:52:38.590592118 +0200 CEST m=+0.001146149 7 // 8 // $ ebnf2y -o ql.y -start StatementList -pkg ql -p _ 9 // 10 // CAUTION: If this file is a Go source file (*.go), it was generated 11 // automatically by '$ go tool yacc' from a *.y file - DO NOT EDIT in that case! 12 // 13 // [1]: http://modernc.org/ebnf2y 14 15 package ql //TODO real package name 16 17 //TODO required only be the demo _dump function 18 import ( 19 "bytes" 20 "fmt" 21 "strings" 22 23 "modernc.org/strutil" 24 ) 25 26 %} 27 28 %union { 29 item interface{} //TODO insert real field(s) 30 } 31 32 %token _ANDAND 33 %token _ANDNOT 34 %token _EQ 35 %token _FLOAT_LIT 36 %token _GE 37 %token _IDENTIFIER 38 %token _IMAGINARY_LIT 39 %token _INT_LIT 40 %token _LE 41 %token _LSH 42 %token _NEQ 43 %token _OROR 44 %token _QL_PARAMETER 45 %token _RSH 46 %token _RUNE_LIT 47 %token _STRING_LIT 48 49 %type <item> /*TODO real type(s), if/where applicable */ 50 _ANDAND 51 _ANDNOT 52 _EQ 53 _FLOAT_LIT 54 _GE 55 _IDENTIFIER 56 _IMAGINARY_LIT 57 _INT_LIT 58 _LE 59 _LSH 60 _NEQ 61 _OROR 62 _QL_PARAMETER 63 _RSH 64 _RUNE_LIT 65 _STRING_LIT 66 67 %token _ADD 68 %token _ALTER 69 %token _AND 70 %token _AS 71 %token _ASC 72 %token _BEGIN 73 %token _BETWEEN 74 %token _BIGINT 75 %token _BIGRAT 76 %token _BLOB 77 %token _BOOL 78 %token _BY 79 %token _BYTE 80 %token _COLUMN 81 %token _COMMIT 82 %token _COMPLEX128 83 %token _COMPLEX64 84 %token _CREATE 85 %token _DEFAULT 86 %token _DELETE 87 %token _DESC 88 %token _DISTINCT 89 %token _DROP 90 %token _DURATION 91 %token _EXISTS 92 %token _EXPLAIN 93 %token _FALSE 94 %token _FLOAT 95 %token _FLOAT32 96 %token _FLOAT64 97 %token _FROM 98 %token _FULL 99 %token _GROUPBY 100 %token _IF 101 %token _IN 102 %token _INDEX 103 %token _INSERT 104 %token _INT 105 %token _INT16 106 %token _INT32 107 %token _INT64 108 %token _INT8 109 %token _INTO 110 %token _IS 111 %token _JOIN 112 %token _LEFT 113 %token _LIKE 114 %token _LIMIT 115 %token _NOT 116 %token _NULL 117 %token _OFFSET 118 %token _ON 119 %token _OR 120 %token _ORDER 121 %token _OUTER 122 %token _RIGHT 123 %token _ROLLBACK 124 %token _RUNE 125 %token _SELECT 126 %token _SET 127 %token _STRING 128 %token _TABLE 129 %token _TIME 130 %token _TRANSACTION 131 %token _TRUE 132 %token _TRUNCATE 133 %token _UINT 134 %token _UINT16 135 %token _UINT32 136 %token _UINT64 137 %token _UINT8 138 %token _UNIQUE 139 %token _UPDATE 140 %token _VALUES 141 %token _WHERE 142 143 %type <item> /*TODO real type(s), if/where applicable */ 144 AlterTableStmt 145 AlterTableStmt1 146 Assignment 147 AssignmentList 148 AssignmentList1 149 AssignmentList2 150 BeginTransactionStmt 151 Call 152 Call1 153 Call11 154 ColumnDef 155 ColumnDef1 156 ColumnDef11 157 ColumnDef2 158 ColumnName 159 ColumnNameList 160 ColumnNameList1 161 ColumnNameList2 162 CommitStmt 163 Conversion 164 CreateIndexStmt 165 CreateIndexStmt1 166 CreateIndexStmt2 167 CreateTableStmt 168 CreateTableStmt1 169 CreateTableStmt2 170 CreateTableStmt3 171 DeleteFromStmt 172 DeleteFromStmt1 173 DropIndexStmt 174 DropIndexStmt1 175 DropTableStmt 176 DropTableStmt1 177 EmptyStmt 178 ExplainStmt 179 Expression 180 Expression1 181 Expression11 182 ExpressionList 183 ExpressionList1 184 ExpressionList2 185 Factor 186 Factor1 187 Factor11 188 Factor2 189 Field 190 Field1 191 FieldList 192 FieldList1 193 FieldList2 194 GroupByClause 195 Index 196 IndexName 197 InsertIntoStmt 198 InsertIntoStmt1 199 InsertIntoStmt2 200 JoinClause 201 JoinClause1 202 JoinClause2 203 Limit 204 Literal 205 Offset 206 Operand 207 OrderBy 208 OrderBy1 209 OrderBy11 210 Predicate 211 Predicate1 212 Predicate11 213 Predicate12 214 Predicate121 215 Predicate13 216 PrimaryExpression 217 PrimaryFactor 218 PrimaryFactor1 219 PrimaryFactor11 220 PrimaryTerm 221 PrimaryTerm1 222 PrimaryTerm11 223 QualifiedIdent 224 QualifiedIdent1 225 RecordSet 226 RecordSet1 227 RecordSet11 228 RecordSet2 229 RecordSetList 230 RecordSetList1 231 RecordSetList2 232 RollbackStmt 233 SelectStmt 234 SelectStmt1 235 SelectStmt2 236 SelectStmt3 237 SelectStmt4 238 SelectStmt5 239 SelectStmt6 240 SelectStmt7 241 SelectStmt8 242 SelectStmt9 243 Slice 244 Slice1 245 Slice2 246 Start 247 Statement 248 StatementList 249 StatementList1 250 TableName 251 Term 252 Term1 253 Term11 254 TruncateTableStmt 255 Type 256 UnaryExpr 257 UnaryExpr1 258 UnaryExpr11 259 UpdateStmt 260 UpdateStmt1 261 UpdateStmt2 262 Values 263 Values1 264 Values2 265 WhereClause 266 267 /*TODO %left, %right, ... declarations */ 268 269 %start Start 270 271 %% 272 273 AlterTableStmt: 274 _ALTER _TABLE TableName AlterTableStmt1 275 { 276 $$ = []AlterTableStmt{"ALTER", "TABLE", $3, $4} //TODO 1 277 } 278 279 AlterTableStmt1: 280 _ADD ColumnDef 281 { 282 $$ = []AlterTableStmt1{"ADD", $2} //TODO 2 283 } 284 | _DROP _COLUMN ColumnName 285 { 286 $$ = []AlterTableStmt1{"DROP", "COLUMN", $3} //TODO 3 287 } 288 289 Assignment: 290 ColumnName '=' Expression 291 { 292 $$ = []Assignment{$1, "=", $3} //TODO 4 293 } 294 295 AssignmentList: 296 Assignment AssignmentList1 AssignmentList2 297 { 298 $$ = []AssignmentList{$1, $2, $3} //TODO 5 299 } 300 301 AssignmentList1: 302 /* EMPTY */ 303 { 304 $$ = []AssignmentList1(nil) //TODO 6 305 } 306 | AssignmentList1 ',' Assignment 307 { 308 $$ = append($1.([]AssignmentList1), ",", $3) //TODO 7 309 } 310 311 AssignmentList2: 312 /* EMPTY */ 313 { 314 $$ = nil //TODO 8 315 } 316 | ',' 317 { 318 $$ = "," //TODO 9 319 } 320 321 BeginTransactionStmt: 322 _BEGIN _TRANSACTION 323 { 324 $$ = []BeginTransactionStmt{"BEGIN", "TRANSACTION"} //TODO 10 325 } 326 327 Call: 328 '(' Call1 ')' 329 { 330 $$ = []Call{"(", $2, ")"} //TODO 11 331 } 332 333 Call1: 334 /* EMPTY */ 335 { 336 $$ = nil //TODO 12 337 } 338 | Call11 339 { 340 $$ = $1 //TODO 13 341 } 342 343 Call11: 344 '*' 345 { 346 $$ = "*" //TODO 14 347 } 348 | ExpressionList 349 { 350 $$ = $1 //TODO 15 351 } 352 353 ColumnDef: 354 ColumnName Type ColumnDef1 ColumnDef2 355 { 356 $$ = []ColumnDef{$1, $2, $3, $4} //TODO 16 357 } 358 359 ColumnDef1: 360 /* EMPTY */ 361 { 362 $$ = nil //TODO 17 363 } 364 | ColumnDef11 365 { 366 $$ = $1 //TODO 18 367 } 368 369 ColumnDef11: 370 _NOT _NULL 371 { 372 $$ = []ColumnDef11{"NOT", "NULL"} //TODO 19 373 } 374 | Expression 375 { 376 $$ = $1 //TODO 20 377 } 378 379 ColumnDef2: 380 /* EMPTY */ 381 { 382 $$ = nil //TODO 21 383 } 384 | _DEFAULT Expression 385 { 386 $$ = []ColumnDef2{"DEFAULT", $2} //TODO 22 387 } 388 389 ColumnName: 390 _IDENTIFIER 391 { 392 $$ = $1 //TODO 23 393 } 394 395 ColumnNameList: 396 ColumnName ColumnNameList1 ColumnNameList2 397 { 398 $$ = []ColumnNameList{$1, $2, $3} //TODO 24 399 } 400 401 ColumnNameList1: 402 /* EMPTY */ 403 { 404 $$ = []ColumnNameList1(nil) //TODO 25 405 } 406 | ColumnNameList1 ',' ColumnName 407 { 408 $$ = append($1.([]ColumnNameList1), ",", $3) //TODO 26 409 } 410 411 ColumnNameList2: 412 /* EMPTY */ 413 { 414 $$ = nil //TODO 27 415 } 416 | ',' 417 { 418 $$ = "," //TODO 28 419 } 420 421 CommitStmt: 422 _COMMIT 423 { 424 $$ = "COMMIT" //TODO 29 425 } 426 427 Conversion: 428 Type '(' Expression ')' 429 { 430 $$ = []Conversion{$1, "(", $3, ")"} //TODO 30 431 } 432 433 CreateIndexStmt: 434 _CREATE CreateIndexStmt1 _INDEX CreateIndexStmt2 IndexName _ON TableName '(' ExpressionList ')' 435 { 436 $$ = []CreateIndexStmt{"CREATE", $2, "INDEX", $4, $5, "ON", $7, "(", $9, ")"} //TODO 31 437 } 438 439 CreateIndexStmt1: 440 /* EMPTY */ 441 { 442 $$ = nil //TODO 32 443 } 444 | _UNIQUE 445 { 446 $$ = "UNIQUE" //TODO 33 447 } 448 449 CreateIndexStmt2: 450 /* EMPTY */ 451 { 452 $$ = nil //TODO 34 453 } 454 | _IF _NOT _EXISTS 455 { 456 $$ = []CreateIndexStmt2{"IF", "NOT", "EXISTS"} //TODO 35 457 } 458 459 CreateTableStmt: 460 _CREATE _TABLE CreateTableStmt1 TableName '(' ColumnDef CreateTableStmt2 CreateTableStmt3 ')' 461 { 462 $$ = []CreateTableStmt{"CREATE", "TABLE", $3, $4, "(", $6, $7, $8, ")"} //TODO 36 463 } 464 465 CreateTableStmt1: 466 /* EMPTY */ 467 { 468 $$ = nil //TODO 37 469 } 470 | _IF _NOT _EXISTS 471 { 472 $$ = []CreateTableStmt1{"IF", "NOT", "EXISTS"} //TODO 38 473 } 474 475 CreateTableStmt2: 476 /* EMPTY */ 477 { 478 $$ = []CreateTableStmt2(nil) //TODO 39 479 } 480 | CreateTableStmt2 ',' ColumnDef 481 { 482 $$ = append($1.([]CreateTableStmt2), ",", $3) //TODO 40 483 } 484 485 CreateTableStmt3: 486 /* EMPTY */ 487 { 488 $$ = nil //TODO 41 489 } 490 | ',' 491 { 492 $$ = "," //TODO 42 493 } 494 495 DeleteFromStmt: 496 _DELETE _FROM TableName DeleteFromStmt1 497 { 498 $$ = []DeleteFromStmt{"DELETE", "FROM", $3, $4} //TODO 43 499 } 500 501 DeleteFromStmt1: 502 /* EMPTY */ 503 { 504 $$ = nil //TODO 44 505 } 506 | WhereClause 507 { 508 $$ = $1 //TODO 45 509 } 510 511 DropIndexStmt: 512 _DROP _INDEX DropIndexStmt1 IndexName 513 { 514 $$ = []DropIndexStmt{"DROP", "INDEX", $3, $4} //TODO 46 515 } 516 517 DropIndexStmt1: 518 /* EMPTY */ 519 { 520 $$ = nil //TODO 47 521 } 522 | _IF _EXISTS 523 { 524 $$ = []DropIndexStmt1{"IF", "EXISTS"} //TODO 48 525 } 526 527 DropTableStmt: 528 _DROP _TABLE DropTableStmt1 TableName 529 { 530 $$ = []DropTableStmt{"DROP", "TABLE", $3, $4} //TODO 49 531 } 532 533 DropTableStmt1: 534 /* EMPTY */ 535 { 536 $$ = nil //TODO 50 537 } 538 | _IF _EXISTS 539 { 540 $$ = []DropTableStmt1{"IF", "EXISTS"} //TODO 51 541 } 542 543 EmptyStmt: 544 /* EMPTY */ 545 { 546 $$ = nil //TODO 52 547 } 548 549 ExplainStmt: 550 _EXPLAIN Statement 551 { 552 $$ = []ExplainStmt{"EXPLAIN", $2} //TODO 53 553 } 554 555 Expression: 556 Term Expression1 557 { 558 $$ = []Expression{$1, $2} //TODO 54 559 } 560 561 Expression1: 562 /* EMPTY */ 563 { 564 $$ = []Expression1(nil) //TODO 55 565 } 566 | Expression1 Expression11 Term 567 { 568 $$ = append($1.([]Expression1), $2, $3) //TODO 56 569 } 570 571 Expression11: 572 _OROR 573 { 574 $$ = $1 //TODO 57 575 } 576 | _OR 577 { 578 $$ = "OR" //TODO 58 579 } 580 581 ExpressionList: 582 Expression ExpressionList1 ExpressionList2 583 { 584 $$ = []ExpressionList{$1, $2, $3} //TODO 59 585 } 586 587 ExpressionList1: 588 /* EMPTY */ 589 { 590 $$ = []ExpressionList1(nil) //TODO 60 591 } 592 | ExpressionList1 ',' Expression 593 { 594 $$ = append($1.([]ExpressionList1), ",", $3) //TODO 61 595 } 596 597 ExpressionList2: 598 /* EMPTY */ 599 { 600 $$ = nil //TODO 62 601 } 602 | ',' 603 { 604 $$ = "," //TODO 63 605 } 606 607 Factor: 608 PrimaryFactor Factor1 Factor2 609 { 610 $$ = []Factor{$1, $2, $3} //TODO 64 611 } 612 613 Factor1: 614 /* EMPTY */ 615 { 616 $$ = []Factor1(nil) //TODO 65 617 } 618 | Factor1 Factor11 PrimaryFactor 619 { 620 $$ = append($1.([]Factor1), $2, $3) //TODO 66 621 } 622 623 Factor11: 624 _GE 625 { 626 $$ = $1 //TODO 67 627 } 628 | '>' 629 { 630 $$ = ">" //TODO 68 631 } 632 | _LE 633 { 634 $$ = $1 //TODO 69 635 } 636 | '<' 637 { 638 $$ = "<" //TODO 70 639 } 640 | _NEQ 641 { 642 $$ = $1 //TODO 71 643 } 644 | _EQ 645 { 646 $$ = $1 //TODO 72 647 } 648 | _LIKE 649 { 650 $$ = "LIKE" //TODO 73 651 } 652 653 Factor2: 654 /* EMPTY */ 655 { 656 $$ = nil //TODO 74 657 } 658 | Predicate 659 { 660 $$ = $1 //TODO 75 661 } 662 663 Field: 664 Expression Field1 665 { 666 $$ = []Field{$1, $2} //TODO 76 667 } 668 669 Field1: 670 /* EMPTY */ 671 { 672 $$ = nil //TODO 77 673 } 674 | _AS _IDENTIFIER 675 { 676 $$ = []Field1{"AS", $2} //TODO 78 677 } 678 679 FieldList: 680 Field FieldList1 FieldList2 681 { 682 $$ = []FieldList{$1, $2, $3} //TODO 79 683 } 684 685 FieldList1: 686 /* EMPTY */ 687 { 688 $$ = []FieldList1(nil) //TODO 80 689 } 690 | FieldList1 ',' Field 691 { 692 $$ = append($1.([]FieldList1), ",", $3) //TODO 81 693 } 694 695 FieldList2: 696 /* EMPTY */ 697 { 698 $$ = nil //TODO 82 699 } 700 | ',' 701 { 702 $$ = "," //TODO 83 703 } 704 705 GroupByClause: 706 _GROUPBY ColumnNameList 707 { 708 $$ = []GroupByClause{"GROUP BY", $2} //TODO 84 709 } 710 711 Index: 712 '[' Expression ']' 713 { 714 $$ = []Index{"[", $2, "]"} //TODO 85 715 } 716 717 IndexName: 718 _IDENTIFIER 719 { 720 $$ = $1 //TODO 86 721 } 722 723 InsertIntoStmt: 724 _INSERT _INTO TableName InsertIntoStmt1 InsertIntoStmt2 725 { 726 $$ = []InsertIntoStmt{"INSERT", "INTO", $3, $4, $5} //TODO 87 727 } 728 729 InsertIntoStmt1: 730 /* EMPTY */ 731 { 732 $$ = nil //TODO 88 733 } 734 | '(' ColumnNameList ')' 735 { 736 $$ = []InsertIntoStmt1{"(", $2, ")"} //TODO 89 737 } 738 739 InsertIntoStmt2: 740 Values 741 { 742 $$ = $1 //TODO 90 743 } 744 | SelectStmt 745 { 746 $$ = $1 //TODO 91 747 } 748 749 JoinClause: 750 JoinClause1 JoinClause2 _JOIN RecordSet _ON Expression 751 { 752 $$ = []JoinClause{$1, $2, "JOIN", $4, "ON", $6} //TODO 92 753 } 754 755 JoinClause1: 756 _LEFT 757 { 758 $$ = "LEFT" //TODO 93 759 } 760 | _RIGHT 761 { 762 $$ = "RIGHT" //TODO 94 763 } 764 | _FULL 765 { 766 $$ = "FULL" //TODO 95 767 } 768 769 JoinClause2: 770 /* EMPTY */ 771 { 772 $$ = nil //TODO 96 773 } 774 | _OUTER 775 { 776 $$ = "OUTER" //TODO 97 777 } 778 779 Limit: 780 _LIMIT Expression 781 { 782 $$ = []Limit{"Limit", $2} //TODO 98 783 } 784 785 Literal: 786 _FALSE 787 { 788 $$ = "FALSE" //TODO 99 789 } 790 | _NULL 791 { 792 $$ = "NULL" //TODO 100 793 } 794 | _TRUE 795 { 796 $$ = "TRUE" //TODO 101 797 } 798 | _FLOAT_LIT 799 { 800 $$ = $1 //TODO 102 801 } 802 | _IMAGINARY_LIT 803 { 804 $$ = $1 //TODO 103 805 } 806 | _INT_LIT 807 { 808 $$ = $1 //TODO 104 809 } 810 | _RUNE_LIT 811 { 812 $$ = $1 //TODO 105 813 } 814 | _STRING_LIT 815 { 816 $$ = $1 //TODO 106 817 } 818 | _QL_PARAMETER 819 { 820 $$ = $1 //TODO 107 821 } 822 823 Offset: 824 _OFFSET Expression 825 { 826 $$ = []Offset{"OFFSET", $2} //TODO 108 827 } 828 829 Operand: 830 Literal 831 { 832 $$ = $1 //TODO 109 833 } 834 | QualifiedIdent 835 { 836 $$ = $1 //TODO 110 837 } 838 | '(' Expression ')' 839 { 840 $$ = []Operand{"(", $2, ")"} //TODO 111 841 } 842 843 OrderBy: 844 _ORDER _BY ExpressionList OrderBy1 845 { 846 $$ = []OrderBy{"ORDER", "BY", $3, $4} //TODO 112 847 } 848 849 OrderBy1: 850 /* EMPTY */ 851 { 852 $$ = nil //TODO 113 853 } 854 | OrderBy11 855 { 856 $$ = $1 //TODO 114 857 } 858 859 OrderBy11: 860 _ASC 861 { 862 $$ = "ASC" //TODO 115 863 } 864 | _DESC 865 { 866 $$ = "DESC" //TODO 116 867 } 868 869 Predicate: 870 Predicate1 871 { 872 $$ = $1 //TODO 117 873 } 874 875 Predicate1: 876 Predicate11 Predicate12 877 { 878 $$ = []Predicate1{$1, $2} //TODO 118 879 } 880 | _IS Predicate13 _NULL 881 { 882 $$ = []Predicate1{"IS", $2, "NULL"} //TODO 119 883 } 884 885 Predicate11: 886 /* EMPTY */ 887 { 888 $$ = nil //TODO 120 889 } 890 | _NOT 891 { 892 $$ = "NOT" //TODO 121 893 } 894 895 Predicate12: 896 _IN '(' ExpressionList ')' 897 { 898 $$ = []Predicate12{"IN", "(", $3, ")"} //TODO 122 899 } 900 | _IN '(' SelectStmt Predicate121 ')' 901 { 902 $$ = []Predicate12{"IN", "(", $3, $4, ")"} //TODO 123 903 } 904 | _BETWEEN PrimaryFactor _AND PrimaryFactor 905 { 906 $$ = []Predicate12{"BETWEEN", $2, "AND", $4} //TODO 124 907 } 908 909 Predicate121: 910 /* EMPTY */ 911 { 912 $$ = nil //TODO 125 913 } 914 | ';' 915 { 916 $$ = ";" //TODO 126 917 } 918 919 Predicate13: 920 /* EMPTY */ 921 { 922 $$ = nil //TODO 127 923 } 924 | _NOT 925 { 926 $$ = "NOT" //TODO 128 927 } 928 929 PrimaryExpression: 930 Operand 931 { 932 $$ = $1 //TODO 129 933 } 934 | Conversion 935 { 936 $$ = $1 //TODO 130 937 } 938 | PrimaryExpression Index 939 { 940 $$ = []PrimaryExpression{$1, $2} //TODO 131 941 } 942 | PrimaryExpression Slice 943 { 944 $$ = []PrimaryExpression{$1, $2} //TODO 132 945 } 946 | PrimaryExpression Call 947 { 948 $$ = []PrimaryExpression{$1, $2} //TODO 133 949 } 950 951 PrimaryFactor: 952 PrimaryTerm PrimaryFactor1 953 { 954 $$ = []PrimaryFactor{$1, $2} //TODO 134 955 } 956 957 PrimaryFactor1: 958 /* EMPTY */ 959 { 960 $$ = []PrimaryFactor1(nil) //TODO 135 961 } 962 | PrimaryFactor1 PrimaryFactor11 PrimaryTerm 963 { 964 $$ = append($1.([]PrimaryFactor1), $2, $3) //TODO 136 965 } 966 967 PrimaryFactor11: 968 '^' 969 { 970 $$ = "^" //TODO 137 971 } 972 | '|' 973 { 974 $$ = "|" //TODO 138 975 } 976 | '-' 977 { 978 $$ = "-" //TODO 139 979 } 980 | '+' 981 { 982 $$ = "+" //TODO 140 983 } 984 985 PrimaryTerm: 986 UnaryExpr PrimaryTerm1 987 { 988 $$ = []PrimaryTerm{$1, $2} //TODO 141 989 } 990 991 PrimaryTerm1: 992 /* EMPTY */ 993 { 994 $$ = []PrimaryTerm1(nil) //TODO 142 995 } 996 | PrimaryTerm1 PrimaryTerm11 UnaryExpr 997 { 998 $$ = append($1.([]PrimaryTerm1), $2, $3) //TODO 143 999 } 1000 1001 PrimaryTerm11: 1002 _ANDNOT 1003 { 1004 $$ = $1 //TODO 144 1005 } 1006 | '&' 1007 { 1008 $$ = "&" //TODO 145 1009 } 1010 | _LSH 1011 { 1012 $$ = $1 //TODO 146 1013 } 1014 | _RSH 1015 { 1016 $$ = $1 //TODO 147 1017 } 1018 | '%' 1019 { 1020 $$ = "%" //TODO 148 1021 } 1022 | '/' 1023 { 1024 $$ = "/" //TODO 149 1025 } 1026 | '*' 1027 { 1028 $$ = "*" //TODO 150 1029 } 1030 1031 QualifiedIdent: 1032 _IDENTIFIER QualifiedIdent1 1033 { 1034 $$ = []QualifiedIdent{$1, $2} //TODO 151 1035 } 1036 1037 QualifiedIdent1: 1038 /* EMPTY */ 1039 { 1040 $$ = nil //TODO 152 1041 } 1042 | '.' _IDENTIFIER 1043 { 1044 $$ = []QualifiedIdent1{".", $2} //TODO 153 1045 } 1046 1047 RecordSet: 1048 RecordSet1 RecordSet2 1049 { 1050 $$ = []RecordSet{$1, $2} //TODO 154 1051 } 1052 1053 RecordSet1: 1054 TableName 1055 { 1056 $$ = $1 //TODO 155 1057 } 1058 | '(' SelectStmt RecordSet11 ')' 1059 { 1060 $$ = []RecordSet1{"(", $2, $3, ")"} //TODO 156 1061 } 1062 1063 RecordSet11: 1064 /* EMPTY */ 1065 { 1066 $$ = nil //TODO 157 1067 } 1068 | ';' 1069 { 1070 $$ = ";" //TODO 158 1071 } 1072 1073 RecordSet2: 1074 /* EMPTY */ 1075 { 1076 $$ = nil //TODO 159 1077 } 1078 | _AS _IDENTIFIER 1079 { 1080 $$ = []RecordSet2{"AS", $2} //TODO 160 1081 } 1082 1083 RecordSetList: 1084 RecordSet RecordSetList1 RecordSetList2 1085 { 1086 $$ = []RecordSetList{$1, $2, $3} //TODO 161 1087 } 1088 1089 RecordSetList1: 1090 /* EMPTY */ 1091 { 1092 $$ = []RecordSetList1(nil) //TODO 162 1093 } 1094 | RecordSetList1 ',' RecordSet 1095 { 1096 $$ = append($1.([]RecordSetList1), ",", $3) //TODO 163 1097 } 1098 1099 RecordSetList2: 1100 /* EMPTY */ 1101 { 1102 $$ = nil //TODO 164 1103 } 1104 | ',' 1105 { 1106 $$ = "," //TODO 165 1107 } 1108 1109 RollbackStmt: 1110 _ROLLBACK 1111 { 1112 $$ = "ROLLBACK" //TODO 166 1113 } 1114 1115 SelectStmt: 1116 _SELECT SelectStmt1 SelectStmt2 SelectStmt3 SelectStmt4 SelectStmt5 SelectStmt6 SelectStmt7 SelectStmt8 SelectStmt9 1117 { 1118 $$ = []SelectStmt{"SELECT", $2, $3, $4, $5, $6, $7, $8, $9, $10} //TODO 167 1119 } 1120 1121 SelectStmt1: 1122 /* EMPTY */ 1123 { 1124 $$ = nil //TODO 168 1125 } 1126 | _DISTINCT 1127 { 1128 $$ = "DISTINCT" //TODO 169 1129 } 1130 1131 SelectStmt2: 1132 '*' 1133 { 1134 $$ = "*" //TODO 170 1135 } 1136 | FieldList 1137 { 1138 $$ = $1 //TODO 171 1139 } 1140 1141 SelectStmt3: 1142 /* EMPTY */ 1143 { 1144 $$ = nil //TODO 172 1145 } 1146 | _FROM RecordSetList 1147 { 1148 $$ = []SelectStmt3{"FROM", $2} //TODO 173 1149 } 1150 1151 SelectStmt4: 1152 /* EMPTY */ 1153 { 1154 $$ = nil //TODO 174 1155 } 1156 | JoinClause 1157 { 1158 $$ = $1 //TODO 175 1159 } 1160 1161 SelectStmt5: 1162 /* EMPTY */ 1163 { 1164 $$ = nil //TODO 176 1165 } 1166 | WhereClause 1167 { 1168 $$ = $1 //TODO 177 1169 } 1170 1171 SelectStmt6: 1172 /* EMPTY */ 1173 { 1174 $$ = nil //TODO 178 1175 } 1176 | GroupByClause 1177 { 1178 $$ = $1 //TODO 179 1179 } 1180 1181 SelectStmt7: 1182 /* EMPTY */ 1183 { 1184 $$ = nil //TODO 180 1185 } 1186 | OrderBy 1187 { 1188 $$ = $1 //TODO 181 1189 } 1190 1191 SelectStmt8: 1192 /* EMPTY */ 1193 { 1194 $$ = nil //TODO 182 1195 } 1196 | Limit 1197 { 1198 $$ = $1 //TODO 183 1199 } 1200 1201 SelectStmt9: 1202 /* EMPTY */ 1203 { 1204 $$ = nil //TODO 184 1205 } 1206 | Offset 1207 { 1208 $$ = $1 //TODO 185 1209 } 1210 1211 Slice: 1212 '[' Slice1 ':' Slice2 ']' 1213 { 1214 $$ = []Slice{"[", $2, ":", $4, "]"} //TODO 186 1215 } 1216 1217 Slice1: 1218 /* EMPTY */ 1219 { 1220 $$ = nil //TODO 187 1221 } 1222 | Expression 1223 { 1224 $$ = $1 //TODO 188 1225 } 1226 1227 Slice2: 1228 /* EMPTY */ 1229 { 1230 $$ = nil //TODO 189 1231 } 1232 | Expression 1233 { 1234 $$ = $1 //TODO 190 1235 } 1236 1237 Start: 1238 StatementList 1239 { 1240 _parserResult = $1 //TODO 191 1241 } 1242 1243 Statement: 1244 EmptyStmt 1245 { 1246 $$ = $1 //TODO 192 1247 } 1248 | AlterTableStmt 1249 { 1250 $$ = $1 //TODO 193 1251 } 1252 | BeginTransactionStmt 1253 { 1254 $$ = $1 //TODO 194 1255 } 1256 | CommitStmt 1257 { 1258 $$ = $1 //TODO 195 1259 } 1260 | CreateIndexStmt 1261 { 1262 $$ = $1 //TODO 196 1263 } 1264 | CreateTableStmt 1265 { 1266 $$ = $1 //TODO 197 1267 } 1268 | DeleteFromStmt 1269 { 1270 $$ = $1 //TODO 198 1271 } 1272 | DropIndexStmt 1273 { 1274 $$ = $1 //TODO 199 1275 } 1276 | DropTableStmt 1277 { 1278 $$ = $1 //TODO 200 1279 } 1280 | InsertIntoStmt 1281 { 1282 $$ = $1 //TODO 201 1283 } 1284 | RollbackStmt 1285 { 1286 $$ = $1 //TODO 202 1287 } 1288 | SelectStmt 1289 { 1290 $$ = $1 //TODO 203 1291 } 1292 | TruncateTableStmt 1293 { 1294 $$ = $1 //TODO 204 1295 } 1296 | UpdateStmt 1297 { 1298 $$ = $1 //TODO 205 1299 } 1300 | ExplainStmt 1301 { 1302 $$ = $1 //TODO 206 1303 } 1304 1305 StatementList: 1306 Statement StatementList1 1307 { 1308 $$ = []StatementList{$1, $2} //TODO 207 1309 } 1310 1311 StatementList1: 1312 /* EMPTY */ 1313 { 1314 $$ = []StatementList1(nil) //TODO 208 1315 } 1316 | StatementList1 ';' Statement 1317 { 1318 $$ = append($1.([]StatementList1), ";", $3) //TODO 209 1319 } 1320 1321 TableName: 1322 _IDENTIFIER 1323 { 1324 $$ = $1 //TODO 210 1325 } 1326 1327 Term: 1328 Factor Term1 1329 { 1330 $$ = []Term{$1, $2} //TODO 211 1331 } 1332 1333 Term1: 1334 /* EMPTY */ 1335 { 1336 $$ = []Term1(nil) //TODO 212 1337 } 1338 | Term1 Term11 Factor 1339 { 1340 $$ = append($1.([]Term1), $2, $3) //TODO 213 1341 } 1342 1343 Term11: 1344 _ANDAND 1345 { 1346 $$ = $1 //TODO 214 1347 } 1348 | _AND 1349 { 1350 $$ = "AND" //TODO 215 1351 } 1352 1353 TruncateTableStmt: 1354 _TRUNCATE _TABLE TableName 1355 { 1356 $$ = []TruncateTableStmt{"TRUNCATE", "TABLE", $3} //TODO 216 1357 } 1358 1359 Type: 1360 _BIGINT 1361 { 1362 $$ = "bigint" //TODO 217 1363 } 1364 | _BIGRAT 1365 { 1366 $$ = "bigrat" //TODO 218 1367 } 1368 | _BLOB 1369 { 1370 $$ = "blob" //TODO 219 1371 } 1372 | _BOOL 1373 { 1374 $$ = "bool" //TODO 220 1375 } 1376 | _BYTE 1377 { 1378 $$ = "byte" //TODO 221 1379 } 1380 | _COMPLEX128 1381 { 1382 $$ = "complex128" //TODO 222 1383 } 1384 | _COMPLEX64 1385 { 1386 $$ = "complex64" //TODO 223 1387 } 1388 | _DURATION 1389 { 1390 $$ = "duration" //TODO 224 1391 } 1392 | _FLOAT 1393 { 1394 $$ = "float" //TODO 225 1395 } 1396 | _FLOAT32 1397 { 1398 $$ = "float32" //TODO 226 1399 } 1400 | _FLOAT64 1401 { 1402 $$ = "float64" //TODO 227 1403 } 1404 | _INT 1405 { 1406 $$ = "int" //TODO 228 1407 } 1408 | _INT16 1409 { 1410 $$ = "int16" //TODO 229 1411 } 1412 | _INT32 1413 { 1414 $$ = "int32" //TODO 230 1415 } 1416 | _INT64 1417 { 1418 $$ = "int64" //TODO 231 1419 } 1420 | _INT8 1421 { 1422 $$ = "int8" //TODO 232 1423 } 1424 | _RUNE 1425 { 1426 $$ = "rune" //TODO 233 1427 } 1428 | _STRING 1429 { 1430 $$ = "string" //TODO 234 1431 } 1432 | _TIME 1433 { 1434 $$ = "time" //TODO 235 1435 } 1436 | _UINT 1437 { 1438 $$ = "uint" //TODO 236 1439 } 1440 | _UINT16 1441 { 1442 $$ = "uint16" //TODO 237 1443 } 1444 | _UINT32 1445 { 1446 $$ = "uint32" //TODO 238 1447 } 1448 | _UINT64 1449 { 1450 $$ = "uint64" //TODO 239 1451 } 1452 | _UINT8 1453 { 1454 $$ = "uint8" //TODO 240 1455 } 1456 1457 UnaryExpr: 1458 UnaryExpr1 PrimaryExpression 1459 { 1460 $$ = []UnaryExpr{$1, $2} //TODO 241 1461 } 1462 1463 UnaryExpr1: 1464 /* EMPTY */ 1465 { 1466 $$ = nil //TODO 242 1467 } 1468 | UnaryExpr11 1469 { 1470 $$ = $1 //TODO 243 1471 } 1472 1473 UnaryExpr11: 1474 '^' 1475 { 1476 $$ = "^" //TODO 244 1477 } 1478 | '!' 1479 { 1480 $$ = "!" //TODO 245 1481 } 1482 | '-' 1483 { 1484 $$ = "-" //TODO 246 1485 } 1486 | '+' 1487 { 1488 $$ = "+" //TODO 247 1489 } 1490 1491 UpdateStmt: 1492 _UPDATE TableName UpdateStmt1 AssignmentList UpdateStmt2 1493 { 1494 $$ = []UpdateStmt{"UPDATE", $2, $3, $4, $5} //TODO 248 1495 } 1496 1497 UpdateStmt1: 1498 /* EMPTY */ 1499 { 1500 $$ = nil //TODO 249 1501 } 1502 | _SET 1503 { 1504 $$ = "SET" //TODO 250 1505 } 1506 1507 UpdateStmt2: 1508 /* EMPTY */ 1509 { 1510 $$ = nil //TODO 251 1511 } 1512 | WhereClause 1513 { 1514 $$ = $1 //TODO 252 1515 } 1516 1517 Values: 1518 _VALUES '(' ExpressionList ')' Values1 Values2 1519 { 1520 $$ = []Values{"VALUES", "(", $3, ")", $5, $6} //TODO 253 1521 } 1522 1523 Values1: 1524 /* EMPTY */ 1525 { 1526 $$ = []Values1(nil) //TODO 254 1527 } 1528 | Values1 ',' '(' ExpressionList ')' 1529 { 1530 $$ = append($1.([]Values1), ",", "(", $4, ")") //TODO 255 1531 } 1532 1533 Values2: 1534 /* EMPTY */ 1535 { 1536 $$ = nil //TODO 256 1537 } 1538 | ',' 1539 { 1540 $$ = "," //TODO 257 1541 } 1542 1543 WhereClause: 1544 _WHERE Expression 1545 { 1546 $$ = []WhereClause{"WHERE", $2} //TODO 258 1547 } 1548 | _WHERE _EXISTS '(' SelectStmt ')' 1549 { 1550 $$ = []WhereClause{"WHERE", "EXISTS", "(", $4, ")"} //TODO 259 1551 } 1552 | _WHERE _NOT _EXISTS '(' SelectStmt ')' 1553 { 1554 $$ = []WhereClause{"WHERE", "NOT", "EXISTS", "(", $5, ")"} //TODO 260 1555 } 1556 1557 %% 1558 1559 //TODO remove demo stuff below 1560 1561 var _parserResult interface{} 1562 1563 type ( 1564 AlterTableStmt interface{} 1565 AlterTableStmt1 interface{} 1566 Assignment interface{} 1567 AssignmentList interface{} 1568 AssignmentList1 interface{} 1569 AssignmentList2 interface{} 1570 BeginTransactionStmt interface{} 1571 Call interface{} 1572 Call1 interface{} 1573 Call11 interface{} 1574 ColumnDef interface{} 1575 ColumnDef1 interface{} 1576 ColumnDef11 interface{} 1577 ColumnDef2 interface{} 1578 ColumnName interface{} 1579 ColumnNameList interface{} 1580 ColumnNameList1 interface{} 1581 ColumnNameList2 interface{} 1582 CommitStmt interface{} 1583 Conversion interface{} 1584 CreateIndexStmt interface{} 1585 CreateIndexStmt1 interface{} 1586 CreateIndexStmt2 interface{} 1587 CreateTableStmt interface{} 1588 CreateTableStmt1 interface{} 1589 CreateTableStmt2 interface{} 1590 CreateTableStmt3 interface{} 1591 DeleteFromStmt interface{} 1592 DeleteFromStmt1 interface{} 1593 DropIndexStmt interface{} 1594 DropIndexStmt1 interface{} 1595 DropTableStmt interface{} 1596 DropTableStmt1 interface{} 1597 EmptyStmt interface{} 1598 ExplainStmt interface{} 1599 Expression interface{} 1600 Expression1 interface{} 1601 Expression11 interface{} 1602 ExpressionList interface{} 1603 ExpressionList1 interface{} 1604 ExpressionList2 interface{} 1605 Factor interface{} 1606 Factor1 interface{} 1607 Factor11 interface{} 1608 Factor2 interface{} 1609 Field interface{} 1610 Field1 interface{} 1611 FieldList interface{} 1612 FieldList1 interface{} 1613 FieldList2 interface{} 1614 GroupByClause interface{} 1615 Index interface{} 1616 IndexName interface{} 1617 InsertIntoStmt interface{} 1618 InsertIntoStmt1 interface{} 1619 InsertIntoStmt2 interface{} 1620 JoinClause interface{} 1621 JoinClause1 interface{} 1622 JoinClause2 interface{} 1623 Limit interface{} 1624 Literal interface{} 1625 Offset interface{} 1626 Operand interface{} 1627 OrderBy interface{} 1628 OrderBy1 interface{} 1629 OrderBy11 interface{} 1630 Predicate interface{} 1631 Predicate1 interface{} 1632 Predicate11 interface{} 1633 Predicate12 interface{} 1634 Predicate121 interface{} 1635 Predicate13 interface{} 1636 PrimaryExpression interface{} 1637 PrimaryFactor interface{} 1638 PrimaryFactor1 interface{} 1639 PrimaryFactor11 interface{} 1640 PrimaryTerm interface{} 1641 PrimaryTerm1 interface{} 1642 PrimaryTerm11 interface{} 1643 QualifiedIdent interface{} 1644 QualifiedIdent1 interface{} 1645 RecordSet interface{} 1646 RecordSet1 interface{} 1647 RecordSet11 interface{} 1648 RecordSet2 interface{} 1649 RecordSetList interface{} 1650 RecordSetList1 interface{} 1651 RecordSetList2 interface{} 1652 RollbackStmt interface{} 1653 SelectStmt interface{} 1654 SelectStmt1 interface{} 1655 SelectStmt2 interface{} 1656 SelectStmt3 interface{} 1657 SelectStmt4 interface{} 1658 SelectStmt5 interface{} 1659 SelectStmt6 interface{} 1660 SelectStmt7 interface{} 1661 SelectStmt8 interface{} 1662 SelectStmt9 interface{} 1663 Slice interface{} 1664 Slice1 interface{} 1665 Slice2 interface{} 1666 Start interface{} 1667 Statement interface{} 1668 StatementList interface{} 1669 StatementList1 interface{} 1670 TableName interface{} 1671 Term interface{} 1672 Term1 interface{} 1673 Term11 interface{} 1674 TruncateTableStmt interface{} 1675 Type interface{} 1676 UnaryExpr interface{} 1677 UnaryExpr1 interface{} 1678 UnaryExpr11 interface{} 1679 UpdateStmt interface{} 1680 UpdateStmt1 interface{} 1681 UpdateStmt2 interface{} 1682 Values interface{} 1683 Values1 interface{} 1684 Values2 interface{} 1685 WhereClause interface{} 1686 ) 1687 1688 func _dump() { 1689 s := fmt.Sprintf("%#v", _parserResult) 1690 s = strings.Replace(s, "%", "%%", -1) 1691 s = strings.Replace(s, "{", "{%i\n", -1) 1692 s = strings.Replace(s, "}", "%u\n}", -1) 1693 s = strings.Replace(s, ", ", ",\n", -1) 1694 var buf bytes.Buffer 1695 strutil.IndentFormatter(&buf, ". ").Format(s) 1696 buf.WriteString("\n") 1697 a := strings.Split(buf.String(), "\n") 1698 for _, v := range a { 1699 if strings.HasSuffix(v, "(nil)") || strings.HasSuffix(v, "(nil),") { 1700 continue 1701 } 1702 1703 fmt.Println(v) 1704 } 1705 } 1706 1707 // End of demo stuff