-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.py
More file actions
3009 lines (2814 loc) · 133 KB
/
Copy pathparser.py
File metadata and controls
3009 lines (2814 loc) · 133 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
"""
Auto-generated LL(k) recursive-descent parser.
Generated from protobuf specifications.
Do not modify this file! If you need to modify the parser, edit the generator code
in `meta/` or edit the protobuf specification in `proto/v1`.
Command: python -m meta.cli ../proto/relationalai/lqp/v1/fragments.proto ../proto/relationalai/lqp/v1/logic.proto ../proto/relationalai/lqp/v1/transactions.proto --grammar src/meta/grammar.y --parser python
"""
import ast
import hashlib
import re
from collections.abc import Sequence
from typing import List, Optional, Any, Tuple, Callable
from decimal import Decimal
from lqp.proto.v1 import logic_pb2, fragments_pb2, transactions_pb2
class ParseError(Exception):
"""Parse error exception."""
pass
class Token:
"""Token representation."""
def __init__(self, type: str, value: str, pos: int):
self.type = type
self.value = value
self.pos = pos
def __repr__(self) -> str:
return f"Token({self.type}, {self.value!r}, {self.pos})"
_WHITESPACE_RE = re.compile(r"\s+")
_COMMENT_RE = re.compile(r";;.*")
_TOKEN_SPECS = [
("LITERAL", re.compile(r"::"), lambda x: x),
("LITERAL", re.compile(r"<="), lambda x: x),
("LITERAL", re.compile(r">="), lambda x: x),
("LITERAL", re.compile(r"\#"), lambda x: x),
("LITERAL", re.compile(r"\("), lambda x: x),
("LITERAL", re.compile(r"\)"), lambda x: x),
("LITERAL", re.compile(r"\*"), lambda x: x),
("LITERAL", re.compile(r"\+"), lambda x: x),
("LITERAL", re.compile(r"\-"), lambda x: x),
("LITERAL", re.compile(r"/"), lambda x: x),
("LITERAL", re.compile(r":"), lambda x: x),
("LITERAL", re.compile(r"<"), lambda x: x),
("LITERAL", re.compile(r"="), lambda x: x),
("LITERAL", re.compile(r">"), lambda x: x),
("LITERAL", re.compile(r"\["), lambda x: x),
("LITERAL", re.compile(r"\]"), lambda x: x),
("LITERAL", re.compile(r"\{"), lambda x: x),
("LITERAL", re.compile(r"\|"), lambda x: x),
("LITERAL", re.compile(r"\}"), lambda x: x),
("DECIMAL", re.compile(r"[-]?\d+\.\d+d\d+"), lambda x: Lexer.scan_decimal(x)),
("FLOAT", re.compile(r"([-]?\d+\.\d+|inf|nan)"), lambda x: Lexer.scan_float(x)),
("INT", re.compile(r"[-]?\d+"), lambda x: Lexer.scan_int(x)),
("INT128", re.compile(r"[-]?\d+i128"), lambda x: Lexer.scan_int128(x)),
("STRING", re.compile(r'"(?:[^"\\]|\\.)*"'), lambda x: Lexer.scan_string(x)),
("SYMBOL", re.compile(r"[a-zA-Z_][a-zA-Z0-9_.-]*"), lambda x: Lexer.scan_symbol(x)),
("UINT128", re.compile(r"0x[0-9a-fA-F]+"), lambda x: Lexer.scan_uint128(x)),
]
class Lexer:
"""Tokenizer for the input."""
def __init__(self, input_str: str):
self.input = input_str
self.pos = 0
self.tokens: List[Token] = []
self._tokenize()
def _tokenize(self) -> None:
"""Tokenize the input string."""
while self.pos < len(self.input):
match = _WHITESPACE_RE.match(self.input, self.pos)
if match:
self.pos = match.end()
continue
match = _COMMENT_RE.match(self.input, self.pos)
if match:
self.pos = match.end()
continue
# Collect all matching tokens
candidates = []
for token_type, regex, action in _TOKEN_SPECS:
match = regex.match(self.input, self.pos)
if match:
value = match.group(0)
candidates.append((token_type, value, action, match.end()))
if not candidates:
raise ParseError(
f"Unexpected character at position {self.pos}: {self.input[self.pos]!r}"
)
# Pick the longest match
token_type, value, action, end_pos = max(candidates, key=lambda x: x[3])
self.tokens.append(Token(token_type, action(value), self.pos))
self.pos = end_pos
self.tokens.append(Token("$", "", self.pos))
@staticmethod
def scan_symbol(s: str) -> str:
"""Parse SYMBOL token."""
return s
@staticmethod
def scan_string(s: str) -> str:
"""Parse STRING token."""
return ast.literal_eval(s)
@staticmethod
def scan_int(n: str) -> int:
"""Parse INT token."""
val = int(n)
if val < -(1 << 63) or val >= (1 << 63):
raise ParseError(f"Integer literal out of 64-bit range: {n}")
return val
@staticmethod
def scan_float(f: str) -> float:
"""Parse FLOAT token."""
if f == "inf":
return float("inf")
elif f == "nan":
return float("nan")
return float(f)
@staticmethod
def scan_uint128(u: str) -> Any:
"""Parse UINT128 token."""
uint128_val = int(u, 16)
if uint128_val < 0 or uint128_val >= (1 << 128):
raise ParseError(f"UInt128 literal out of range: {u}")
low = uint128_val & 0xFFFFFFFFFFFFFFFF
high = (uint128_val >> 64) & 0xFFFFFFFFFFFFFFFF
return logic_pb2.UInt128Value(low=low, high=high)
@staticmethod
def scan_int128(u: str) -> Any:
"""Parse INT128 token."""
u = u[:-4] # Remove the "i128" suffix
int128_val = int(u)
if int128_val < -(1 << 127) or int128_val >= (1 << 127):
raise ParseError(f"Int128 literal out of range: {u}")
low = int128_val & 0xFFFFFFFFFFFFFFFF
high = (int128_val >> 64) & 0xFFFFFFFFFFFFFFFF
return logic_pb2.Int128Value(low=low, high=high)
@staticmethod
def scan_decimal(d: str) -> Any:
"""Parse DECIMAL token."""
# Decimal is a string like "123.456d12" where the last part after `d` is the
# precision, and the scale is the number of digits between the decimal point and `d`
parts = d.split("d")
if len(parts) != 2:
raise ValueError(f"Invalid decimal format: {d}")
scale = len(parts[0].split(".")[1])
precision = int(parts[1])
# Parse the integer value directly without calling scan_int128 which strips "i128" suffix
int_str = parts[0].replace(".", "")
int128_val = int(int_str)
low = int128_val & 0xFFFFFFFFFFFFFFFF
high = (int128_val >> 64) & 0xFFFFFFFFFFFFFFFF
value = logic_pb2.Int128Value(low=low, high=high)
return logic_pb2.DecimalValue(precision=precision, scale=scale, value=value)
class Parser:
"""LL(k) recursive-descent parser with backtracking."""
def __init__(self, tokens: List[Token]):
self.tokens = tokens
self.pos = 0
self.id_to_debuginfo = {}
self._current_fragment_id: bytes | None = None
self._relation_id_to_name = {}
def lookahead(self, k: int = 0) -> Token:
"""Get lookahead token at offset k."""
idx = self.pos + k
return self.tokens[idx] if idx < len(self.tokens) else Token("$", "", -1)
def consume_literal(self, expected: str) -> None:
"""Consume a literal token."""
if not self.match_lookahead_literal(expected, 0):
token = self.lookahead(0)
raise ParseError(
f"Expected literal {expected!r} but got {token.type}=`{token.value!r}` at position {token.pos}"
)
self.pos += 1
def consume_terminal(self, expected: str) -> Any:
"""Consume a terminal token and return parsed value."""
if not self.match_lookahead_terminal(expected, 0):
token = self.lookahead(0)
raise ParseError(
f"Expected terminal {expected} but got {token.type}=`{token.value!r}` at position {token.pos}"
)
token = self.lookahead(0)
self.pos += 1
return token.value
def match_lookahead_literal(self, literal: str, k: int) -> bool:
"""Check if lookahead token at position k matches literal.
Supports soft keywords: alphanumeric literals are lexed as SYMBOL tokens,
so we check both LITERAL and SYMBOL token types.
"""
token = self.lookahead(k)
if token.type == "LITERAL" and token.value == literal:
return True
if token.type == "SYMBOL" and token.value == literal:
return True
return False
def match_lookahead_terminal(self, terminal: str, k: int) -> bool:
"""Check if lookahead token at position k matches terminal."""
token = self.lookahead(k)
return token.type == terminal
def start_fragment(
self, fragment_id: fragments_pb2.FragmentId
) -> fragments_pb2.FragmentId:
"""Set current fragment ID for debug info tracking."""
self._current_fragment_id = fragment_id.id
return fragment_id
def relation_id_from_string(self, name: str) -> Any:
"""Create RelationId from string and track mapping for debug info."""
hash_bytes = hashlib.sha256(name.encode()).digest()
# Use big-endian and the lower 128 bits of the hash, consistent with pyrel.
id_high = int.from_bytes(hash_bytes[16:24], byteorder='big')
id_low = int.from_bytes(hash_bytes[24:32], byteorder='big')
relation_id = logic_pb2.RelationId(id_low=id_low, id_high=id_high)
# Store the mapping for the current fragment if we're inside one
if self._current_fragment_id is not None:
if self._current_fragment_id not in self.id_to_debuginfo:
self.id_to_debuginfo[self._current_fragment_id] = {}
key = (relation_id.id_low, relation_id.id_high)
self.id_to_debuginfo[self._current_fragment_id][key] = name
return relation_id
def construct_fragment(
self,
fragment_id: fragments_pb2.FragmentId,
declarations: List[logic_pb2.Declaration],
) -> fragments_pb2.Fragment:
"""Construct Fragment from fragment_id, declarations, and debug info from parser state."""
# Get the debug info for this fragment
debug_info_dict = self.id_to_debuginfo.get(fragment_id.id, {})
# Convert to DebugInfo protobuf
ids = []
orig_names = []
for (id_low, id_high), name in debug_info_dict.items():
ids.append(logic_pb2.RelationId(id_low=id_low, id_high=id_high))
orig_names.append(name)
# Create DebugInfo
debug_info = fragments_pb2.DebugInfo(ids=ids, orig_names=orig_names)
# Clear _current_fragment_id before the return
self._current_fragment_id = None
# Create and return Fragment
return fragments_pb2.Fragment(
id=fragment_id, declarations=declarations, debug_info=debug_info
)
def relation_id_to_string(self, msg) -> str:
"""Stub: only used in pretty printer."""
raise NotImplementedError(
"relation_id_to_string is only available in PrettyPrinter"
)
def relation_id_to_uint128(self, msg):
"""Stub: only used in pretty printer."""
raise NotImplementedError(
"relation_id_to_uint128 is only available in PrettyPrinter"
)
# --- Helper functions ---
def _extract_value_int32(self, value: Optional[logic_pb2.Value], default: int) -> int:
if value is not None:
assert value is not None
_t1378 = value.HasField("int_value")
else:
_t1378 = False
if _t1378:
assert value is not None
return int(value.int_value)
else:
_t1379 = None
return int(default)
def _extract_value_int64(self, value: Optional[logic_pb2.Value], default: int) -> int:
if value is not None:
assert value is not None
_t1380 = value.HasField("int_value")
else:
_t1380 = False
if _t1380:
assert value is not None
return value.int_value
else:
_t1381 = None
return default
def _extract_value_string(self, value: Optional[logic_pb2.Value], default: str) -> str:
if value is not None:
assert value is not None
_t1382 = value.HasField("string_value")
else:
_t1382 = False
if _t1382:
assert value is not None
return value.string_value
else:
_t1383 = None
return default
def _extract_value_boolean(self, value: Optional[logic_pb2.Value], default: bool) -> bool:
if value is not None:
assert value is not None
_t1384 = value.HasField("boolean_value")
else:
_t1384 = False
if _t1384:
assert value is not None
return value.boolean_value
else:
_t1385 = None
return default
def _extract_value_string_list(self, value: Optional[logic_pb2.Value], default: Sequence[str]) -> Sequence[str]:
if value is not None:
assert value is not None
_t1386 = value.HasField("string_value")
else:
_t1386 = False
if _t1386:
assert value is not None
return [value.string_value]
else:
_t1387 = None
return default
def _try_extract_value_int64(self, value: Optional[logic_pb2.Value]) -> Optional[int]:
if value is not None:
assert value is not None
_t1388 = value.HasField("int_value")
else:
_t1388 = False
if _t1388:
assert value is not None
return value.int_value
else:
_t1389 = None
return None
def _try_extract_value_float64(self, value: Optional[logic_pb2.Value]) -> Optional[float]:
if value is not None:
assert value is not None
_t1390 = value.HasField("float_value")
else:
_t1390 = False
if _t1390:
assert value is not None
return value.float_value
else:
_t1391 = None
return None
def _try_extract_value_bytes(self, value: Optional[logic_pb2.Value]) -> Optional[bytes]:
if value is not None:
assert value is not None
_t1392 = value.HasField("string_value")
else:
_t1392 = False
if _t1392:
assert value is not None
return value.string_value.encode()
else:
_t1393 = None
return None
def _try_extract_value_uint128(self, value: Optional[logic_pb2.Value]) -> Optional[logic_pb2.UInt128Value]:
if value is not None:
assert value is not None
_t1394 = value.HasField("uint128_value")
else:
_t1394 = False
if _t1394:
assert value is not None
return value.uint128_value
else:
_t1395 = None
return None
def construct_csv_config(self, config_dict: Sequence[tuple[str, logic_pb2.Value]]) -> logic_pb2.CSVConfig:
config = dict(config_dict)
_t1396 = self._extract_value_int32(config.get("csv_header_row"), 1)
header_row = _t1396
_t1397 = self._extract_value_int64(config.get("csv_skip"), 0)
skip = _t1397
_t1398 = self._extract_value_string(config.get("csv_new_line"), "")
new_line = _t1398
_t1399 = self._extract_value_string(config.get("csv_delimiter"), ",")
delimiter = _t1399
_t1400 = self._extract_value_string(config.get("csv_quotechar"), '"')
quotechar = _t1400
_t1401 = self._extract_value_string(config.get("csv_escapechar"), '"')
escapechar = _t1401
_t1402 = self._extract_value_string(config.get("csv_comment"), "")
comment = _t1402
_t1403 = self._extract_value_string_list(config.get("csv_missing_strings"), [])
missing_strings = _t1403
_t1404 = self._extract_value_string(config.get("csv_decimal_separator"), ".")
decimal_separator = _t1404
_t1405 = self._extract_value_string(config.get("csv_encoding"), "utf-8")
encoding = _t1405
_t1406 = self._extract_value_string(config.get("csv_compression"), "auto")
compression = _t1406
_t1407 = self._extract_value_int64(config.get("csv_partition_size_mb"), 0)
partition_size_mb = _t1407
_t1408 = logic_pb2.CSVConfig(header_row=header_row, skip=skip, new_line=new_line, delimiter=delimiter, quotechar=quotechar, escapechar=escapechar, comment=comment, missing_strings=missing_strings, decimal_separator=decimal_separator, encoding=encoding, compression=compression, partition_size_mb=partition_size_mb)
return _t1408
def construct_betree_info(self, key_types: Sequence[logic_pb2.Type], value_types: Sequence[logic_pb2.Type], config_dict: Sequence[tuple[str, logic_pb2.Value]]) -> logic_pb2.BeTreeInfo:
config = dict(config_dict)
_t1409 = self._try_extract_value_float64(config.get("betree_config_epsilon"))
epsilon = _t1409
_t1410 = self._try_extract_value_int64(config.get("betree_config_max_pivots"))
max_pivots = _t1410
_t1411 = self._try_extract_value_int64(config.get("betree_config_max_deltas"))
max_deltas = _t1411
_t1412 = self._try_extract_value_int64(config.get("betree_config_max_leaf"))
max_leaf = _t1412
_t1413 = logic_pb2.BeTreeConfig(epsilon=epsilon, max_pivots=max_pivots, max_deltas=max_deltas, max_leaf=max_leaf)
storage_config = _t1413
_t1414 = self._try_extract_value_uint128(config.get("betree_locator_root_pageid"))
root_pageid = _t1414
_t1415 = self._try_extract_value_bytes(config.get("betree_locator_inline_data"))
inline_data = _t1415
_t1416 = self._try_extract_value_int64(config.get("betree_locator_element_count"))
element_count = _t1416
_t1417 = self._try_extract_value_int64(config.get("betree_locator_tree_height"))
tree_height = _t1417
_t1418 = logic_pb2.BeTreeLocator(root_pageid=root_pageid, inline_data=inline_data, element_count=element_count, tree_height=tree_height)
relation_locator = _t1418
_t1419 = logic_pb2.BeTreeInfo(key_types=key_types, value_types=value_types, storage_config=storage_config, relation_locator=relation_locator)
return _t1419
def default_configure(self) -> transactions_pb2.Configure:
_t1420 = transactions_pb2.IVMConfig(level=transactions_pb2.MaintenanceLevel.MAINTENANCE_LEVEL_OFF)
ivm_config = _t1420
_t1421 = transactions_pb2.Configure(semantics_version=0, ivm_config=ivm_config)
return _t1421
def construct_configure(self, config_dict: Sequence[tuple[str, logic_pb2.Value]]) -> transactions_pb2.Configure:
config = dict(config_dict)
maintenance_level_val = config.get("ivm.maintenance_level")
maintenance_level = transactions_pb2.MaintenanceLevel.MAINTENANCE_LEVEL_OFF
if (maintenance_level_val is not None and maintenance_level_val.HasField("string_value")):
if maintenance_level_val.string_value == "off":
maintenance_level = transactions_pb2.MaintenanceLevel.MAINTENANCE_LEVEL_OFF
else:
if maintenance_level_val.string_value == "auto":
maintenance_level = transactions_pb2.MaintenanceLevel.MAINTENANCE_LEVEL_AUTO
else:
if maintenance_level_val.string_value == "all":
maintenance_level = transactions_pb2.MaintenanceLevel.MAINTENANCE_LEVEL_ALL
else:
maintenance_level = transactions_pb2.MaintenanceLevel.MAINTENANCE_LEVEL_OFF
_t1422 = transactions_pb2.IVMConfig(level=maintenance_level)
ivm_config = _t1422
_t1423 = self._extract_value_int64(config.get("semantics_version"), 0)
semantics_version = _t1423
_t1424 = transactions_pb2.Configure(semantics_version=semantics_version, ivm_config=ivm_config)
return _t1424
def construct_export_csv_config(self, path: str, columns: Sequence[transactions_pb2.ExportCSVColumn], config_dict: Sequence[tuple[str, logic_pb2.Value]]) -> transactions_pb2.ExportCSVConfig:
config = dict(config_dict)
_t1425 = self._extract_value_int64(config.get("partition_size"), 0)
partition_size = _t1425
_t1426 = self._extract_value_string(config.get("compression"), "")
compression = _t1426
_t1427 = self._extract_value_boolean(config.get("syntax_header_row"), True)
syntax_header_row = _t1427
_t1428 = self._extract_value_string(config.get("syntax_missing_string"), "")
syntax_missing_string = _t1428
_t1429 = self._extract_value_string(config.get("syntax_delim"), ",")
syntax_delim = _t1429
_t1430 = self._extract_value_string(config.get("syntax_quotechar"), '"')
syntax_quotechar = _t1430
_t1431 = self._extract_value_string(config.get("syntax_escapechar"), "\\")
syntax_escapechar = _t1431
_t1432 = transactions_pb2.ExportCSVConfig(path=path, data_columns=columns, partition_size=partition_size, compression=compression, syntax_header_row=syntax_header_row, syntax_missing_string=syntax_missing_string, syntax_delim=syntax_delim, syntax_quotechar=syntax_quotechar, syntax_escapechar=syntax_escapechar)
return _t1432
def construct_export_csv_config_with_source(self, path: str, csv_source: transactions_pb2.ExportCSVSource, csv_config: logic_pb2.CSVConfig) -> transactions_pb2.ExportCSVConfig:
_t1433 = transactions_pb2.ExportCSVConfig(path=path, csv_source=csv_source, csv_config=csv_config)
return _t1433
# --- Parse methods ---
def parse_transaction(self) -> transactions_pb2.Transaction:
self.consume_literal("(")
self.consume_literal("transaction")
if (self.match_lookahead_literal("(", 0) and self.match_lookahead_literal("configure", 1)):
_t753 = self.parse_configure()
_t752 = _t753
else:
_t752 = None
configure376 = _t752
if (self.match_lookahead_literal("(", 0) and self.match_lookahead_literal("sync", 1)):
_t755 = self.parse_sync()
_t754 = _t755
else:
_t754 = None
sync377 = _t754
xs378 = []
cond379 = self.match_lookahead_literal("(", 0)
while cond379:
_t756 = self.parse_epoch()
item380 = _t756
xs378.append(item380)
cond379 = self.match_lookahead_literal("(", 0)
epochs381 = xs378
self.consume_literal(")")
_t757 = self.default_configure()
_t758 = transactions_pb2.Transaction(epochs=epochs381, configure=(configure376 if configure376 is not None else _t757), sync=sync377)
return _t758
def parse_configure(self) -> transactions_pb2.Configure:
self.consume_literal("(")
self.consume_literal("configure")
_t759 = self.parse_config_dict()
config_dict382 = _t759
self.consume_literal(")")
_t760 = self.construct_configure(config_dict382)
return _t760
def parse_config_dict(self) -> Sequence[tuple[str, logic_pb2.Value]]:
self.consume_literal("{")
xs383 = []
cond384 = self.match_lookahead_literal(":", 0)
while cond384:
_t761 = self.parse_config_key_value()
item385 = _t761
xs383.append(item385)
cond384 = self.match_lookahead_literal(":", 0)
config_key_values386 = xs383
self.consume_literal("}")
return config_key_values386
def parse_config_key_value(self) -> tuple[str, logic_pb2.Value]:
self.consume_literal(":")
symbol387 = self.consume_terminal("SYMBOL")
_t762 = self.parse_value()
value388 = _t762
return (symbol387, value388,)
def parse_value(self) -> logic_pb2.Value:
if self.match_lookahead_literal("true", 0):
_t763 = 9
else:
if self.match_lookahead_literal("missing", 0):
_t764 = 8
else:
if self.match_lookahead_literal("false", 0):
_t765 = 9
else:
if self.match_lookahead_literal("(", 0):
if self.match_lookahead_literal("datetime", 1):
_t767 = 1
else:
if self.match_lookahead_literal("date", 1):
_t768 = 0
else:
_t768 = -1
_t767 = _t768
_t766 = _t767
else:
if self.match_lookahead_terminal("UINT128", 0):
_t769 = 5
else:
if self.match_lookahead_terminal("STRING", 0):
_t770 = 2
else:
if self.match_lookahead_terminal("INT128", 0):
_t771 = 6
else:
if self.match_lookahead_terminal("INT", 0):
_t772 = 3
else:
if self.match_lookahead_terminal("FLOAT", 0):
_t773 = 4
else:
if self.match_lookahead_terminal("DECIMAL", 0):
_t774 = 7
else:
_t774 = -1
_t773 = _t774
_t772 = _t773
_t771 = _t772
_t770 = _t771
_t769 = _t770
_t766 = _t769
_t765 = _t766
_t764 = _t765
_t763 = _t764
prediction389 = _t763
if prediction389 == 9:
_t776 = self.parse_boolean_value()
boolean_value398 = _t776
_t777 = logic_pb2.Value(boolean_value=boolean_value398)
_t775 = _t777
else:
if prediction389 == 8:
self.consume_literal("missing")
_t779 = logic_pb2.MissingValue()
_t780 = logic_pb2.Value(missing_value=_t779)
_t778 = _t780
else:
if prediction389 == 7:
decimal397 = self.consume_terminal("DECIMAL")
_t782 = logic_pb2.Value(decimal_value=decimal397)
_t781 = _t782
else:
if prediction389 == 6:
int128396 = self.consume_terminal("INT128")
_t784 = logic_pb2.Value(int128_value=int128396)
_t783 = _t784
else:
if prediction389 == 5:
uint128395 = self.consume_terminal("UINT128")
_t786 = logic_pb2.Value(uint128_value=uint128395)
_t785 = _t786
else:
if prediction389 == 4:
float394 = self.consume_terminal("FLOAT")
_t788 = logic_pb2.Value(float_value=float394)
_t787 = _t788
else:
if prediction389 == 3:
int393 = self.consume_terminal("INT")
_t790 = logic_pb2.Value(int_value=int393)
_t789 = _t790
else:
if prediction389 == 2:
string392 = self.consume_terminal("STRING")
_t792 = logic_pb2.Value(string_value=string392)
_t791 = _t792
else:
if prediction389 == 1:
_t794 = self.parse_datetime()
datetime391 = _t794
_t795 = logic_pb2.Value(datetime_value=datetime391)
_t793 = _t795
else:
if prediction389 == 0:
_t797 = self.parse_date()
date390 = _t797
_t798 = logic_pb2.Value(date_value=date390)
_t796 = _t798
else:
raise ParseError("Unexpected token in value" + f": {self.lookahead(0).type}=`{self.lookahead(0).value}`")
_t793 = _t796
_t791 = _t793
_t789 = _t791
_t787 = _t789
_t785 = _t787
_t783 = _t785
_t781 = _t783
_t778 = _t781
_t775 = _t778
return _t775
def parse_date(self) -> logic_pb2.DateValue:
self.consume_literal("(")
self.consume_literal("date")
int399 = self.consume_terminal("INT")
int_3400 = self.consume_terminal("INT")
int_4401 = self.consume_terminal("INT")
self.consume_literal(")")
_t799 = logic_pb2.DateValue(year=int(int399), month=int(int_3400), day=int(int_4401))
return _t799
def parse_datetime(self) -> logic_pb2.DateTimeValue:
self.consume_literal("(")
self.consume_literal("datetime")
int402 = self.consume_terminal("INT")
int_3403 = self.consume_terminal("INT")
int_4404 = self.consume_terminal("INT")
int_5405 = self.consume_terminal("INT")
int_6406 = self.consume_terminal("INT")
int_7407 = self.consume_terminal("INT")
if self.match_lookahead_terminal("INT", 0):
_t800 = self.consume_terminal("INT")
else:
_t800 = None
int_8408 = _t800
self.consume_literal(")")
_t801 = logic_pb2.DateTimeValue(year=int(int402), month=int(int_3403), day=int(int_4404), hour=int(int_5405), minute=int(int_6406), second=int(int_7407), microsecond=int((int_8408 if int_8408 is not None else 0)))
return _t801
def parse_boolean_value(self) -> bool:
if self.match_lookahead_literal("true", 0):
_t802 = 0
else:
if self.match_lookahead_literal("false", 0):
_t803 = 1
else:
_t803 = -1
_t802 = _t803
prediction409 = _t802
if prediction409 == 1:
self.consume_literal("false")
_t804 = False
else:
if prediction409 == 0:
self.consume_literal("true")
_t805 = True
else:
raise ParseError("Unexpected token in boolean_value" + f": {self.lookahead(0).type}=`{self.lookahead(0).value}`")
_t804 = _t805
return _t804
def parse_sync(self) -> transactions_pb2.Sync:
self.consume_literal("(")
self.consume_literal("sync")
xs410 = []
cond411 = self.match_lookahead_literal(":", 0)
while cond411:
_t806 = self.parse_fragment_id()
item412 = _t806
xs410.append(item412)
cond411 = self.match_lookahead_literal(":", 0)
fragment_ids413 = xs410
self.consume_literal(")")
_t807 = transactions_pb2.Sync(fragments=fragment_ids413)
return _t807
def parse_fragment_id(self) -> fragments_pb2.FragmentId:
self.consume_literal(":")
symbol414 = self.consume_terminal("SYMBOL")
return fragments_pb2.FragmentId(id=symbol414.encode())
def parse_epoch(self) -> transactions_pb2.Epoch:
self.consume_literal("(")
self.consume_literal("epoch")
if (self.match_lookahead_literal("(", 0) and self.match_lookahead_literal("writes", 1)):
_t809 = self.parse_epoch_writes()
_t808 = _t809
else:
_t808 = None
epoch_writes415 = _t808
if self.match_lookahead_literal("(", 0):
_t811 = self.parse_epoch_reads()
_t810 = _t811
else:
_t810 = None
epoch_reads416 = _t810
self.consume_literal(")")
_t812 = transactions_pb2.Epoch(writes=(epoch_writes415 if epoch_writes415 is not None else []), reads=(epoch_reads416 if epoch_reads416 is not None else []))
return _t812
def parse_epoch_writes(self) -> Sequence[transactions_pb2.Write]:
self.consume_literal("(")
self.consume_literal("writes")
xs417 = []
cond418 = self.match_lookahead_literal("(", 0)
while cond418:
_t813 = self.parse_write()
item419 = _t813
xs417.append(item419)
cond418 = self.match_lookahead_literal("(", 0)
writes420 = xs417
self.consume_literal(")")
return writes420
def parse_write(self) -> transactions_pb2.Write:
if self.match_lookahead_literal("(", 0):
if self.match_lookahead_literal("undefine", 1):
_t815 = 1
else:
if self.match_lookahead_literal("snapshot", 1):
_t816 = 3
else:
if self.match_lookahead_literal("define", 1):
_t817 = 0
else:
if self.match_lookahead_literal("context", 1):
_t818 = 2
else:
_t818 = -1
_t817 = _t818
_t816 = _t817
_t815 = _t816
_t814 = _t815
else:
_t814 = -1
prediction421 = _t814
if prediction421 == 3:
_t820 = self.parse_snapshot()
snapshot425 = _t820
_t821 = transactions_pb2.Write(snapshot=snapshot425)
_t819 = _t821
else:
if prediction421 == 2:
_t823 = self.parse_context()
context424 = _t823
_t824 = transactions_pb2.Write(context=context424)
_t822 = _t824
else:
if prediction421 == 1:
_t826 = self.parse_undefine()
undefine423 = _t826
_t827 = transactions_pb2.Write(undefine=undefine423)
_t825 = _t827
else:
if prediction421 == 0:
_t829 = self.parse_define()
define422 = _t829
_t830 = transactions_pb2.Write(define=define422)
_t828 = _t830
else:
raise ParseError("Unexpected token in write" + f": {self.lookahead(0).type}=`{self.lookahead(0).value}`")
_t825 = _t828
_t822 = _t825
_t819 = _t822
return _t819
def parse_define(self) -> transactions_pb2.Define:
self.consume_literal("(")
self.consume_literal("define")
_t831 = self.parse_fragment()
fragment426 = _t831
self.consume_literal(")")
_t832 = transactions_pb2.Define(fragment=fragment426)
return _t832
def parse_fragment(self) -> fragments_pb2.Fragment:
self.consume_literal("(")
self.consume_literal("fragment")
_t833 = self.parse_new_fragment_id()
new_fragment_id427 = _t833
xs428 = []
cond429 = self.match_lookahead_literal("(", 0)
while cond429:
_t834 = self.parse_declaration()
item430 = _t834
xs428.append(item430)
cond429 = self.match_lookahead_literal("(", 0)
declarations431 = xs428
self.consume_literal(")")
return self.construct_fragment(new_fragment_id427, declarations431)
def parse_new_fragment_id(self) -> fragments_pb2.FragmentId:
_t835 = self.parse_fragment_id()
fragment_id432 = _t835
self.start_fragment(fragment_id432)
return fragment_id432
def parse_declaration(self) -> logic_pb2.Declaration:
if self.match_lookahead_literal("(", 0):
if self.match_lookahead_literal("functional_dependency", 1):
_t837 = 2
else:
if self.match_lookahead_literal("edb", 1):
_t838 = 3
else:
if self.match_lookahead_literal("def", 1):
_t839 = 0
else:
if self.match_lookahead_literal("csv_data", 1):
_t840 = 3
else:
if self.match_lookahead_literal("betree_relation", 1):
_t841 = 3
else:
if self.match_lookahead_literal("algorithm", 1):
_t842 = 1
else:
_t842 = -1
_t841 = _t842
_t840 = _t841
_t839 = _t840
_t838 = _t839
_t837 = _t838
_t836 = _t837
else:
_t836 = -1
prediction433 = _t836
if prediction433 == 3:
_t844 = self.parse_data()
data437 = _t844
_t845 = logic_pb2.Declaration(data=data437)
_t843 = _t845
else:
if prediction433 == 2:
_t847 = self.parse_constraint()
constraint436 = _t847
_t848 = logic_pb2.Declaration(constraint=constraint436)
_t846 = _t848
else:
if prediction433 == 1:
_t850 = self.parse_algorithm()
algorithm435 = _t850
_t851 = logic_pb2.Declaration(algorithm=algorithm435)
_t849 = _t851
else:
if prediction433 == 0:
_t853 = self.parse_def()
def434 = _t853
_t854 = logic_pb2.Declaration()
getattr(_t854, 'def').CopyFrom(def434)
_t852 = _t854
else:
raise ParseError("Unexpected token in declaration" + f": {self.lookahead(0).type}=`{self.lookahead(0).value}`")
_t849 = _t852
_t846 = _t849
_t843 = _t846
return _t843
def parse_def(self) -> logic_pb2.Def:
self.consume_literal("(")
self.consume_literal("def")
_t855 = self.parse_relation_id()
relation_id438 = _t855
_t856 = self.parse_abstraction()
abstraction439 = _t856
if self.match_lookahead_literal("(", 0):
_t858 = self.parse_attrs()
_t857 = _t858
else:
_t857 = None
attrs440 = _t857
self.consume_literal(")")
_t859 = logic_pb2.Def(name=relation_id438, body=abstraction439, attrs=(attrs440 if attrs440 is not None else []))
return _t859
def parse_relation_id(self) -> logic_pb2.RelationId:
if self.match_lookahead_literal(":", 0):
_t860 = 0
else:
if self.match_lookahead_terminal("UINT128", 0):
_t861 = 1
else:
_t861 = -1
_t860 = _t861
prediction441 = _t860
if prediction441 == 1:
uint128443 = self.consume_terminal("UINT128")
_t862 = logic_pb2.RelationId(id_low=uint128443.low, id_high=uint128443.high)
else:
if prediction441 == 0:
self.consume_literal(":")
symbol442 = self.consume_terminal("SYMBOL")
_t863 = self.relation_id_from_string(symbol442)
else:
raise ParseError("Unexpected token in relation_id" + f": {self.lookahead(0).type}=`{self.lookahead(0).value}`")
_t862 = _t863
return _t862
def parse_abstraction(self) -> logic_pb2.Abstraction:
self.consume_literal("(")
_t864 = self.parse_bindings()
bindings444 = _t864
_t865 = self.parse_formula()
formula445 = _t865
self.consume_literal(")")
_t866 = logic_pb2.Abstraction(vars=(list(bindings444[0]) + list(bindings444[1] if bindings444[1] is not None else [])), value=formula445)
return _t866
def parse_bindings(self) -> tuple[Sequence[logic_pb2.Binding], Sequence[logic_pb2.Binding]]:
self.consume_literal("[")
xs446 = []
cond447 = self.match_lookahead_terminal("SYMBOL", 0)
while cond447:
_t867 = self.parse_binding()
item448 = _t867