-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrammar.y
More file actions
1812 lines (1578 loc) · 72.3 KB
/
Copy pathgrammar.y
File metadata and controls
1812 lines (1578 loc) · 72.3 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
# The structure of this file is similar to yacc.
#
# <tokens>
# <grammar directives>
# %%
# <rules>
# %%
# <helper functions>
#
# Actions and helper functions are written in a restricted Python.
# Type annotations are required.
# Not all expression forms are supported. Indeed, one can only call helper
# functions declared below and builtin functions via `builtin.func(...)`.
# We translate this restricted Python into actual Python, Julia, and Go.
#
# Each rule has a construct action and a deconstruct action.
#
# Construct actions use `$$ = expr` to build the LHS value from the RHS
# elements ($1, $2, ...). If omitted, the default is `$$ = $N` when there
# is exactly one non-literal RHS element.
#
# Deconstruct actions use `$N = expr` assignments to extract RHS element
# values from the LHS value ($$). If omitted, the default is the identity
# deconstruct. Use `deconstruct if COND:` to guard the deconstructor: if the
# condition fails, the deconstructor returns None, signaling that this rule
# does not match the LHS value.
#
# The pretty printer uses the deconstruct actions. For nonterminals with
# multiple alternatives, it tries the rules in declaration order, choosing
# the first whose deconstructor returns a non-None value.
# Start symbol
%start transaction
# Token declarations: %token NAME Type PATTERN
# PATTERN can be r'...' for regex or '...' for fixed string
%token DECIMAL logic.DecimalValue r'[-]?\d+\.\d+d\d+'
%token FLOAT32 Float32 r'([-]?\d+\.\d+f32|inf32|nan32)'
%token FLOAT Float64 r'([-]?\d+\.\d+|inf|nan)'
%token INT32 Int32 r'[-]?\d+i32'
%token INT Int64 r'[-]?\d+'
%token UINT32 UInt32 r'\d+u32'
%token INT128 logic.Int128Value r'[-]?\d+i128'
%token STRING String r'"(?:[^"\\]|\\.)*"'
%token SYMBOL String r'[a-zA-Z_][a-zA-Z0-9_.#/-]*'
%token UINT128 logic.UInt128Value r'0x[0-9a-fA-F]+'
# Token aliases for formula constants (use hookable formatting in pretty printer)
%token_alias FORMATTED_INT INT
%token_alias FORMATTED_FLOAT FLOAT
%token_alias FORMATTED_STRING STRING
%token_alias FORMATTED_INT32 INT32
%token_alias FORMATTED_FLOAT32 FLOAT32
%token_alias FORMATTED_DECIMAL DECIMAL
%token_alias FORMATTED_INT128 INT128
%token_alias FORMATTED_UINT32 UINT32
%token_alias FORMATTED_UINT128 UINT128
# Type declarations for rules
%nonterm abstraction logic.Abstraction
%nonterm abstraction_with_arity Tuple[logic.Abstraction, Int64]
%nonterm add logic.Primitive
%nonterm algorithm logic.Algorithm
%nonterm assign logic.Assign
%nonterm atom logic.Atom
%nonterm attribute logic.Attribute
%nonterm attrs Sequence[logic.Attribute]
%nonterm betree_info logic.BeTreeInfo
%nonterm betree_info_key_types Sequence[logic.Type]
%nonterm betree_info_value_types Sequence[logic.Type]
%nonterm betree_relation logic.BeTreeRelation
%nonterm binding logic.Binding
%nonterm bindings Tuple[Sequence[logic.Binding], Sequence[logic.Binding]]
%nonterm boolean_type logic.BooleanType
%nonterm boolean_value Boolean
%nonterm break logic.Break
%nonterm cast logic.Cast
%nonterm config_dict Sequence[Tuple[String, logic.Value]]
%nonterm config_key_value Tuple[String, logic.Value]
%nonterm configure transactions.Configure
%nonterm conjunction logic.Conjunction
%nonterm constraint logic.Constraint
%nonterm construct logic.Construct
%nonterm context transactions.Context
%nonterm csv_asof String
%nonterm gnf_column logic.GNFColumn
%nonterm gnf_column_path Sequence[String]
%nonterm gnf_columns Sequence[logic.GNFColumn]
%nonterm csv_config logic.CSVConfig
%nonterm csv_data logic.CSVData
%nonterm csv_locator_inline_data String
%nonterm csv_locator_paths Sequence[String]
%nonterm csvlocator logic.CSVLocator
%nonterm data logic.Data
%nonterm date logic.DateValue
%nonterm date_type logic.DateType
%nonterm datetime logic.DateTimeValue
%nonterm datetime_type logic.DateTimeType
%nonterm decimal_type logic.DecimalType
%nonterm declaration logic.Declaration
%nonterm def logic.Def
%nonterm define transactions.Define
%nonterm demand transactions.Demand
%nonterm disjunction logic.Disjunction
%nonterm divide logic.Primitive
%nonterm abort transactions.Abort
%nonterm epoch transactions.Epoch
%nonterm epoch_reads Sequence[transactions.Read]
%nonterm epoch_writes Sequence[transactions.Write]
%nonterm eq logic.Primitive
%nonterm exists logic.Exists
%nonterm export transactions.Export
%nonterm export_csv_column transactions.ExportCSVColumn
%nonterm export_csv_columns_list Sequence[transactions.ExportCSVColumn]
%nonterm export_csv_config transactions.ExportCSVConfig
%nonterm export_csv_path String
%nonterm export_csv_source transactions.ExportCSVSource
%nonterm export_iceberg_config transactions.ExportIcebergConfig
%nonterm export_iceberg_table_def logic.RelationId
%nonterm iceberg_auth_properties Sequence[Tuple[String, String]]
%nonterm iceberg_catalog_config logic.IcebergCatalogConfig
%nonterm iceberg_catalog_config_scope String
%nonterm iceberg_catalog_uri String
%nonterm iceberg_data logic.IcebergData
%nonterm iceberg_from_snapshot String
%nonterm iceberg_locator logic.IcebergLocator
%nonterm iceberg_locator_namespace Sequence[String]
%nonterm iceberg_locator_table_name String
%nonterm iceberg_locator_warehouse String
%nonterm iceberg_masked_property_entry Tuple[String, String]
%nonterm iceberg_properties Sequence[Tuple[String, String]]
%nonterm iceberg_property_entry Tuple[String, String]
%nonterm iceberg_table_properties Sequence[Tuple[String, String]]
%nonterm iceberg_to_snapshot String
%nonterm false logic.Disjunction
%nonterm ffi logic.FFI
%nonterm ffi_args Sequence[logic.Abstraction]
%nonterm float_type logic.FloatType
%nonterm float32_type logic.Float32Type
%nonterm formula logic.Formula
%nonterm fragment fragments.Fragment
%nonterm fragment_id fragments.FragmentId
%nonterm functional_dependency_keys Sequence[logic.Var]
%nonterm functional_dependency_values Sequence[logic.Var]
%nonterm gt logic.Primitive
%nonterm gt_eq logic.Primitive
%nonterm init Sequence[logic.Instruction]
%nonterm instruction logic.Instruction
%nonterm int_type logic.IntType
%nonterm int32_type logic.Int32Type
%nonterm uint32_type logic.UInt32Type
%nonterm int128_type logic.Int128Type
%nonterm loop logic.Loop
%nonterm lt logic.Primitive
%nonterm lt_eq logic.Primitive
%nonterm max_monoid logic.MaxMonoid
%nonterm min_monoid logic.MinMonoid
%nonterm minus logic.Primitive
%nonterm missing_type logic.MissingType
%nonterm monoid logic.Monoid
%nonterm monoid_def logic.MonoidDef
%nonterm monus_def logic.MonusDef
%nonterm multiply logic.Primitive
%nonterm name String
%nonterm new_fragment_id fragments.FragmentId
%nonterm not logic.Not
%nonterm or_monoid logic.OrMonoid
%nonterm output transactions.Output
%nonterm pragma logic.Pragma
%nonterm primitive logic.Primitive
%nonterm raw_date logic.DateValue
%nonterm raw_datetime logic.DateTimeValue
%nonterm raw_value logic.Value
%nonterm read transactions.Read
%nonterm reduce logic.Reduce
%nonterm rel_atom logic.RelAtom
%nonterm edb logic.EDB
%nonterm edb_path Sequence[String]
%nonterm edb_types Sequence[logic.Type]
%nonterm rel_term logic.RelTerm
%nonterm relation_id logic.RelationId
%nonterm script logic.Script
%nonterm specialized_value logic.Value
%nonterm string_type logic.StringType
%nonterm sum_monoid logic.SumMonoid
%nonterm snapshot transactions.Snapshot
%nonterm snapshot_mapping transactions.SnapshotMapping
%nonterm sync transactions.Sync
%nonterm term logic.Term
%nonterm terms Sequence[logic.Term]
%nonterm transaction transactions.Transaction
%nonterm true logic.Conjunction
%nonterm type logic.Type
%nonterm uint128_type logic.UInt128Type
%nonterm undefine transactions.Undefine
%nonterm unspecified_type logic.UnspecifiedType
%nonterm upsert logic.Upsert
%nonterm value logic.Value
%nonterm value_bindings Sequence[logic.Binding]
%nonterm var logic.Var
%nonterm what_if transactions.WhatIf
%nonterm write transactions.Write
# Messages that are constructed imperatively by the parser, not parsed from grammar rules.
# These protobuf message types are excluded from completeness validation because they are
# built programmatically by builtin functions (like construct_betree_info, construct_csv_config)
# or by parser internals, rather than being directly produced by grammar production rules.
# Without these directives, the validator would report errors that these message types have
# no grammar rules producing them.
%validator_ignore_completeness DebugInfo
%validator_ignore_completeness IVMConfig
%validator_ignore_completeness UInt128Value
%validator_ignore_completeness Int128Value
%validator_ignore_completeness DecimalValue
%validator_ignore_completeness BeTreeLocator
%validator_ignore_completeness BeTreeConfig
%validator_ignore_completeness ExportCSVColumns
%%
transaction
: "(" "transaction" configure? sync? epoch* ")"
construct: $$ = transactions.Transaction(epochs=$5, configure=builtin.unwrap_option_or($3, default_configure()), sync=$4)
deconstruct:
$3: Optional[transactions.Configure] = $$.configure if builtin.has_proto_field($$, "configure") else None
$4: Optional[transactions.Sync] = $$.sync if builtin.has_proto_field($$, "sync") else None
$5: Sequence[transactions.Epoch] = $$.epochs
configure
: "(" "configure" config_dict ")"
construct: $$ = construct_configure($3)
deconstruct: $3: Sequence[Tuple[String, logic.Value]] = deconstruct_configure($$)
config_dict
: "{" config_key_value* "}"
config_key_value
: ":" SYMBOL raw_value
construct: $$ = builtin.tuple($2, $3)
deconstruct:
$2: String = $$[0]
$3: logic.Value = $$[1]
value
: date
construct: $$ = logic.Value(date_value=$1)
deconstruct if builtin.has_proto_field($$, 'date_value'):
$1: logic.DateValue = $$.date_value
| datetime
construct: $$ = logic.Value(datetime_value=$1)
deconstruct if builtin.has_proto_field($$, 'datetime_value'):
$1: logic.DateTimeValue = $$.datetime_value
| FORMATTED_STRING
construct: $$ = logic.Value(string_value=$1)
deconstruct if builtin.has_proto_field($$, 'string_value'):
$1: String = $$.string_value
| FORMATTED_INT32
construct: $$ = logic.Value(int32_value=$1)
deconstruct if builtin.has_proto_field($$, 'int32_value'):
$1: Int32 = $$.int32_value
| FORMATTED_INT
construct: $$ = logic.Value(int_value=$1)
deconstruct if builtin.has_proto_field($$, 'int_value'):
$1: Int64 = $$.int_value
| FORMATTED_FLOAT32
construct: $$ = logic.Value(float32_value=$1)
deconstruct if builtin.has_proto_field($$, 'float32_value'):
$1: Float32 = $$.float32_value
| FORMATTED_FLOAT
construct: $$ = logic.Value(float_value=$1)
deconstruct if builtin.has_proto_field($$, 'float_value'):
$1: Float64 = $$.float_value
| FORMATTED_UINT32
construct: $$ = logic.Value(uint32_value=$1)
deconstruct if builtin.has_proto_field($$, 'uint32_value'):
$1: UInt32 = $$.uint32_value
| FORMATTED_UINT128
construct: $$ = logic.Value(uint128_value=$1)
deconstruct if builtin.has_proto_field($$, 'uint128_value'):
$1: logic.UInt128Value = $$.uint128_value
| FORMATTED_INT128
construct: $$ = logic.Value(int128_value=$1)
deconstruct if builtin.has_proto_field($$, 'int128_value'):
$1: logic.Int128Value = $$.int128_value
| FORMATTED_DECIMAL
construct: $$ = logic.Value(decimal_value=$1)
deconstruct if builtin.has_proto_field($$, 'decimal_value'):
$1: logic.DecimalValue = $$.decimal_value
| "missing"
construct: $$ = logic.Value(missing_value=logic.MissingValue())
| boolean_value
construct: $$ = logic.Value(boolean_value=$1)
deconstruct if builtin.has_proto_field($$, 'boolean_value'):
$1: Boolean = $$.boolean_value
raw_value
: raw_date
construct: $$ = logic.Value(date_value=$1)
deconstruct if builtin.has_proto_field($$, 'date_value'):
$1: logic.DateValue = $$.date_value
| raw_datetime
construct: $$ = logic.Value(datetime_value=$1)
deconstruct if builtin.has_proto_field($$, 'datetime_value'):
$1: logic.DateTimeValue = $$.datetime_value
| STRING
construct: $$ = logic.Value(string_value=$1)
deconstruct if builtin.has_proto_field($$, 'string_value'):
$1: String = $$.string_value
| INT32
construct: $$ = logic.Value(int32_value=$1)
deconstruct if builtin.has_proto_field($$, 'int32_value'):
$1: Int32 = $$.int32_value
| INT
construct: $$ = logic.Value(int_value=$1)
deconstruct if builtin.has_proto_field($$, 'int_value'):
$1: Int64 = $$.int_value
| FLOAT32
construct: $$ = logic.Value(float32_value=$1)
deconstruct if builtin.has_proto_field($$, 'float32_value'):
$1: Float32 = $$.float32_value
| FLOAT
construct: $$ = logic.Value(float_value=$1)
deconstruct if builtin.has_proto_field($$, 'float_value'):
$1: Float64 = $$.float_value
| UINT32
construct: $$ = logic.Value(uint32_value=$1)
deconstruct if builtin.has_proto_field($$, 'uint32_value'):
$1: UInt32 = $$.uint32_value
| UINT128
construct: $$ = logic.Value(uint128_value=$1)
deconstruct if builtin.has_proto_field($$, 'uint128_value'):
$1: logic.UInt128Value = $$.uint128_value
| INT128
construct: $$ = logic.Value(int128_value=$1)
deconstruct if builtin.has_proto_field($$, 'int128_value'):
$1: logic.Int128Value = $$.int128_value
| DECIMAL
construct: $$ = logic.Value(decimal_value=$1)
deconstruct if builtin.has_proto_field($$, 'decimal_value'):
$1: logic.DecimalValue = $$.decimal_value
| "missing"
construct: $$ = logic.Value(missing_value=logic.MissingValue())
| boolean_value
construct: $$ = logic.Value(boolean_value=$1)
deconstruct if builtin.has_proto_field($$, 'boolean_value'):
$1: Boolean = $$.boolean_value
raw_date
: "(" "date" INT INT INT ")"
construct: $$ = logic.DateValue(year=builtin.int64_to_int32($3), month=builtin.int64_to_int32($4), day=builtin.int64_to_int32($5))
deconstruct:
$3: Int64 = builtin.int32_to_int64($$.year)
$4: Int64 = builtin.int32_to_int64($$.month)
$5: Int64 = builtin.int32_to_int64($$.day)
date
: "(" "date" FORMATTED_INT FORMATTED_INT FORMATTED_INT ")"
construct: $$ = logic.DateValue(year=builtin.int64_to_int32($3), month=builtin.int64_to_int32($4), day=builtin.int64_to_int32($5))
deconstruct:
$3: Int64 = builtin.int32_to_int64($$.year)
$4: Int64 = builtin.int32_to_int64($$.month)
$5: Int64 = builtin.int32_to_int64($$.day)
raw_datetime
: "(" "datetime" INT INT INT INT INT INT INT? ")"
construct: $$ = logic.DateTimeValue(year=builtin.int64_to_int32($3), month=builtin.int64_to_int32($4), day=builtin.int64_to_int32($5), hour=builtin.int64_to_int32($6), minute=builtin.int64_to_int32($7), second=builtin.int64_to_int32($8), microsecond=builtin.int64_to_int32(builtin.unwrap_option_or($9, 0)))
deconstruct:
$3: Int64 = builtin.int32_to_int64($$.year)
$4: Int64 = builtin.int32_to_int64($$.month)
$5: Int64 = builtin.int32_to_int64($$.day)
$6: Int64 = builtin.int32_to_int64($$.hour)
$7: Int64 = builtin.int32_to_int64($$.minute)
$8: Int64 = builtin.int32_to_int64($$.second)
$9: Optional[Int64] = builtin.some(builtin.int32_to_int64($$.microsecond))
datetime
: "(" "datetime" FORMATTED_INT FORMATTED_INT FORMATTED_INT FORMATTED_INT FORMATTED_INT FORMATTED_INT FORMATTED_INT? ")"
construct: $$ = logic.DateTimeValue(year=builtin.int64_to_int32($3), month=builtin.int64_to_int32($4), day=builtin.int64_to_int32($5), hour=builtin.int64_to_int32($6), minute=builtin.int64_to_int32($7), second=builtin.int64_to_int32($8), microsecond=builtin.int64_to_int32(builtin.unwrap_option_or($9, 0)))
deconstruct:
$3: Int64 = builtin.int32_to_int64($$.year)
$4: Int64 = builtin.int32_to_int64($$.month)
$5: Int64 = builtin.int32_to_int64($$.day)
$6: Int64 = builtin.int32_to_int64($$.hour)
$7: Int64 = builtin.int32_to_int64($$.minute)
$8: Int64 = builtin.int32_to_int64($$.second)
$9: Optional[Int64] = builtin.some(builtin.int32_to_int64($$.microsecond))
boolean_value
: "true"
construct: $$ = True
deconstruct if $$:
pass
| "false"
construct: $$ = False
deconstruct if not $$:
pass
sync
: "(" "sync" fragment_id* ")"
construct: $$ = transactions.Sync(fragments=$3)
deconstruct: $3: Sequence[fragments.FragmentId] = $$.fragments
fragment_id
: ":" SYMBOL
construct: $$ = builtin.fragment_id_from_string($2)
deconstruct: $2: String = builtin.fragment_id_to_string($$)
epoch
: "(" "epoch" epoch_writes? epoch_reads? ")"
construct: $$ = transactions.Epoch(writes=builtin.unwrap_option_or($3, list[transactions.Write]()), reads=builtin.unwrap_option_or($4, list[transactions.Read]()))
deconstruct:
$3: Optional[Sequence[transactions.Write]] = $$.writes if not builtin.is_empty($$.writes) else None
$4: Optional[Sequence[transactions.Read]] = $$.reads if not builtin.is_empty($$.reads) else None
epoch_writes
: "(" "writes" write* ")"
write
: define
construct: $$ = transactions.Write(define=$1)
deconstruct if builtin.has_proto_field($$, 'define'):
$1: transactions.Define = $$.define
| undefine
construct: $$ = transactions.Write(undefine=$1)
deconstruct if builtin.has_proto_field($$, 'undefine'):
$1: transactions.Undefine = $$.undefine
| context
construct: $$ = transactions.Write(context=$1)
deconstruct if builtin.has_proto_field($$, 'context'):
$1: transactions.Context = $$.context
| snapshot
construct: $$ = transactions.Write(snapshot=$1)
deconstruct if builtin.has_proto_field($$, 'snapshot'):
$1: transactions.Snapshot = $$.snapshot
define
: "(" "define" fragment ")"
construct: $$ = transactions.Define(fragment=$3)
deconstruct: $3: fragments.Fragment = $$.fragment
fragment
: "(" "fragment" new_fragment_id declaration* ")"
construct: $$ = builtin.construct_fragment($3, $4)
deconstruct:
builtin.start_pretty_fragment($$)
$3: fragments.FragmentId = $$.id
$4: Sequence[logic.Declaration] = $$.declarations
new_fragment_id
: fragment_id
construct:
builtin.start_fragment($1)
$$ = $1
declaration
: def
construct: $$ = logic.Declaration(def=$1)
deconstruct if builtin.has_proto_field($$, 'def'):
$1: logic.Def = $$.def
| algorithm
construct: $$ = logic.Declaration(algorithm=$1)
deconstruct if builtin.has_proto_field($$, 'algorithm'):
$1: logic.Algorithm = $$.algorithm
| constraint
construct: $$ = logic.Declaration(constraint=$1)
deconstruct if builtin.has_proto_field($$, 'constraint'):
$1: logic.Constraint = $$.constraint
| data
construct: $$ = logic.Declaration(data=$1)
deconstruct if builtin.has_proto_field($$, 'data'):
$1: logic.Data = $$.data
def
: "(" "def" relation_id abstraction attrs? ")"
construct: $$ = logic.Def(name=$3, body=$4, attrs=builtin.unwrap_option_or($5, list[logic.Attribute]()))
deconstruct:
$3: logic.RelationId = $$.name
$4: logic.Abstraction = $$.body
$5: Optional[Sequence[logic.Attribute]] = $$.attrs if not builtin.is_empty($$.attrs) else None
relation_id
: ":" SYMBOL
construct: $$ = builtin.relation_id_from_string($2)
deconstruct if builtin.relation_id_to_string($$) is not None:
$2: String = deconstruct_relation_id_string($$)
| UINT128
construct: $$ = builtin.relation_id_from_uint128($1)
deconstruct:
$1: logic.UInt128Value = deconstruct_relation_id_uint128($$)
abstraction
: "(" bindings formula ")"
construct: $$ = logic.Abstraction(vars=builtin.list_concat($2[0], $2[1]), value=$3)
deconstruct:
$2: Tuple[Sequence[logic.Binding], Sequence[logic.Binding]] = deconstruct_bindings($$)
$3: logic.Formula = $$.value
bindings
: "[" binding* value_bindings? "]"
construct: $$ = builtin.tuple($2, builtin.unwrap_option_or($3, list[logic.Binding]()))
deconstruct:
$2: Sequence[logic.Binding] = $$[0]
$3: Optional[Sequence[logic.Binding]] = $$[1] if not builtin.is_empty($$[1]) else None
binding
: SYMBOL "::" type
construct: $$ = logic.Binding(var=logic.Var(name=$1), type=$3)
deconstruct:
$1: String = $$.var.name
$3: logic.Type = $$.type
type
: unspecified_type
construct: $$ = logic.Type(unspecified_type=$1)
deconstruct if builtin.has_proto_field($$, 'unspecified_type'):
$1: logic.UnspecifiedType = $$.unspecified_type
| string_type
construct: $$ = logic.Type(string_type=$1)
deconstruct if builtin.has_proto_field($$, 'string_type'):
$1: logic.StringType = $$.string_type
| int_type
construct: $$ = logic.Type(int_type=$1)
deconstruct if builtin.has_proto_field($$, 'int_type'):
$1: logic.IntType = $$.int_type
| float_type
construct: $$ = logic.Type(float_type=$1)
deconstruct if builtin.has_proto_field($$, 'float_type'):
$1: logic.FloatType = $$.float_type
| uint128_type
construct: $$ = logic.Type(uint128_type=$1)
deconstruct if builtin.has_proto_field($$, 'uint128_type'):
$1: logic.UInt128Type = $$.uint128_type
| int128_type
construct: $$ = logic.Type(int128_type=$1)
deconstruct if builtin.has_proto_field($$, 'int128_type'):
$1: logic.Int128Type = $$.int128_type
| date_type
construct: $$ = logic.Type(date_type=$1)
deconstruct if builtin.has_proto_field($$, 'date_type'):
$1: logic.DateType = $$.date_type
| datetime_type
construct: $$ = logic.Type(datetime_type=$1)
deconstruct if builtin.has_proto_field($$, 'datetime_type'):
$1: logic.DateTimeType = $$.datetime_type
| missing_type
construct: $$ = logic.Type(missing_type=$1)
deconstruct if builtin.has_proto_field($$, 'missing_type'):
$1: logic.MissingType = $$.missing_type
| decimal_type
construct: $$ = logic.Type(decimal_type=$1)
deconstruct if builtin.has_proto_field($$, 'decimal_type'):
$1: logic.DecimalType = $$.decimal_type
| boolean_type
construct: $$ = logic.Type(boolean_type=$1)
deconstruct if builtin.has_proto_field($$, 'boolean_type'):
$1: logic.BooleanType = $$.boolean_type
| int32_type
construct: $$ = logic.Type(int32_type=$1)
deconstruct if builtin.has_proto_field($$, 'int32_type'):
$1: logic.Int32Type = $$.int32_type
| float32_type
construct: $$ = logic.Type(float32_type=$1)
deconstruct if builtin.has_proto_field($$, 'float32_type'):
$1: logic.Float32Type = $$.float32_type
| uint32_type
construct: $$ = logic.Type(uint32_type=$1)
deconstruct if builtin.has_proto_field($$, 'uint32_type'):
$1: logic.UInt32Type = $$.uint32_type
unspecified_type
: "UNKNOWN"
construct: $$ = logic.UnspecifiedType()
string_type
: "STRING"
construct: $$ = logic.StringType()
int32_type
: "INT32"
construct: $$ = logic.Int32Type()
int_type
: "INT"
construct: $$ = logic.IntType()
float32_type
: "FLOAT32"
construct: $$ = logic.Float32Type()
float_type
: "FLOAT"
construct: $$ = logic.FloatType()
uint32_type
: "UINT32"
construct: $$ = logic.UInt32Type()
uint128_type
: "UINT128"
construct: $$ = logic.UInt128Type()
int128_type
: "INT128"
construct: $$ = logic.Int128Type()
date_type
: "DATE"
construct: $$ = logic.DateType()
datetime_type
: "DATETIME"
construct: $$ = logic.DateTimeType()
missing_type
: "MISSING"
construct: $$ = logic.MissingType()
decimal_type
: "(" "DECIMAL" INT INT ")"
construct: $$ = logic.DecimalType(precision=builtin.int64_to_int32($3), scale=builtin.int64_to_int32($4))
deconstruct:
$3: Int64 = builtin.int32_to_int64($$.precision)
$4: Int64 = builtin.int32_to_int64($$.scale)
boolean_type
: "BOOLEAN"
construct: $$ = logic.BooleanType()
value_bindings
: "|" binding*
formula
: true
construct: $$ = logic.Formula(conjunction=$1)
deconstruct if builtin.has_proto_field($$, 'conjunction') and builtin.is_empty($$.conjunction.args):
$1: logic.Conjunction = $$.conjunction
| false
construct: $$ = logic.Formula(disjunction=$1)
deconstruct if builtin.has_proto_field($$, 'disjunction') and builtin.is_empty($$.disjunction.args):
$1: logic.Disjunction = $$.disjunction
| exists
construct: $$ = logic.Formula(exists=$1)
deconstruct if builtin.has_proto_field($$, 'exists'):
$1: logic.Exists = $$.exists
| reduce
construct: $$ = logic.Formula(reduce=$1)
deconstruct if builtin.has_proto_field($$, 'reduce'):
$1: logic.Reduce = $$.reduce
| conjunction
construct: $$ = logic.Formula(conjunction=$1)
deconstruct if builtin.has_proto_field($$, 'conjunction') and not builtin.is_empty($$.conjunction.args):
$1: logic.Conjunction = $$.conjunction
| disjunction
construct: $$ = logic.Formula(disjunction=$1)
deconstruct if builtin.has_proto_field($$, 'disjunction') and not builtin.is_empty($$.disjunction.args):
$1: logic.Disjunction = $$.disjunction
| not
construct: $$ = logic.Formula(not=$1)
deconstruct if builtin.has_proto_field($$, 'not'):
$1: logic.Not = $$.not
| ffi
construct: $$ = logic.Formula(ffi=$1)
deconstruct if builtin.has_proto_field($$, 'ffi'):
$1: logic.FFI = $$.ffi
| atom
construct: $$ = logic.Formula(atom=$1)
deconstruct if builtin.has_proto_field($$, 'atom'):
$1: logic.Atom = $$.atom
| pragma
construct: $$ = logic.Formula(pragma=$1)
deconstruct if builtin.has_proto_field($$, 'pragma'):
$1: logic.Pragma = $$.pragma
| primitive
construct: $$ = logic.Formula(primitive=$1)
deconstruct if builtin.has_proto_field($$, 'primitive'):
$1: logic.Primitive = $$.primitive
| rel_atom
construct: $$ = logic.Formula(rel_atom=$1)
deconstruct if builtin.has_proto_field($$, 'rel_atom'):
$1: logic.RelAtom = $$.rel_atom
| cast
construct: $$ = logic.Formula(cast=$1)
deconstruct if builtin.has_proto_field($$, 'cast'):
$1: logic.Cast = $$.cast
true
: "(" "true" ")"
construct: $$ = logic.Conjunction(args=list[logic.Formula]())
false
: "(" "false" ")"
construct: $$ = logic.Disjunction(args=list[logic.Formula]())
exists
: "(" "exists" bindings formula ")"
construct: $$ = logic.Exists(body=logic.Abstraction(vars=builtin.list_concat($3[0], $3[1]), value=$4))
deconstruct:
$3: Tuple[Sequence[logic.Binding], Sequence[logic.Binding]] = deconstruct_bindings($$.body)
$4: logic.Formula = $$.body.value
reduce
: "(" "reduce" abstraction abstraction terms ")"
construct: $$ = logic.Reduce(op=$3, body=$4, terms=$5)
deconstruct:
$3: logic.Abstraction = $$.op
$4: logic.Abstraction = $$.body
$5: Sequence[logic.Term] = $$.terms
term
: var
construct: $$ = logic.Term(var=$1)
deconstruct if builtin.has_proto_field($$, 'var'):
$1: logic.Var = $$.var
| value
construct: $$ = logic.Term(constant=$1)
deconstruct if builtin.has_proto_field($$, 'constant'):
$1: logic.Value = $$.constant
var
: SYMBOL
construct: $$ = logic.Var(name=$1)
deconstruct: $1: String = $$.name
conjunction
: "(" "and" formula* ")"
construct: $$ = logic.Conjunction(args=$3)
deconstruct: $3: Sequence[logic.Formula] = $$.args
disjunction
: "(" "or" formula* ")"
construct: $$ = logic.Disjunction(args=$3)
deconstruct: $3: Sequence[logic.Formula] = $$.args
not
: "(" "not" formula ")"
construct: $$ = logic.Not(arg=$3)
deconstruct: $3: logic.Formula = $$.arg
ffi
: "(" "ffi" name ffi_args terms ")"
construct: $$ = logic.FFI(name=$3, args=$4, terms=$5)
deconstruct:
$3: String = $$.name
$4: Sequence[logic.Abstraction] = $$.args
$5: Sequence[logic.Term] = $$.terms
ffi_args
: "(" "args" abstraction* ")"
terms
: "(" "terms" term* ")"
name
: ":" SYMBOL
atom
: "(" "atom" relation_id term* ")"
construct: $$ = logic.Atom(name=$3, terms=$4)
deconstruct:
$3: logic.RelationId = $$.name
$4: Sequence[logic.Term] = $$.terms
pragma
: "(" "pragma" name term* ")"
construct: $$ = logic.Pragma(name=$3, terms=$4)
deconstruct:
$3: String = $$.name
$4: Sequence[logic.Term] = $$.terms
primitive
: eq
| lt
| lt_eq
| gt
| gt_eq
| add
| minus
| multiply
| divide
| "(" "primitive" name rel_term* ")"
construct: $$ = logic.Primitive(name=$3, terms=$4)
deconstruct:
$3: String = $$.name
$4: Sequence[logic.RelTerm] = $$.terms
eq
: "(" "=" term term ")"
construct: $$ = logic.Primitive(name="rel_primitive_eq", terms=[logic.RelTerm(term=$3), logic.RelTerm(term=$4)])
deconstruct if $$.name == "rel_primitive_eq":
$3: logic.Term = $$.terms[0].term
$4: logic.Term = $$.terms[1].term
lt
: "(" "<" term term ")"
construct: $$ = logic.Primitive(name="rel_primitive_lt_monotype", terms=[logic.RelTerm(term=$3), logic.RelTerm(term=$4)])
deconstruct if $$.name == "rel_primitive_lt_monotype":
$3: logic.Term = $$.terms[0].term
$4: logic.Term = $$.terms[1].term
lt_eq
: "(" "<=" term term ")"
construct: $$ = logic.Primitive(name="rel_primitive_lt_eq_monotype", terms=[logic.RelTerm(term=$3), logic.RelTerm(term=$4)])
deconstruct if $$.name == "rel_primitive_lt_eq_monotype":
$3: logic.Term = $$.terms[0].term
$4: logic.Term = $$.terms[1].term
gt
: "(" ">" term term ")"
construct: $$ = logic.Primitive(name="rel_primitive_gt_monotype", terms=[logic.RelTerm(term=$3), logic.RelTerm(term=$4)])
deconstruct if $$.name == "rel_primitive_gt_monotype":
$3: logic.Term = $$.terms[0].term
$4: logic.Term = $$.terms[1].term
gt_eq
: "(" ">=" term term ")"
construct: $$ = logic.Primitive(name="rel_primitive_gt_eq_monotype", terms=[logic.RelTerm(term=$3), logic.RelTerm(term=$4)])
deconstruct if $$.name == "rel_primitive_gt_eq_monotype":
$3: logic.Term = $$.terms[0].term
$4: logic.Term = $$.terms[1].term
add
: "(" "+" term term term ")"
construct: $$ = logic.Primitive(name="rel_primitive_add_monotype", terms=[logic.RelTerm(term=$3), logic.RelTerm(term=$4), logic.RelTerm(term=$5)])
deconstruct if $$.name == "rel_primitive_add_monotype":
$3: logic.Term = $$.terms[0].term
$4: logic.Term = $$.terms[1].term
$5: logic.Term = $$.terms[2].term
minus
: "(" "-" term term term ")"
construct: $$ = logic.Primitive(name="rel_primitive_subtract_monotype", terms=[logic.RelTerm(term=$3), logic.RelTerm(term=$4), logic.RelTerm(term=$5)])
deconstruct if $$.name == "rel_primitive_subtract_monotype":
$3: logic.Term = $$.terms[0].term
$4: logic.Term = $$.terms[1].term
$5: logic.Term = $$.terms[2].term
multiply
: "(" "*" term term term ")"
construct: $$ = logic.Primitive(name="rel_primitive_multiply_monotype", terms=[logic.RelTerm(term=$3), logic.RelTerm(term=$4), logic.RelTerm(term=$5)])
deconstruct if $$.name == "rel_primitive_multiply_monotype":
$3: logic.Term = $$.terms[0].term
$4: logic.Term = $$.terms[1].term
$5: logic.Term = $$.terms[2].term
divide
: "(" "/" term term term ")"
construct: $$ = logic.Primitive(name="rel_primitive_divide_monotype", terms=[logic.RelTerm(term=$3), logic.RelTerm(term=$4), logic.RelTerm(term=$5)])
deconstruct if $$.name == "rel_primitive_divide_monotype":
$3: logic.Term = $$.terms[0].term
$4: logic.Term = $$.terms[1].term
$5: logic.Term = $$.terms[2].term
rel_term
: specialized_value
construct: $$ = logic.RelTerm(specialized_value=$1)
deconstruct if builtin.has_proto_field($$, 'specialized_value'):
$1: logic.Value = $$.specialized_value
| term
construct: $$ = logic.RelTerm(term=$1)
deconstruct if builtin.has_proto_field($$, 'term'):
$1: logic.Term = $$.term
specialized_value
: "#" raw_value
rel_atom
: "(" "relatom" name rel_term* ")"
construct: $$ = logic.RelAtom(name=$3, terms=$4)
deconstruct:
$3: String = $$.name
$4: Sequence[logic.RelTerm] = $$.terms
cast
: "(" "cast" term term ")"
construct: $$ = logic.Cast(input=$3, result=$4)
deconstruct:
$3: logic.Term = $$.input
$4: logic.Term = $$.result
attrs
: "(" "attrs" attribute* ")"
attribute
: "(" "attribute" name raw_value* ")"
construct: $$ = logic.Attribute(name=$3, args=$4)
deconstruct:
$3: String = $$.name
$4: Sequence[logic.Value] = $$.args
algorithm
: "(" "algorithm" relation_id* script attrs? ")"
construct: $$ = logic.Algorithm(global=$3, body=$4, attrs=builtin.unwrap_option_or($5, list[logic.Attribute]()))
deconstruct:
$3: Sequence[logic.RelationId] = $$.global
$4: logic.Script = $$.body
$5: Optional[Sequence[logic.Attribute]] = $$.attrs if not builtin.is_empty($$.attrs) else None
script
: "(" "script" construct* ")"
construct: $$ = logic.Script(constructs=$3)
deconstruct: $3: Sequence[logic.Construct] = $$.constructs
construct
: loop
construct: $$ = logic.Construct(loop=$1)
deconstruct if builtin.has_proto_field($$, 'loop'):
$1: logic.Loop = $$.loop
| instruction
construct: $$ = logic.Construct(instruction=$1)
deconstruct if builtin.has_proto_field($$, 'instruction'):
$1: logic.Instruction = $$.instruction
loop
: "(" "loop" init script attrs? ")"
construct: $$ = logic.Loop(init=$3, body=$4, attrs=builtin.unwrap_option_or($5, list[logic.Attribute]()))
deconstruct:
$3: Sequence[logic.Instruction] = $$.init
$4: logic.Script = $$.body
$5: Optional[Sequence[logic.Attribute]] = $$.attrs if not builtin.is_empty($$.attrs) else None
init
: "(" "init" instruction* ")"
instruction
: assign
construct: $$ = logic.Instruction(assign=$1)
deconstruct if builtin.has_proto_field($$, 'assign'):
$1: logic.Assign = $$.assign
| upsert
construct: $$ = logic.Instruction(upsert=$1)
deconstruct if builtin.has_proto_field($$, 'upsert'):
$1: logic.Upsert = $$.upsert
| break
construct: $$ = logic.Instruction(break=$1)
deconstruct if builtin.has_proto_field($$, 'break'):
$1: logic.Break = $$.break
| monoid_def
construct: $$ = logic.Instruction(monoid_def=$1)
deconstruct if builtin.has_proto_field($$, 'monoid_def'):
$1: logic.MonoidDef = $$.monoid_def
| monus_def
construct: $$ = logic.Instruction(monus_def=$1)
deconstruct if builtin.has_proto_field($$, 'monus_def'):
$1: logic.MonusDef = $$.monus_def
assign
: "(" "assign" relation_id abstraction attrs? ")"
construct: $$ = logic.Assign(name=$3, body=$4, attrs=builtin.unwrap_option_or($5, list[logic.Attribute]()))
deconstruct:
$3: logic.RelationId = $$.name
$4: logic.Abstraction = $$.body
$5: Optional[Sequence[logic.Attribute]] = $$.attrs if not builtin.is_empty($$.attrs) else None
upsert
: "(" "upsert" relation_id abstraction_with_arity attrs? ")"
construct: $$ = logic.Upsert(name=$3, body=$4[0], attrs=builtin.unwrap_option_or($5, list[logic.Attribute]()), value_arity=$4[1])
deconstruct:
$3: logic.RelationId = $$.name
$4: Tuple[logic.Abstraction, Int64] = builtin.tuple($$.body, $$.value_arity)
$5: Optional[Sequence[logic.Attribute]] = $$.attrs if not builtin.is_empty($$.attrs) else None
abstraction_with_arity
: "(" bindings formula ")"
construct: $$ = builtin.tuple(logic.Abstraction(vars=builtin.list_concat($2[0], $2[1]), value=$3), builtin.length($2[1]))
deconstruct:
$2: Tuple[Sequence[logic.Binding], Sequence[logic.Binding]] = deconstruct_bindings_with_arity($$[0], $$[1])
$3: logic.Formula = $$[0].value
break
: "(" "break" relation_id abstraction attrs? ")"
construct: $$ = logic.Break(name=$3, body=$4, attrs=builtin.unwrap_option_or($5, list[logic.Attribute]()))
deconstruct:
$3: logic.RelationId = $$.name
$4: logic.Abstraction = $$.body
$5: Optional[Sequence[logic.Attribute]] = $$.attrs if not builtin.is_empty($$.attrs) else None
monoid_def
: "(" "monoid" monoid relation_id abstraction_with_arity attrs? ")"
construct: $$ = logic.MonoidDef(monoid=$3, name=$4, body=$5[0], attrs=builtin.unwrap_option_or($6, list[logic.Attribute]()), value_arity=$5[1])
deconstruct:
$3: logic.Monoid = $$.monoid
$4: logic.RelationId = $$.name
$5: Tuple[logic.Abstraction, Int64] = builtin.tuple($$.body, $$.value_arity)
$6: Optional[Sequence[logic.Attribute]] = $$.attrs if not builtin.is_empty($$.attrs) else None
monoid
: or_monoid
construct: $$ = logic.Monoid(or_monoid=$1)
deconstruct if builtin.has_proto_field($$, 'or_monoid'):
$1: logic.OrMonoid = $$.or_monoid
| min_monoid
construct: $$ = logic.Monoid(min_monoid=$1)
deconstruct if builtin.has_proto_field($$, 'min_monoid'):
$1: logic.MinMonoid = $$.min_monoid
| max_monoid
construct: $$ = logic.Monoid(max_monoid=$1)
deconstruct if builtin.has_proto_field($$, 'max_monoid'):
$1: logic.MaxMonoid = $$.max_monoid
| sum_monoid