/
ddl.py
2230 lines (1740 loc) · 56.3 KB
/
ddl.py
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
#
# This source file is part of the EdgeDB open source project.
#
# Copyright 2015-present MagicStack Inc. and the EdgeDB authors.
#
# 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.
#
from __future__ import annotations
import collections
import re
import typing
from edb import errors
from edb.errors import EdgeQLSyntaxError
from edb.edgeql import ast as qlast
from edb.edgeql import qltypes
from edb.common import parsing
from . import expressions
from . import commondl
from .precedence import * # NOQA
from .tokens import * # NOQA
from .commondl import * # NOQA
from .sdl import * # NOQA
ListNonterm = parsing.ListNonterm
Nonterm = expressions.Nonterm
Semicolons = commondl.Semicolons
sdl_nontem_helper = commondl.NewNontermHelper(__name__)
_new_nonterm = sdl_nontem_helper._new_nonterm
class DDLStmt(Nonterm):
def reduce_CreateDatabaseStmt(self, *kids):
self.val = kids[0].val
def reduce_DropDatabaseStmt(self, *kids):
self.val = kids[0].val
def reduce_CreateRoleStmt(self, *kids):
self.val = kids[0].val
def reduce_AlterRoleStmt(self, *kids):
self.val = kids[0].val
def reduce_DropRoleStmt(self, *kids):
self.val = kids[0].val
def reduce_OptWithDDLStmt(self, *kids):
self.val = kids[0].val
def reduce_MigrationStmt(self, *kids):
self.val = kids[0].val
class DDLWithBlock(Nonterm):
def reduce_WithBlock(self, *kids):
self.val = kids[0].val
class OptWithDDLStmt(Nonterm):
def reduce_DDLWithBlock_WithDDLStmt(self, *kids):
self.val = kids[1].val
self.val.aliases = kids[0].val.aliases
def reduce_WithDDLStmt(self, *kids):
self.val = kids[0].val
class WithDDLStmt(Nonterm):
def reduce_InnerDDLStmt(self, *kids):
self.val = kids[0].val
class InnerDDLStmt(Nonterm):
def reduce_CreatePseudoTypeStmt(self, *kids):
self.val = kids[0].val
def reduce_CreateScalarTypeStmt(self, *kids):
self.val = kids[0].val
def reduce_AlterScalarTypeStmt(self, *kids):
self.val = kids[0].val
def reduce_DropScalarTypeStmt(self, *kids):
self.val = kids[0].val
def reduce_CreateAnnotationStmt(self, *kids):
self.val = kids[0].val
def reduce_AlterAnnotationStmt(self, *kids):
self.val = kids[0].val
def reduce_DropAnnotationStmt(self, *kids):
self.val = kids[0].val
def reduce_CreateObjectTypeStmt(self, *kids):
self.val = kids[0].val
def reduce_AlterObjectTypeStmt(self, *kids):
self.val = kids[0].val
def reduce_DropObjectTypeStmt(self, *kids):
self.val = kids[0].val
def reduce_CreateAliasStmt(self, *kids):
self.val = kids[0].val
def reduce_AlterAliasStmt(self, *kids):
self.val = kids[0].val
def reduce_DropAliasStmt(self, *kids):
self.val = kids[0].val
def reduce_CreateConstraintStmt(self, *kids):
self.val = kids[0].val
def reduce_AlterConstraintStmt(self, *kids):
self.val = kids[0].val
def reduce_DropConstraintStmt(self, *kids):
self.val = kids[0].val
def reduce_CreateLinkStmt(self, *kids):
self.val = kids[0].val
def reduce_AlterLinkStmt(self, *kids):
self.val = kids[0].val
def reduce_DropLinkStmt(self, *kids):
self.val = kids[0].val
def reduce_CreatePropertyStmt(self, *kids):
self.val = kids[0].val
def reduce_AlterPropertyStmt(self, *kids):
self.val = kids[0].val
def reduce_DropPropertyStmt(self, *kids):
self.val = kids[0].val
def reduce_CreateModuleStmt(self, *kids):
self.val = kids[0].val
def reduce_AlterModuleStmt(self, *kids):
self.val = kids[0].val
def reduce_DropModuleStmt(self, *kids):
self.val = kids[0].val
def reduce_CreateFunctionStmt(self, *kids):
self.val = kids[0].val
def reduce_AlterFunctionStmt(self, *kids):
self.val = kids[0].val
def reduce_DropFunctionStmt(self, *kids):
self.val = kids[0].val
def reduce_CreateOperatorStmt(self, *kids):
self.val = kids[0].val
def reduce_AlterOperatorStmt(self, *kids):
self.val = kids[0].val
def reduce_DropOperatorStmt(self, *kids):
self.val = kids[0].val
def reduce_CreateCastStmt(self, *kids):
self.val = kids[0].val
def reduce_AlterCastStmt(self, *kids):
self.val = kids[0].val
def reduce_DropCastStmt(self, *kids):
self.val = kids[0].val
class InnerDDLStmtBlock(ListNonterm, element=InnerDDLStmt,
separator=Semicolons):
pass
class PointerName(Nonterm):
def reduce_NodeName(self, *kids):
self.val = kids[0].val
def reduce_DUNDERTYPE(self, *kids):
self.val = qlast.ObjectRef(name=kids[0].val)
class UnqualifiedPointerName(Nonterm):
def reduce_PointerName(self, *kids):
if kids[0].val.module:
raise EdgeQLSyntaxError(
'unexpected fully-qualified name',
context=kids[0].val.context)
self.val = kids[0].val
class ProductionHelper:
def _passthrough(self, cmd):
self.val = cmd.val
def _singleton_list(self, cmd):
self.val = [cmd.val]
def _empty(self):
self.val = []
def _block(self, lbrace, cmdlist, sc2, rbrace):
self.val = cmdlist.val
def _block2(self, lbrace, sc1, cmdlist, sc2, rbrace):
self.val = cmdlist.val
def commands_block(parent, *commands, opt=True):
if parent is None:
parent = ''
clsdict = collections.OrderedDict()
# Command := Command1 | Command2 ...
#
for command in commands:
clsdict['reduce_{}'.format(command.__name__)] = \
ProductionHelper._passthrough
cmd = _new_nonterm(parent + 'Command', clsdict=clsdict)
# CommandsList := Command [; Command ...]
cmdlist = _new_nonterm(parent + 'CommandsList', clsbases=(ListNonterm,),
clskwds=dict(element=cmd, separator=Semicolons))
# CommandsBlock :=
#
# { [ ; ] CommandsList ; }
clsdict = collections.OrderedDict()
clsdict['reduce_LBRACE_' + cmdlist.__name__ + '_OptSemicolons_RBRACE'] = \
ProductionHelper._block
clsdict['reduce_LBRACE_Semicolons_' + cmdlist.__name__ +
'_OptSemicolons_RBRACE'] = \
ProductionHelper._block2
if not opt:
#
# | Command
clsdict['reduce_{}'.format(cmd.__name__)] = \
ProductionHelper._singleton_list
cmdblock = _new_nonterm(parent + 'CommandsBlock', clsdict=clsdict)
# OptCommandsBlock := CommandsBlock | <e>
clsdict = collections.OrderedDict()
clsdict['reduce_{}'.format(cmdblock.__name__)] = \
ProductionHelper._passthrough
clsdict['reduce_empty'] = ProductionHelper._empty
if opt:
_new_nonterm('Opt' + parent + 'CommandsBlock', clsdict=clsdict)
class UsingStmt(Nonterm):
def reduce_USING_ParenExpr(self, *kids):
self.val = qlast.SetSpecialField(
name='expr',
value=kids[1].val
)
class SetFieldStmt(Nonterm):
# field := <expr>
def reduce_SET_Identifier_ASSIGN_Expr(self, *kids):
self.val = qlast.SetField(
name=kids[1].val,
value=kids[3].val,
)
class CreateAnnotationValueStmt(Nonterm):
def reduce_CREATE_ANNOTATION_NodeName_ASSIGN_Expr(self, *kids):
self.val = qlast.CreateAnnotationValue(
name=kids[2].val,
value=kids[4].val,
)
class AlterAnnotationValueStmt(Nonterm):
def reduce_ALTER_ANNOTATION_NodeName_ASSIGN_Expr(self, *kids):
self.val = qlast.AlterAnnotationValue(
name=kids[2].val,
value=kids[4].val,
)
class DropAnnotationValueStmt(Nonterm):
def reduce_DROP_ANNOTATION_NodeName(self, *kids):
self.val = qlast.DropAnnotationValue(
name=kids[2].val,
)
class RenameStmt(Nonterm):
def reduce_RENAME_TO_NodeName(self, *kids):
self.val = qlast.Rename(new_name=kids[2].val)
commands_block(
'Create',
UsingStmt,
SetFieldStmt,
CreateAnnotationValueStmt,
AlterAnnotationValueStmt,
)
commands_block(
'Alter',
UsingStmt,
RenameStmt,
SetFieldStmt,
CreateAnnotationValueStmt,
AlterAnnotationValueStmt,
DropAnnotationValueStmt,
opt=False)
class AlterAbstract(Nonterm):
def reduce_DROP_ABSTRACT(self, *kids):
self.val = qlast.SetSpecialField(
name='is_abstract', value=False)
def reduce_SET_ABSTRACT(self, *kids):
self.val = qlast.SetSpecialField(
name='is_abstract', value=True)
class AlterFinal(Nonterm):
def reduce_DROP_FINAL(self, *kids):
self.val = qlast.SetSpecialField(
name='is_final', value=False)
def reduce_SET_FINAL(self, *kids):
self.val = qlast.SetSpecialField(
name='is_final', value=True)
class OptInheritPosition(Nonterm):
def reduce_BEFORE_NodeName(self, *kids):
self.val = qlast.Position(ref=kids[1].val, position='BEFORE')
def reduce_AFTER_NodeName(self, *kids):
self.val = qlast.Position(ref=kids[1].val, position='AFTER')
def reduce_FIRST(self, *kids):
self.val = qlast.Position(position='FIRST')
def reduce_LAST(self, *kids):
self.val = qlast.Position(position='LAST')
def reduce_empty(self, *kids):
self.val = None
class AlterSimpleExtending(Nonterm):
def reduce_EXTENDING_SimpleTypeNameList_OptInheritPosition(self, *kids):
self.val = qlast.AlterAddInherit(bases=kids[1].val,
position=kids[2].val)
def reduce_DROP_EXTENDING_SimpleTypeNameList(self, *kids):
self.val = qlast.AlterDropInherit(bases=kids[2].val)
def reduce_AlterAbstract(self, *kids):
self.val = kids[0].val
def reduce_AlterFinal(self, *kids):
self.val = kids[0].val
class AlterExtending(Nonterm):
def reduce_EXTENDING_TypeNameList_OptInheritPosition(self, *kids):
self.val = qlast.AlterAddInherit(bases=kids[1].val,
position=kids[2].val)
def reduce_DROP_EXTENDING_TypeNameList(self, *kids):
self.val = qlast.AlterDropInherit(bases=kids[2].val)
def reduce_AlterAbstract(self, *kids):
self.val = kids[0].val
def reduce_AlterFinal(self, *kids):
self.val = kids[0].val
commands_block(
'CreateDatabase',
SetFieldStmt,
)
#
# CREATE DATABASE
#
class CreateDatabaseStmt(Nonterm):
def reduce_CREATE_DATABASE_AnyNodeName_OptCreateRoleCommandsBlock(
self,
*kids,
):
self.val = qlast.CreateDatabase(name=kids[2].val, commands=kids[3].val)
#
# DROP DATABASE
#
class DropDatabaseStmt(Nonterm):
def reduce_DROP_DATABASE_AnyNodeName(self, *kids):
self.val = qlast.DropDatabase(name=kids[2].val)
#
# CREATE ROLE
#
class ShortExtending(Nonterm):
def reduce_EXTENDING_ShortNodeNameList(self, *kids):
self.val = [qlast.TypeName(maintype=v) for v in kids[1].val]
class OptShortExtending(Nonterm):
def reduce_ShortExtending(self, *kids):
self.val = kids[0].val
def reduce_empty(self, *kids):
self.val = []
commands_block(
'CreateRole',
SetFieldStmt,
)
class OptSuperuser(Nonterm):
def reduce_SUPERUSER(self, *kids):
self.val = True
def reduce_empty(self, *kids):
self.val = False
class CreateRoleStmt(Nonterm):
def reduce_CreateRoleStmt(self, *kids):
r"""%reduce CREATE OptSuperuser ROLE ShortNodeName
OptShortExtending OptCreateRoleCommandsBlock
"""
self.val = qlast.CreateRole(
name=kids[3].val,
bases=kids[4].val,
commands=kids[5].val,
superuser=kids[1].val,
)
#
# ALTER ROLE
#
class AlterRoleExtending(Nonterm):
def reduce_EXTENDING_ShortNodeNameList_OptInheritPosition(self, *kids):
self.val = qlast.AlterAddInherit(
bases=[qlast.TypeName(maintype=b) for b in kids[1].val],
position=kids[2].val)
def reduce_DROP_EXTENDING_ShortNodeNameList(self, *kids):
self.val = qlast.AlterDropInherit(
bases=[qlast.TypeName(maintype=b) for b in kids[2].val])
commands_block(
'AlterRole',
RenameStmt,
SetFieldStmt,
AlterRoleExtending,
opt=False
)
class AlterRoleStmt(Nonterm):
def reduce_ALTER_ROLE_ShortNodeName_AlterRoleCommandsBlock(self, *kids):
self.val = qlast.AlterRole(
name=kids[2].val,
commands=kids[3].val,
)
#
# DROP ROLE
#
class DropRoleStmt(Nonterm):
def reduce_DROP_ROLE_ShortNodeName(self, *kids):
self.val = qlast.DropRole(
name=kids[2].val,
)
#
# CREATE CONSTRAINT
#
class CreateConstraintStmt(Nonterm):
def reduce_CreateConstraint(self, *kids):
r"""%reduce CREATE ABSTRACT CONSTRAINT NodeName OptOnExpr \
OptExtendingSimple OptCreateCommandsBlock"""
self.val = qlast.CreateConstraint(
name=kids[3].val,
subjectexpr=kids[4].val,
bases=kids[5].val,
commands=kids[6].val,
)
def reduce_CreateConstraint_CreateFunctionArgs(self, *kids):
r"""%reduce CREATE ABSTRACT CONSTRAINT NodeName CreateFunctionArgs \
OptOnExpr OptExtendingSimple OptCreateCommandsBlock"""
self.val = qlast.CreateConstraint(
name=kids[3].val,
params=kids[4].val,
subjectexpr=kids[5].val,
bases=kids[6].val,
commands=kids[7].val,
)
class AlterConstraintStmt(Nonterm):
def reduce_CreateConstraint(self, *kids):
r"""%reduce ALTER ABSTRACT CONSTRAINT NodeName \
AlterCommandsBlock"""
self.val = qlast.AlterConstraint(
name=kids[3].val,
commands=kids[4].val,
)
class DropConstraintStmt(Nonterm):
def reduce_CreateConstraint(self, *kids):
r"""%reduce DROP ABSTRACT CONSTRAINT NodeName"""
self.val = qlast.DropConstraint(
name=kids[3].val
)
class OptDelegated(Nonterm):
def reduce_DELEGATED(self, *kids):
self.val = True
def reduce_empty(self):
self.val = False
class CreateConcreteConstraintStmt(Nonterm):
def reduce_CreateConstraint(self, *kids):
r"""%reduce CREATE OptDelegated CONSTRAINT \
NodeName OptConcreteConstraintArgList OptOnExpr \
OptCreateCommandsBlock"""
self.val = qlast.CreateConcreteConstraint(
delegated=kids[1].val,
name=kids[3].val,
args=kids[4].val,
subjectexpr=kids[5].val,
commands=kids[6].val,
)
class SetDelegatedStmt(Nonterm):
def reduce_SET_DELEGATED(self, *kids):
self.val = qlast.SetSpecialField(
name='delegated',
value=True,
)
def reduce_DROP_DELEGATED(self, *kids):
self.val = qlast.SetSpecialField(
name='delegated',
value=False,
)
class AlterConstraintOwned(Nonterm):
def reduce_DROP_OWNED(self, *kids):
self.val = qlast.AlterConstraintOwned(owned=False)
def reduce_SET_OWNED(self, *kids):
self.val = qlast.AlterConstraintOwned(owned=True)
commands_block(
'AlterConcreteConstraint',
RenameStmt,
SetFieldStmt,
SetDelegatedStmt,
AlterConstraintOwned,
CreateAnnotationValueStmt,
AlterAnnotationValueStmt,
DropAnnotationValueStmt,
AlterAbstract,
opt=False
)
class AlterConcreteConstraintStmt(Nonterm):
def reduce_CreateConstraint(self, *kids):
r"""%reduce ALTER CONSTRAINT NodeName
OptConcreteConstraintArgList OptOnExpr
AlterConcreteConstraintCommandsBlock"""
self.val = qlast.AlterConcreteConstraint(
name=kids[2].val,
args=kids[3].val,
subjectexpr=kids[4].val,
commands=kids[5].val,
)
class DropConcreteConstraintStmt(Nonterm):
def reduce_DropConstraint(self, *kids):
r"""%reduce DROP CONSTRAINT NodeName
OptConcreteConstraintArgList OptOnExpr"""
self.val = qlast.DropConcreteConstraint(
name=kids[2].val,
args=kids[3].val,
subjectexpr=kids[4].val,
)
#
# CREATE PSEUDO TYPE
#
commands_block(
'CreatePseudoType',
SetFieldStmt,
CreateAnnotationValueStmt,
AlterAnnotationValueStmt,
)
class CreatePseudoTypeStmt(Nonterm):
def reduce_CreatePseudoTypeStmt(self, *kids):
r"""%reduce
CREATE PSEUDO TYPE NodeName OptCreatePseudoTypeCommandsBlock
"""
self.val = qlast.CreatePseudoType(
name=kids[3].val,
commands=kids[4].val,
)
#
# CREATE SCALAR TYPE
#
commands_block(
'CreateScalarType',
SetFieldStmt,
CreateAnnotationValueStmt,
AlterAnnotationValueStmt,
CreateConcreteConstraintStmt)
class CreateScalarTypeStmt(Nonterm):
def reduce_CreateAbstractScalarTypeStmt(self, *kids):
r"""%reduce \
CREATE ABSTRACT SCALAR TYPE NodeName \
OptExtending OptCreateScalarTypeCommandsBlock \
"""
self.val = qlast.CreateScalarType(
name=kids[4].val,
is_abstract=True,
bases=kids[5].val,
commands=kids[6].val
)
def reduce_CreateFinalScalarTypeStmt(self, *kids):
r"""%reduce \
CREATE FINAL SCALAR TYPE NodeName \
OptExtending OptCreateScalarTypeCommandsBlock \
"""
self.val = qlast.CreateScalarType(
name=kids[4].val,
is_final=True,
bases=kids[5].val,
commands=kids[6].val
)
def reduce_CreateScalarTypeStmt(self, *kids):
r"""%reduce \
CREATE SCALAR TYPE NodeName \
OptExtending OptCreateScalarTypeCommandsBlock \
"""
self.val = qlast.CreateScalarType(
name=kids[3].val,
bases=kids[4].val,
commands=kids[5].val
)
#
# ALTER SCALAR TYPE
#
commands_block(
'AlterScalarType',
RenameStmt,
SetFieldStmt,
CreateAnnotationValueStmt,
AlterAnnotationValueStmt,
DropAnnotationValueStmt,
AlterExtending,
CreateConcreteConstraintStmt,
AlterConcreteConstraintStmt,
DropConcreteConstraintStmt,
opt=False
)
class AlterScalarTypeStmt(Nonterm):
def reduce_AlterScalarTypeStmt(self, *kids):
r"""%reduce \
ALTER SCALAR TYPE NodeName \
AlterScalarTypeCommandsBlock \
"""
self.val = qlast.AlterScalarType(
name=kids[3].val,
commands=kids[4].val
)
class DropScalarTypeStmt(Nonterm):
def reduce_DROP_SCALAR_TYPE_NodeName(self, *kids):
self.val = qlast.DropScalarType(
name=kids[3].val
)
#
# CREATE ANNOTATION
#
commands_block(
'CreateAnnotation',
CreateAnnotationValueStmt,
)
class CreateAnnotationStmt(Nonterm):
def reduce_CreateAnnotation(self, *kids):
r"""%reduce CREATE ABSTRACT ANNOTATION NodeName \
OptCreateAnnotationCommandsBlock"""
self.val = qlast.CreateAnnotation(
name=kids[3].val,
commands=kids[4].val,
inheritable=False,
)
def reduce_CreateInheritableAnnotation(self, *kids):
r"""%reduce CREATE ABSTRACT INHERITABLE ANNOTATION
NodeName OptCreateCommandsBlock"""
self.val = qlast.CreateAnnotation(
name=kids[4].val,
commands=kids[5].val,
inheritable=True,
)
#
# ALTER ANNOTATION
#
commands_block(
'AlterAnnotation',
RenameStmt,
CreateAnnotationValueStmt,
AlterAnnotationValueStmt,
DropAnnotationValueStmt,
opt=False,
)
class AlterAnnotationStmt(Nonterm):
def reduce_AlterAnnotation(self, *kids):
r"""%reduce ALTER ABSTRACT ANNOTATION NodeName \
AlterAnnotationCommandsBlock"""
self.val = qlast.AlterAnnotation(
name=kids[3].val,
commands=kids[4].val
)
#
# DROP ANNOTATION
#
class DropAnnotationStmt(Nonterm):
def reduce_DropAnnotation(self, *kids):
r"""%reduce DROP ABSTRACT ANNOTATION NodeName"""
self.val = qlast.DropAnnotation(
name=kids[3].val,
)
class AlterIndexOwned(Nonterm):
def reduce_DROP_OWNED(self, *kids):
self.val = qlast.AlterIndexOwned(owned=False)
def reduce_SET_OWNED(self, *kids):
self.val = qlast.AlterIndexOwned(owned=True)
commands_block(
'AlterIndex',
SetFieldStmt,
AlterIndexOwned,
CreateAnnotationValueStmt,
AlterAnnotationValueStmt,
DropAnnotationValueStmt,
opt=False)
#
# CREATE INDEX
#
class CreateIndexStmt(Nonterm):
def reduce_CREATE_INDEX_OnExpr_OptCreateCommandsBlock(self, *kids):
self.val = qlast.CreateIndex(
name=qlast.ObjectRef(name='idx'),
expr=kids[2].val,
commands=kids[3].val,
)
#
# ALTER INDEX
#
class AlterIndexStmt(Nonterm):
def reduce_ALTER_INDEX_OnExpr_AlterIndexCommandsBlock(self, *kids):
self.val = qlast.AlterIndex(
name=qlast.ObjectRef(name='idx'),
expr=kids[2].val,
commands=kids[3].val,
)
commands_block(
'DropIndex',
SetFieldStmt,
opt=True,
)
#
# DROP INDEX
#
class DropIndexStmt(Nonterm):
def reduce_DROP_INDEX_OnExpr_OptDropIndexCommandsBlock(self, *kids):
self.val = qlast.DropIndex(
name=qlast.ObjectRef(name='idx'),
expr=kids[2].val,
commands=kids[3].val,
)
class SetPropertyTypeStmt(Nonterm):
def reduce_SETTYPE_FullTypeExpr(self, *kids):
self.val = qlast.SetPropertyType(type=kids[1].val)
class SetLinkTypeStmt(Nonterm):
def reduce_SETTYPE_FullTypeExpr(self, *kids):
self.val = qlast.SetLinkType(type=kids[1].val)
#
# CREATE PROPERTY
#
class CreatePropertyStmt(Nonterm):
def reduce_CreateProperty(self, *kids):
r"""%reduce CREATE ABSTRACT PROPERTY NodeName OptExtendingSimple \
OptCreateCommandsBlock \
"""
self.val = qlast.CreateProperty(
name=kids[3].val,
bases=kids[4].val,
commands=kids[5].val
)
#
# ALTER PROPERTY
#
commands_block(
'AlterProperty',
RenameStmt,
SetFieldStmt,
CreateAnnotationValueStmt,
AlterAnnotationValueStmt,
DropAnnotationValueStmt,
opt=False
)
class AlterPropertyStmt(Nonterm):
def reduce_AlterProperty(self, *kids):
r"""%reduce \
ALTER ABSTRACT PROPERTY NodeName \
AlterPropertyCommandsBlock \
"""
self.val = qlast.AlterProperty(
name=kids[3].val,
commands=kids[4].val
)
#
# DROP PROPERTY
#
class DropPropertyStmt(Nonterm):
def reduce_DropProperty(self, *kids):
r"""%reduce DROP ABSTRACT PROPERTY NodeName"""
self.val = qlast.DropProperty(
name=kids[3].val
)
#
# CREATE LINK ... { CREATE PROPERTY
#
commands_block(
'CreateConcreteProperty',
UsingStmt,
SetFieldStmt,
CreateAnnotationValueStmt,
AlterAnnotationValueStmt,
CreateConcreteConstraintStmt
)
class CreateConcretePropertyStmt(Nonterm):
def reduce_CreateRegularProperty(self, *kids):
"""%reduce
CREATE OptPtrQuals PROPERTY UnqualifiedPointerName
OptExtendingSimple ARROW FullTypeExpr
OptCreateConcretePropertyCommandsBlock
"""
self.val = qlast.CreateConcreteProperty(
name=kids[3].val,
bases=kids[4].val,
is_required=kids[1].val.required,
cardinality=kids[1].val.cardinality,
target=kids[6].val,
commands=kids[7].val,
)
def reduce_CreateComputableProperty(self, *kids):
"""%reduce
CREATE OptPtrQuals PROPERTY UnqualifiedPointerName ASSIGN Expr
"""
self.val = qlast.CreateConcreteProperty(
name=kids[3].val,
is_required=kids[1].val.required,
cardinality=kids[1].val.cardinality,
target=kids[5].val,
)
def reduce_CreateComputablePropertyWithUsing(self, *kids):
"""%reduce
CREATE OptPtrQuals PROPERTY UnqualifiedPointerName
OptCreateConcretePropertyCommandsBlock
"""
cmds = kids[4].val
new_cmds = []
target = None
for cmd in cmds: