This repository has been archived by the owner on Nov 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
/
ql.y
1707 lines (1564 loc) · 22.9 KB
/
ql.y
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
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%{
//TODO Put your favorite license here
// yacc source generated by ebnf2y[1]
// at 2017-11-22 13:44:30.7008477 +0100 CET m=+0.004756809
//
// $ ebnf2y -o ql.y -oe ql.ebnf -start StatementList -pkg ql -p _
//
// CAUTION: If this file is a Go source file (*.go), it was generated
// automatically by '$ go tool yacc' from a *.y file - DO NOT EDIT in that case!
//
// [1]: http://github.com/cznic/ebnf2y
package ql //TODO real package name
//TODO required only be the demo _dump function
import (
"bytes"
"fmt"
"strings"
"github.com/cznic/strutil"
)
%}
%union {
item interface{} //TODO insert real field(s)
}
%token _ANDAND
%token _ANDNOT
%token _EQ
%token _FLOAT_LIT
%token _GE
%token _IDENTIFIER
%token _IMAGINARY_LIT
%token _INT_LIT
%token _LE
%token _LSH
%token _NEQ
%token _OROR
%token _QL_PARAMETER
%token _RSH
%token _RUNE_LIT
%token _STRING_LIT
%type <item> /*TODO real type(s), if/where applicable */
_ANDAND
_ANDNOT
_EQ
_FLOAT_LIT
_GE
_IDENTIFIER
_IMAGINARY_LIT
_INT_LIT
_LE
_LSH
_NEQ
_OROR
_QL_PARAMETER
_RSH
_RUNE_LIT
_STRING_LIT
%token _ADD
%token _ALTER
%token _AND
%token _AS
%token _ASC
%token _BEGIN
%token _BETWEEN
%token _BIGINT
%token _BIGRAT
%token _BLOB
%token _BOOL
%token _BY
%token _BYTE
%token _COLUMN
%token _COMMIT
%token _COMPLEX128
%token _COMPLEX64
%token _CREATE
%token _DEFAULT
%token _DELETE
%token _DESC
%token _DISTINCT
%token _DROP
%token _DURATION
%token _EXISTS
%token _EXPLAIN
%token _FALSE
%token _FLOAT
%token _FLOAT32
%token _FLOAT64
%token _FROM
%token _FULL
%token _GROUPBY
%token _IF
%token _IN
%token _INDEX
%token _INSERT
%token _INT
%token _INT16
%token _INT32
%token _INT64
%token _INT8
%token _INTO
%token _IS
%token _JOIN
%token _LEFT
%token _LIKE
%token _LIMIT
%token _NOT
%token _NULL
%token _OFFSET
%token _ON
%token _OR
%token _ORDER
%token _OUTER
%token _RIGHT
%token _ROLLBACK
%token _RUNE
%token _SELECT
%token _SET
%token _STRING
%token _TABLE
%token _TIME
%token _TRANSACTION
%token _TRUE
%token _TRUNCATE
%token _UINT
%token _UINT16
%token _UINT32
%token _UINT64
%token _UINT8
%token _UNIQUE
%token _UPDATE
%token _VALUES
%token _WHERE
%type <item> /*TODO real type(s), if/where applicable */
AlterTableStmt
AlterTableStmt1
Assignment
AssignmentList
AssignmentList1
AssignmentList2
BeginTransactionStmt
Call
Call1
Call11
ColumnDef
ColumnDef1
ColumnDef11
ColumnDef2
ColumnName
ColumnNameList
ColumnNameList1
ColumnNameList2
CommitStmt
Conversion
CreateIndexStmt
CreateIndexStmt1
CreateIndexStmt2
CreateTableStmt
CreateTableStmt1
CreateTableStmt2
CreateTableStmt3
DeleteFromStmt
DeleteFromStmt1
DropIndexStmt
DropIndexStmt1
DropTableStmt
DropTableStmt1
EmptyStmt
ExplainStmt
Expression
Expression1
Expression11
ExpressionList
ExpressionList1
ExpressionList2
Factor
Factor1
Factor11
Factor2
Field
Field1
FieldList
FieldList1
FieldList2
GroupByClause
Index
IndexName
InsertIntoStmt
InsertIntoStmt1
InsertIntoStmt2
JoinClause
JoinClause1
JoinClause2
Limit
Literal
Offset
Operand
OrderBy
OrderBy1
OrderBy11
Predicate
Predicate1
Predicate11
Predicate12
Predicate121
Predicate13
PrimaryExpression
PrimaryFactor
PrimaryFactor1
PrimaryFactor11
PrimaryTerm
PrimaryTerm1
PrimaryTerm11
QualifiedIdent
QualifiedIdent1
RecordSet
RecordSet1
RecordSet11
RecordSet2
RecordSetList
RecordSetList1
RecordSetList2
RollbackStmt
SelectStmt
SelectStmt1
SelectStmt2
SelectStmt3
SelectStmt4
SelectStmt5
SelectStmt6
SelectStmt7
SelectStmt8
SelectStmt9
Slice
Slice1
Slice2
Start
Statement
StatementList
StatementList1
TableName
Term
Term1
Term11
TruncateTableStmt
Type
UnaryExpr
UnaryExpr1
UnaryExpr11
UpdateStmt
UpdateStmt1
UpdateStmt2
Values
Values1
Values2
WhereClause
/*TODO %left, %right, ... declarations */
%start Start
%%
AlterTableStmt:
_ALTER _TABLE TableName AlterTableStmt1
{
$$ = []AlterTableStmt{"ALTER", "TABLE", $3, $4} //TODO 1
}
AlterTableStmt1:
_ADD ColumnDef
{
$$ = []AlterTableStmt1{"ADD", $2} //TODO 2
}
| _DROP _COLUMN ColumnName
{
$$ = []AlterTableStmt1{"DROP", "COLUMN", $3} //TODO 3
}
Assignment:
ColumnName '=' Expression
{
$$ = []Assignment{$1, "=", $3} //TODO 4
}
AssignmentList:
Assignment AssignmentList1 AssignmentList2
{
$$ = []AssignmentList{$1, $2, $3} //TODO 5
}
AssignmentList1:
/* EMPTY */
{
$$ = []AssignmentList1(nil) //TODO 6
}
| AssignmentList1 ',' Assignment
{
$$ = append($1.([]AssignmentList1), ",", $3) //TODO 7
}
AssignmentList2:
/* EMPTY */
{
$$ = nil //TODO 8
}
| ','
{
$$ = "," //TODO 9
}
BeginTransactionStmt:
_BEGIN _TRANSACTION
{
$$ = []BeginTransactionStmt{"BEGIN", "TRANSACTION"} //TODO 10
}
Call:
'(' Call1 ')'
{
$$ = []Call{"(", $2, ")"} //TODO 11
}
Call1:
/* EMPTY */
{
$$ = nil //TODO 12
}
| Call11
{
$$ = $1 //TODO 13
}
Call11:
'*'
{
$$ = "*" //TODO 14
}
| ExpressionList
{
$$ = $1 //TODO 15
}
ColumnDef:
ColumnName Type ColumnDef1 ColumnDef2
{
$$ = []ColumnDef{$1, $2, $3, $4} //TODO 16
}
ColumnDef1:
/* EMPTY */
{
$$ = nil //TODO 17
}
| ColumnDef11
{
$$ = $1 //TODO 18
}
ColumnDef11:
_NOT _NULL
{
$$ = []ColumnDef11{"NOT", "NULL"} //TODO 19
}
| Expression
{
$$ = $1 //TODO 20
}
ColumnDef2:
/* EMPTY */
{
$$ = nil //TODO 21
}
| _DEFAULT Expression
{
$$ = []ColumnDef2{"DEFAULT", $2} //TODO 22
}
ColumnName:
_IDENTIFIER
{
$$ = $1 //TODO 23
}
ColumnNameList:
ColumnName ColumnNameList1 ColumnNameList2
{
$$ = []ColumnNameList{$1, $2, $3} //TODO 24
}
ColumnNameList1:
/* EMPTY */
{
$$ = []ColumnNameList1(nil) //TODO 25
}
| ColumnNameList1 ',' ColumnName
{
$$ = append($1.([]ColumnNameList1), ",", $3) //TODO 26
}
ColumnNameList2:
/* EMPTY */
{
$$ = nil //TODO 27
}
| ','
{
$$ = "," //TODO 28
}
CommitStmt:
_COMMIT
{
$$ = "COMMIT" //TODO 29
}
Conversion:
Type '(' Expression ')'
{
$$ = []Conversion{$1, "(", $3, ")"} //TODO 30
}
CreateIndexStmt:
_CREATE CreateIndexStmt1 _INDEX CreateIndexStmt2 IndexName _ON TableName '(' ExpressionList ')'
{
$$ = []CreateIndexStmt{"CREATE", $2, "INDEX", $4, $5, "ON", $7, "(", $9, ")"} //TODO 31
}
CreateIndexStmt1:
/* EMPTY */
{
$$ = nil //TODO 32
}
| _UNIQUE
{
$$ = "UNIQUE" //TODO 33
}
CreateIndexStmt2:
/* EMPTY */
{
$$ = nil //TODO 34
}
| _IF _NOT _EXISTS
{
$$ = []CreateIndexStmt2{"IF", "NOT", "EXISTS"} //TODO 35
}
CreateTableStmt:
_CREATE _TABLE CreateTableStmt1 TableName '(' ColumnDef CreateTableStmt2 CreateTableStmt3 ')'
{
$$ = []CreateTableStmt{"CREATE", "TABLE", $3, $4, "(", $6, $7, $8, ")"} //TODO 36
}
CreateTableStmt1:
/* EMPTY */
{
$$ = nil //TODO 37
}
| _IF _NOT _EXISTS
{
$$ = []CreateTableStmt1{"IF", "NOT", "EXISTS"} //TODO 38
}
CreateTableStmt2:
/* EMPTY */
{
$$ = []CreateTableStmt2(nil) //TODO 39
}
| CreateTableStmt2 ',' ColumnDef
{
$$ = append($1.([]CreateTableStmt2), ",", $3) //TODO 40
}
CreateTableStmt3:
/* EMPTY */
{
$$ = nil //TODO 41
}
| ','
{
$$ = "," //TODO 42
}
DeleteFromStmt:
_DELETE _FROM TableName DeleteFromStmt1
{
$$ = []DeleteFromStmt{"DELETE", "FROM", $3, $4} //TODO 43
}
DeleteFromStmt1:
/* EMPTY */
{
$$ = nil //TODO 44
}
| WhereClause
{
$$ = $1 //TODO 45
}
DropIndexStmt:
_DROP _INDEX DropIndexStmt1 IndexName
{
$$ = []DropIndexStmt{"DROP", "INDEX", $3, $4} //TODO 46
}
DropIndexStmt1:
/* EMPTY */
{
$$ = nil //TODO 47
}
| _IF _EXISTS
{
$$ = []DropIndexStmt1{"IF", "EXISTS"} //TODO 48
}
DropTableStmt:
_DROP _TABLE DropTableStmt1 TableName
{
$$ = []DropTableStmt{"DROP", "TABLE", $3, $4} //TODO 49
}
DropTableStmt1:
/* EMPTY */
{
$$ = nil //TODO 50
}
| _IF _EXISTS
{
$$ = []DropTableStmt1{"IF", "EXISTS"} //TODO 51
}
EmptyStmt:
/* EMPTY */
{
$$ = nil //TODO 52
}
ExplainStmt:
_EXPLAIN Statement
{
$$ = []ExplainStmt{"EXPLAIN", $2} //TODO 53
}
Expression:
Term Expression1
{
$$ = []Expression{$1, $2} //TODO 54
}
Expression1:
/* EMPTY */
{
$$ = []Expression1(nil) //TODO 55
}
| Expression1 Expression11 Term
{
$$ = append($1.([]Expression1), $2, $3) //TODO 56
}
Expression11:
_OROR
{
$$ = $1 //TODO 57
}
| _OR
{
$$ = "OR" //TODO 58
}
ExpressionList:
Expression ExpressionList1 ExpressionList2
{
$$ = []ExpressionList{$1, $2, $3} //TODO 59
}
ExpressionList1:
/* EMPTY */
{
$$ = []ExpressionList1(nil) //TODO 60
}
| ExpressionList1 ',' Expression
{
$$ = append($1.([]ExpressionList1), ",", $3) //TODO 61
}
ExpressionList2:
/* EMPTY */
{
$$ = nil //TODO 62
}
| ','
{
$$ = "," //TODO 63
}
Factor:
PrimaryFactor Factor1 Factor2
{
$$ = []Factor{$1, $2, $3} //TODO 64
}
Factor1:
/* EMPTY */
{
$$ = []Factor1(nil) //TODO 65
}
| Factor1 Factor11 PrimaryFactor
{
$$ = append($1.([]Factor1), $2, $3) //TODO 66
}
Factor11:
_GE
{
$$ = $1 //TODO 67
}
| '>'
{
$$ = ">" //TODO 68
}
| _LE
{
$$ = $1 //TODO 69
}
| '<'
{
$$ = "<" //TODO 70
}
| _NEQ
{
$$ = $1 //TODO 71
}
| _EQ
{
$$ = $1 //TODO 72
}
| _LIKE
{
$$ = "LIKE" //TODO 73
}
Factor2:
/* EMPTY */
{
$$ = nil //TODO 74
}
| Predicate
{
$$ = $1 //TODO 75
}
Field:
Expression Field1
{
$$ = []Field{$1, $2} //TODO 76
}
Field1:
/* EMPTY */
{
$$ = nil //TODO 77
}
| _AS _IDENTIFIER
{
$$ = []Field1{"AS", $2} //TODO 78
}
FieldList:
Field FieldList1 FieldList2
{
$$ = []FieldList{$1, $2, $3} //TODO 79
}
FieldList1:
/* EMPTY */
{
$$ = []FieldList1(nil) //TODO 80
}
| FieldList1 ',' Field
{
$$ = append($1.([]FieldList1), ",", $3) //TODO 81
}
FieldList2:
/* EMPTY */
{
$$ = nil //TODO 82
}
| ','
{
$$ = "," //TODO 83
}
GroupByClause:
_GROUPBY ColumnNameList
{
$$ = []GroupByClause{"GROUP BY", $2} //TODO 84
}
Index:
'[' Expression ']'
{
$$ = []Index{"[", $2, "]"} //TODO 85
}
IndexName:
_IDENTIFIER
{
$$ = $1 //TODO 86
}
InsertIntoStmt:
_INSERT _INTO TableName InsertIntoStmt1 InsertIntoStmt2
{
$$ = []InsertIntoStmt{"INSERT", "INTO", $3, $4, $5} //TODO 87
}
InsertIntoStmt1:
/* EMPTY */
{
$$ = nil //TODO 88
}
| '(' ColumnNameList ')'
{
$$ = []InsertIntoStmt1{"(", $2, ")"} //TODO 89
}
InsertIntoStmt2:
Values
{
$$ = $1 //TODO 90
}
| SelectStmt
{
$$ = $1 //TODO 91
}
JoinClause:
JoinClause1 JoinClause2 _JOIN RecordSet _ON Expression
{
$$ = []JoinClause{$1, $2, "JOIN", $4, "ON", $6} //TODO 92
}
JoinClause1:
_LEFT
{
$$ = "LEFT" //TODO 93
}
| _RIGHT
{
$$ = "RIGHT" //TODO 94
}
| _FULL
{
$$ = "FULL" //TODO 95
}
JoinClause2:
/* EMPTY */
{
$$ = nil //TODO 96
}
| _OUTER
{
$$ = "OUTER" //TODO 97
}
Limit:
_LIMIT Expression
{
$$ = []Limit{"Limit", $2} //TODO 98
}
Literal:
_FALSE
{
$$ = "FALSE" //TODO 99
}
| _NULL
{
$$ = "NULL" //TODO 100
}
| _TRUE
{
$$ = "TRUE" //TODO 101
}
| _FLOAT_LIT
{
$$ = $1 //TODO 102
}
| _IMAGINARY_LIT
{
$$ = $1 //TODO 103
}
| _INT_LIT
{
$$ = $1 //TODO 104
}
| _RUNE_LIT
{
$$ = $1 //TODO 105
}
| _STRING_LIT
{
$$ = $1 //TODO 106
}
| _QL_PARAMETER
{
$$ = $1 //TODO 107
}
Offset:
_OFFSET Expression
{
$$ = []Offset{"OFFSET", $2} //TODO 108
}
Operand:
Literal
{
$$ = $1 //TODO 109
}
| QualifiedIdent
{
$$ = $1 //TODO 110
}
| '(' Expression ')'
{
$$ = []Operand{"(", $2, ")"} //TODO 111
}
OrderBy:
_ORDER _BY ExpressionList OrderBy1
{
$$ = []OrderBy{"ORDER", "BY", $3, $4} //TODO 112
}
OrderBy1:
/* EMPTY */
{
$$ = nil //TODO 113
}
| OrderBy11
{
$$ = $1 //TODO 114
}
OrderBy11:
_ASC
{
$$ = "ASC" //TODO 115
}
| _DESC
{
$$ = "DESC" //TODO 116
}
Predicate:
Predicate1
{
$$ = $1 //TODO 117
}
Predicate1:
Predicate11 Predicate12
{
$$ = []Predicate1{$1, $2} //TODO 118
}
| _IS Predicate13 _NULL
{
$$ = []Predicate1{"IS", $2, "NULL"} //TODO 119
}
Predicate11:
/* EMPTY */
{
$$ = nil //TODO 120
}
| _NOT
{
$$ = "NOT" //TODO 121
}
Predicate12:
_IN '(' ExpressionList ')'
{
$$ = []Predicate12{"IN", "(", $3, ")"} //TODO 122
}
| _IN '(' SelectStmt Predicate121 ')'
{
$$ = []Predicate12{"IN", "(", $3, $4, ")"} //TODO 123
}
| _BETWEEN PrimaryFactor _AND PrimaryFactor
{
$$ = []Predicate12{"BETWEEN", $2, "AND", $4} //TODO 124
}
Predicate121:
/* EMPTY */
{
$$ = nil //TODO 125
}
| ';'
{
$$ = ";" //TODO 126
}
Predicate13:
/* EMPTY */
{
$$ = nil //TODO 127
}
| _NOT
{
$$ = "NOT" //TODO 128
}
PrimaryExpression:
Operand
{
$$ = $1 //TODO 129
}
| Conversion
{
$$ = $1 //TODO 130
}
| PrimaryExpression Index
{
$$ = []PrimaryExpression{$1, $2} //TODO 131
}
| PrimaryExpression Slice
{
$$ = []PrimaryExpression{$1, $2} //TODO 132
}
| PrimaryExpression Call
{
$$ = []PrimaryExpression{$1, $2} //TODO 133
}
PrimaryFactor:
PrimaryTerm PrimaryFactor1
{
$$ = []PrimaryFactor{$1, $2} //TODO 134
}
PrimaryFactor1:
/* EMPTY */
{
$$ = []PrimaryFactor1(nil) //TODO 135
}
| PrimaryFactor1 PrimaryFactor11 PrimaryTerm
{
$$ = append($1.([]PrimaryFactor1), $2, $3) //TODO 136
}
PrimaryFactor11:
'^'
{
$$ = "^" //TODO 137
}
| '|'
{
$$ = "|" //TODO 138
}
| '-'
{
$$ = "-" //TODO 139
}
| '+'
{
$$ = "+" //TODO 140
}
PrimaryTerm:
UnaryExpr PrimaryTerm1
{
$$ = []PrimaryTerm{$1, $2} //TODO 141
}
PrimaryTerm1:
/* EMPTY */
{
$$ = []PrimaryTerm1(nil) //TODO 142
}
| PrimaryTerm1 PrimaryTerm11 UnaryExpr
{
$$ = append($1.([]PrimaryTerm1), $2, $3) //TODO 143
}