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