myrtille 0.1.0__py3-none-any.whl → 0.1.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1093 @@
1
+ import dataclasses
2
+ import pathlib
3
+ import typing
4
+
5
+ import lark
6
+ import pydantic
7
+
8
+ from myrtille.mysql import types
9
+
10
+ GRAMMAR_FILE = pathlib.Path(__file__).parent / 'grammar.lark'
11
+ GRAMMAR_START = 'create_table'
12
+
13
+
14
+ Terminal: typing.TypeAlias = lark.lexer.Token
15
+ Meta: typing.TypeAlias = lark.tree.Meta
16
+
17
+
18
+ def v_args[R, **P](
19
+ inline: bool = False, meta: bool = False
20
+ ) -> typing.Callable[[typing.Callable[P, R]], typing.Callable[P, R]]:
21
+ # type ignore because original lark.v_args typing does not work
22
+ return lark.v_args(inline=inline, meta=meta, tree=False) # type: ignore
23
+
24
+
25
+ def inline[R, **P](f: typing.Callable[P, R]) -> typing.Callable[P, R]:
26
+ return v_args(inline=True)(f)
27
+
28
+
29
+ def get_child[R](children: typing.Sequence[R], *, position: int | None) -> R:
30
+ if position is None:
31
+ assert len(children) == 1
32
+ return children[0]
33
+ else:
34
+ return children[position]
35
+
36
+
37
+ def through(position: int | None = None):
38
+ def _handler(self: typing.Any, children: typing.Sequence[typing.Any]):
39
+ return get_child(children, position=position)
40
+
41
+ return _handler
42
+
43
+
44
+ def list_(self: typing.Any, children: list[typing.Any]):
45
+ return children
46
+
47
+
48
+ def wrap_pydantic(model: type[pydantic.BaseModel], position: int | None = None):
49
+ field_name = next(iter(model.model_fields))
50
+
51
+ def _handler(self: typing.Any, children: typing.Sequence[typing.Any]):
52
+ return model(**{field_name: get_child(children, position=position)})
53
+
54
+ return _handler
55
+
56
+
57
+ def call(f: typing.Callable[[Terminal], typing.Any]):
58
+ @inline
59
+ def _handler(self: typing.Any, child: Terminal):
60
+ return f(child)
61
+
62
+ return _handler
63
+
64
+
65
+ def const(v: typing.Any):
66
+ def _handler(self: typing.Any, children: typing.Any):
67
+ return v
68
+
69
+ return _handler
70
+
71
+
72
+ def const_call(f: typing.Callable[[], typing.Any]):
73
+ def _handler(self: typing.Any, children: typing.Any):
74
+ return f()
75
+
76
+ return _handler
77
+
78
+
79
+ class Transformer(lark.Transformer[typing.Any, types.Table]):
80
+ def __init__(self, original_text: str, visit_tokens: bool = True) -> None:
81
+ self.original_text = original_text
82
+
83
+ super().__init__(visit_tokens)
84
+
85
+ ### Main
86
+
87
+ @inline
88
+ def column_definition(self, name: str, data_type: types.DataType, *attributes: types.Attribute):
89
+ column = types.Column(
90
+ name=name,
91
+ data_type=data_type,
92
+ non_nullable=None,
93
+ default_value=None,
94
+ comment=None,
95
+ invisible=False,
96
+ format=types.ColumnFormat.DEFAULT,
97
+ storage_media=types.StorageMedia.DEFAULT,
98
+ generated=None,
99
+ )
100
+ for attribute in attributes:
101
+ match attribute:
102
+ case types.NonNullableAttribute():
103
+ column.non_nullable = True
104
+ case types.NullableAttribute():
105
+ column.non_nullable = False
106
+ case types.LiteralDefaultAttribute():
107
+ column.default_value = attribute
108
+ case types.ExprDefaultAttribute():
109
+ column.default_value = attribute
110
+ case types.NowDefaultAttribute():
111
+ assert isinstance(column.data_type, (types.Datetime, types.Timestamp))
112
+ column.data_type.default_now = True
113
+ case types.GeneratedAttribute():
114
+ column.generated = attribute
115
+ case types.OnUpdateNowAttribute():
116
+ assert isinstance(column.data_type, (types.Datetime, types.Timestamp))
117
+ column.data_type.on_update_now = True
118
+ case types.CommentAttribute():
119
+ column.comment = attribute.comment.text
120
+ case types.ColumnFormat():
121
+ column.format = attribute
122
+ case types.StorageMedia():
123
+ column.storage_media = attribute
124
+ case types.InvisibleAttribute():
125
+ column.invisible = True
126
+ case types.AutoIncrementAttribute():
127
+ assert isinstance(column.data_type, types.IntegerDataType)
128
+ column.data_type.auto_increment = True
129
+ case types.UnsignedAttribute():
130
+ assert isinstance(column.data_type, types.IntegerDataType)
131
+ column.data_type.unsigned = True
132
+ case types.CharsetAttribute():
133
+ assert isinstance(column.data_type, types.TextDataType)
134
+ if isinstance(attribute.charset, types.BinaryCharset):
135
+ column.data_type.charset = 'binary'
136
+ else:
137
+ column.data_type.charset = attribute.charset
138
+ case types.CollateAttribute():
139
+ assert isinstance(column.data_type, types.TextDataType)
140
+ column.data_type.collate = attribute.collate
141
+ case types.SridAttribute():
142
+ assert isinstance(column.data_type, types.SpatialDataType)
143
+ column.data_type.srid = attribute.srid
144
+ return column
145
+
146
+ table_element = through()
147
+ table_element_list = list_
148
+
149
+ @inline
150
+ def create_table(
151
+ self,
152
+ name: str,
153
+ elements: list[types.Column | types.Constraint],
154
+ options: types.CreateOptions,
155
+ partitioning: types.Partitioning | None,
156
+ ):
157
+ return types.Table(
158
+ name=name,
159
+ columns=[e for e in elements if isinstance(e, types.Column)],
160
+ constraints=[e for e in elements if isinstance(e, types.Constraint)],
161
+ options=options,
162
+ partitioning=partitioning,
163
+ )
164
+
165
+ ### Types
166
+
167
+ tinyint_data_type = const_call(lambda: types.Tinyint(unsigned=False, auto_increment=False))
168
+ smallint_data_type = const_call(lambda: types.Smallint(unsigned=False, auto_increment=False))
169
+ mediumint_data_type = const_call(lambda: types.Mediumint(unsigned=False, auto_increment=False))
170
+ int_data_type = const_call(lambda: types.Int(unsigned=False, auto_increment=False))
171
+ bigint_data_type = const_call(lambda: types.Bigint(unsigned=False, auto_increment=False))
172
+
173
+ @inline
174
+ def fixed_point_data_type(self, _: typing.Any, args: tuple[int, int]):
175
+ return types.Decimal(precision=args[0], scale=args[1])
176
+
177
+ float_data_type = const_call(types.Float)
178
+ double_data_type = const_call(types.Double)
179
+
180
+ @inline
181
+ def bit_data_type(self, length: int | None):
182
+ return types.Bit(length=length or 1)
183
+
184
+ @inline
185
+ def datetime_data_type(self, precision: int | None):
186
+ return types.Datetime(precision=precision, default_now=False, on_update_now=False)
187
+
188
+ @inline
189
+ def timestamp_data_type(self, precision: int | None):
190
+ return types.Timestamp(precision=precision, default_now=False, on_update_now=False)
191
+
192
+ date_data_type = const_call(types.Date)
193
+
194
+ @inline
195
+ def time_data_type(self, precision: int | None):
196
+ return types.Time(precision=precision)
197
+
198
+ year_data_type = const_call(types.Year)
199
+
200
+ @inline
201
+ def char_data_type(self, _char: Terminal, length: int | None):
202
+ return types.Char(length=length or 1, charset=None, collate=None)
203
+
204
+ @inline
205
+ def varchar_data_type(self, _char: Terminal, length: int):
206
+ return types.Varchar(length=length, charset=None, collate=None)
207
+
208
+ @inline
209
+ def binary_data_type(self, _: Terminal, length: int | None):
210
+ return types.Binary(length=length or 1)
211
+
212
+ @inline
213
+ def varbinary_data_type(self, length: int):
214
+ return types.Varbinary(length=length)
215
+
216
+ tinytext_data_type = const_call(lambda: types.TinyText(charset=None, collate=None))
217
+ text_data_type = const_call(lambda: types.Text(charset=None, collate=None))
218
+ mediumtext_data_type = const_call(lambda: types.MediumText(charset=None, collate=None))
219
+ longtext_data_type = const_call(lambda: types.LongText(charset=None, collate=None))
220
+ tinyblob_data_type = const_call(types.TinyBlob)
221
+ blob_data_type = const_call(types.Blob)
222
+ mediumblob_data_type = const_call(types.MediumBlob)
223
+ longblob_data_type = const_call(types.LongBlob)
224
+
225
+ @inline
226
+ def enum_data_type(self, values: list[str]):
227
+ return types.Enum(values=values, charset=None, collate=None)
228
+
229
+ @inline
230
+ def set_data_type(self, values: list[str]):
231
+ return types.Set(values=values, charset=None, collate=None)
232
+
233
+ geometry_data_type = const_call(lambda: types.Geometry(srid=None))
234
+ point_data_type = const_call(lambda: types.Point(srid=None))
235
+ linestring_data_type = const_call(lambda: types.Linestring(srid=None))
236
+ polygon_data_type = const_call(lambda: types.Polygon(srid=None))
237
+ geometrycollection_data_type = const_call(lambda: types.Geometrycollection(srid=None))
238
+ multipoint_data_type = const_call(lambda: types.Multipoint(srid=None))
239
+ multilinestring_data_type = const_call(lambda: types.Multilinestring(srid=None))
240
+ multipolygon_data_type = const_call(lambda: types.Multipolygon(srid=None))
241
+
242
+ json_data_type = const_call(types.Json)
243
+
244
+ ### Attributes
245
+
246
+ virtual_generation_type = const(types.GenerationType.VIRTUAL)
247
+ stored_generation_type = const(types.GenerationType.STORED)
248
+
249
+ non_nullable_attribute = const_call(types.NonNullableAttribute)
250
+ nullable_attribute = const_call(types.NullableAttribute)
251
+ literal_default_attribute = wrap_pydantic(types.LiteralDefaultAttribute)
252
+ expr_default_attribute = wrap_pydantic(types.ExprDefaultAttribute)
253
+ now_default_attribute = const_call(types.NowDefaultAttribute)
254
+
255
+ @inline
256
+ def generated_attribute(self, expr: str, type: types.GenerationType | None):
257
+ return types.GeneratedAttribute(
258
+ expr=expr, type=type if type is not None else types.GenerationType.VIRTUAL
259
+ )
260
+
261
+ on_update_attribute = const_call(types.OnUpdateNowAttribute)
262
+ comment_attribute = wrap_pydantic(types.CommentAttribute)
263
+
264
+ dynamic_column_format = const(types.ColumnFormat.DYNAMIC)
265
+ fixed_column_format = const(types.ColumnFormat.FIXED)
266
+ column_format_attribute = through()
267
+
268
+ disk_storage_media = const(types.StorageMedia.DISK)
269
+ memory_storage_media = const(types.StorageMedia.MEMORY)
270
+ storage_attribute = through()
271
+
272
+ auto_increment_attribute = const_call(types.AutoIncrementAttribute)
273
+ unsigned_attribute = const_call(types.UnsignedAttribute)
274
+
275
+ charset_attribute = wrap_pydantic(types.CharsetAttribute, position=1)
276
+ collate_attribute = wrap_pydantic(types.CollateAttribute)
277
+
278
+ custom_charset = through()
279
+ binary_charset = const_call(types.BinaryCharset)
280
+
281
+ invisible_attribute = const_call(types.InvisibleAttribute)
282
+ srid_attribute = wrap_pydantic(types.SridAttribute)
283
+
284
+ ### Constraints
285
+
286
+ @inline
287
+ def identifier_key_part(
288
+ self, identifier: str, length: int | None, direction: types.Direction | None
289
+ ):
290
+ return types.IdentifierKeyPart(identifier=identifier, length=length, direction=direction)
291
+
292
+ constraint_name = through()
293
+
294
+ btree_index_type = const(types.IndexType.BTREE)
295
+ rtree_index_type = const(types.IndexType.RTREE)
296
+ hash_index_type = const(types.IndexType.HASH)
297
+ index_type_clause = through()
298
+ type_index_option = through()
299
+
300
+ restrict_ref_action = const(types.RefAction.RESTRICT)
301
+ cascade_ref_action = const(types.RefAction.CASCADE)
302
+ set_null_ref_action = const(types.RefAction.SET_NULL)
303
+ no_action_ref_action = const(None)
304
+
305
+ on_delete_ref_rule = wrap_pydantic(types.OnDeleteRefRule)
306
+ on_update_ref_rule = wrap_pydantic(types.OnUpdateRefRule)
307
+
308
+ @inline
309
+ def primary_constraint(
310
+ self,
311
+ _constraint_name: str | None,
312
+ _name: str | None,
313
+ index_type_clause: types.IndexType | None,
314
+ key_list: list[types.KeyPart],
315
+ *index_options: typing.Any,
316
+ ):
317
+ return types.PrimaryConstraint(
318
+ type=index_type_clause,
319
+ key_list=key_list,
320
+ options=types.IndexOptions(key_block_size=None, comment=None, invisible=False),
321
+ )
322
+
323
+ @inline
324
+ def unique_constraint(
325
+ self,
326
+ constraint_name: str | None,
327
+ _key_or_index: typing.Any,
328
+ name: str | None,
329
+ index_type_clause: types.IndexType | None,
330
+ key_list: list[types.KeyPart],
331
+ *index_options: typing.Any,
332
+ ):
333
+ return types.UniqueConstraint(
334
+ name=(name if name is not None else constraint_name),
335
+ type=index_type_clause,
336
+ key_list=key_list,
337
+ options=types.IndexOptions(key_block_size=None, comment=None, invisible=False),
338
+ )
339
+
340
+ @inline
341
+ def index_constraint(
342
+ self,
343
+ _key_or_index: typing.Any,
344
+ name: str | None,
345
+ index_type_clause: types.IndexType | None,
346
+ key_list: list[types.KeyPart],
347
+ *index_options: typing.Any,
348
+ ):
349
+ return types.IndexConstraint(
350
+ name=name,
351
+ type=index_type_clause,
352
+ key_list=key_list,
353
+ options=types.IndexOptions(key_block_size=None, comment=None, invisible=False),
354
+ )
355
+
356
+ @inline
357
+ def fulltext_constraint(
358
+ self,
359
+ _key_or_index: typing.Any,
360
+ name: str | None,
361
+ key_list: list[types.KeyPart],
362
+ *index_option: typing.Any,
363
+ ):
364
+ return types.FulltextConstraint(
365
+ name=name,
366
+ key_list=key_list,
367
+ parser=None,
368
+ options=types.IndexOptions(key_block_size=None, comment=None, invisible=False),
369
+ )
370
+
371
+ @inline
372
+ def spatial_constraint(
373
+ self,
374
+ _key_or_index: typing.Any,
375
+ name: str | None,
376
+ key_list: list[types.KeyPart],
377
+ *index_option: typing.Any,
378
+ ):
379
+ return types.SpatialConstraint(
380
+ name=name,
381
+ key_list=key_list,
382
+ options=types.IndexOptions(key_block_size=None, comment=None, invisible=False),
383
+ )
384
+
385
+ @inline
386
+ def references(
387
+ self,
388
+ ref_table: str,
389
+ ref_columns: list[str] | None,
390
+ _match: typing.Any,
391
+ *ref_rules: types.RefRule,
392
+ ):
393
+ on_update = None
394
+ on_delete = None
395
+ for ref_rule in ref_rules:
396
+ if isinstance(ref_rule, types.OnUpdateRefRule):
397
+ on_update = ref_rule.action
398
+ else:
399
+ on_delete = ref_rule.action
400
+ return types.References(
401
+ ref_table=ref_table,
402
+ ref_columns=ref_columns or [],
403
+ on_update=on_update,
404
+ on_delete=on_delete,
405
+ )
406
+
407
+ @inline
408
+ def foreign_contraint(
409
+ self,
410
+ constraint_name: str | None,
411
+ name: str | None,
412
+ key_list: list[types.KeyPart],
413
+ references: types.References,
414
+ ):
415
+ return types.ForeignConstraint(
416
+ name=name if name is not None else constraint_name,
417
+ columns=[k.identifier for k in key_list],
418
+ references=references,
419
+ )
420
+
421
+ @inline
422
+ def check_contraint(
423
+ self,
424
+ constraint_name: str | None,
425
+ expr: str,
426
+ enforcement: types.ConstraintEnforcement | None,
427
+ ):
428
+ return types.CheckConstraint(
429
+ name=constraint_name,
430
+ expr=expr,
431
+ enforcement=enforcement
432
+ if enforcement is not None
433
+ else types.ConstraintEnforcement.ENFORCED,
434
+ )
435
+
436
+ ### Create Options
437
+
438
+ zero_ternary_option = const(False)
439
+ one_ternary_option = const(True)
440
+ default_row_format = const(types.Rowformat.DEFAULT)
441
+ dynamic_row_format = const(types.Rowformat.DYNAMIC)
442
+ fixed_row_format = const(types.Rowformat.FIXED)
443
+ compressed_row_format = const(types.Rowformat.COMPRESSED)
444
+ redundant_row_format = const(types.Rowformat.REDUNDANT)
445
+ compact_row_format = const(types.Rowformat.COMPACT)
446
+
447
+ engine_create_option = wrap_pydantic(types.EngineCreateOption)
448
+ secondary_engine_create_option = wrap_pydantic(types.SecondaryEngineCreateOption)
449
+ avg_row_length_create_option = wrap_pydantic(types.AvgRowLength)
450
+ comment_create_option = wrap_pydantic(types.CommentCreateOption)
451
+ auto_increment_create_option = wrap_pydantic(types.AutoIncrementCreateOption)
452
+ stats_persistent_create_option = wrap_pydantic(types.StatsPersistentCreateOption)
453
+ row_format_create_option = wrap_pydantic(types.RowFormatCreateOption)
454
+ charset_create_option = wrap_pydantic(types.CharsetCreateOption, position=1)
455
+ collate_create_option = wrap_pydantic(types.CollateCreateOption)
456
+ tablespace_create_option = wrap_pydantic(types.TablespaceCreateOption)
457
+
458
+ def create_table_options(self, options: list[types.CreateOption]):
459
+ create_options = types.CreateOptions(
460
+ engine=None,
461
+ secondary_engine=None,
462
+ max_rows=None,
463
+ min_rows=None,
464
+ avg_row_length=None,
465
+ password=None,
466
+ comment=None,
467
+ compression=None,
468
+ encryption=None,
469
+ auto_increment=None,
470
+ pack_keys=None,
471
+ stats_auto_recalc=None,
472
+ stats_persistent=None,
473
+ stats_sample_pages=None,
474
+ checksum=None,
475
+ delay_key_write=None,
476
+ row_format=None,
477
+ union=None,
478
+ charset=None,
479
+ collate=None,
480
+ insert_method=None,
481
+ data_directory=None,
482
+ index_directory=None,
483
+ tablespace=None,
484
+ storage=None,
485
+ connection=None,
486
+ key_block_size=None,
487
+ )
488
+ for option in options:
489
+ match option:
490
+ case types.EngineCreateOption():
491
+ create_options.engine = option.name
492
+ case types.SecondaryEngineCreateOption():
493
+ create_options.secondary_engine = option.name
494
+ case types.AvgRowLength():
495
+ create_options.avg_row_length = option.length
496
+ case types.AutoIncrementCreateOption():
497
+ create_options.auto_increment = option.value
498
+ case types.CommentCreateOption():
499
+ create_options.comment = option.comment.text
500
+ case types.StatsPersistentCreateOption():
501
+ create_options.stats_persistent = option.option
502
+ case types.RowFormatCreateOption():
503
+ create_options.row_format = option.format
504
+ case types.CharsetCreateOption():
505
+ if isinstance(option.charset, types.BinaryCharset):
506
+ create_options.charset = 'binary'
507
+ else:
508
+ create_options.charset = option.charset
509
+ case types.CollateCreateOption():
510
+ create_options.collate = option.collate
511
+ case types.TablespaceCreateOption():
512
+ create_options.tablespace = option.name
513
+
514
+ return create_options
515
+
516
+ ### Partition
517
+
518
+ engine_partition_option = wrap_pydantic(types.EnginePartitionOption_)
519
+
520
+ @inline
521
+ def partition_options(self, *options_: types.PartitionOption_):
522
+ options = types.PartitionOptions(
523
+ tablespace=None,
524
+ engine=None,
525
+ nodegroup=None,
526
+ max_rows=None,
527
+ min_rows=None,
528
+ data_directory=None,
529
+ index_directory=None,
530
+ comment=None,
531
+ )
532
+ for option in options_:
533
+ match option:
534
+ case types.EnginePartitionOption_():
535
+ options.engine = option.engine
536
+ return options
537
+
538
+ max_value = const(None)
539
+ partition_lt_value = through()
540
+ partition_lt_value_list = list_
541
+
542
+ @inline
543
+ def partition_values_lt(self, values: list[str | None] | None) -> types.ValuesLessThan:
544
+ if values is None:
545
+ values = [None]
546
+ return values
547
+
548
+ @inline
549
+ def range_partition(
550
+ self,
551
+ name: str,
552
+ values: types.ValuesLessThan,
553
+ options: types.PartitionOptions,
554
+ subpartitions: list[types.KeyHashPartition] | None,
555
+ ):
556
+ return types.RangePartition(
557
+ name=name, values=values, subpartitions=subpartitions or [], options=options
558
+ )
559
+
560
+ range_partitions = list_
561
+
562
+ @inline
563
+ def key_hash_partition_def(self, name: str, options: types.PartitionOptions):
564
+ return types.KeyHashPartition(name=name, options=options)
565
+
566
+ key_hash_subpartition = through()
567
+ key_hash_subpartitions = list_
568
+
569
+ @inline
570
+ def expr_or_columns(self, expr_or_columns: str | list[str] | None):
571
+ if expr_or_columns is None:
572
+ expr_or_columns = []
573
+ return expr_or_columns
574
+
575
+ @inline
576
+ def hash_partition_type(self, linear: bool | None, expr: str):
577
+ return types.HashPartitionType(linear=linear or False, expr=expr)
578
+
579
+ @inline
580
+ def subpartition_clause(self, type: types.HashPartitionType, count: int | None):
581
+ return types.Subpartitioning(type=type, subpartition_count=count)
582
+
583
+ @inline
584
+ def range_partition_clause(
585
+ self,
586
+ expr_or_columns: str | list[str],
587
+ subpartitioning: types.Subpartitioning | None,
588
+ partitions: list[types.RangePartition],
589
+ ):
590
+ return types.RangePartitioning(
591
+ expr_or_columns=expr_or_columns, partitions=partitions, sub=subpartitioning
592
+ )
593
+
594
+ partition_clause = through()
595
+
596
+ ### General
597
+
598
+ int_arg = through()
599
+
600
+ @inline
601
+ def int_pair_arg(self, i1: int, i2: int):
602
+ return (i1, i2)
603
+
604
+ key_list = list_
605
+ text_list = list_
606
+
607
+ desc_direction = const(types.Direction.DESC)
608
+ asc_direction = const(types.Direction.ASC)
609
+
610
+ ### Keywords
611
+
612
+ charset = const(True)
613
+ varchar = const(True)
614
+ binary = const(True)
615
+ key_or_index = const(True)
616
+
617
+ ### Identifier
618
+
619
+ unquoted_identifier = through()
620
+ back_tick_text = call(lambda t: t[1:-1])
621
+ identifier = through()
622
+ dot_identifier = through()
623
+ identifier_list = list_
624
+ identifier_list_with_par = through()
625
+ qual_identifier = const(True)
626
+
627
+ ### Literal
628
+
629
+ literal = through()
630
+
631
+ int_literal = call(int)
632
+ real_literal = call(float)
633
+
634
+ text_literal = through(0)
635
+ quoted_text = call(lambda t: t[1:-1])
636
+
637
+ @inline
638
+ def underscore_charset_text(self, underscore_charset: Terminal | None, text: str):
639
+ return types.TextLiteral(
640
+ charset=underscore_charset[1:] if underscore_charset is not None else None, text=text
641
+ )
642
+
643
+ null_literal = const_call(types.NullLiteral)
644
+
645
+ # Expression
646
+
647
+ expr_with_par = through()
648
+ expr_list = list_
649
+
650
+ @v_args(inline=False, meta=True)
651
+ def expr(self, meta: Meta, children: typing.Any):
652
+ return self.original_text[meta.start_pos : meta.end_pos]
653
+
654
+ bool_pri = const(True)
655
+ comp_op = const(True)
656
+ predicate = const(True)
657
+ predicate_operations = const(True)
658
+ bit_expr = const(True)
659
+ simple_expr = const(True)
660
+ else_expression = const(True)
661
+ then_expression = const(True)
662
+ when_expression = const(True)
663
+ array_cast = const(True)
664
+ cast_type = const(True)
665
+ charset_with_opt_binary = const(True)
666
+ unicode = const(True)
667
+ ascii = const(True)
668
+ fulltext_options = const(True)
669
+ ident_list_arg = const(True)
670
+ ident_list = const(True)
671
+ simple_identifier = const(True)
672
+ query_expression_parens = const(True)
673
+ locking_clause_list = const(True)
674
+ locking_clause = const(True)
675
+ locked_row_action = const(True)
676
+ table_alias_ref_list = const(True)
677
+ table_ref_with_wildcard = const(True)
678
+ lock_strengh = const(True)
679
+ query_expression = const(True)
680
+ limit_clause = const(True)
681
+ limit_options = const(True)
682
+ limit_option = const(True)
683
+ query_expression_body = const(True)
684
+ union_option = const(True)
685
+ query_primary = const(True)
686
+ explicit_table = const(True)
687
+ table_ref = const(True)
688
+ table_value_constructor = const(True)
689
+ row_value_explicit = const(True)
690
+ values = const(True)
691
+ query_specification = const(True)
692
+ window_clause = const(True)
693
+ window_definition = const(True)
694
+ window_spec = const(True)
695
+ having_clause = const(True)
696
+ group_by_clause = const(True)
697
+ olap_option = const(True)
698
+ where_clause = const(True)
699
+ from_clause = const(True)
700
+ table_reference_list = const(True)
701
+ table_reference = const(True)
702
+ escaped_table_reference = const(True)
703
+ joined_table = const(True)
704
+ natural_join_type = const(True)
705
+ outer_join_type = const(True)
706
+ inner_join_type = const(True)
707
+ table_factor = const(True)
708
+ table_function = const(True)
709
+ columns_clause = const(True)
710
+ jt_column = const(True)
711
+ on_empty_or_error = const(True)
712
+ on_empty = const(True)
713
+ on_error = const(True)
714
+ jt_on_response = const(True)
715
+ table_reference_list_parens = const(True)
716
+ derived_table = const(True)
717
+ single_table_parens = const(True)
718
+ single_table = const(True)
719
+ index_hint_list = const(True)
720
+ index_hint = const(True)
721
+ index_list = const(True)
722
+ index_list_element = const(True)
723
+ index_hint_clause = const(True)
724
+ index_hint_type = const(True)
725
+ table_alias = const(True)
726
+ use_partition = const(True)
727
+ into_clause = const(True)
728
+ lines_clause = const(True)
729
+ line_term = const(True)
730
+ fields_clause = const(True)
731
+ field_term = const(True)
732
+ select_item_list = const(True)
733
+ select_item = const(True)
734
+ select_alias = const(True)
735
+ table_wild = const(True)
736
+ select_option = const(True)
737
+ query_spec_option = const(True)
738
+ with_clause = const(True)
739
+ common_table_expression = const(True)
740
+ window_function_call = const(True)
741
+ null_treatment = const(True)
742
+ lead_lag_info = const(True)
743
+ simple_expr_with_parentheses = const(True)
744
+ grouping_operation = const(True)
745
+ sum_expr = const(True)
746
+ json_function = const(True)
747
+ windowing_clause = const(True)
748
+ window_spec_details = const(True)
749
+ window_frame_clause = const(True)
750
+ window_frame_exclusion = const(True)
751
+ window_frame_extent = const(True)
752
+ window_frame_start = const(True)
753
+ window_frame_between = const(True)
754
+ window_frame_bound = const(True)
755
+ window_frame_units = const(True)
756
+ order_clause = const(True)
757
+ order_list = const(True)
758
+ order_expression = const(True)
759
+ in_sum_expr = const(True)
760
+ function_call = const(True)
761
+ udf_expr_list = const(True)
762
+ udf_expr = const(True)
763
+ runtime_function_call = const(True)
764
+ geometry_function = const(True)
765
+ ws_num_codepoints = const(True)
766
+ expr_list_with_parentheses = const(True)
767
+ substring_function = const(True)
768
+ date_time_ttype = const(True)
769
+ interval = const(True)
770
+ interval_time_stamp = const(True)
771
+ trim_function = const(True)
772
+ parentheses = const(True)
773
+ json_operator = const(True)
774
+ field_identifier = const(True)
775
+ variable = const(True)
776
+ system_variable = const(True)
777
+ var_ident_type = const(True)
778
+ user_variable = const(True)
779
+
780
+ @inline
781
+ def b_quote(self):
782
+ pass
783
+
784
+ @inline
785
+ def bin_literal(self):
786
+ pass
787
+
788
+ @inline
789
+ def bool_data_type(self):
790
+ pass
791
+
792
+ @inline
793
+ def bool_literal(self):
794
+ pass
795
+
796
+ @inline
797
+ def checksum_create_option(self):
798
+ pass
799
+
800
+ @inline
801
+ def comment_index_option(self):
802
+ pass
803
+
804
+ @inline
805
+ def comment_partition_option(self):
806
+ pass
807
+
808
+ @inline
809
+ def compression_create_option(self):
810
+ pass
811
+
812
+ @inline
813
+ def connection_create_option(self):
814
+ pass
815
+
816
+ @inline
817
+ def data_directory_create_option(self):
818
+ pass
819
+
820
+ @inline
821
+ def data_directory_partition_option(self):
822
+ pass
823
+
824
+ @inline
825
+ def date_literal(self):
826
+ pass
827
+
828
+ @inline
829
+ def default_column_format(self):
830
+ pass
831
+
832
+ @inline
833
+ def default_storage_media(self):
834
+ pass
835
+
836
+ @inline
837
+ def default_ternary_option(self):
838
+ pass
839
+
840
+ @inline
841
+ def delay_key_write_create_option(self):
842
+ pass
843
+
844
+ @inline
845
+ def encryption_create_option(self):
846
+ pass
847
+
848
+ @inline
849
+ def enforced_constraint_enforcement(self):
850
+ pass
851
+
852
+ @inline
853
+ def equal(self):
854
+ pass
855
+
856
+ @inline
857
+ def expr_key_part(self):
858
+ pass
859
+
860
+ @inline
861
+ def full_ref_match_type(self):
862
+ pass
863
+
864
+ @inline
865
+ def hex_literal(self):
866
+ pass
867
+
868
+ @inline
869
+ def index_directory_create_option(self):
870
+ pass
871
+
872
+ @inline
873
+ def index_directory_partition_option(self):
874
+ pass
875
+
876
+ @inline
877
+ def insert_method(self):
878
+ pass
879
+
880
+ @inline
881
+ def insert_method_create_option(self):
882
+ pass
883
+
884
+ @inline
885
+ def invisible_index_option(self):
886
+ pass
887
+
888
+ @inline
889
+ def key_block_size_create_option(self):
890
+ pass
891
+
892
+ @inline
893
+ def key_block_size_index_option(self):
894
+ pass
895
+
896
+ @inline
897
+ def key_hash_partition(self):
898
+ pass
899
+
900
+ @inline
901
+ def key_hash_partition_clause(self):
902
+ pass
903
+
904
+ @inline
905
+ def key_hash_partitions(self):
906
+ pass
907
+
908
+ @inline
909
+ def key_partition_type(self):
910
+ pass
911
+
912
+ @inline
913
+ def list_partition(self):
914
+ pass
915
+
916
+ @inline
917
+ def list_partition_clause(self):
918
+ pass
919
+
920
+ @inline
921
+ def list_partitions(self):
922
+ pass
923
+
924
+ @inline
925
+ def max_rows_create_option(self):
926
+ pass
927
+
928
+ @inline
929
+ def max_rows_partition_option(self):
930
+ pass
931
+
932
+ @inline
933
+ def min_rows_create_option(self):
934
+ pass
935
+
936
+ @inline
937
+ def min_rows_partition_option(self):
938
+ pass
939
+
940
+ @inline
941
+ def national_char_text(self):
942
+ pass
943
+
944
+ @inline
945
+ def nchar(self):
946
+ pass
947
+
948
+ @inline
949
+ def nchar_data_type(self):
950
+ pass
951
+
952
+ @inline
953
+ def nodegroup_partition_option(self):
954
+ pass
955
+
956
+ @inline
957
+ def not_enforced_constraint_enforcement(self):
958
+ pass
959
+
960
+ @inline
961
+ def nvarchar(self):
962
+ pass
963
+
964
+ @inline
965
+ def nvarchar_data_type(self):
966
+ pass
967
+
968
+ @inline
969
+ def pack_keys_create_option(self):
970
+ pass
971
+
972
+ @inline
973
+ def partial_ref_match_type(self):
974
+ pass
975
+
976
+ @inline
977
+ def partition_in_value_list(self):
978
+ pass
979
+
980
+ @inline
981
+ def partition_in_value_list_list(self):
982
+ pass
983
+
984
+ @inline
985
+ def partition_values_in(self):
986
+ pass
987
+
988
+ @inline
989
+ def password_create_option(self):
990
+ pass
991
+
992
+ @inline
993
+ def qual_identifier_list(self):
994
+ pass
995
+
996
+ @inline
997
+ def serial_data_type(self):
998
+ pass
999
+
1000
+ @inline
1001
+ def simple_ref_match_type(self):
1002
+ pass
1003
+
1004
+ @inline
1005
+ def stats_auto_recalc_create_option(self):
1006
+ pass
1007
+
1008
+ @inline
1009
+ def stats_sample_pages_create_option(self):
1010
+ pass
1011
+
1012
+ @inline
1013
+ def storage_create_option(self):
1014
+ pass
1015
+
1016
+ @inline
1017
+ def storage_type(self):
1018
+ pass
1019
+
1020
+ @inline
1021
+ def tablespace_partition_option(self):
1022
+ pass
1023
+
1024
+ @inline
1025
+ def text_or_identifier(self, _: object):
1026
+ pass
1027
+
1028
+ @inline
1029
+ def time_literal(self):
1030
+ pass
1031
+
1032
+ @inline
1033
+ def timestamp_literal(self):
1034
+ pass
1035
+
1036
+ @inline
1037
+ def union_create_option(self):
1038
+ pass
1039
+
1040
+ @inline
1041
+ def visible_attribute(self):
1042
+ pass
1043
+
1044
+ @inline
1045
+ def not_secondary_attribute(self):
1046
+ pass
1047
+
1048
+ @inline
1049
+ def visible_index_option(self):
1050
+ pass
1051
+
1052
+ @inline
1053
+ def with_parser_index_option(self):
1054
+ pass
1055
+
1056
+ @inline
1057
+ def x_quote(self):
1058
+ pass
1059
+
1060
+ @inline
1061
+ def zero_b(self):
1062
+ pass
1063
+
1064
+ @inline
1065
+ def zero_x(self):
1066
+ pass
1067
+
1068
+ @inline
1069
+ def zerofill_attribute(self):
1070
+ pass
1071
+
1072
+
1073
+ @dataclasses.dataclass
1074
+ class DDLParser:
1075
+ lark: lark.Lark
1076
+
1077
+ @staticmethod
1078
+ def make():
1079
+ return DDLParser(
1080
+ lark=lark.Lark(
1081
+ GRAMMAR_FILE.read_text(encoding='utf-8'),
1082
+ start=GRAMMAR_START,
1083
+ debug=True,
1084
+ strict=True,
1085
+ maybe_placeholders=True,
1086
+ propagate_positions=True,
1087
+ )
1088
+ )
1089
+
1090
+ def parse(self, ddl: str, transformer_cls: type[Transformer] | None = None):
1091
+ transformer = (transformer_cls or Transformer)(original_text=ddl)
1092
+ tree = self.lark.parse(ddl)
1093
+ return transformer.transform(tree)