-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.jl
More file actions
3384 lines (3187 loc) · 133 KB
/
Copy pathparser.jl
File metadata and controls
3384 lines (3187 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
"""
Parser
Auto-generated LL(k) recursive-descent parser module.
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 julia
"""
module Parser
using SHA
using ProtoBuf: OneOf
# Import protobuf modules and helpers from parent
using ..relationalai: relationalai
using ..relationalai.lqp.v1
using ..LogicalQueryProtocol: _has_proto_field, _get_oneof_field
const Proto = relationalai.lqp.v1
struct ParseError <: Exception
msg::String
end
Base.showerror(io::IO, e::ParseError) = print(io, "ParseError: ", e.msg)
struct Token
type::String
value::Any
pos::Int
end
Base.show(io::IO, t::Token) = print(io, "Token(", t.type, ", ", repr(t.value), ", ", t.pos, ")")
mutable struct Lexer
input::String
pos::Int
tokens::Vector{Token}
function Lexer(input::String)
lexer = new(input, 1, Token[])
tokenize!(lexer)
return lexer
end
end
# Scanner functions for each token type
scan_symbol(s::String) = s
function scan_string(s::String)
# Strip quotes using Unicode-safe chop (handles multi-byte characters)
content = chop(s, head=1, tail=1)
# Process \\ first so that \\n doesn't become a newline.
result = replace(content, "\\\\" => "\x00")
result = replace(result, "\\n" => "\n")
result = replace(result, "\\t" => "\t")
result = replace(result, "\\r" => "\r")
result = replace(result, "\\\"" => "\"")
result = replace(result, "\x00" => "\\")
return result
end
scan_int(n::String) = Base.parse(Int64, n)
function scan_float(f::String)
if f == "inf"
return Inf
elseif f == "nan"
return NaN
end
return Base.parse(Float64, f)
end
function scan_uint128(u::String)
# Remove the '0x' prefix
hex_str = u[3:end]
uint128_val = Base.parse(UInt128, hex_str, base=16)
low = UInt64(uint128_val & 0xFFFFFFFFFFFFFFFF)
high = UInt64((uint128_val >> 64) & 0xFFFFFFFFFFFFFFFF)
return Proto.UInt128Value(low, high)
end
function scan_int128(u::String)
# Remove the 'i128' suffix
u = u[1:end-4]
int128_val = Base.parse(Int128, u)
low = UInt64(int128_val & 0xFFFFFFFFFFFFFFFF)
high = UInt64((int128_val >> 64) & 0xFFFFFFFFFFFFFFFF)
return Proto.Int128Value(low, high)
end
function scan_decimal(d::String)
# 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 = split(d, 'd')
if length(parts) != 2
throw(ArgumentError("Invalid decimal format: $d"))
end
scale = length(split(parts[1], '.')[2])
precision = Base.parse(Int32, parts[2])
# Parse the integer value
int_str = replace(parts[1], "." => "")
int128_val = Base.parse(Int128, int_str)
low = UInt64(int128_val & 0xFFFFFFFFFFFFFFFF)
high = UInt64((int128_val >> 64) & 0xFFFFFFFFFFFFFFFF)
value = Proto.Int128Value(low, high)
return Proto.DecimalValue(precision, scale, value)
end
const _WHITESPACE_RE = r"\s+"
const _COMMENT_RE = r";;.*"
const _TOKEN_SPECS = [
("LITERAL", r"::", identity),
("LITERAL", r"<=", identity),
("LITERAL", r">=", identity),
("LITERAL", r"\#", identity),
("LITERAL", r"\(", identity),
("LITERAL", r"\)", identity),
("LITERAL", r"\*", identity),
("LITERAL", r"\+", identity),
("LITERAL", r"\-", identity),
("LITERAL", r"/", identity),
("LITERAL", r":", identity),
("LITERAL", r"<", identity),
("LITERAL", r"=", identity),
("LITERAL", r">", identity),
("LITERAL", r"\[", identity),
("LITERAL", r"\]", identity),
("LITERAL", r"\{", identity),
("LITERAL", r"\|", identity),
("LITERAL", r"\}", identity),
("DECIMAL", r"[-]?\d+\.\d+d\d+", scan_decimal),
("FLOAT", r"([-]?\d+\.\d+|inf|nan)", scan_float),
("INT", r"[-]?\d+", scan_int),
("INT128", r"[-]?\d+i128", scan_int128),
("STRING", r"\"(?:[^\"\\]|\\.)*\"", scan_string),
("SYMBOL", r"[a-zA-Z_][a-zA-Z0-9_.-]*", scan_symbol),
("UINT128", r"0x[0-9a-fA-F]+", scan_uint128),
]
function tokenize!(lexer::Lexer)
# Use ncodeunits for byte-based position tracking (UTF-8 safe)
while lexer.pos <= ncodeunits(lexer.input)
# Skip whitespace
m = match(_WHITESPACE_RE, lexer.input, lexer.pos)
if m !== nothing && m.offset == lexer.pos
lexer.pos = m.offset + ncodeunits(m.match)
continue
end
# Skip comments
m = match(_COMMENT_RE, lexer.input, lexer.pos)
if m !== nothing && m.offset == lexer.pos
lexer.pos = m.offset + ncodeunits(m.match)
continue
end
# Collect all matching tokens
candidates = Tuple{String,String,Function,Int}[]
for (token_type, regex, action) in _TOKEN_SPECS
m = match(regex, lexer.input, lexer.pos)
if m !== nothing && m.offset == lexer.pos
value = m.match
push!(candidates, (token_type, value, action, m.offset + ncodeunits(value)))
end
end
if isempty(candidates)
throw(ParseError("Unexpected character at position $(lexer.pos): $(repr(lexer.input[lexer.pos]))"))
end
# Pick the longest match
token_type, value, action, end_pos = candidates[argmax([c[4] for c in candidates])]
push!(lexer.tokens, Token(token_type, action(value), lexer.pos))
lexer.pos = end_pos
end
push!(lexer.tokens, Token("\$", "", lexer.pos))
return nothing
end
mutable struct ParserState
tokens::Vector{Token}
pos::Int
id_to_debuginfo::Dict{Vector{UInt8},Vector{Pair{Tuple{UInt64,UInt64},String}}}
_current_fragment_id::Union{Nothing,Vector{UInt8}}
_relation_id_to_name::Dict{Tuple{UInt64,UInt64},String}
function ParserState(tokens::Vector{Token})
return new(tokens, 1, Dict(), nothing, Dict())
end
end
function lookahead(parser::ParserState, k::Int=0)::Token
idx = parser.pos + k
return idx <= length(parser.tokens) ? parser.tokens[idx] : Token("\$", "", -1)
end
function consume_literal!(parser::ParserState, expected::String)
if !match_lookahead_literal(parser, expected, 0)
token = lookahead(parser, 0)
throw(ParseError("Expected literal $(repr(expected)) but got $(token.type)=`$(repr(token.value))` at position $(token.pos)"))
end
parser.pos += 1
return nothing
end
function consume_terminal!(parser::ParserState, expected::String)
if !match_lookahead_terminal(parser, expected, 0)
token = lookahead(parser, 0)
throw(ParseError("Expected terminal $expected but got $(token.type)=`$(repr(token.value))` at position $(token.pos)"))
end
token = lookahead(parser, 0)
parser.pos += 1
return token.value
end
function match_lookahead_literal(parser::ParserState, literal::String, k::Int)::Bool
token = lookahead(parser, k)
# Support soft keywords: alphanumeric literals are lexed as SYMBOL tokens
if token.type == "LITERAL" && token.value == literal
return true
end
if token.type == "SYMBOL" && token.value == literal
return true
end
return false
end
function match_lookahead_terminal(parser::ParserState, terminal::String, k::Int)::Bool
token = lookahead(parser, k)
return token.type == terminal
end
function start_fragment!(parser::ParserState, fragment_id::Proto.FragmentId)
parser._current_fragment_id = fragment_id.id
return fragment_id
end
function relation_id_from_string(parser::ParserState, name::String)
# Create RelationId from string and track mapping for debug info
hash_bytes = sha256(name)
# Use big-endian and the lower 128 bits of the hash, consistent with pyrel.
id_high = ntoh(reinterpret(UInt64, hash_bytes[17:24])[1])
id_low = ntoh(reinterpret(UInt64, hash_bytes[25:32])[1])
relation_id = Proto.RelationId(id_low, id_high)
# Store the mapping for the current fragment if we're inside one
if parser._current_fragment_id !== nothing
if !haskey(parser.id_to_debuginfo, parser._current_fragment_id)
parser.id_to_debuginfo[parser._current_fragment_id] = Pair{Tuple{UInt64,UInt64},String}[]
end
entries = parser.id_to_debuginfo[parser._current_fragment_id]
key = (relation_id.id_low, relation_id.id_high)
if !any(p -> p.first == key, entries)
push!(entries, key => name)
end
end
return relation_id
end
function construct_fragment(
parser::ParserState,
fragment_id::Proto.FragmentId,
declarations::Vector{Proto.Declaration}
)
# Get the debug info for this fragment
debug_info_entries = get(parser.id_to_debuginfo, fragment_id.id, Pair{Tuple{UInt64,UInt64},String}[])
# Convert to DebugInfo protobuf (preserving insertion order)
ids = Proto.RelationId[]
orig_names = String[]
for (key, name) in debug_info_entries
push!(ids, Proto.RelationId(key[1], key[2]))
push!(orig_names, name)
end
# Create DebugInfo
debug_info = Proto.DebugInfo(ids, orig_names)
# Clear _current_fragment_id before the return
parser._current_fragment_id = nothing
# Create and return Fragment
return Proto.Fragment(fragment_id, declarations, debug_info)
end
# --- Helper functions ---
function _extract_value_int32(parser::ParserState, value::Union{Nothing, Proto.Value}, default::Int64)::Int32
if (!isnothing(value) && _has_proto_field(value, Symbol("int_value")))
return Int32(_get_oneof_field(value, :int_value))
else
_t1378 = nothing
end
return Int32(default)
end
function _extract_value_int64(parser::ParserState, value::Union{Nothing, Proto.Value}, default::Int64)::Int64
if (!isnothing(value) && _has_proto_field(value, Symbol("int_value")))
return _get_oneof_field(value, :int_value)
else
_t1379 = nothing
end
return default
end
function _extract_value_string(parser::ParserState, value::Union{Nothing, Proto.Value}, default::String)::String
if (!isnothing(value) && _has_proto_field(value, Symbol("string_value")))
return _get_oneof_field(value, :string_value)
else
_t1380 = nothing
end
return default
end
function _extract_value_boolean(parser::ParserState, value::Union{Nothing, Proto.Value}, default::Bool)::Bool
if (!isnothing(value) && _has_proto_field(value, Symbol("boolean_value")))
return _get_oneof_field(value, :boolean_value)
else
_t1381 = nothing
end
return default
end
function _extract_value_string_list(parser::ParserState, value::Union{Nothing, Proto.Value}, default::Vector{String})::Vector{String}
if (!isnothing(value) && _has_proto_field(value, Symbol("string_value")))
return String[_get_oneof_field(value, :string_value)]
else
_t1382 = nothing
end
return default
end
function _try_extract_value_int64(parser::ParserState, value::Union{Nothing, Proto.Value})::Union{Nothing, Int64}
if (!isnothing(value) && _has_proto_field(value, Symbol("int_value")))
return _get_oneof_field(value, :int_value)
else
_t1383 = nothing
end
return nothing
end
function _try_extract_value_float64(parser::ParserState, value::Union{Nothing, Proto.Value})::Union{Nothing, Float64}
if (!isnothing(value) && _has_proto_field(value, Symbol("float_value")))
return _get_oneof_field(value, :float_value)
else
_t1384 = nothing
end
return nothing
end
function _try_extract_value_bytes(parser::ParserState, value::Union{Nothing, Proto.Value})::Union{Nothing, Vector{UInt8}}
if (!isnothing(value) && _has_proto_field(value, Symbol("string_value")))
return Vector{UInt8}(_get_oneof_field(value, :string_value))
else
_t1385 = nothing
end
return nothing
end
function _try_extract_value_uint128(parser::ParserState, value::Union{Nothing, Proto.Value})::Union{Nothing, Proto.UInt128Value}
if (!isnothing(value) && _has_proto_field(value, Symbol("uint128_value")))
return _get_oneof_field(value, :uint128_value)
else
_t1386 = nothing
end
return nothing
end
function construct_csv_config(parser::ParserState, config_dict::Vector{Tuple{String, Proto.Value}})::Proto.CSVConfig
config = Dict(config_dict)
_t1387 = _extract_value_int32(parser, get(config, "csv_header_row", nothing), 1)
header_row = _t1387
_t1388 = _extract_value_int64(parser, get(config, "csv_skip", nothing), 0)
skip = _t1388
_t1389 = _extract_value_string(parser, get(config, "csv_new_line", nothing), "")
new_line = _t1389
_t1390 = _extract_value_string(parser, get(config, "csv_delimiter", nothing), ",")
delimiter = _t1390
_t1391 = _extract_value_string(parser, get(config, "csv_quotechar", nothing), "\"")
quotechar = _t1391
_t1392 = _extract_value_string(parser, get(config, "csv_escapechar", nothing), "\"")
escapechar = _t1392
_t1393 = _extract_value_string(parser, get(config, "csv_comment", nothing), "")
comment = _t1393
_t1394 = _extract_value_string_list(parser, get(config, "csv_missing_strings", nothing), String[])
missing_strings = _t1394
_t1395 = _extract_value_string(parser, get(config, "csv_decimal_separator", nothing), ".")
decimal_separator = _t1395
_t1396 = _extract_value_string(parser, get(config, "csv_encoding", nothing), "utf-8")
encoding = _t1396
_t1397 = _extract_value_string(parser, get(config, "csv_compression", nothing), "auto")
compression = _t1397
_t1398 = _extract_value_int64(parser, get(config, "csv_partition_size_mb", nothing), 0)
partition_size_mb = _t1398
_t1399 = Proto.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 _t1399
end
function construct_betree_info(parser::ParserState, key_types::Vector{Proto.var"#Type"}, value_types::Vector{Proto.var"#Type"}, config_dict::Vector{Tuple{String, Proto.Value}})::Proto.BeTreeInfo
config = Dict(config_dict)
_t1400 = _try_extract_value_float64(parser, get(config, "betree_config_epsilon", nothing))
epsilon = _t1400
_t1401 = _try_extract_value_int64(parser, get(config, "betree_config_max_pivots", nothing))
max_pivots = _t1401
_t1402 = _try_extract_value_int64(parser, get(config, "betree_config_max_deltas", nothing))
max_deltas = _t1402
_t1403 = _try_extract_value_int64(parser, get(config, "betree_config_max_leaf", nothing))
max_leaf = _t1403
_t1404 = Proto.BeTreeConfig(epsilon=epsilon, max_pivots=max_pivots, max_deltas=max_deltas, max_leaf=max_leaf)
storage_config = _t1404
_t1405 = _try_extract_value_uint128(parser, get(config, "betree_locator_root_pageid", nothing))
root_pageid = _t1405
_t1406 = _try_extract_value_bytes(parser, get(config, "betree_locator_inline_data", nothing))
inline_data = _t1406
_t1407 = _try_extract_value_int64(parser, get(config, "betree_locator_element_count", nothing))
element_count = _t1407
_t1408 = _try_extract_value_int64(parser, get(config, "betree_locator_tree_height", nothing))
tree_height = _t1408
_t1409 = Proto.BeTreeLocator(location=(!isnothing(root_pageid) ? OneOf(:root_pageid, root_pageid) : (!isnothing(inline_data) ? OneOf(:inline_data, inline_data) : nothing)), element_count=element_count, tree_height=tree_height)
relation_locator = _t1409
_t1410 = Proto.BeTreeInfo(key_types=key_types, value_types=value_types, storage_config=storage_config, relation_locator=relation_locator)
return _t1410
end
function default_configure(parser::ParserState)::Proto.Configure
_t1411 = Proto.IVMConfig(level=Proto.MaintenanceLevel.MAINTENANCE_LEVEL_OFF)
ivm_config = _t1411
_t1412 = Proto.Configure(semantics_version=0, ivm_config=ivm_config)
return _t1412
end
function construct_configure(parser::ParserState, config_dict::Vector{Tuple{String, Proto.Value}})::Proto.Configure
config = Dict(config_dict)
maintenance_level_val = get(config, "ivm.maintenance_level", nothing)
maintenance_level = Proto.MaintenanceLevel.MAINTENANCE_LEVEL_OFF
if (!isnothing(maintenance_level_val) && _has_proto_field(maintenance_level_val, Symbol("string_value")))
if _get_oneof_field(maintenance_level_val, :string_value) == "off"
maintenance_level = Proto.MaintenanceLevel.MAINTENANCE_LEVEL_OFF
else
if _get_oneof_field(maintenance_level_val, :string_value) == "auto"
maintenance_level = Proto.MaintenanceLevel.MAINTENANCE_LEVEL_AUTO
else
if _get_oneof_field(maintenance_level_val, :string_value) == "all"
maintenance_level = Proto.MaintenanceLevel.MAINTENANCE_LEVEL_ALL
else
maintenance_level = Proto.MaintenanceLevel.MAINTENANCE_LEVEL_OFF
end
end
end
end
_t1413 = Proto.IVMConfig(level=maintenance_level)
ivm_config = _t1413
_t1414 = _extract_value_int64(parser, get(config, "semantics_version", nothing), 0)
semantics_version = _t1414
_t1415 = Proto.Configure(semantics_version=semantics_version, ivm_config=ivm_config)
return _t1415
end
function construct_export_csv_config(parser::ParserState, path::String, columns::Vector{Proto.ExportCSVColumn}, config_dict::Vector{Tuple{String, Proto.Value}})::Proto.ExportCSVConfig
config = Dict(config_dict)
_t1416 = _extract_value_int64(parser, get(config, "partition_size", nothing), 0)
partition_size = _t1416
_t1417 = _extract_value_string(parser, get(config, "compression", nothing), "")
compression = _t1417
_t1418 = _extract_value_boolean(parser, get(config, "syntax_header_row", nothing), true)
syntax_header_row = _t1418
_t1419 = _extract_value_string(parser, get(config, "syntax_missing_string", nothing), "")
syntax_missing_string = _t1419
_t1420 = _extract_value_string(parser, get(config, "syntax_delim", nothing), ",")
syntax_delim = _t1420
_t1421 = _extract_value_string(parser, get(config, "syntax_quotechar", nothing), "\"")
syntax_quotechar = _t1421
_t1422 = _extract_value_string(parser, get(config, "syntax_escapechar", nothing), "\\")
syntax_escapechar = _t1422
_t1423 = Proto.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 _t1423
end
function construct_export_csv_config_with_source(parser::ParserState, path::String, csv_source::Proto.ExportCSVSource, csv_config::Proto.CSVConfig)::Proto.ExportCSVConfig
_t1424 = Proto.ExportCSVConfig(path=path, csv_source=csv_source, csv_config=csv_config)
return _t1424
end
# --- Parse functions ---
function parse_transaction(parser::ParserState)::Proto.Transaction
consume_literal!(parser, "(")
consume_literal!(parser, "transaction")
if (match_lookahead_literal(parser, "(", 0) && match_lookahead_literal(parser, "configure", 1))
_t753 = parse_configure(parser)
_t752 = _t753
else
_t752 = nothing
end
configure376 = _t752
if (match_lookahead_literal(parser, "(", 0) && match_lookahead_literal(parser, "sync", 1))
_t755 = parse_sync(parser)
_t754 = _t755
else
_t754 = nothing
end
sync377 = _t754
xs378 = Proto.Epoch[]
cond379 = match_lookahead_literal(parser, "(", 0)
while cond379
_t756 = parse_epoch(parser)
item380 = _t756
push!(xs378, item380)
cond379 = match_lookahead_literal(parser, "(", 0)
end
epochs381 = xs378
consume_literal!(parser, ")")
_t757 = default_configure(parser)
_t758 = Proto.Transaction(epochs=epochs381, configure=(!isnothing(configure376) ? configure376 : _t757), sync=sync377)
return _t758
end
function parse_configure(parser::ParserState)::Proto.Configure
consume_literal!(parser, "(")
consume_literal!(parser, "configure")
_t759 = parse_config_dict(parser)
config_dict382 = _t759
consume_literal!(parser, ")")
_t760 = construct_configure(parser, config_dict382)
return _t760
end
function parse_config_dict(parser::ParserState)::Vector{Tuple{String, Proto.Value}}
consume_literal!(parser, "{")
xs383 = Tuple{String, Proto.Value}[]
cond384 = match_lookahead_literal(parser, ":", 0)
while cond384
_t761 = parse_config_key_value(parser)
item385 = _t761
push!(xs383, item385)
cond384 = match_lookahead_literal(parser, ":", 0)
end
config_key_values386 = xs383
consume_literal!(parser, "}")
return config_key_values386
end
function parse_config_key_value(parser::ParserState)::Tuple{String, Proto.Value}
consume_literal!(parser, ":")
symbol387 = consume_terminal!(parser, "SYMBOL")
_t762 = parse_value(parser)
value388 = _t762
return (symbol387, value388,)
end
function parse_value(parser::ParserState)::Proto.Value
if match_lookahead_literal(parser, "true", 0)
_t763 = 9
else
if match_lookahead_literal(parser, "missing", 0)
_t764 = 8
else
if match_lookahead_literal(parser, "false", 0)
_t765 = 9
else
if match_lookahead_literal(parser, "(", 0)
if match_lookahead_literal(parser, "datetime", 1)
_t767 = 1
else
if match_lookahead_literal(parser, "date", 1)
_t768 = 0
else
_t768 = -1
end
_t767 = _t768
end
_t766 = _t767
else
if match_lookahead_terminal(parser, "UINT128", 0)
_t769 = 5
else
if match_lookahead_terminal(parser, "STRING", 0)
_t770 = 2
else
if match_lookahead_terminal(parser, "INT128", 0)
_t771 = 6
else
if match_lookahead_terminal(parser, "INT", 0)
_t772 = 3
else
if match_lookahead_terminal(parser, "FLOAT", 0)
_t773 = 4
else
if match_lookahead_terminal(parser, "DECIMAL", 0)
_t774 = 7
else
_t774 = -1
end
_t773 = _t774
end
_t772 = _t773
end
_t771 = _t772
end
_t770 = _t771
end
_t769 = _t770
end
_t766 = _t769
end
_t765 = _t766
end
_t764 = _t765
end
_t763 = _t764
end
prediction389 = _t763
if prediction389 == 9
_t776 = parse_boolean_value(parser)
boolean_value398 = _t776
_t777 = Proto.Value(value=OneOf(:boolean_value, boolean_value398))
_t775 = _t777
else
if prediction389 == 8
consume_literal!(parser, "missing")
_t779 = Proto.MissingValue()
_t780 = Proto.Value(value=OneOf(:missing_value, _t779))
_t778 = _t780
else
if prediction389 == 7
decimal397 = consume_terminal!(parser, "DECIMAL")
_t782 = Proto.Value(value=OneOf(:decimal_value, decimal397))
_t781 = _t782
else
if prediction389 == 6
int128396 = consume_terminal!(parser, "INT128")
_t784 = Proto.Value(value=OneOf(:int128_value, int128396))
_t783 = _t784
else
if prediction389 == 5
uint128395 = consume_terminal!(parser, "UINT128")
_t786 = Proto.Value(value=OneOf(:uint128_value, uint128395))
_t785 = _t786
else
if prediction389 == 4
float394 = consume_terminal!(parser, "FLOAT")
_t788 = Proto.Value(value=OneOf(:float_value, float394))
_t787 = _t788
else
if prediction389 == 3
int393 = consume_terminal!(parser, "INT")
_t790 = Proto.Value(value=OneOf(:int_value, int393))
_t789 = _t790
else
if prediction389 == 2
string392 = consume_terminal!(parser, "STRING")
_t792 = Proto.Value(value=OneOf(:string_value, string392))
_t791 = _t792
else
if prediction389 == 1
_t794 = parse_datetime(parser)
datetime391 = _t794
_t795 = Proto.Value(value=OneOf(:datetime_value, datetime391))
_t793 = _t795
else
if prediction389 == 0
_t797 = parse_date(parser)
date390 = _t797
_t798 = Proto.Value(value=OneOf(:date_value, date390))
_t796 = _t798
else
throw(ParseError("Unexpected token in value" * ": " * string(lookahead(parser, 0))))
end
_t793 = _t796
end
_t791 = _t793
end
_t789 = _t791
end
_t787 = _t789
end
_t785 = _t787
end
_t783 = _t785
end
_t781 = _t783
end
_t778 = _t781
end
_t775 = _t778
end
return _t775
end
function parse_date(parser::ParserState)::Proto.DateValue
consume_literal!(parser, "(")
consume_literal!(parser, "date")
int399 = consume_terminal!(parser, "INT")
int_3400 = consume_terminal!(parser, "INT")
int_4401 = consume_terminal!(parser, "INT")
consume_literal!(parser, ")")
_t799 = Proto.DateValue(year=Int32(int399), month=Int32(int_3400), day=Int32(int_4401))
return _t799
end
function parse_datetime(parser::ParserState)::Proto.DateTimeValue
consume_literal!(parser, "(")
consume_literal!(parser, "datetime")
int402 = consume_terminal!(parser, "INT")
int_3403 = consume_terminal!(parser, "INT")
int_4404 = consume_terminal!(parser, "INT")
int_5405 = consume_terminal!(parser, "INT")
int_6406 = consume_terminal!(parser, "INT")
int_7407 = consume_terminal!(parser, "INT")
if match_lookahead_terminal(parser, "INT", 0)
_t800 = consume_terminal!(parser, "INT")
else
_t800 = nothing
end
int_8408 = _t800
consume_literal!(parser, ")")
_t801 = Proto.DateTimeValue(year=Int32(int402), month=Int32(int_3403), day=Int32(int_4404), hour=Int32(int_5405), minute=Int32(int_6406), second=Int32(int_7407), microsecond=Int32((!isnothing(int_8408) ? int_8408 : 0)))
return _t801
end
function parse_boolean_value(parser::ParserState)::Bool
if match_lookahead_literal(parser, "true", 0)
_t802 = 0
else
if match_lookahead_literal(parser, "false", 0)
_t803 = 1
else
_t803 = -1
end
_t802 = _t803
end
prediction409 = _t802
if prediction409 == 1
consume_literal!(parser, "false")
_t804 = false
else
if prediction409 == 0
consume_literal!(parser, "true")
_t805 = true
else
throw(ParseError("Unexpected token in boolean_value" * ": " * string(lookahead(parser, 0))))
end
_t804 = _t805
end
return _t804
end
function parse_sync(parser::ParserState)::Proto.Sync
consume_literal!(parser, "(")
consume_literal!(parser, "sync")
xs410 = Proto.FragmentId[]
cond411 = match_lookahead_literal(parser, ":", 0)
while cond411
_t806 = parse_fragment_id(parser)
item412 = _t806
push!(xs410, item412)
cond411 = match_lookahead_literal(parser, ":", 0)
end
fragment_ids413 = xs410
consume_literal!(parser, ")")
_t807 = Proto.Sync(fragments=fragment_ids413)
return _t807
end
function parse_fragment_id(parser::ParserState)::Proto.FragmentId
consume_literal!(parser, ":")
symbol414 = consume_terminal!(parser, "SYMBOL")
return Proto.FragmentId(Vector{UInt8}(symbol414))
end
function parse_epoch(parser::ParserState)::Proto.Epoch
consume_literal!(parser, "(")
consume_literal!(parser, "epoch")
if (match_lookahead_literal(parser, "(", 0) && match_lookahead_literal(parser, "writes", 1))
_t809 = parse_epoch_writes(parser)
_t808 = _t809
else
_t808 = nothing
end
epoch_writes415 = _t808
if match_lookahead_literal(parser, "(", 0)
_t811 = parse_epoch_reads(parser)
_t810 = _t811
else
_t810 = nothing
end
epoch_reads416 = _t810
consume_literal!(parser, ")")
_t812 = Proto.Epoch(writes=(!isnothing(epoch_writes415) ? epoch_writes415 : Proto.Write[]), reads=(!isnothing(epoch_reads416) ? epoch_reads416 : Proto.Read[]))
return _t812
end
function parse_epoch_writes(parser::ParserState)::Vector{Proto.Write}
consume_literal!(parser, "(")
consume_literal!(parser, "writes")
xs417 = Proto.Write[]
cond418 = match_lookahead_literal(parser, "(", 0)
while cond418
_t813 = parse_write(parser)
item419 = _t813
push!(xs417, item419)
cond418 = match_lookahead_literal(parser, "(", 0)
end
writes420 = xs417
consume_literal!(parser, ")")
return writes420
end
function parse_write(parser::ParserState)::Proto.Write
if match_lookahead_literal(parser, "(", 0)
if match_lookahead_literal(parser, "undefine", 1)
_t815 = 1
else
if match_lookahead_literal(parser, "snapshot", 1)
_t816 = 3
else
if match_lookahead_literal(parser, "define", 1)
_t817 = 0
else
if match_lookahead_literal(parser, "context", 1)
_t818 = 2
else
_t818 = -1
end
_t817 = _t818
end
_t816 = _t817
end
_t815 = _t816
end
_t814 = _t815
else
_t814 = -1
end
prediction421 = _t814
if prediction421 == 3
_t820 = parse_snapshot(parser)
snapshot425 = _t820
_t821 = Proto.Write(write_type=OneOf(:snapshot, snapshot425))
_t819 = _t821
else
if prediction421 == 2
_t823 = parse_context(parser)
context424 = _t823
_t824 = Proto.Write(write_type=OneOf(:context, context424))
_t822 = _t824
else
if prediction421 == 1
_t826 = parse_undefine(parser)
undefine423 = _t826
_t827 = Proto.Write(write_type=OneOf(:undefine, undefine423))
_t825 = _t827
else
if prediction421 == 0
_t829 = parse_define(parser)
define422 = _t829
_t830 = Proto.Write(write_type=OneOf(:define, define422))
_t828 = _t830
else
throw(ParseError("Unexpected token in write" * ": " * string(lookahead(parser, 0))))
end
_t825 = _t828
end
_t822 = _t825
end
_t819 = _t822
end
return _t819
end
function parse_define(parser::ParserState)::Proto.Define
consume_literal!(parser, "(")
consume_literal!(parser, "define")
_t831 = parse_fragment(parser)
fragment426 = _t831
consume_literal!(parser, ")")
_t832 = Proto.Define(fragment=fragment426)
return _t832
end
function parse_fragment(parser::ParserState)::Proto.Fragment
consume_literal!(parser, "(")
consume_literal!(parser, "fragment")
_t833 = parse_new_fragment_id(parser)
new_fragment_id427 = _t833
xs428 = Proto.Declaration[]
cond429 = match_lookahead_literal(parser, "(", 0)
while cond429
_t834 = parse_declaration(parser)
item430 = _t834
push!(xs428, item430)
cond429 = match_lookahead_literal(parser, "(", 0)
end
declarations431 = xs428
consume_literal!(parser, ")")
return construct_fragment(parser, new_fragment_id427, declarations431)
end
function parse_new_fragment_id(parser::ParserState)::Proto.FragmentId
_t835 = parse_fragment_id(parser)
fragment_id432 = _t835
start_fragment!(parser, fragment_id432)
return fragment_id432
end
function parse_declaration(parser::ParserState)::Proto.Declaration
if match_lookahead_literal(parser, "(", 0)
if match_lookahead_literal(parser, "functional_dependency", 1)
_t837 = 2
else
if match_lookahead_literal(parser, "edb", 1)
_t838 = 3
else
if match_lookahead_literal(parser, "def", 1)
_t839 = 0
else
if match_lookahead_literal(parser, "csv_data", 1)
_t840 = 3
else
if match_lookahead_literal(parser, "betree_relation", 1)
_t841 = 3
else
if match_lookahead_literal(parser, "algorithm", 1)
_t842 = 1
else
_t842 = -1
end
_t841 = _t842
end
_t840 = _t841
end
_t839 = _t840
end
_t838 = _t839
end
_t837 = _t838
end
_t836 = _t837
else
_t836 = -1
end
prediction433 = _t836
if prediction433 == 3
_t844 = parse_data(parser)
data437 = _t844
_t845 = Proto.Declaration(declaration_type=OneOf(:data, data437))
_t843 = _t845
else
if prediction433 == 2
_t847 = parse_constraint(parser)
constraint436 = _t847
_t848 = Proto.Declaration(declaration_type=OneOf(:constraint, constraint436))
_t846 = _t848
else
if prediction433 == 1
_t850 = parse_algorithm(parser)
algorithm435 = _t850
_t851 = Proto.Declaration(declaration_type=OneOf(:algorithm, algorithm435))
_t849 = _t851
else
if prediction433 == 0
_t853 = parse_def(parser)
def434 = _t853
_t854 = Proto.Declaration(declaration_type=OneOf(:def, def434))
_t852 = _t854
else
throw(ParseError("Unexpected token in declaration" * ": " * string(lookahead(parser, 0))))
end
_t849 = _t852
end
_t846 = _t849
end
_t843 = _t846
end
return _t843
end
function parse_def(parser::ParserState)::Proto.Def
consume_literal!(parser, "(")
consume_literal!(parser, "def")
_t855 = parse_relation_id(parser)
relation_id438 = _t855
_t856 = parse_abstraction(parser)