This repository was archived by the owner on Feb 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathPLSQLParser.g
More file actions
1400 lines (1199 loc) · 42.6 KB
/
PLSQLParser.g
File metadata and controls
1400 lines (1199 loc) · 42.6 KB
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
/**
* Oracle(c) PL/SQL 11g Parser
*
* Copyright (c) 2009-2011 Alexandre Porcelli <alexandre.porcelli@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
parser grammar PLSQLParser;
options {
output=AST;
tokenVocab=PLSQLLexer;
}
import PLSQLKeys, PLSQLCommons, PLSQL_DMLParser, SQLPLUSParser;
tokens {
COMPILATION_UNIT;
DROP_FUNCTION;
ALTER_FUNCTION;
CREATE_FUNCTION;
USING_MODE;
CALL_MODE;
BODY_MODE;
EXTERNAL_MODE;
STREAMING_CLAUSE;
EXPR;
CREATE_PACKAGE_SPEC;
CREATE_PACKAGE_BODY;
COLUMNS;
DROP_PACKAGE;
ALTER_PACKAGE;
PROCEDURE_SPEC;
FUNCTION_SPEC;
DROP_PROCEDURE;
ALTER_PROCEDURE;
CREATE_PROCEDURE;
DROP_TRIGGER;
ALTER_TRIGGER;
CREATE_TRIGGER;
LOGIC_EXPR;
SIMPLE_DML;
FOR_EACH_ROW;
COMPOUND_DML;
NON_DML;
BEFORE_STATEMENT;
BEFORE_EACH_ROW;
AFTER_STATEMENT;
AFTER_EACH_ROW;
DML_EVENT;
DML_EVENT_ELEMENT;
DROP_TYPE;
ALTER_TYPE;
ALTER_METHOD;
ALTER_METHOD_ELEMENT;
ALTER_ATTRIBUTE;
ATTRIBUTES;
DEPENDENT_HANDLING;
ALTER_COLLECTION;
CREATE_TYPE_BODY;
CREATE_TYPE_SPEC;
ASSIGN;
THREE_DOTS;
COMPILER_PARAMETER;
MODIFIER;
DEFAULT_VALUE;
OBJECT_MEMBERS;
OBJECT_TYPE_DEF;
OBJECT_AS;
NESTED_TABLE_TYPE_DEF;
TYPE_BODY_ELEMENTS;
ELEMENT_SPEC;
FIELD_SPEC;
CONSTRUCTOR_SPEC;
VARIABLE_DECLARE;
SUBTYPE_DECLARE;
CURSOR_DECLARE;
PARAMETERS;
PARAMETER;
EXCEPTION_DECLARE;
PRAGMA_DECLARE;
RECORD_TYPE_DECLARE;
FIELDS;
RECORD_VAR_DECLARE;
TABLE_TYPE_DECLARE;
TABLE_TYPE_DECLARE;
INDEXED_BY;
VARR_ARRAY_DEF;
TABLE_VAR_DECLARE;
LABEL_DECLARE;
FOR_LOOP;
WHILE_LOOP;
INDEXED_FOR;
CURSOR_BASED_FOR;
SELECT_BASED_FOR;
SIMPLE_BOUND;
INDICES_BOUND;
VALUES_BOUND;
ROUTINE_CALL;
BODY;
BLOCK;
STATEMENTS;
DYNAMIC_RETURN;
SET_TRANSACTION;
SET_CONSTRAINT;
SELECTED_TABLEVIEW;
SQL_SCRIPT;
SET_SERVEROUTPUT;
ATTRIBUTE;
DROP_SEQUENCE;
ALTER_SEQUENCE;
CREATE_SEQUENCE;
}
@header {
/**
* Oracle(c) PL/SQL 11g Parser
*
* Copyright (c) 2009-2011 Alexandre Porcelli <alexandre.porcelli@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package br.com.porcelli.parser.plsql;
}
swallow_to_semi
: ~( SEMICOLON )+
;
compilation_unit
: unit_statement* EOF
-> ^(COMPILATION_UNIT unit_statement*)
;
sql_script
: (unit_statement|sql_plus_command)* EOF
-> ^(SQL_SCRIPT sql_plus_command* unit_statement*)
;
unit_statement
options{
backtrack=true;
} : alter_function
| alter_package
| alter_procedure
| alter_sequence
| alter_trigger
| alter_type
| create_function_body
| create_procedure_body
| create_package
| create_sequence
// | create_index //TODO
// | create_table //TODO
// | create_view //TODO
// | create_directory //TODO
// | create_materialized_view //TODO
| create_trigger
| create_type
| drop_function
| drop_package
| drop_procedure
| drop_sequence
| drop_trigger
| drop_type
;
// $<DDL -> SQL Statements for Stored PL/SQL Units
// $<Function DDLs
drop_function
: drop_key function_key function_name
SEMICOLON
-> ^(DROP_FUNCTION[$drop_key.start] function_name)
;
alter_function
: alter_key function_key function_name
compile_key debug_key? compiler_parameters_clause*
(reuse_key settings_key)?
SEMICOLON
-> ^(ALTER_FUNCTION[$alter_key.start] function_name debug_key? reuse_key? compiler_parameters_clause*)
;
create_function_body
@init { int mode = 0; }
: (create_key ( or_key replace_key )?)? function_key function_name
( LEFT_PAREN parameter (COMMA parameter)* RIGHT_PAREN)?
return_key type_spec
(invoker_rights_clause|parallel_enable_clause|result_cache_clause|deterministic_key)*
(
( pipelined_key? ( is_key | as_key )
( declare_key? declare_spec* body
| call_spec {mode = 2;})
)
| (pipelined_key|aggregate_key) using_key implementation_type_name {mode = 1;}
)
SEMICOLON
-> {mode == 1}?
^(CREATE_FUNCTION[$function_key.start] replace_key? function_name type_spec ^(PARAMETERS parameter*)
invoker_rights_clause* parallel_enable_clause* result_cache_clause* deterministic_key*
^(USING_MODE pipelined_key? aggregate_key? implementation_type_name))
-> {mode == 2}?
^(CREATE_FUNCTION[$function_key.start] replace_key? function_name type_spec ^(PARAMETERS parameter*)
invoker_rights_clause* parallel_enable_clause* result_cache_clause* deterministic_key*
^(CALL_MODE pipelined_key? call_spec))
-> ^(CREATE_FUNCTION[$function_key.start] replace_key? function_name type_spec ^(PARAMETERS parameter*)
invoker_rights_clause* parallel_enable_clause* result_cache_clause* deterministic_key*
^(BODY_MODE pipelined_key? declare_spec* body))
;
// $<Creation Function - Specific Clauses
parallel_enable_clause
: parallel_enable_key^ partition_by_clause?
;
partition_by_clause
@init { int mode = 0; }
: LEFT_PAREN
partition_key expression by_key
( any_key {mode = 1;}
| (hash_key {mode = 2;}|range_key) LEFT_PAREN column_name (COMMA column_name)* RIGHT_PAREN
)
streaming_clause?
RIGHT_PAREN
->{mode == 1}?
^(partition_key ^(EXPR expression) any_key streaming_clause?)
->{mode == 2}?
^(partition_key ^(EXPR expression) ^(hash_key ^(COLUMNS column_name+)) streaming_clause?)
->
^(partition_key ^(EXPR expression) ^(range_key ^(COLUMNS column_name+)) streaming_clause?)
;
result_cache_clause
: result_cache_key relies_on_part?
-> ^(result_cache_key relies_on_part?)
;
relies_on_part
: relies_on_key^ LEFT_PAREN! tableview_name (COMMA! tableview_name)* RIGHT_PAREN!
;
streaming_clause
: (order_key|cluster_key) expression by_key
LEFT_PAREN column_name (COMMA column_name)* RIGHT_PAREN
-> ^(STREAMING_CLAUSE order_key? cluster_key? ^(EXPR expression) ^(COLUMNS column_name+))
;
// $>
// $>
// $<Package DDLs
drop_package
: drop_key package_key body_key? package_name
SEMICOLON
-> ^(DROP_PACKAGE[$drop_key.start] package_name body_key?)
;
alter_package
: alter_key package_key package_name
compile_key debug_key? (package_key|body_key|specification_key)?
compiler_parameters_clause*
(reuse_key settings_key)?
SEMICOLON
-> ^(ALTER_PACKAGE[$alter_key.start] package_name debug_key? reuse_key?
package_key? body_key? specification_key? compiler_parameters_clause*)
;
create_package
@init { int mode = 0; }
: create_key ( or_key replace_key )? package_key
( package_spec {mode = 1;} | package_body )?
SEMICOLON
-> {mode == 1}? ^(CREATE_PACKAGE_SPEC[$create_key.start] replace_key? package_spec)
-> ^(CREATE_PACKAGE_BODY[$create_key.start] replace_key? package_body)
;
// $<Create Package - Specific Clauses
package_body
: body_key package_name (is_key | as_key)
package_obj_body*
(begin_key seq_of_statements|end_key package_name?)
-> package_name+ package_obj_body* seq_of_statements?
;
package_spec
: package_name invoker_rights_clause? (is_key | as_key)
package_obj_spec*
end_key package_name?
-> package_name+ invoker_rights_clause? package_obj_spec*
;
package_obj_spec
options{
backtrack=true;
} : variable_declaration
| subtype_declaration
| cursor_declaration
| exception_declaration
| record_declaration
| table_declaration
| procedure_spec
| function_spec
;
procedure_spec
: procedure_key procedure_name
( LEFT_PAREN parameter ( COMMA parameter )* RIGHT_PAREN )? SEMICOLON
-> ^(PROCEDURE_SPEC[$procedure_key.start] procedure_name ^(PARAMETERS parameter*))
;
function_spec
: function_key function_name
(LEFT_PAREN parameter ( COMMA parameter)* RIGHT_PAREN )?
return_key type_spec SEMICOLON
-> ^(FUNCTION_SPEC[$function_key.start] function_name type_spec ^(PARAMETERS parameter*))
;
package_obj_body
options{
backtrack=true;
} : variable_declaration
| subtype_declaration
| cursor_declaration
| exception_declaration
| record_declaration
| table_declaration
| create_procedure_body
| create_function_body
;
// $>
// $>
// $<Procedure DDLs
drop_procedure
: drop_key procedure_key procedure_name
SEMICOLON
-> ^(DROP_PROCEDURE[$drop_key.start] procedure_name)
;
alter_procedure
: alter_key procedure_key procedure_name
compile_key debug_key? compiler_parameters_clause*
(reuse_key settings_key)?
SEMICOLON
-> ^(ALTER_PROCEDURE[$alter_key.start] procedure_name debug_key? reuse_key? compiler_parameters_clause*)
;
create_procedure_body
@init { int mode = 0; }
: (create_key ( or_key replace_key )?)? procedure_key procedure_name
( LEFT_PAREN parameter ( COMMA parameter )* RIGHT_PAREN )?
invoker_rights_clause?
( is_key | as_key )
( declare_key? declare_spec* body
| call_spec {mode = 2;}
| external_key {mode = 1;}
)
SEMICOLON
-> {mode == 1}?
^(CREATE_PROCEDURE[$procedure_key.start] replace_key? procedure_name ^(PARAMETERS parameter*)
invoker_rights_clause? external_key)
-> {mode == 2}?
^(CREATE_PROCEDURE[$procedure_key.start] replace_key? procedure_name ^(PARAMETERS parameter*)
invoker_rights_clause?
^(CALL_MODE call_spec))
-> ^(CREATE_PROCEDURE[$procedure_key.start] replace_key? procedure_name ^(PARAMETERS parameter*)
invoker_rights_clause?
^(BODY_MODE declare_spec* body))
;
// $>
// $<Trigger DDLs
drop_trigger
: drop_key trigger_key trigger_name
SEMICOLON
-> ^(DROP_TRIGGER[$drop_key.start] trigger_name)
;
alter_trigger
@init { int mode = 0; }
: alter_key trigger_key tn1=trigger_name
( (enable_key|disable_key) {mode = 1;}
| rename_key to_key tn2=trigger_name {mode = 2;}
| compile_key debug_key? compiler_parameters_clause* (reuse_key settings_key)?
) SEMICOLON
-> {mode == 1}? ^(ALTER_TRIGGER[$alter_key.start] $tn1 enable_key? disable_key?)
-> {mode == 2}? ^(ALTER_TRIGGER[$alter_key.start] $tn1 ^(rename_key $tn2))
-> ^(ALTER_TRIGGER[$alter_key.start] $tn1 debug_key? reuse_key? compiler_parameters_clause*)
;
create_trigger
: create_key ( or_key replace_key )? trigger_key trigger_name
( simple_dml_trigger
| compound_dml_trigger
| non_dml_trigger
)
trigger_follows_clause?
(enable_key|disable_key)?
trigger_when_clause?
trigger_body SEMICOLON
-> ^(CREATE_TRIGGER[$create_key.start] replace_key? trigger_name
simple_dml_trigger? compound_dml_trigger? non_dml_trigger?
trigger_follows_clause? enable_key? disable_key? trigger_when_clause? trigger_body)
;
trigger_follows_clause
: follows_key trigger_name (COMMA trigger_name)*
-> ^(follows_key trigger_name+)
;
trigger_when_clause
: when_key LEFT_PAREN condition RIGHT_PAREN
-> ^(when_key ^(LOGIC_EXPR condition))
;
// $<Create Trigger- Specific Clauses
simple_dml_trigger
: (before_key|after_key|instead_key of_key) dml_event_clause referencing_clause? for_each_row?
-> ^(SIMPLE_DML before_key? after_key? instead_key? for_each_row? referencing_clause? dml_event_clause)
;
for_each_row
: for_key each_key row_key -> FOR_EACH_ROW[$for_key.start]
;
compound_dml_trigger
: for_key dml_event_clause referencing_clause?
-> ^(COMPOUND_DML[$for_key.start] referencing_clause? dml_event_clause)
;
non_dml_trigger
: (before_key|after_key) non_dml_event (or_key non_dml_event)*
on_key (database_key | (schema_name PERIOD)? schema_key )
-> ^(NON_DML before_key? after_key? non_dml_event+ database_key? schema_name? schema_key?)
;
trigger_body
: (compound_key trigger_key)=> compound_trigger_block
| (call_key id)=> call_key^ routine_clause
| block -> ^(BODY_MODE block)
;
routine_clause
: routine_name function_argument?
;
compound_trigger_block
: compound_key trigger_key declare_spec* timing_point_section+ end_key trigger_name
-> ^(compound_key trigger_name declare_spec* timing_point_section+)
;
timing_point_section
options{
k=3;
} : bk=before_key statement_key is_key block before_key statement_key SEMICOLON
-> ^(BEFORE_STATEMENT[$bk.start] block)
| bk=before_key each_key row_key is_key block before_key each_key row_key SEMICOLON
-> ^(BEFORE_EACH_ROW[$bk.start] block)
| ak=after_key statement_key is_key block after_key statement_key SEMICOLON
-> ^(AFTER_STATEMENT[$ak.start] block)
| ak=after_key each_key row_key is_key block after_key each_key row_key SEMICOLON
-> ^(AFTER_EACH_ROW[$ak.start] block)
;
non_dml_event
: alter_key
| analyze_key
| associate_key statistics_key
| audit_key
| comment_key
| create_key
| disassociate_key statistics_key
| drop_key
| grant_key
| noaudit_key
| rename_key
| revoke_key
| truncate_key
| ddl_key
| startup_key
| shutdown_key
| db_role_change_key
| logon_key
| logoff_key
| servererror_key
| suspend_key
| database_key
| schema_key
| follows_key
;
dml_event_clause
: dml_event_element (or_key dml_event_element)*
on_key
dml_event_nested_clause? tableview_name
-> ^(DML_EVENT dml_event_element+ ^(on_key tableview_name dml_event_nested_clause?))
;
dml_event_element
: (delete_key|insert_key|update_key) (of_key column_name (COMMA column_name)*)?
-> ^(DML_EVENT_ELEMENT delete_key? insert_key? update_key? ^(COLUMNS column_name*))
;
dml_event_nested_clause
: nested_key table_key tableview_name of_key
-> ^(nested_key tableview_name)
;
referencing_clause
: referencing_key^ referencing_element+
;
referencing_element
: ( new_key^ | old_key^ | parent_key^ ) column_alias
;
// $>
// $>
// $<Type DDLs
drop_type
: drop_key type_key body_key? type_name (force_key|validate_key)?
SEMICOLON
-> ^(DROP_TYPE[$drop_key.start] type_name body_key? force_key? validate_key?)
;
alter_type
@init { int mode = 0; }
: alter_key type_key type_name
( compile_type_clause
| replace_type_clause {mode = 1;}
| {input.LT(2).getText().equalsIgnoreCase("attribute")}? alter_attribute_definition {mode = 2;}
| alter_method_spec {mode = 3;}
| alter_collection_clauses {mode = 4;}
| modifier_clause {mode = 5;}
)
dependent_handling_clause?
SEMICOLON
-> {mode == 1}? ^(ALTER_TYPE[$alter_key.start] type_name replace_type_clause dependent_handling_clause?)
-> {mode == 2}? ^(ALTER_TYPE[$alter_key.start] type_name alter_attribute_definition dependent_handling_clause?)
-> {mode == 3}? ^(ALTER_TYPE[$alter_key.start] type_name alter_method_spec dependent_handling_clause?)
-> {mode == 4}? ^(ALTER_TYPE[$alter_key.start] type_name alter_collection_clauses dependent_handling_clause?)
-> {mode == 5}? ^(ALTER_TYPE[$alter_key.start] type_name modifier_clause dependent_handling_clause?)
-> ^(ALTER_TYPE[$alter_key.start] type_name compile_type_clause dependent_handling_clause?)
;
// $<Alter Type - Specific Clauses
compile_type_clause
: compile_key debug_key? (specification_key|body_key)? compiler_parameters_clause* (reuse_key settings_key)?
-> ^(compile_key specification_key? body_key? debug_key? reuse_key? compiler_parameters_clause*)
;
replace_type_clause
: replace_key invoker_rights_clause? as_key object_key
LEFT_PAREN object_member_spec (COMMA object_member_spec)* RIGHT_PAREN
-> ^(replace_key ^(OBJECT_MEMBERS object_member_spec+) invoker_rights_clause?)
;
alter_method_spec
: alter_method_element (COMMA alter_method_element)*
-> ^(ALTER_METHOD alter_method_element+)
;
alter_method_element
: (add_key|drop_key) (map_order_function_spec|subprogram_spec)
-> ^(ALTER_METHOD_ELEMENT add_key? drop_key? map_order_function_spec? subprogram_spec?)
;
alter_attribute_definition
: (add_key|modify_key|drop_key) attribute_key
( attribute_definition
| LEFT_PAREN attribute_definition (COMMA attribute_definition)* RIGHT_PAREN
)
-> ^(ALTER_ATTRIBUTE add_key? modify_key? drop_key? ^(ATTRIBUTES attribute_definition+))
;
attribute_definition
: attribute_name type_spec?
-> ^(ATTRIBUTE attribute_name type_spec?)
;
alter_collection_clauses
@init { int mode = 0; }
: modify_key
( limit_key expression
| element_key type_key type_spec {mode = 1;}
)
-> {mode == 1}? ^(ALTER_COLLECTION[$modify_key.start] ^(type_key type_spec))
-> ^(ALTER_COLLECTION[$modify_key.start] ^(limit_key ^(EXPR expression)))
;
dependent_handling_clause
@init { int mode = 0; }
: invalidate_key -> ^(DEPENDENT_HANDLING invalidate_key)
| cascade_key
( convert_key to_key substitutable_key {mode = 1;}
| not_key? including_key table_key data_key {mode = 2;}
)?
dependent_exceptions_part?
-> {mode == 1}? ^(DEPENDENT_HANDLING ^(cascade_key convert_key) dependent_exceptions_part?)
-> {mode == 2}? ^(DEPENDENT_HANDLING ^(cascade_key not_key? including_key) dependent_exceptions_part?)
-> ^(DEPENDENT_HANDLING ^(cascade_key) dependent_exceptions_part?)
;
dependent_exceptions_part
: force_key? exceptions_key into_key tableview_name
-> ^(exceptions_key force_key? tableview_name)
;
// $>
create_type
@init { int mode = 0; }
: create_key (or_key replace_key)? type_key
( type_definition | type_body {mode = 1;})
SEMICOLON
->{mode == 1}? ^(CREATE_TYPE_BODY[$create_key.start] replace_key? type_body)
-> ^(CREATE_TYPE_SPEC[$create_key.start] replace_key? type_definition)
;
// $<Create Type - Specific Clauses
type_definition
: type_name
(oid_key CHAR_STRING)?
object_type_def?
-> type_name CHAR_STRING? object_type_def?
;
object_type_def
: invoker_rights_clause?
( object_as_part
| object_under_part
)
sqlj_object_type?
(LEFT_PAREN object_member_spec (COMMA object_member_spec)* RIGHT_PAREN)?
modifier_clause*
-> ^(OBJECT_TYPE_DEF object_as_part? object_under_part? invoker_rights_clause?
sqlj_object_type? modifier_clause* ^(OBJECT_MEMBERS object_member_spec*))
;
object_as_part
: (is_key|as_key) (object_key|varray_type_def|nested_table_type_def)
-> ^(OBJECT_AS object_key? varray_type_def? nested_table_type_def?)
;
object_under_part
: under_key^ type_spec
;
nested_table_type_def
: table_key of_key type_spec
(not_key null_key)?
-> ^(NESTED_TABLE_TYPE_DEF[$table_key.start] type_spec null_key?)
;
sqlj_object_type
: external_key name_key expression language_key java_key using_key (sqldata_key|customdatum_key|oradata_key)
-> ^(java_key ^(EXPR expression) sqldata_key? customdatum_key? oradata_key?)
;
type_body
: body_key type_name
(is_key|as_key) type_body_elements (COMMA type_body_elements)*
end_key
-> type_name ^(TYPE_BODY_ELEMENTS type_body_elements+)
;
type_body_elements
: map_order_func_declaration
| subprog_decl_in_type
;
map_order_func_declaration
: (map_key^|order_key^) member_key! func_decl_in_type
;
subprog_decl_in_type
: (member_key^|static_key^)
( proc_decl_in_type
| func_decl_in_type
| constructor_declaration)
;
proc_decl_in_type
@init { int mode = 0; }
: procedure_key procedure_name
LEFT_PAREN type_elements_parameter (COMMA type_elements_parameter)* RIGHT_PAREN
(is_key|as_key)
(call_spec {mode = 1;}|declare_key? declare_spec* body SEMICOLON)
-> {mode == 1}? ^(CREATE_PROCEDURE procedure_name ^(PARAMETERS type_elements_parameter+) ^(CALL_MODE call_spec))
-> ^(CREATE_PROCEDURE procedure_name ^(PARAMETERS type_elements_parameter+) ^(BODY_MODE declare_spec* body))
;
func_decl_in_type
@init { int mode = 0; }
: function_key function_name
(LEFT_PAREN type_elements_parameter (COMMA type_elements_parameter)* RIGHT_PAREN)?
return_key type_spec
(is_key|as_key)
(call_spec {mode = 1;}|declare_key? declare_spec* body SEMICOLON)
-> {mode == 1}? ^(CREATE_FUNCTION function_name type_spec ^(PARAMETERS type_elements_parameter*) ^(CALL_MODE call_spec))
-> ^(CREATE_FUNCTION function_name type_spec ^(PARAMETERS type_elements_parameter*) ^(BODY_MODE declare_spec* body))
;
constructor_declaration
@init { int mode = 0; }
: final_key? instantiable_key? constructor_key function_key type_spec
(LEFT_PAREN (self_key in_key out_key type_spec COMMA) type_elements_parameter (COMMA type_elements_parameter)* RIGHT_PAREN)?
return_key self_key as_key result_key
(is_key|as_key)
(call_spec {mode = 1;}|declare_key? declare_spec* body SEMICOLON)
-> {mode == 1}? ^(constructor_key type_spec final_key? instantiable_key? ^(PARAMETERS type_elements_parameter*) ^(CALL_MODE call_spec))
-> ^(constructor_key type_spec final_key? instantiable_key? ^(PARAMETERS type_elements_parameter*) ^(BODY_MODE declare_spec* body))
;
// $>
// $<Common Type Clauses
modifier_clause
: not_key? (instantiable_key|final_key|overriding_key)
-> ^(MODIFIER not_key? instantiable_key? final_key? overriding_key?)
;
object_member_spec
options{
backtrack=true;
} : id type_spec sqlj_object_type_attr? -> ^(ELEMENT_SPEC ^(FIELD_SPEC id type_spec sqlj_object_type_attr?))
| element_spec
;
sqlj_object_type_attr
: external_key name_key expression
-> ^(external_key ^(EXPR expression))
;
element_spec
: modifier_clause?
element_spec_options+
(COMMA pragma_clause)?
-> ^(ELEMENT_SPEC element_spec_options+ modifier_clause? pragma_clause?)
;
element_spec_options
: subprogram_spec
| constructor_spec
| map_order_function_spec
;
subprogram_spec
: (member_key^|static_key^)
(type_procedure_spec|type_function_spec)
;
type_procedure_spec
@init { int mode = 0; }
: procedure_key procedure_name
LEFT_PAREN type_elements_parameter (COMMA type_elements_parameter)* RIGHT_PAREN
((is_key|as_key) call_spec {mode = 1;})?
->{mode == 1}? ^(PROCEDURE_SPEC procedure_name ^(PARAMETERS type_elements_parameter+) ^(CALL_MODE call_spec))
-> ^(PROCEDURE_SPEC procedure_name ^(PARAMETERS type_elements_parameter+))
;
type_function_spec
@init { int mode = 0; }
: function_key function_name
(LEFT_PAREN type_elements_parameter (COMMA type_elements_parameter)* RIGHT_PAREN)?
return_key ( type_spec | self_key as_key result_key)
((is_key|as_key) call_spec {mode = 1;}| external_key variable_key? name_key expression {mode = 2;})?
->{mode == 1}? ^(FUNCTION_SPEC function_name type_spec? self_key? ^(PARAMETERS type_elements_parameter*) ^(CALL_MODE call_spec))
->{mode == 2}? ^(FUNCTION_SPEC function_name type_spec? self_key? ^(PARAMETERS type_elements_parameter*) ^(external_key ^(EXPR expression)))
-> ^(FUNCTION_SPEC function_name type_spec? self_key? ^(PARAMETERS type_elements_parameter*))
;
constructor_spec
@init { int mode = 0; }
: final_key? instantiable_key? constructor_key function_key type_spec
(LEFT_PAREN (self_key in_key out_key type_spec COMMA) type_elements_parameter (COMMA type_elements_parameter)* RIGHT_PAREN)?
return_key self_key as_key result_key ((is_key|as_key) call_spec {mode = 1;})?
->{mode == 1}? ^(CONSTRUCTOR_SPEC[$constructor_key.start] type_spec final_key? instantiable_key? ^(PARAMETERS type_elements_parameter*) ^(CALL_MODE call_spec))
-> ^(CONSTRUCTOR_SPEC[$constructor_key.start] type_spec final_key? instantiable_key? ^(PARAMETERS type_elements_parameter*))
;
map_order_function_spec
: (map_key^|order_key^) member_key! type_function_spec
;
pragma_clause
: pragma_key restrict_references_key LEFT_PAREN pragma_elements (COMMA pragma_elements)* RIGHT_PAREN
-> ^(pragma_key pragma_elements+)
;
pragma_elements
: id
| default_key
;
type_elements_parameter
: parameter_name type_spec
-> ^(PARAMETER parameter_name type_spec)
;
// $>
// $>
// $<Sequence DDLs
drop_sequence
: drop_key sequence_key sequence_name
SEMICOLON
-> ^(DROP_SEQUENCE[$drop_key.start] sequence_name)
;
alter_sequence
: alter_key sequence_key sequence_name sequence_spec+
SEMICOLON
-> ^(ALTER_SEQUENCE[$alter_key.start] sequence_name sequence_spec+)
;
create_sequence
: create_key sequence_key sequence_name
( sequence_start_clause
| sequence_spec
)* SEMICOLON
-> ^(CREATE_SEQUENCE[$create_key.start] sequence_name sequence_start_clause* sequence_spec*)
;
// $<Common Sequence
sequence_spec
: increment_key^ by_key! UNSIGNED_INTEGER
| maxvalue_key^ UNSIGNED_INTEGER
| minvalue_key^ UNSIGNED_INTEGER
| cache_key^ UNSIGNED_INTEGER
| nomaxvalue_key
| nominvalue_key
| cycle_key
| nocycle_key
| nocache_key
| order_key
| noorder_key
;
sequence_start_clause
: start_key^ with_key! UNSIGNED_INTEGER
;
// $>
// $>
// $<Common DDL Clauses
invoker_rights_clause
: authid_key (current_user_key|definer_key)
-> ^(authid_key current_user_key? definer_key?)
;
compiler_parameters_clause
: id EQUALS_OP expression
-> ^(COMPILER_PARAMETER ^(ASSIGN[$EQUALS_OP] id ^(EXPR expression)))
;
call_spec
: language_key^ ( java_spec | c_spec )
;
// $<Call Spec - Specific Clauses
java_spec
: java_key^ name_key! CHAR_STRING
;
c_spec
: c_key (name_key CHAR_STRING)?
library_key id
c_agent_in_clause? (with_key context_key)? c_parameters_clause?
-> ^(c_key CHAR_STRING? context_key? ^(library_key id) c_agent_in_clause? c_parameters_clause?)
;
c_agent_in_clause
: agent_key in_key LEFT_PAREN expression (COMMA expression)* RIGHT_PAREN
-> ^(agent_key ^(EXPR expression)+)
;
c_parameters_clause
@init { int mode = 0; }
: parameters_key LEFT_PAREN (expression (COMMA expression)* | DOUBLE_PERIOD PERIOD {mode = 1;}) RIGHT_PAREN
-> {mode == 1}? ^(parameters_key THREE_DOTS[$DOUBLE_PERIOD, "..."])
-> ^(parameters_key ^(EXPR expression)+)
;
// $>
parameter
: parameter_name ( in_key | out_key | inout_key | nocopy_key)* type_spec? default_value_part?
-> ^(PARAMETER parameter_name in_key* out_key* inout_key* type_spec? default_value_part?)
;
default_value_part
: (ASSIGN_OP|default_key) expression
-> ^(DEFAULT_VALUE ^(EXPR expression))
;
// $>
// $>
// $<PL/SQL Elements Declarations
declare_spec
options{
backtrack=true;
} : variable_declaration
| subtype_declaration
| cursor_declaration
| exception_declaration
| pragma_declaration
| record_declaration
| table_declaration
| create_procedure_body
| create_function_body
;
//incorporates constant_declaration
variable_declaration
: variable_name constant_key?
type_spec (not_key null_key)?
default_value_part? SEMICOLON
-> ^(VARIABLE_DECLARE variable_name type_spec constant_key? null_key? default_value_part?)
;
subtype_declaration
@init { int mode = 0; }
: subtype_key type_name is_key type_spec
(range_key expression DOUBLE_PERIOD expression {mode = 1;})?
(not_key null_key)? SEMICOLON
-> {mode == 1}? ^(SUBTYPE_DECLARE[$subtype_key.start] type_name type_spec null_key? ^(range_key ^(EXPR expression)+))
-> ^(SUBTYPE_DECLARE[$subtype_key.start] type_name type_spec null_key?)
;
//cursor_declaration incorportates curscursor_body and cursor_spec
cursor_declaration
: cursor_key cursor_name
(LEFT_PAREN parameter_spec (COMMA parameter_spec)* RIGHT_PAREN )?
(return_key type_spec)? (is_key select_statement)? SEMICOLON
-> ^(CURSOR_DECLARE[$cursor_key.start] cursor_name type_spec? select_statement? ^(PARAMETERS parameter_spec*))
;
parameter_spec
: parameter_name (in_key? type_spec)?
default_value_part?
-> ^(PARAMETER parameter_name type_spec? default_value_part?)
;
exception_declaration
: exception_name exception_key SEMICOLON
-> ^(EXCEPTION_DECLARE[$exception_key.start] exception_name)
;
pragma_declaration
@init { int mode = 0; }
: pragma_key
( serially_reusable_key {mode = 1;}
| autonomous_transaction_key {mode = 2;}
| exception_init_key LEFT_PAREN exception_name COMMA numeric RIGHT_PAREN {mode = 3;}
| inline_key LEFT_PAREN id1=id COMMA expression RIGHT_PAREN {mode = 4;}