-
Notifications
You must be signed in to change notification settings - Fork 34
/
cql.y
2955 lines (2530 loc) · 117 KB
/
cql.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
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// In case there is any doubt, 'cql.y' is included in the license as well as
// the code bison generates from it.
// cql - pronounced "see-cue-el" is a basic tool for enabling stored
// procedures for SQLite. The tool does this by parsing specialized
// .sql files:
//
// - loose DDL (not in a proc) in the .sql is used to declare tables and views
// has no other effect
// - SQL DML and DDL logic is converted to the equivalent sqlite calls to do the work
// - loose DML and loose control flow is consolidated into a global proc you can name
// with the --global_proc command line switch
// - control flow is converted to C control flow
// - stored procs map into C functions directly, stored procs with a result set
// become a series of procs for creating, accessing, and destroying the result set
// - all sqlite code gen has full error checking and participates in SQL try/catch
// and throw patterns
// - strings and result sets can be mapped into assorted native objects by
// defining the items in cqlrt.h
// - everything is strongly typed, and type checked, using the primitive types:
// bool, int, long int, real, and text
//
// Design principles:
//
// 1. Keep each pass in one file (simple, focused, and easy refactor).
// 2. Use simple printable AST parse nodes (no separate #define per AST node type).
// 3. 100% unit test coverage on all passes including output validation.
%{
#include <inttypes.h>
#include <setjmp.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include "cql.h"
#include "charbuf.h"
#include "ast.h"
#include "cg_common.h"
#include "cg_c.h"
#include "cg_schema.h"
#include "cg_json_schema.h"
#include "cg_test_helpers.h"
#include "cg_query_plan.h"
#include "cg_udf.h"
#include "cg_objc.h"
#include "gen_sql.h"
#include "sem.h"
#include "encoders.h"
#include "unit_tests.h"
#include "rt.h"
// The stack needed is modest (32k) and this prevents leaks in error cases because
// it's just a stack alloc.
#define YYSTACK_USE_ALLOCA 1
// Bison defines this only if __GNUC__ is defined, but Clang defines _MSC_VER
// and not __GNUC__ on Windows.
#ifdef __clang__
#define YY_ATTRIBUTE_UNUSED __attribute__((unused))
#endif
static void parse_cmd(int argc, char **argv);
static void print_dot(struct ast_node* node);
static ast_node *file_literal(ast_node *);
static void cql_exit_on_parse_errors();
static void parse_cleanup();
static void cql_usage();
static ast_node *make_statement_node(ast_node *misc_attrs, ast_node *any_stmt);
static ast_node *make_coldef_node(ast_node *col_def_tye_attrs, ast_node *misc_attrs);
static ast_node *reduce_str_chain(ast_node *str_chain);
// Set to true upon a call to `yyerror`.
static bool_t parse_error_occurred;
static CSTR table_comment_saved;
int yylex();
void yyerror(const char *s, ...);
void yyset_in(FILE *);
void yyset_lineno(int);
void yyrestart(FILE *);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wsign-conversion"
#pragma clang diagnostic ignored "-Wimplicit-int-conversion"
#pragma clang diagnostic ignored "-Wconversion"
// In two places in the grammar we have to include an optional name list
// even though the name list isn't actually allowed. We do this to avoid
// a shift reduce conflict. We can't avoid the conflict case without a lot
// of very ugly grammar duplication. So this is the lesser of two evils
// and definitely more maintainable.
#define YY_ERROR_ON_COLUMNS(x) \
if (x) yyerror("Cursor columns not allowed in this form.")
// We insert calls to `cql_inferred_notnull` as part of a rewrite so we expect
// to see it during semantic analysis, but it cannot be allowed to appear in a
// program. It would be unsafe if it could: It coerces a value from a nullable
// type to a nonnull type without any runtime check.
#define YY_ERROR_ON_CQL_INFERRED_NOTNULL(x) \
EXTRACT_STRING(proc_name, x); \
if (!strcmp(proc_name, "cql_inferred_notnull")) { \
yyerror("Call to internal function is not allowed 'cql_inferred_notnull'"); \
}
#ifdef CQL_AMALGAM
static void cql_reset_globals(void);
#endif
#define AST_STR(node) (((str_ast_node *)node)->value)
%}
%define parse.error verbose
%union {
struct ast_node *aval;
int ival;
char *sval;
}
%token <sval> ID TRUE_ "TRUE" FALSE_ "FALSE"
%token <sval> STRLIT CSTRLIT BLOBLIT
%token <sval> INTLIT
%token <ival> BOOL_ "BOOL"
%token <ival> AT_DUMMY_NULLABLES
%token <ival> AT_DUMMY_DEFAULTS
%token <sval> LONGLIT
%token <sval> REALLIT
/*
SQLite understands the following binary operators, in order from LOWEST to HIGHEST precedence:
OR
AND
= == != <> IS IS NOT IN NOT IN LIKE NOT LIKE GLOB MATCH REGEXP
< <= > >=
<< >> & |
+ -
* / %
||
*/
// NOTE the precedence declared here in the grammar MUST agree with the precedence
// declared in ast.h EXPR_PRI_XXX or else badness ensues. It must also agree
// with the SQLite precedence shown below or badness ensues...
// Don't try to remove the NOT_IN, IS_NOT, NOT_BETWEEN, or NOT_LIKE tokens
// you can match the language with those but the precedence of NOT is wrong
// so order of operations will be subtlely off. There are now tests for this.
%left UNION_ALL UNION INTERSECT EXCEPT
%right ASSIGN
%left OR
%left AND
%left NOT
%left BETWEEN NOT_BETWEEN NE NE_ '=' EQEQ LIKE NOT_LIKE GLOB NOT_GLOB MATCH NOT_MATCH REGEXP NOT_REGEXP IN NOT_IN IS_NOT IS IS_TRUE IS_FALSE IS_NOT_TRUE IS_NOT_FALSE
%right ISNULL NOTNULL
%left '<' '>' GE LE
%left LS RS '&' '|'
%left '+' '-'
%left '*' '/' '%'
%left CONCAT
%left COLLATE
%right UMINUS '~'
/* from the SQLite grammar for comparison
left OR.
left AND.
right NOT.
left IS MATCH LIKE_KW BETWEEN IN ISNULL NOTNULL NE EQ.
left GT LE LT GE.
right ESCAPE. (NYI in CQL)
left BITAND BITOR LSHIFT RSHIFT.
left PLUS MINUS.
left STAR SLASH REM.
left CONCAT.
left COLLATE.
right BITNOT.
*/
// String representations for operators mentioned above. (These cannot be given
// in the precedence declarations themselves.)
%token ASSIGN ":="
%token CONCAT "||"
%token EQEQ "=="
%token GE ">="
%token LE "<="
%token LS "<<"
%token NE "<>"
%token NE_ "!="
%token RS ">>"
%token EXCLUDE_GROUP EXCLUDE_CURRENT_ROW EXCLUDE_TIES EXCLUDE_NO_OTHERS CURRENT_ROW UNBOUNDED PRECEDING FOLLOWING
%token AT_BLOB_GET_KEY_TYPE AT_BLOB_GET_VAL_TYPE AT_BLOB_GET_KEY AT_BLOB_GET_VAL AT_BLOB_CREATE_KEY AT_BLOB_CREATE_VAL AT_BLOB_UPDATE_KEY AT_BLOB_UPDATE_VAL
%token CREATE DROP TABLE WITHOUT ROWID PRIMARY KEY NULL_ "NULL" DEFAULT CHECK AT_DUMMY_SEED VIRTUAL AT_EMIT_GROUP AT_EMIT_ENUMS AT_EMIT_CONSTANTS
%token OBJECT TEXT BLOB LONG_ INT_ INTEGER LONG_INT LONG_INTEGER REAL ON UPDATE CASCADE ON_CONFLICT DO NOTHING
%token DELETE INDEX FOREIGN REFERENCES CONSTRAINT UPSERT STATEMENT CONST
%token INSERT INTO VALUES VIEW SELECT QUERY_PLAN EXPLAIN OVER WINDOW FILTER PARTITION RANGE ROWS GROUPS
%token AS CASE WHEN FROM FROM_BLOB THEN ELSE END LEFT SWITCH
%token OUTER JOIN WHERE GROUP BY ORDER ASC NULLS FIRST LAST
%token DESC INNER AUTOINCREMENT DISTINCT
%token LIMIT OFFSET TEMP TRIGGER IF ALL CROSS USING RIGHT AT_EPONYMOUS
%token HIDDEN UNIQUE HAVING SET LET TO DISTINCTROW ENUM
%token FUNC FUNCTION PROC PROCEDURE INTERFACE BEGIN_ OUT INOUT CURSOR DECLARE VAR TYPE FETCH LOOP LEAVE CONTINUE FOR ENCODE CONTEXT_COLUMN CONTEXT_TYPE
%token OPEN CLOSE ELSE_IF WHILE CALL TRY CATCH THROW RETURN
%token SAVEPOINT ROLLBACK COMMIT TRANSACTION RELEASE ARGUMENTS
%token TYPE_CHECK CAST WITH RECURSIVE REPLACE IGNORE ADD COLUMN COLUMNS RENAME ALTER
%token AT_ECHO AT_CREATE AT_RECREATE AT_DELETE AT_SCHEMA_UPGRADE_VERSION AT_PREVIOUS_SCHEMA AT_SCHEMA_UPGRADE_SCRIPT
%token AT_RC AT_PROC AT_FILE AT_ATTRIBUTE AT_SENSITIVE DEFERRED NOT_DEFERRABLE DEFERRABLE IMMEDIATE EXCLUSIVE RESTRICT ACTION INITIALLY NO
%token BEFORE AFTER INSTEAD OF FOR_EACH_ROW EXISTS RAISE FAIL ABORT AT_ENFORCE_STRICT AT_ENFORCE_NORMAL AT_ENFORCE_RESET AT_ENFORCE_PUSH AT_ENFORCE_POP
%token AT_BEGIN_SCHEMA_REGION AT_END_SCHEMA_REGION
%token AT_DECLARE_SCHEMA_REGION AT_DECLARE_DEPLOYABLE_REGION AT_SCHEMA_AD_HOC_MIGRATION PRIVATE
%token SIGN_FUNCTION CURSOR_HAS_ROW AT_UNSUB
/* ddl stuff */
%type <ival> opt_temp opt_if_not_exists opt_unique opt_no_rowid dummy_modifier compound_operator opt_query_plan
%type <ival> opt_fk_options fk_options fk_on_options fk_action fk_initial_state fk_deferred_options transaction_mode conflict_clause
%type <ival> frame_type frame_exclude join_type
%type <ival> opt_vtab_flags
%type <aval> col_key_list col_key_def col_def col_name
%type <aval> version_attrs opt_version_attrs version_attrs_opt_recreate opt_delete_version_attr opt_delete_plain_attr
%type <aval> misc_attr_key misc_attr misc_attrs misc_attr_value misc_attr_value_list
%type <aval> col_attrs str_literal num_literal any_literal const_expr str_chain str_leaf
%type <aval> pk_def fk_def unq_def check_def fk_target_options opt_module_args opt_conflict_clause
%type <aval> col_calc col_calcs column_calculation
%type <aval> alter_table_add_column_stmt
%type <aval> create_index_stmt create_table_stmt create_view_stmt create_virtual_table_stmt
%type <aval> indexed_column indexed_columns
%type <aval> drop_index_stmt drop_table_stmt drop_view_stmt drop_trigger_stmt
%type <ival> create_table_prefix_opt_temp
%type <aval> trigger_update_stmt trigger_delete_stmt trigger_insert_stmt trigger_select_stmt select_nothing_stmt
%type <aval> trigger_stmt trigger_stmts opt_when_expr trigger_action opt_of
%type <aval> trigger_def trigger_operation create_trigger_stmt raise_expr
%type <ival> trigger_condition opt_foreachrow
/* dml stuff */
%type <aval> with_delete_stmt delete_stmt
%type <aval> insert_stmt with_insert_stmt insert_list_item insert_list insert_stmt_type opt_column_spec opt_insert_dummy_spec expr_names expr_name
%type <aval> with_prefix with_select_stmt cte_table cte_tables cte_binding_list cte_binding cte_decl shared_cte
%type <aval> select_expr select_expr_list select_opts select_stmt select_core values explain_stmt explain_target
%type <aval> select_stmt_no_with select_core_list
%type <aval> window_func_inv opt_filter_clause window_name_or_defn window_defn opt_select_window
%type <aval> opt_partition_by opt_frame_spec frame_boundary_opts frame_boundary_start frame_boundary_end frame_boundary
%type <aval> opt_where opt_groupby opt_having opt_orderby opt_limit opt_offset opt_as_alias as_alias window_clause
%type <aval> groupby_item groupby_list orderby_item orderby_list opt_asc_desc opt_nullsfirst_nullslast window_name_defn window_name_defn_list
%type <aval> table_or_subquery table_or_subquery_list query_parts table_function opt_from_query_parts
%type <aval> opt_join_cond join_cond join_clause join_target join_target_list
%type <aval> basic_update_stmt with_update_stmt update_stmt update_cursor_stmt update_entry update_list upsert_stmt conflict_target
%type <aval> declare_schema_region_stmt declare_deployable_region_stmt call with_upsert_stmt
%type <aval> begin_schema_region_stmt end_schema_region_stmt schema_ad_hoc_migration_stmt region_list region_spec
%type <aval> schema_unsub_stmt
/* expressions and types */
%type <aval> expr basic_expr math_expr expr_list typed_name typed_names case_list call_expr_list call_expr shape_arguments
%type <aval> name name_list opt_name_list opt_name
%type <aval> data_type_any data_type_numeric data_type_with_options opt_kind
/* proc stuff */
%type <aval> create_proc_stmt declare_func_stmt declare_select_func_no_check_stmt declare_proc_stmt declare_interface_stmt declare_proc_no_check_stmt declare_out_call_stmt
%type <aval> arg_expr arg_list inout param params func_params func_param
/* statements */
%type <aval> stmt
%type <aval> stmt_list opt_stmt_list
%type <aval> any_stmt
%type <aval> begin_trans_stmt
%type <aval> call_stmt
%type <aval> close_stmt
%type <aval> commit_trans_stmt commit_return_stmt
%type <aval> continue_stmt
%type <aval> control_stmt
%type <aval> declare_vars_stmt declare_value_cursor declare_forward_read_cursor_stmt declare_type_stmt declare_fetched_value_cursor_stmt
%type <aval> declare_enum_stmt enum_values enum_value emit_enums_stmt emit_group_stmt
%type <aval> declare_const_stmt const_values const_value emit_constants_stmt declare_group_stmt simple_variable_decls
%type <aval> echo_stmt
%type <aval> fetch_stmt fetch_values_stmt fetch_call_stmt from_shape fetch_cursor_from_blob_stmt
%type <aval> guard_stmt
%type <aval> if_stmt elseif_item elseif_list opt_else opt_elseif_list proc_savepoint_stmt
%type <aval> leave_stmt return_stmt
%type <aval> loop_stmt
%type <aval> out_stmt out_union_stmt out_union_parent_child_stmt child_results child_result
%type <aval> previous_schema_stmt
%type <aval> release_savepoint_stmt
%type <aval> rollback_trans_stmt rollback_return_stmt savepoint_name
%type <aval> savepoint_stmt
%type <aval> schema_upgrade_script_stmt
%type <aval> schema_upgrade_version_stmt
%type <aval> set_stmt let_stmt
%type <aval> switch_stmt switch_cases switch_case
%type <aval> throw_stmt
%type <aval> trycatch_stmt
%type <aval> version_annotation
%type <aval> while_stmt
%type <aval> enforce_strict_stmt enforce_normal_stmt enforce_reset_stmt enforce_push_stmt enforce_pop_stmt
%type <aval> enforcement_options shape_def shape_def_base shape_expr shape_exprs
%type <aval> blob_get_key_type_stmt blob_get_val_type_stmt blob_get_key_stmt blob_get_val_stmt
%type <aval> blob_create_key_stmt blob_create_val_stmt blob_update_key_stmt blob_update_val_stmt
%type <aval> opt_use_offset
%start program
%%
program:
opt_stmt_list {
if (parse_error_occurred) {
cql_exit_on_parse_errors();
}
gen_init();
if (options.semantic) {
sem_main($opt_stmt_list);
}
if (options.codegen) {
rt->code_generator($opt_stmt_list);
}
else if (options.print_ast) {
print_root_ast($opt_stmt_list);
cql_output("\n");
} else if (options.print_dot) {
cql_output("\ndigraph parse {");
print_dot($opt_stmt_list);
cql_output("\n}\n");
}
else if (options.echo_input) {
gen_stmt_list_to_stdout($opt_stmt_list);
}
if (options.semantic) {
cql_exit_on_semantic_errors($opt_stmt_list);
}
}
;
opt_stmt_list:
/*nil*/ { $opt_stmt_list = NULL; }
| stmt_list { $opt_stmt_list = $stmt_list; }
;
stmt_list[result]:
stmt {
// We're going to do this cheesy thing with the stmt_list structures so that we can
// code the stmt_list rules using left recursion. We're doing this because it's
// possible that there could be a LOT of statements and this minimizes the use
// of the bison stack because reductions happen sooner with this pattern. It does
// mean we have to do some weird stuff because we need to build the list so that the
// tail is on the right. To accomplish this we take advantage of the fact that the
// parent pointer of the statement list is meaningless while it is unrooted. It
// would always be null. We store the tail of the statement list there so we know
// where to add new nodes on the right. When the statement list is put into the tree
// the parent node is set as usual so nobody will know we did this and we don't
// have to add anything to the node for this one case.
// With this done we can handle several thousand statements without using much stack space.
$result = new_ast_stmt_list($stmt, NULL);
$result->lineno = $stmt->lineno;
// set up the tail pointer invariant to use later
$result->parent = $result;
}
| stmt_list[slist] stmt {
ast_node *new_stmt = new_ast_stmt_list($stmt, NULL);
new_stmt->lineno = $stmt->lineno;
// use our tail pointer invariant so we can add at the tail without searching
ast_node *tail = $slist->parent;
ast_set_right(tail, new_stmt);
// re-establish the tail invariant per the above
$slist->parent = new_stmt;
$result = $slist;
}
;
stmt:
misc_attrs any_stmt ';' { $stmt = make_statement_node($misc_attrs, $any_stmt); }
;
any_stmt:
alter_table_add_column_stmt
| begin_schema_region_stmt
| begin_trans_stmt
| blob_get_key_type_stmt
| blob_get_val_type_stmt
| blob_get_key_stmt
| blob_get_val_stmt
| blob_create_key_stmt
| blob_create_val_stmt
| blob_update_key_stmt
| blob_update_val_stmt
| call_stmt
| close_stmt
| commit_return_stmt
| commit_trans_stmt
| continue_stmt
| create_index_stmt
| create_proc_stmt
| create_table_stmt
| create_trigger_stmt
| create_view_stmt
| create_virtual_table_stmt
| declare_deployable_region_stmt
| declare_enum_stmt
| declare_const_stmt
| declare_group_stmt
| declare_select_func_no_check_stmt
| declare_func_stmt
| declare_out_call_stmt
| declare_proc_no_check_stmt
| declare_proc_stmt
| declare_interface_stmt
| declare_schema_region_stmt
| declare_vars_stmt
| declare_forward_read_cursor_stmt
| declare_fetched_value_cursor_stmt
| declare_type_stmt
| delete_stmt
| drop_index_stmt
| drop_table_stmt
| drop_trigger_stmt
| drop_view_stmt
| echo_stmt
| emit_enums_stmt
| emit_group_stmt
| emit_constants_stmt
| end_schema_region_stmt
| enforce_normal_stmt
| enforce_pop_stmt
| enforce_push_stmt
| enforce_reset_stmt
| enforce_strict_stmt
| explain_stmt
| select_nothing_stmt
| fetch_call_stmt
| fetch_stmt
| fetch_values_stmt
| fetch_cursor_from_blob_stmt
| guard_stmt
| if_stmt
| insert_stmt
| leave_stmt
| let_stmt
| loop_stmt
| out_stmt
| out_union_stmt
| out_union_parent_child_stmt
| previous_schema_stmt
| proc_savepoint_stmt
| release_savepoint_stmt
| return_stmt
| rollback_return_stmt
| rollback_trans_stmt
| savepoint_stmt
| select_stmt
| schema_ad_hoc_migration_stmt
| schema_unsub_stmt
| schema_upgrade_script_stmt
| schema_upgrade_version_stmt
| set_stmt
| switch_stmt
| throw_stmt
| trycatch_stmt
| update_cursor_stmt
| update_stmt
| upsert_stmt
| while_stmt
| with_delete_stmt
| with_insert_stmt
| with_update_stmt
| with_upsert_stmt
;
explain_stmt:
EXPLAIN opt_query_plan explain_target { $explain_stmt = new_ast_explain_stmt(new_ast_opt($opt_query_plan), $explain_target); }
;
opt_query_plan:
/* nil */ { $opt_query_plan = EXPLAIN_NONE; }
| QUERY_PLAN { $opt_query_plan = EXPLAIN_QUERY_PLAN; }
;
explain_target: select_stmt
| update_stmt
| delete_stmt
| with_delete_stmt
| with_insert_stmt
| insert_stmt
| upsert_stmt
| drop_table_stmt
| drop_view_stmt
| drop_index_stmt
| drop_trigger_stmt
| begin_trans_stmt
| commit_trans_stmt
;
previous_schema_stmt:
AT_PREVIOUS_SCHEMA { $previous_schema_stmt = new_ast_previous_schema_stmt(); }
;
schema_upgrade_script_stmt:
AT_SCHEMA_UPGRADE_SCRIPT { $schema_upgrade_script_stmt = new_ast_schema_upgrade_script_stmt(); }
;
schema_upgrade_version_stmt:
AT_SCHEMA_UPGRADE_VERSION '(' INTLIT ')' {
$schema_upgrade_version_stmt = new_ast_schema_upgrade_version_stmt(new_ast_opt(atoi($INTLIT))); }
;
set_stmt:
SET name ASSIGN expr { $set_stmt = new_ast_assign($name, $expr); }
| SET name[id] FROM CURSOR name[cursor] { $set_stmt = new_ast_set_from_cursor($id, $cursor); }
;
let_stmt:
LET name ASSIGN expr { $let_stmt = new_ast_let_stmt($name, $expr); }
;
version_attrs_opt_recreate:
/* nil */ { $version_attrs_opt_recreate = NULL; }
| AT_RECREATE opt_delete_plain_attr { $version_attrs_opt_recreate = new_ast_recreate_attr(NULL, $opt_delete_plain_attr); }
| AT_RECREATE '(' name ')' opt_delete_plain_attr { $version_attrs_opt_recreate = new_ast_recreate_attr($name, $opt_delete_plain_attr); }
| version_attrs { $version_attrs_opt_recreate = $version_attrs; }
;
opt_delete_plain_attr:
/* nil */ {$opt_delete_plain_attr = NULL; }
| AT_DELETE { $opt_delete_plain_attr = new_ast_delete_attr(NULL, NULL); }
;
opt_version_attrs:
/* nil */ { $opt_version_attrs = NULL; }
| version_attrs { $opt_version_attrs = $version_attrs; }
;
version_attrs:
AT_CREATE version_annotation opt_version_attrs { $version_attrs = new_ast_create_attr($version_annotation, $opt_version_attrs); }
| AT_DELETE version_annotation opt_version_attrs { $version_attrs = new_ast_delete_attr($version_annotation, $opt_version_attrs); }
;
opt_delete_version_attr:
/* nil */ {$opt_delete_version_attr = NULL; }
| AT_DELETE version_annotation { $opt_delete_version_attr = new_ast_delete_attr($version_annotation, NULL); }
;
drop_table_stmt:
DROP TABLE IF EXISTS name { $drop_table_stmt = new_ast_drop_table_stmt(new_ast_opt(1), $name); }
| DROP TABLE name { $drop_table_stmt = new_ast_drop_table_stmt(NULL, $name); }
;
drop_view_stmt:
DROP VIEW IF EXISTS name { $drop_view_stmt = new_ast_drop_view_stmt(new_ast_opt(1), $name); }
| DROP VIEW name { $drop_view_stmt = new_ast_drop_view_stmt(NULL, $name); }
;
drop_index_stmt:
DROP INDEX IF EXISTS name { $drop_index_stmt = new_ast_drop_index_stmt(new_ast_opt(1), $name); }
| DROP INDEX name { $drop_index_stmt = new_ast_drop_index_stmt(NULL, $name); }
;
drop_trigger_stmt:
DROP TRIGGER IF EXISTS name { $drop_trigger_stmt = new_ast_drop_trigger_stmt(new_ast_opt(1), $name); }
| DROP TRIGGER name { $drop_trigger_stmt = new_ast_drop_trigger_stmt(NULL, $name); }
;
create_virtual_table_stmt: CREATE VIRTUAL TABLE opt_vtab_flags name[table_name]
USING name[module_name] opt_module_args
AS '(' col_key_list ')' opt_delete_version_attr {
int flags = $opt_vtab_flags;
struct ast_node *flags_node = new_ast_opt(flags);
struct ast_node *name = $table_name;
struct ast_node *col_key_list = $col_key_list;
struct ast_node *version_info = $opt_delete_version_attr ? $opt_delete_version_attr : new_ast_recreate_attr(NULL, NULL);
struct ast_node *table_flags_attrs = new_ast_table_flags_attrs(flags_node, version_info);
struct ast_node *table_name_flags = new_ast_create_table_name_flags(table_flags_attrs, name);
struct ast_node *create_table_stmt = new_ast_create_table_stmt(table_name_flags, col_key_list);
struct ast_node *module_info = new_ast_module_info($module_name, $opt_module_args);
$create_virtual_table_stmt = new_ast_create_virtual_table_stmt(module_info, create_table_stmt);
};
opt_module_args: /* nil */ { $opt_module_args = NULL; }
| '(' misc_attr_value_list ')' { $opt_module_args = $misc_attr_value_list; }
| '(' ARGUMENTS FOLLOWING ')' { $opt_module_args = new_ast_following(); }
;
create_table_prefix_opt_temp:
CREATE opt_temp TABLE {
/* This node only exists so that we can get an early reduce in the table flow to grab the doc comment */
$create_table_prefix_opt_temp = $opt_temp; table_comment_saved = get_last_doc_comment();
};
create_table_stmt:
create_table_prefix_opt_temp opt_if_not_exists name '(' col_key_list ')' opt_no_rowid version_attrs_opt_recreate {
int flags = $create_table_prefix_opt_temp | $opt_if_not_exists | $opt_no_rowid;
struct ast_node *flags_node = new_ast_opt(flags);
struct ast_node *name = $name;
struct ast_node *col_key_list = $col_key_list;
struct ast_node *table_flags_attrs = new_ast_table_flags_attrs(flags_node, $version_attrs_opt_recreate);
struct ast_node *table_name_flags = new_ast_create_table_name_flags(table_flags_attrs, name);
$create_table_stmt = new_ast_create_table_stmt(table_name_flags, col_key_list);
}
;
opt_temp:
/* nil */ { $opt_temp = 0; }
| TEMP { $opt_temp = GENERIC_IS_TEMP; }
;
opt_if_not_exists:
/* nil */ { $opt_if_not_exists = 0; }
| IF NOT EXISTS { $opt_if_not_exists = GENERIC_IF_NOT_EXISTS; }
;
opt_no_rowid:
/* nil */ { $opt_no_rowid = 0; }
| WITHOUT ROWID { $opt_no_rowid = TABLE_IS_NO_ROWID; }
;
opt_vtab_flags:
/* nil */ { $opt_vtab_flags = 0; }
| IF NOT EXISTS { $opt_vtab_flags = GENERIC_IF_NOT_EXISTS; }
| AT_EPONYMOUS { $opt_vtab_flags = VTAB_IS_EPONYMOUS; }
| AT_EPONYMOUS IF NOT EXISTS { $opt_vtab_flags = VTAB_IS_EPONYMOUS | GENERIC_IF_NOT_EXISTS; }
| IF NOT EXISTS AT_EPONYMOUS { $opt_vtab_flags = VTAB_IS_EPONYMOUS | GENERIC_IF_NOT_EXISTS; }
;
col_key_list[result]:
col_key_def { $result = new_ast_col_key_list($col_key_def, NULL); }
| col_key_def ',' col_key_list[ckl] { $result = new_ast_col_key_list($col_key_def, $ckl); }
;
col_key_def:
col_def
| pk_def
| fk_def
| unq_def
| check_def
| shape_def
;
check_def:
CONSTRAINT name CHECK '(' expr ')' { $check_def = new_ast_check_def($name, $expr); }
| CHECK '(' expr ')' { $check_def = new_ast_check_def(NULL, $expr); }
;
shape_exprs[result] :
shape_expr ',' shape_exprs[next] { $result = new_ast_shape_exprs($shape_expr, $next); }
| shape_expr { $result = new_ast_shape_exprs($shape_expr, NULL); }
;
shape_expr:
name { $shape_expr = new_ast_shape_expr($name, $name); }
| '-' name { $shape_expr = new_ast_shape_expr($name, NULL); }
;
shape_def:
shape_def_base { $shape_def = new_ast_shape_def($shape_def_base, NULL); }
| shape_def_base '(' shape_exprs ')' { $shape_def = new_ast_shape_def($shape_def_base, $shape_exprs); }
;
shape_def_base:
LIKE name { $shape_def_base = new_ast_like($name, NULL); }
| LIKE name ARGUMENTS { $shape_def_base = new_ast_like($name, $name); }
;
col_name:
name { $col_name = $name; }
;
misc_attr_key:
name { $misc_attr_key = $name; }
| name[lhs] ':' name[rhs] { $misc_attr_key = new_ast_dot($lhs, $rhs); }
;
misc_attr_value_list[result]:
misc_attr_value { $result = new_ast_misc_attr_value_list($misc_attr_value, NULL); }
| misc_attr_value ',' misc_attr_value_list[mav] { $result = new_ast_misc_attr_value_list($misc_attr_value, $mav); }
;
misc_attr_value:
name { $misc_attr_value = $name; }
| any_literal { $misc_attr_value = $any_literal; }
| const_expr { $misc_attr_value = $const_expr; }
| '(' misc_attr_value_list ')' { $misc_attr_value = $misc_attr_value_list; }
| '-' num_literal { $misc_attr_value = new_ast_uminus($num_literal);}
| '+' num_literal { $misc_attr_value = $num_literal;}
;
misc_attr:
AT_ATTRIBUTE '(' misc_attr_key ')' { $misc_attr = new_ast_misc_attr($misc_attr_key, NULL); }
| AT_ATTRIBUTE '(' misc_attr_key '=' misc_attr_value ')' { $misc_attr = new_ast_misc_attr($misc_attr_key, $misc_attr_value); }
;
misc_attrs[result]:
/* nil */ { $result = NULL; }
| misc_attr misc_attrs[ma] { $result = new_ast_misc_attrs($misc_attr, $ma); }
;
col_def:
misc_attrs col_name data_type_any col_attrs {
struct ast_node *name_type = new_ast_col_def_name_type($col_name, $data_type_any);
struct ast_node *col_def_type_attrs = new_ast_col_def_type_attrs(name_type, $col_attrs);
$col_def = make_coldef_node(col_def_type_attrs, $misc_attrs);
}
;
pk_def:
CONSTRAINT name PRIMARY KEY '(' indexed_columns ')' opt_conflict_clause {
ast_node *indexed_columns_conflict_clause = new_ast_indexed_columns_conflict_clause($indexed_columns, $opt_conflict_clause);
$pk_def = new_ast_pk_def($name, indexed_columns_conflict_clause);
}
| PRIMARY KEY '(' indexed_columns ')' opt_conflict_clause {
ast_node *indexed_columns_conflict_clause = new_ast_indexed_columns_conflict_clause($indexed_columns, $opt_conflict_clause);
$pk_def = new_ast_pk_def(NULL, indexed_columns_conflict_clause);
}
;
opt_conflict_clause:
/* nil */ { $opt_conflict_clause = NULL; }
| conflict_clause { $opt_conflict_clause = new_ast_opt($conflict_clause); }
;
conflict_clause:
ON_CONFLICT ROLLBACK { $conflict_clause = ON_CONFLICT_ROLLBACK; }
| ON_CONFLICT ABORT { $conflict_clause = ON_CONFLICT_ABORT; }
| ON_CONFLICT FAIL { $conflict_clause = ON_CONFLICT_FAIL; }
| ON_CONFLICT IGNORE { $conflict_clause = ON_CONFLICT_IGNORE; }
| ON_CONFLICT REPLACE { $conflict_clause = ON_CONFLICT_REPLACE; }
;
opt_fk_options:
/* nil */ { $opt_fk_options = 0; }
| fk_options { $opt_fk_options = $fk_options; }
;
fk_options:
fk_on_options { $fk_options = $fk_on_options; }
| fk_deferred_options { $fk_options = $fk_deferred_options; }
| fk_on_options fk_deferred_options { $fk_options = $fk_on_options | $fk_deferred_options; }
;
fk_on_options:
ON DELETE fk_action { $fk_on_options = $fk_action; }
| ON UPDATE fk_action { $fk_on_options = ($fk_action << 4); }
| ON UPDATE fk_action[lhs] ON DELETE fk_action[rhs] { $fk_on_options = ($lhs << 4) | $rhs; }
| ON DELETE fk_action[lhs] ON UPDATE fk_action[rhs] { $fk_on_options = ($rhs << 4) | $lhs; }
;
fk_action:
SET NULL_ { $fk_action = FK_SET_NULL; }
| SET DEFAULT { $fk_action = FK_SET_DEFAULT; }
| CASCADE { $fk_action = FK_CASCADE; }
| RESTRICT { $fk_action = FK_RESTRICT; }
| NO ACTION { $fk_action = FK_NO_ACTION; }
;
fk_deferred_options:
DEFERRABLE fk_initial_state { $fk_deferred_options = FK_DEFERRABLE | $fk_initial_state; }
| NOT_DEFERRABLE fk_initial_state { $fk_deferred_options = FK_NOT_DEFERRABLE | $fk_initial_state; }
;
fk_initial_state:
/* nil */ { $fk_initial_state = 0; }
| INITIALLY DEFERRED { $fk_initial_state = FK_INITIALLY_DEFERRED; }
| INITIALLY IMMEDIATE { $fk_initial_state = FK_INITIALLY_IMMEDIATE; }
;
fk_def:
CONSTRAINT name FOREIGN KEY '(' name_list ')' fk_target_options {
ast_node *fk_info = new_ast_fk_info($name_list, $fk_target_options);
$fk_def = new_ast_fk_def($name, fk_info); }
| FOREIGN KEY '(' name_list ')' fk_target_options {
ast_node *fk_info = new_ast_fk_info($name_list, $fk_target_options);
$fk_def = new_ast_fk_def(NULL, fk_info); }
;
fk_target_options:
REFERENCES name '(' name_list ')' opt_fk_options {
$fk_target_options = new_ast_fk_target_options(new_ast_fk_target($name, $name_list), new_ast_opt($opt_fk_options)); }
;
unq_def:
CONSTRAINT name UNIQUE '(' indexed_columns ')' opt_conflict_clause {
ast_node *indexed_columns_conflict_clause = new_ast_indexed_columns_conflict_clause($indexed_columns, $opt_conflict_clause);
$unq_def = new_ast_unq_def($name, indexed_columns_conflict_clause);
}
| UNIQUE '(' indexed_columns ')' opt_conflict_clause {
ast_node *indexed_columns_conflict_clause = new_ast_indexed_columns_conflict_clause($indexed_columns, $opt_conflict_clause);
$unq_def = new_ast_unq_def(NULL, indexed_columns_conflict_clause);
}
;
opt_unique:
/* nil */ { $opt_unique = 0; }
| UNIQUE { $opt_unique = 1; }
;
indexed_column:
expr opt_asc_desc {
$indexed_column = new_ast_indexed_column($expr, $opt_asc_desc); }
;
indexed_columns[result]:
indexed_column { $result = new_ast_indexed_columns($indexed_column, NULL); }
| indexed_column ',' indexed_columns[ic] { $result = new_ast_indexed_columns($indexed_column, $ic); }
;
create_index_stmt:
CREATE opt_unique INDEX opt_if_not_exists name[tbl_name] ON name[idx_name] '(' indexed_columns ')' opt_where opt_delete_version_attr {
int flags = 0;
if ($opt_unique) flags |= INDEX_UNIQUE;
if ($opt_if_not_exists) flags |= INDEX_IFNE;
ast_node *create_index_on_list = new_ast_create_index_on_list($tbl_name, $idx_name);
ast_node *index_names_and_attrs = new_ast_index_names_and_attrs($indexed_columns, $opt_where);
ast_node *connector = new_ast_connector(index_names_and_attrs, $opt_delete_version_attr);
ast_node *flags_names_attrs = new_ast_flags_names_attrs(new_ast_opt(flags), connector);
$create_index_stmt = new_ast_create_index_stmt(create_index_on_list, flags_names_attrs);
}
;
name:
ID { $name = new_ast_str($ID); }
| TEXT { $name = new_ast_str("text"); }
| TRIGGER { $name = new_ast_str("trigger"); }
| ROWID { $name = new_ast_str("rowid"); }
| REPLACE { $name = new_ast_str("replace"); }
| KEY { $name = new_ast_str("key"); }
| VIRTUAL { $name = new_ast_str("virtual"); }
| TYPE { $name = new_ast_str("type"); }
| HIDDEN { $name = new_ast_str("hidden"); }
| PRIVATE { $name = new_ast_str("private"); }
| FIRST { $name = new_ast_str("first"); }
| LAST { $name = new_ast_str("last"); }
;
opt_name:
/* nil */ { $opt_name = NULL; }
| name { $opt_name = $name; }
;
name_list[result]:
name { $result = new_ast_name_list($name, NULL); }
| name ',' name_list[nl] { $result = new_ast_name_list($name, $nl); }
;
opt_name_list:
/* nil */ { $opt_name_list = NULL; }
| name_list {$opt_name_list = $name_list; }
;
cte_binding_list[result]:
cte_binding { $result = new_ast_cte_binding_list($cte_binding, NULL); }
| cte_binding ',' cte_binding_list[nl] { $result = new_ast_cte_binding_list($cte_binding, $nl); }
;
cte_binding: name[formal] name[actual] { $cte_binding = new_ast_cte_binding($formal, $actual); }
| name[formal] AS name[actual] { $cte_binding = new_ast_cte_binding($formal, $actual); }
;
col_attrs[result]:
/* nil */ { $result = NULL; }
| NOT NULL_ opt_conflict_clause col_attrs[ca] { $result = new_ast_col_attrs_not_null($opt_conflict_clause, $ca); }
| PRIMARY KEY opt_conflict_clause col_attrs[ca] {
ast_node *autoinc_and_conflict_clause = new_ast_autoinc_and_conflict_clause(NULL, $opt_conflict_clause);
$result = new_ast_col_attrs_pk(autoinc_and_conflict_clause, $ca);
}
| PRIMARY KEY opt_conflict_clause AUTOINCREMENT col_attrs[ca] {
ast_node *autoinc_and_conflict_clause = new_ast_autoinc_and_conflict_clause(new_ast_col_attrs_autoinc(), $opt_conflict_clause);
$result = new_ast_col_attrs_pk(autoinc_and_conflict_clause, $ca);
}
| DEFAULT '-' num_literal col_attrs[ca] { $result = new_ast_col_attrs_default(new_ast_uminus($num_literal), $ca);}
| DEFAULT '+' num_literal col_attrs[ca] { $result = new_ast_col_attrs_default($num_literal, $ca);}
| DEFAULT num_literal col_attrs[ca] { $result = new_ast_col_attrs_default($num_literal, $ca);}
| DEFAULT const_expr col_attrs[ca] { $result = new_ast_col_attrs_default($const_expr, $ca);}
| DEFAULT str_literal col_attrs[ca] { $result = new_ast_col_attrs_default($str_literal, $ca);}
| COLLATE name col_attrs[ca] { $result = new_ast_col_attrs_collate($name, $ca);}
| CHECK '(' expr ')' col_attrs[ca] { $result = new_ast_col_attrs_check($expr, $ca);}
| UNIQUE opt_conflict_clause col_attrs[ca] { $result = new_ast_col_attrs_unique($opt_conflict_clause, $ca);}
| HIDDEN col_attrs[ca] { $result = new_ast_col_attrs_hidden(NULL, $ca);}
| AT_SENSITIVE col_attrs[ca] { $result = new_ast_sensitive_attr(NULL, $ca); }
| AT_CREATE version_annotation col_attrs[ca] { $result = new_ast_create_attr($version_annotation, $ca);}
| AT_DELETE version_annotation col_attrs[ca] { $result = new_ast_delete_attr($version_annotation, $ca);}
| fk_target_options col_attrs[ca] { $result = new_ast_col_attrs_fk($fk_target_options, $ca); }
;
version_annotation:
'(' INTLIT ',' name ')' {
$version_annotation = new_ast_version_annotation(new_ast_opt(atoi($INTLIT)), $name); }
| '(' INTLIT ',' name[lhs] ':' name[rhs] ')' {
ast_node *dot = new_ast_dot($lhs, $rhs);
$version_annotation = new_ast_version_annotation(new_ast_opt(atoi($INTLIT)), dot); }
| '(' INTLIT ')' {
$version_annotation = new_ast_version_annotation(new_ast_opt(atoi($INTLIT)), NULL); }
;
opt_kind:
/* nil */ { $opt_kind = NULL; }
| '<' name '>' {$opt_kind = $name; }
;
data_type_numeric:
INT_ opt_kind { $data_type_numeric = new_ast_type_int($opt_kind); }
| INTEGER opt_kind { $data_type_numeric = new_ast_type_int($opt_kind); }
| REAL opt_kind { $data_type_numeric = new_ast_type_real($opt_kind); }
| LONG_ opt_kind { $data_type_numeric = new_ast_type_long($opt_kind); }
| BOOL_ opt_kind { $data_type_numeric = new_ast_type_bool($opt_kind); }
| LONG_ INTEGER opt_kind { $data_type_numeric = new_ast_type_long($opt_kind); }
| LONG_ INT_ opt_kind { $data_type_numeric = new_ast_type_long($opt_kind); }
| LONG_INT opt_kind { $data_type_numeric = new_ast_type_long($opt_kind); }
| LONG_INTEGER opt_kind { $data_type_numeric = new_ast_type_long($opt_kind); }
;
data_type_any:
data_type_numeric { $data_type_any = $data_type_numeric; }
| TEXT opt_kind { $data_type_any = new_ast_type_text($opt_kind); }
| BLOB opt_kind { $data_type_any = new_ast_type_blob($opt_kind); }
| OBJECT opt_kind { $data_type_any = new_ast_type_object($opt_kind); }
| OBJECT '<' name CURSOR '>' { /* special case for boxed cursor */
CSTR type = dup_printf("%s CURSOR", AST_STR($name));
$data_type_any = new_ast_type_object(new_ast_str(type)); }
| OBJECT '<' name SET '>' { /* special case for result sets */
CSTR type = dup_printf("%s SET", AST_STR($name));
$data_type_any = new_ast_type_object(new_ast_str(type)); }
| ID { $data_type_any = new_ast_str($ID); }
;
data_type_with_options:
data_type_any { $data_type_with_options = $data_type_any; }
| data_type_any NOT NULL_ { $data_type_with_options = new_ast_notnull($data_type_any); }
| data_type_any AT_SENSITIVE { $data_type_with_options = new_ast_sensitive_attr($data_type_any, NULL); }
| data_type_any AT_SENSITIVE NOT NULL_ { $data_type_with_options = new_ast_sensitive_attr(new_ast_notnull($data_type_any), NULL); }
| data_type_any NOT NULL_ AT_SENSITIVE { $data_type_with_options = new_ast_sensitive_attr(new_ast_notnull($data_type_any), NULL); }
;
str_literal:
str_chain { $str_literal = reduce_str_chain($str_chain); }
;
str_chain[result]:
str_leaf { $result = new_ast_str_chain($str_leaf, NULL); }
| str_leaf str_chain[next] { $result = new_ast_str_chain($str_leaf, $next); }
;
str_leaf:
STRLIT { $str_leaf = new_ast_str($STRLIT);}
| CSTRLIT { $str_leaf = new_ast_cstr($CSTRLIT); }
;
num_literal:
INTLIT { $num_literal = new_ast_num(NUM_INT, $INTLIT); }
| LONGLIT { $num_literal = new_ast_num(NUM_LONG, $LONGLIT); }
| REALLIT { $num_literal = new_ast_num(NUM_REAL, $REALLIT); }
| TRUE_ { $num_literal = new_ast_num(NUM_BOOL, "1"); }
| FALSE_ { $num_literal = new_ast_num(NUM_BOOL, "0"); }
;
const_expr:
CONST '(' expr ')' { $const_expr = new_ast_const($expr); }
;
any_literal:
str_literal { $any_literal = $str_literal; }
| num_literal { $any_literal = $num_literal; }
| NULL_ { $any_literal = new_ast_null(); }
| AT_FILE '(' str_literal ')' { $any_literal = file_literal($str_literal); }
| AT_PROC { $any_literal = new_ast_str("@PROC"); }
| BLOBLIT { $any_literal = new_ast_blob($BLOBLIT); }
;
raise_expr:
RAISE '(' IGNORE ')' { $raise_expr = new_ast_raise(new_ast_opt(RAISE_IGNORE), NULL); }
| RAISE '(' ROLLBACK ',' expr ')' { $raise_expr = new_ast_raise(new_ast_opt(RAISE_ROLLBACK), $expr); }
| RAISE '(' ABORT ',' expr ')' { $raise_expr = new_ast_raise(new_ast_opt(RAISE_ABORT), $expr); }
| RAISE '(' FAIL ',' expr ')' { $raise_expr = new_ast_raise(new_ast_opt(RAISE_FAIL), $expr); }
;
call:
name '(' arg_list ')' opt_filter_clause {
YY_ERROR_ON_CQL_INFERRED_NOTNULL($name);
struct ast_node *call_filter_clause = new_ast_call_filter_clause(NULL, $opt_filter_clause);
struct ast_node *call_arg_list = new_ast_call_arg_list(call_filter_clause, $arg_list);
$call = new_ast_call($name, call_arg_list);
}
| name '(' DISTINCT arg_list ')' opt_filter_clause {
YY_ERROR_ON_CQL_INFERRED_NOTNULL($name);