-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgrammar.y
1706 lines (1578 loc) · 31.3 KB
/
grammar.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
%{
package sqlparser
import (
"bytes"
"strings"
"errors"
)
var keywordsNotAllowed = map[string]struct{}{
// We don't allow non-deterministic keywords as identifiers.
"CURRENT_TIME": {},
"CURRENT_DATE": {},
"CURRENT_TIMESTAMP": {},
// SQLite reserved keywords that are not part of Tableland spec.
// We can't allow them as identifiers because it will throw an error in SQLite.
//
// SQLite has more reserved keywords (eg. CREATE, INSERT, ...). But those are part of the Tableland grammar,
// that means that the parser already checks from them.
//
// These were identified by running the `TestReservedKeywords` test.
"REFERENCES" : {},
"AUTOINCREMENT": {},
"COMMIT": {},
"DEFERRABLE": {},
"FOREIGN": {},
"INDEX": {},
"RETURNING": {},
"TRANSACTION": {},
}
func isRowID(column Identifier) bool {
if strings.EqualFold(string(column), "rowid") || strings.EqualFold(string(column), "_rowid_") || strings.EqualFold(string(column), "oid") {
return true
}
return false
}
%}
%union{
bool bool
string string
bytes []byte
expr Expr
exprs Exprs
column *Column
table *Table
convertType ConvertType
when *When
whens []*When
selectColumn SelectColumn
selectColumnList SelectColumnList
readStmt ReadStatement
baseSelect *Select
where *Where
limit *Limit
orderBy OrderBy
orderingTerm *OrderingTerm
nulls NullsType
tableExpr TableExpr
joinTableExpr *JoinTableExpr
columnList ColumnList
indexedColumnList IndexedColumnList
indexedColumn *IndexedColumn
subquery *Subquery
colTuple ColTuple
statement Statement
identifier Identifier
createTableStmt *CreateTable
columnDefList []*ColumnDef
columnDef *ColumnDef
columnConstraint ColumnConstraint
columnConstraints []ColumnConstraint
value *Value
tableConstraint TableConstraint
tableConstraints []TableConstraint
insertStmt *Insert
insertRows []Exprs
deleteStmt *Delete
updateStmt *Update
updateExpression *UpdateExpr
updateList []*UpdateExpr
grant *Grant
revoke *Revoke
alterTableStmt *AlterTable
strings []string
privileges Privileges
stmts []Statement
upsertClause Upsert
onConflictClauseList []*OnConflictClause
onConflictClause *OnConflictClause
onConflictTarget *OnConflictTarget
collateOpt Identifier
joinOperator *JoinOperator
param *Param
}
%token <bytes> IDENTIFIER STRING INTEGRAL HEXNUM FLOAT BLOBVAL
%token ERROR
%token <empty> TRUE FALSE NULL AND
%token <empty> '(' ',' ')' '.' ';' '?'
%token <empty> NONE INTEGER TEXT CAST AS
%token <empty> CASE WHEN THEN ELSE END
%token <empty> SELECT FROM WHERE GROUP BY HAVING LIMIT OFFSET ORDER ASC DESC NULLS FIRST LAST DISTINCT ALL EXISTS FILTER UNION EXCEPT INTERSECT
%token <empty> CREATE TABLE INT BLOB PRIMARY KEY UNIQUE CHECK DEFAULT GENERATED ALWAYS STORED VIRTUAL CONSTRAINT
%token <empty> INSERT INTO VALUES DELETE UPDATE SET CONFLICT DO NOTHING
%token <empty> GRANT TO REVOKE
%token <empty> ALTER RENAME COLUMN ADD DROP
%left <empty> RIGHT FULL INNER LEFT NATURAL OUTER CROSS JOIN
%left <empty> ON USING
%left <empty> OR
%left <empty> ANDOP
%right <empty> NOT
%left <empty> IS ISNOT MATCH GLOB REGEXP LIKE BETWEEN IN ISNULL NOTNULL NE '='
%left <empty> '<' '>' LE GE INEQUALITY
%right <empty> ESCAPE
%left '&' '|' LSHIFT RSHIFT
%left <empty> '+' '-'
%left <empty> '*' '/' '%'
%left <empty> CONCAT JSON_EXTRACT_OP JSON_UNQUOTE_EXTRACT_OP
%left <empty> COLLATE
%right <empty> '~' UNARY
%type <statement> multi_stmt single_stmt
%type <readStmt> select_stmt
%type <baseSelect> base_select
%type <createTableStmt> create_table_stmt
%type <expr> expr literal_value function_call_keyword function_call_generic expr_opt else_expr_opt exists_subquery signed_number
%type <exprs> expr_list expr_list_opt group_by_opt
%type <string> cmp_op cmp_inequality_op like_op between_op asc_desc_opt distinct_opt type_name primary_key_order privilege compound_op
%type <column> column_name
%type <identifier> as_column_opt col_alias as_table_opt table_alias constraint_name identifier collate_opt
%type <selectColumn> select_column
%type <selectColumnList> select_column_list
%type <table> table_name
%type <where> where_opt having_opt filter_opt
%type <convertType> convert_type
%type <when> when
%type <whens> when_expr_list
%type <limit> limit_opt
%type <orderBy> order_by_opt order_list
%type <orderingTerm> ordering_term
%type <nulls> nulls
%type <tableExpr> table_expr from_clause
%type <joinTableExpr> join_clause join_constraint
%type <columnList> column_name_list column_name_list_opt
%type <indexedColumnList> indexed_column_list
%type <indexedColumn> indexed_column
%type <subquery> subquery
%type <colTuple> col_tuple
%type <bool> distinct_function_opt is_stored natural_opt outer_opt
%type <columnDefList> column_def_list
%type <columnDef> column_def
%type <columnConstraint> column_constraint
%type <columnConstraints> column_constraints column_constraints_opt
%type <value> numeric_literal
%type <tableConstraint> table_constraint
%type <tableConstraints> table_constraint_list table_constraint_list_opt
%type <insertStmt> insert_stmt
%type <insertRows> insert_rows
%type <deleteStmt> delete_stmt
%type <updateStmt> update_stmt
%type <updateExpression> update_expression
%type <updateList> update_list common_update_list paren_update_list
%type <grant> grant_stmt
%type <revoke> revoke_stmt
%type <alterTableStmt> alter_table_stmt
%type <strings> roles
%type <privileges> privileges
%type <stmts> stmts multi_stmts
%type <upsertClause> upsert_clause_opt
%type <onConflictClauseList> on_conflict_clause_list
%type <onConflictClause> on_conflict_clause
%type <onConflictTarget> conflict_target_opt
%type <joinOperator> join_op
%type <param> param
%%
start:
stmts { yylex.(*Lexer).ast = &AST{Statements: $1} }
;
stmts:
single_stmt semicolon_opt
{
$$ = []Statement{$1}
}
| multi_stmts semicolon_opt
{
$$ = $1
}
;
single_stmt:
select_stmt
{
$$ = $1
}
| create_table_stmt
{
$$ = $1
}
;
multi_stmts:
multi_stmt
{
$$ = []Statement{$1}
}
| multi_stmts ';' multi_stmt
{
$$ = append($1, $3)
}
;
multi_stmt:
insert_stmt
{
yylex.(*Lexer).statementIdx++
$$ = $1
}
| delete_stmt
{
yylex.(*Lexer).statementIdx++
$$ = $1
}
| update_stmt
{
yylex.(*Lexer).statementIdx++
$$ = $1
}
| grant_stmt
{
yylex.(*Lexer).statementIdx++
$$ = $1
}
| revoke_stmt
{
yylex.(*Lexer).statementIdx++
$$ = $1
}
| alter_table_stmt
{
yylex.(*Lexer).statementIdx++
$$ = $1
}
;
semicolon_opt:
{}
| ';'
{}
;
select_stmt:
base_select order_by_opt limit_opt
{
$1.OrderBy = $2
$1.Limit = $3
$$ = $1
}
| base_select compound_op select_stmt
{
$$ = &CompoundSelect{Type: $2, Left: $1, Right: $3}
}
;
compound_op:
UNION
{
$$ = CompoundUnionStr
}
| UNION ALL
{
$$ = CompoundUnionAllStr
}
| EXCEPT
{
$$ = CompoundExceptStr
}
| INTERSECT
{
$$ = CompoundIntersectStr
}
;
base_select:
SELECT distinct_opt select_column_list from_clause where_opt group_by_opt having_opt
{
$$ = &Select{
Distinct: $2,
SelectColumnList: $3,
From: $4,
Where: $5,
GroupBy: GroupBy($6),
Having: $7,
}
}
;
distinct_opt:
{
$$ = ""
}
| DISTINCT
{
$$ = DistinctStr
}
| ALL
{
$$ = AllStr
}
;
select_column_list:
select_column
{
$$ = SelectColumnList{$1}
}
| select_column_list ',' select_column
{
$$ = append($1, $3)
}
select_column:
'*'
{
$$ = &StarSelectColumn{}
}
| expr as_column_opt
{
$$ = &AliasedSelectColumn{Expr: $1, As: $2}
}
| table_name '.' '*'
{
$$ = &StarSelectColumn{TableRef: $1}
}
as_column_opt:
{
$$ = Identifier("")
}
| col_alias
{
$$ = $1
}
| AS col_alias
{
$$ = $2
}
col_alias:
identifier
{
$$ = $1
}
| STRING
{
$$ = Identifier(string($1[0:len($1)]))
}
;
from_clause:
FROM table_expr
{
$$ = $2
}
| FROM join_clause
{
$$ = $2
}
;
table_expr:
table_name as_table_opt
{
$1.IsTarget = true
$$ = &AliasedTableExpr{Expr: $1, As: $2}
}
| '(' select_stmt ')' as_table_opt
{
$$ = &AliasedTableExpr{Expr: &Subquery{Select: $2}, As: $4}
}
| '(' table_expr ')'
{
$$ = &ParenTableExpr{TableExpr: $2}
}
| '(' join_clause ')'
{
$$ = $2
}
;
as_table_opt:
{
$$ = Identifier("")
}
| table_alias
{
$$ = $1
}
| AS table_alias
{
$$ = $2
}
table_alias:
identifier
{
$$ = $1
}
| STRING
{
$$ = Identifier(string($1[0:len($1)]))
}
;
join_clause:
table_expr join_op table_expr join_constraint
{
if $4 == nil {
$$ = &JoinTableExpr{LeftExpr: $1, JoinOperator: $2, RightExpr: $3}
} else {
if $2.Natural {
yylex.(*Lexer).AddError(&ErrNaturalJoinWithOnOrUsingClause{})
}
$4.LeftExpr = $1
$4.JoinOperator = $2
$4.RightExpr = $3
$$ = $4
}
}
| join_clause join_op table_expr join_constraint
{
if $4 == nil {
$$ = &JoinTableExpr{LeftExpr: $1, JoinOperator: $2, RightExpr: $3}
} else {
if $2.Natural {
yylex.(*Lexer).AddError(&ErrNaturalJoinWithOnOrUsingClause{})
}
$4.LeftExpr = $1
$4.JoinOperator = $2
$4.RightExpr = $3
$$ = $4
}
}
;
join_op:
JOIN
{
$$ = &JoinOperator{Op: JoinStr}
}
| ','
{
$$ = &JoinOperator{Op: JoinStr}
}
| CROSS JOIN
{
$$ = &JoinOperator{Op: JoinStr}
}
| natural_opt LEFT outer_opt JOIN
{
$$ = &JoinOperator{Op: LeftJoinStr, Natural: $1, Outer: $3}
}
| natural_opt RIGHT outer_opt JOIN
{
$$ = &JoinOperator{Op: RightJoinStr, Natural: $1, Outer: $3}
}
| natural_opt FULL outer_opt JOIN
{
$$ = &JoinOperator{Op: FullJoinStr, Natural: $1, Outer: $3}
}
| natural_opt INNER JOIN
{
$$ = &JoinOperator{Op: InnerJoinStr, Natural: $1}
}
;
natural_opt:
{
$$ = false
}
| NATURAL
{
$$ = true
}
;
outer_opt:
{
$$ = false
}
| OUTER
{
$$ = true
}
;
join_constraint:
%prec JOIN
{
$$ = nil
}
| ON expr
{
$$ = &JoinTableExpr{On: $2}
}
| USING '(' column_name_list ')'
{
$$ = &JoinTableExpr{Using: $3}
}
;
where_opt:
{
$$ = nil
}
| WHERE expr
{
$$ = NewWhere(WhereStr, $2)
}
;
group_by_opt:
{
$$ = nil
}
| GROUP BY expr_list
{
$$ = $3
}
;
having_opt:
{
$$ = nil
}
| HAVING expr
{
$$ = NewWhere(HavingStr, $2)
}
;
order_by_opt:
{
$$ = nil
}
| ORDER BY order_list
{
$$ = $3
}
;
order_list:
ordering_term
{
$$ = OrderBy{$1}
}
| order_list ',' ordering_term
{
$$ = append($1, $3)
}
;
ordering_term:
expr asc_desc_opt nulls
{
$$ = &OrderingTerm{Expr: $1, Direction: $2, Nulls: $3}
}
;
asc_desc_opt:
{
$$ = AscStr
}
| ASC
{
$$ = AscStr
}
| DESC
{
$$ = DescStr
}
;
nulls:
{
$$ = NullsNil
}
| NULLS FIRST
{
$$ = NullsFirst
}
| NULLS LAST
{
$$ = NullsLast
}
;
limit_opt:
{
$$ = nil
}
| LIMIT expr
{
$$ = &Limit{Limit: $2}
}
| LIMIT expr ',' expr
{
$$ = &Limit{Offset: $2, Limit: $4}
}
| LIMIT expr OFFSET expr
{
$$ = &Limit{Offset: $4, Limit: $2}
}
;
table_name:
identifier
{
$$ = &Table{Name: $1}
}
;
expr:
literal_value { $$ = $1 }
| param { $$ = $1 }
| column_name { $$ = $1 }
| table_name '.' column_name
{
$3.TableRef = $1
$$ = $3
}
| expr '+' expr
{
$$ = &BinaryExpr{Left: $1, Operator: PlusStr, Right: $3}
}
| expr '-' expr
{
$$ = &BinaryExpr{Left: $1, Operator: MinusStr, Right: $3}
}
| expr '*' expr
{
$$ = &BinaryExpr{Left: $1, Operator: MultStr, Right: $3}
}
| expr '/' expr
{
$$ = &BinaryExpr{Left: $1, Operator: DivStr, Right: $3}
}
| expr '%' expr
{
$$ = &BinaryExpr{Left: $1, Operator: ModStr, Right: $3}
}
| expr '&' expr
{
$$ = &BinaryExpr{Left: $1, Operator: BitAndStr, Right: $3}
}
| expr '|' expr
{
$$ = &BinaryExpr{Left: $1, Operator: BitOrStr, Right: $3}
}
| expr LSHIFT expr
{
$$ = &BinaryExpr{Left: $1, Operator: ShiftLeftStr, Right: $3}
}
| expr RSHIFT expr
{
$$ = &BinaryExpr{Left: $1, Operator: ShiftRightStr, Right: $3}
}
| expr CONCAT expr
{
$$ = &BinaryExpr{Left: $1, Operator: ConcatStr, Right: $3}
}
| expr JSON_EXTRACT_OP expr
{
$$ = &BinaryExpr{Left: $1, Operator: JSONExtractOp, Right: $3}
}
| expr JSON_UNQUOTE_EXTRACT_OP expr
{
$$ = &BinaryExpr{Left: $1, Operator: JSONUnquoteExtractOp, Right: $3}
}
| expr cmp_op expr %prec IS
{
$$ = &CmpExpr{Left: $1, Operator: $2, Right: $3}
}
| expr cmp_inequality_op expr %prec INEQUALITY
{
$$ = &CmpExpr{Left: $1, Operator: $2, Right: $3}
}
| expr like_op expr %prec LIKE
{
$$ = &CmpExpr{Left: $1, Operator: $2, Right: $3}
}
| expr like_op expr ESCAPE expr %prec LIKE
{
$$ = &CmpExpr{Left: $1, Operator: $2, Right: $3, Escape: $5}
}
| '-' expr %prec UNARY
{
if value, ok := $2.(*Value); ok && value.Type == IntValue {
$$ = &Value{Type: IntValue, Value: append([]byte("-"), value.Value...)}
} else {
$$ = &UnaryExpr{Operator: UMinusStr, Expr: $2}
}
}
| '+' expr %prec UNARY
{
$$ = &UnaryExpr{Operator: UPlusStr, Expr: $2}
}
| '~' expr %prec UNARY
{
$$ = &UnaryExpr{Operator: TildaStr, Expr: $2}
}
| expr ANDOP expr
{
$$ = &AndExpr{Left: $1, Right: $3}
}
| expr OR expr
{
$$ = &OrExpr{Left: $1, Right: $3}
}
| expr IS expr
{
$$ = &IsExpr{Left: $1, Right: $3}
}
| expr IS ISNOT expr
{
$$ = &IsExpr{Left: $1, Right: &NotExpr{Expr: $4}}
}
| expr ISNULL
{
$$ = &IsNullExpr{Expr : $1}
}
| expr NOTNULL
{
$$ = &NotNullExpr{Expr : $1}
}
| expr NOT NULL
{
$$ = &NotNullExpr{Expr : $1}
}
| expr between_op expr AND expr %prec BETWEEN
{
$$ = &BetweenExpr{Left : $1, Operator: $2, From: $3 , To: $5}
}
| CASE expr_opt when_expr_list else_expr_opt END
{
$$ = &CaseExpr{Expr: $2, Whens: $3, Else: $4}
}
| expr COLLATE identifier
{
$$ = &CollateExpr{Expr : $1, CollationName: $3}
}
| '(' expr ')'
{
$$ = &ParenExpr{Expr: $2}
}
| expr IN col_tuple
{
$$ = &CmpExpr{Left: $1, Operator: InStr, Right: $3}
}
| expr NOT IN col_tuple
{
$$ = &CmpExpr{Left: $1, Operator: NotInStr, Right: $4}
}
| subquery
{
$$ = $1
}
| exists_subquery
{
$$ = $1
}
| CAST '(' expr AS convert_type ')'
{
$$ = &ConvertExpr{Expr: $3, Type: $5}
}
| function_call_keyword
| function_call_generic
;
literal_value:
numeric_literal
{
$$ = $1
}
| STRING
{
str := $1[1:len($1)-1]
if len(str) > MaxTextLength {
yylex.(*Lexer).AddError(&ErrTextTooLong{Length: len(str), MaxAllowed: MaxTextLength})
}
$$ = &Value{Type: StrValue, Value: str}
}
| BLOBVAL
{
if len($1) > MaxBlobLength {
yylex.(*Lexer).AddError(&ErrBlobTooBig{Length: len($1), MaxAllowed: MaxBlobLength})
}
$$ = &Value{Type: BlobValue, Value: $1}
}
| TRUE
{
$$ = BoolValue(true)
}
| FALSE
{
$$ = BoolValue(false)
}
| NULL
{
$$ = &NullValue{}
}
;
column_name:
identifier
{
$$ = &Column{Name : Identifier(string($1))}
}
;
column_name_list:
column_name
{
$$ = ColumnList{$1}
}
| column_name_list ',' column_name
{
$$ = append($1, $3)
}
;
cmp_op:
'='
{
$$ = EqualStr
}
| NE
{
$$ = NotEqualStr
}
| REGEXP
{
$$ = RegexpStr
}
| NOT REGEXP
{
$$ = NotRegexpStr
}
| GLOB
{
$$ = GlobStr
}
| NOT GLOB
{
$$ = NotGlobStr
}
| MATCH
{
$$ = MatchStr
}
| NOT MATCH
{
$$ = NotMatchStr
}
;
cmp_inequality_op:
'<'
{
$$ = LessThanStr
}
| '>'
{
$$ = GreaterThanStr
}
| LE
{
$$ = LessEqualStr
}
| GE
{
$$ = GreaterEqualStr
}
;
like_op:
LIKE
{
$$ = LikeStr
}
| NOT LIKE
{
$$ = NotLikeStr
}
;
between_op:
BETWEEN
{
$$ = BetweenStr
}
| NOT BETWEEN
{
$$ = NotBetweenStr
}
;
convert_type:
NONE { $$ = NoneStr}
| TEXT { $$ = TextStr}
| INTEGER { $$ = IntegerStr}
;
col_tuple:
'(' ')'
{
$$ = Exprs{}
}
| subquery
{
$$ = $1
}
| '(' expr_list ')'
{
$$ = $2
}
;
subquery:
'(' select_stmt ')'
{
$$ = &Subquery{Select: $2}
}
;
exists_subquery:
EXISTS subquery
{
$$ = &ExistsExpr{Subquery: $2}
}
| NOT EXISTS subquery
{
$$ = &NotExpr{Expr: &ExistsExpr{Subquery: $3}}
}
;
function_call_keyword:
GLOB '(' expr ',' expr ')'
{
$$ = &FuncExpr{Name: Identifier("glob"), Args: Exprs{$3, $5}}
}
| LIKE '(' expr ',' expr ')'
{
$$ = &FuncExpr{Name: Identifier("like"), Args: Exprs{$3, $5}}
}
| LIKE '(' expr ',' expr ',' expr ')'
{
$$ = &FuncExpr{Name: Identifier("like"), Args: Exprs{$3, $5, $7}}
}
;
function_call_generic:
identifier '(' distinct_function_opt expr_list_opt ')' filter_opt
{
lowered := strings.ToLower(string($1))
isCustom, ok := AllowedFunctions[lowered];
if !ok {
yylex.(*Lexer).AddError(&ErrNoSuchFunction{FunctionName: string($1)})
}
if isCustom {
if $3 {
yylex.(*Lexer).AddError(errors.New("custom function cannot have DISTINCT"))
}
if $6 != nil {
yylex.(*Lexer).AddError(errors.New("custom function cannot have FILTER"))
}
$$ = &CustomFuncExpr{Name: Identifier(lowered), Args: $4}
} else {
$$ = &FuncExpr{Name: Identifier(lowered), Distinct: $3, Args: $4, Filter: $6}
}
}
| identifier '(' '*' ')' filter_opt
{
lowered := strings.ToLower(string($1))
isCustom, ok := AllowedFunctions[lowered];
if !ok {
yylex.(*Lexer).AddError(&ErrNoSuchFunction{FunctionName: string($1)})
}