-
Notifications
You must be signed in to change notification settings - Fork 197
Expand file tree
/
Copy pathslow.lua
More file actions
13560 lines (12784 loc) · 351 KB
/
Copy pathslow.lua
File metadata and controls
13560 lines (12784 loc) · 351 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
-- Generated by pgen 0.1.0 (Lua target)
-- moonscript_parse_slow - generated parser
--
-- Self-contained pure Lua module (Lua 5.1+ and LuaJIT), no dependencies.
-- local moonscript_parse_slow = require "moonscript_parse_slow"
-- local result = moonscript_parse_slow.parse("your input string")
local select, type, error, pcall, tostring = select, type, error, pcall, tostring
local byte, sub = string.byte, string.sub
local unpack = table.unpack or unpack
local pack = table.pack or function(...) return {n = select("#", ...), ...} end
-- Maximum rule-call recursion depth before the parse is aborted with a Lua
-- error (catch with pcall). Configure with the max_depth compile option.
local MAX_DEPTH = 5000
-- Capture log entry kinds. Captures are recorded as log entries during
-- matching and only materialized into Lua values after the whole parse
-- succeeds; backtracking rewinds the log length, so discarded speculative
-- captures are never built. The exception is Cmt: its callback runs
-- mid-parse and its extra return values are stored in the parser's values
-- array, referenced by CAP_VALUE entries.
local CAP_STR, CAP_CONST, CAP_NIL, CAP_POS, CAP_VALUE = 1, 2, 3, 4, 5
local CAP_TBL_OPEN, CAP_TBL_CLOSE = 6, 7
local CAP_GROUP_OPEN, CAP_GROUP_CLOSE = 8, 9
local CAP_FN_OPEN, CAP_FN_CLOSE = 10, 11
local rules = {}
local sets = {}
local disp = {}
local cmt_fns = {}
-- Sentinel pushed by `prevent`: no measured width compares greater
local IND_PREVENT = math.huge
-- Records the furthest input position where a match attempt failed (only
-- ever increases); parse() reports it when the overall parse fails without
-- a label. Not recorded in single-character matchers, mirroring the C
-- target.
local function record_furthest(parser)
if parser.pos > parser.furthest_fail then
parser.furthest_fail = parser.pos
end
end
-- Append one capture log entry (parallel arrays, truncated by cap_n rewinds)
local function cap_push(parser, kind, aux, start, len)
local n = parser.cap_n + 1
parser.cap_n = n
parser.cap_kind[n] = kind
parser.cap_aux[n] = aux
parser.cap_start[n] = start
parser.cap_size[n] = len
end
-- Advance past one complete log item (a single entry, or a whole bracketed
-- range including anything nested), returning the index after it
local function cap_skip(parser, i)
local ck = parser.cap_kind
local kind = ck[i]
i = i + 1
if kind == CAP_TBL_OPEN or kind == CAP_GROUP_OPEN or kind == CAP_FN_OPEN then
local depth = 1
while depth > 0 do
kind = ck[i]
if kind == CAP_TBL_OPEN or kind == CAP_GROUP_OPEN or kind == CAP_FN_OPEN then
depth = depth + 1
elseif kind == CAP_TBL_CLOSE or kind == CAP_GROUP_CLOSE or kind == CAP_FN_CLOSE then
depth = depth - 1
end
i = i + 1
end
end
return i
end
local cap_eval
-- Append the single value a capture group produces to out: its first inner
-- capture value, or the text it matched when its contents produce no values.
-- Returns the index past the group's close entry.
local function cap_eval_group(parser, i, out)
local open = i
local after = cap_skip(parser, i)
local close = after - 1
local j = open + 1
while j < close do
local before_n = out.n
j = cap_eval(parser, j, out)
if out.n > before_n then
-- keep only the first value
for k = before_n + 2, out.n do out[k] = nil end
out.n = before_n + 1
return after
end
end
-- no values: the group's value is the text it matched
local start = parser.cap_start[open]
out.n = out.n + 1
out[out.n] = sub(parser.input, start + 1, parser.cap_start[close])
return after
end
-- Materialize one log item (entry or bracketed range) at i, appending its
-- values to out (out.n counts values so nil captures are preserved).
-- Returns the index past the item. Runs once after a successful parse (and
-- on demand at Cmt boundaries), so it is not on the matching hot path.
function cap_eval(parser, i, out)
local ck = parser.cap_kind
local kind = ck[i]
if kind == CAP_STR then
local start = parser.cap_start[i]
out.n = out.n + 1
out[out.n] = sub(parser.input, start + 1, start + parser.cap_size[i])
return i + 1
elseif kind == CAP_CONST then
out.n = out.n + 1
out[out.n] = parser.cap_aux[i]
return i + 1
elseif kind == CAP_NIL then
out.n = out.n + 1
out[out.n] = nil
return i + 1
elseif kind == CAP_POS then
out.n = out.n + 1
out[out.n] = parser.cap_start[i] + 1
return i + 1
elseif kind == CAP_VALUE then
out.n = out.n + 1
out[out.n] = parser.values[parser.cap_aux[i]]
return i + 1
elseif kind == CAP_GROUP_OPEN then
return cap_eval_group(parser, i, out)
elseif kind == CAP_FN_OPEN then
-- Transform capture: inner values become arguments, the callback's
-- return values become the capture values (innermost-first order falls
-- out of the recursion here)
local open = i
local fn = parser.cap_aux[i]
local args = {n = 0}
local j = open + 1
while ck[j] ~= CAP_FN_CLOSE do
if ck[j] == CAP_GROUP_OPEN then
-- named groups are not visible as arguments (as at the top level)
j = cap_skip(parser, j)
else
j = cap_eval(parser, j, args)
end
end
if args.n == 0 then
-- no inner captures: the callback receives the matched text
local start = parser.cap_start[open]
args[1] = sub(parser.input, start + 1, parser.cap_start[j])
args.n = 1
end
-- callback errors propagate (abort materialization with the original
-- error value)
local rets = pack(fn(unpack(args, 1, args.n)))
for k = 1, rets.n do
out.n = out.n + 1
out[out.n] = rets[k]
end
return j + 1
else -- CAP_TBL_OPEN
local tbl = {}
local j = i + 1
local array_idx = 1
local item = {n = 0}
while ck[j] ~= CAP_TBL_CLOSE do
if ck[j] == CAP_GROUP_OPEN then
local group_name = parser.cap_aux[j]
item.n = 0
j = cap_eval_group(parser, j, item)
tbl[group_name] = item[1]
else
item.n = 0
j = cap_eval(parser, j, item)
for k = 1, item.n do
tbl[array_idx] = item[k]
array_idx = array_idx + 1
end
end
end
out.n = out.n + 1
out[out.n] = tbl
return j + 1
end
end
-- Match the text of the most recent visible named capture group at the
-- current input position. Groups inside completed capture tables are not
-- visible.
local function cap_match_back(parser, name)
local ck, ca = parser.cap_kind, parser.cap_aux
local cs, cz = parser.cap_start, parser.cap_size
local i = parser.cap_n
while i >= 1 do
local kind = ck[i]
if kind == CAP_TBL_CLOSE or kind == CAP_GROUP_CLOSE or kind == CAP_FN_CLOSE then
local close = i
local depth = 1
while depth > 0 do
i = i - 1
local k2 = ck[i]
if k2 == CAP_TBL_CLOSE or k2 == CAP_GROUP_CLOSE or k2 == CAP_FN_CLOSE then
depth = depth + 1
elseif k2 == CAP_TBL_OPEN or k2 == CAP_GROUP_OPEN or k2 == CAP_FN_OPEN then
depth = depth - 1
end
end
if kind == CAP_GROUP_CLOSE and ca[i] == name then
local text
local inner = i + 1
if inner == close then
-- group captured nothing: its value is the text it matched
text = sub(parser.input, cs[i] + 1, cs[close])
elseif ck[inner] == CAP_STR then
text = sub(parser.input, cs[inner] + 1, cs[inner] + cz[inner])
elseif ck[inner] == CAP_CONST then
if type(ca[inner]) ~= "string" then
return false
end
text = ca[inner]
else
return false -- group holds a non-string value
end
if parser.pos + #text <= parser.input_len and
sub(parser.input, parser.pos + 1, parser.pos + #text) == text then
parser.pos = parser.pos + #text
return true
end
return false
end
end
i = i - 1
end
return false
end
local floor = math.floor
-- Run a match-time capture: materialize the inner captures, call the
-- callback with (subject, pos, ...captures), and interpret its results per
-- lpeg semantics: position/true = success, false/nil = failure, extra
-- return values become captures (stored in the parser's values array)
local function run_cmt(parser, fn, start_pos, cap_base)
local pos_after_inner = parser.pos
local args = {parser.input, pos_after_inner + 1, n = 2}
local i = cap_base + 1
while i <= parser.cap_n do
if parser.cap_kind[i] == CAP_GROUP_OPEN then
-- named groups only matter inside Ct; they aren't passed as arguments
i = cap_skip(parser, i)
else
i = cap_eval(parser, i, args)
end
end
parser.cap_n = cap_base -- consume the inner captures
-- callback errors propagate (abort the parse with the original value)
local rets = pack(fn(unpack(args, 1, args.n)))
local ok = false
if rets.n > 0 then
local first = rets[1]
if type(first) == "number" then
-- number = new position (1-based from Lua), must be in range
-- [pos_after_inner, input_len]. Floored so a fractional return can't
-- put the parser on a non-integer position.
local new_pos = floor(first) - 1
if new_pos >= pos_after_inner and new_pos <= parser.input_len then
parser.pos = new_pos
ok = true
end
elseif first == true then
-- true = succeed without consuming (position stays at pos_after_inner)
ok = true
end
end
if ok then
parser.success = true
if rets.n > 1 then
local values = parser.values
local vn = parser.values_n
for r = 2, rets.n do
vn = vn + 1
values[vn] = rets[r]
cap_push(parser, CAP_VALUE, vn, 0, 0)
end
parser.values_n = vn
end
else
parser.success = false
record_furthest(parser)
parser.pos = start_pos
end
end
-- Rewind the indenter trail to a previous length, undoing pushes and pops
local function ind_trail_rewind(parser, index)
local n = parser.trail_n
if n <= index then return end
local trail_id, trail_op, trail_val = parser.trail_id, parser.trail_op, parser.trail_val
local stacks = parser.ind_stacks
while n > index do
local s = stacks[trail_id[n]]
if trail_op[n] == 0 then
-- undo push
s.n = s.n - 1
else
-- undo pop: restore the popped value
s.n = s.n + 1
s[s.n] = trail_val[n]
end
n = n - 1
end
parser.trail_n = n
end
local function ind_push(parser, sidx, value)
local s = parser.ind_stacks[sidx]
s.n = s.n + 1
s[s.n] = value
local tn = parser.trail_n + 1
parser.trail_n = tn
parser.trail_id[tn] = sidx
parser.trail_op[tn] = 0
parser.trail_val[tn] = value
end
-- Pop the stack; returns false if the stack is empty
local function ind_pop(parser, sidx)
local s = parser.ind_stacks[sidx]
local sn = s.n
if sn == 0 then
return false
end
local value = s[sn]
s.n = sn - 1
local tn = parser.trail_n + 1
parser.trail_n = tn
parser.trail_id[tn] = sidx
parser.trail_op[tn] = 1
parser.trail_val[tn] = value
return true
end
-- Measure the indentation width of the run of space/tab characters at the
-- current position (space = 1, tab = tab_width). Also returns the first
-- position past the run.
local function ind_measure(parser, tab_width)
local input, input_len = parser.input, parser.input_len
local p = parser.pos
local width = 0
while p < input_len do
local c = byte(input, p + 1)
if c == 32 then
width = width + 1
elseif c == 9 then
width = width + tab_width
else
break
end
p = p + 1
end
return width, p
end
-- Callback (Cmt/Cfn) infrastructure: load each callback's Lua code once
do
local load_chunk = loadstring or load
do
local chunk, load_err = load_chunk(" local tree = require(\"moonscript.parse.tree\")\n return function(lhs, assign)\n return tree.format_single_assign(lhs, assign)\n end", "pgen Cfn 0")
if not chunk then
error("Failed to load Cfn callback 0: " .. tostring(load_err))
end
local run_ok, fn = pcall(chunk)
if not run_ok then
error("Failed to run Cfn chunk 0: " .. tostring(fn))
end
if type(fn) ~= "function" then
error("Cfn chunk 0 did not return a function")
end
cmt_fns[0] = fn
end
do
local chunk, load_err = load_chunk("return function(stm, dec)\n if dec then\n return {\"decorated\", stm, dec}\n end\n return stm\n end", "pgen Cfn 1")
if not chunk then
error("Failed to load Cfn callback 1: " .. tostring(load_err))
end
local run_ok, fn = pcall(chunk)
if not run_ok then
error("Failed to run Cfn chunk 1: " .. tostring(fn))
end
if type(fn) ~= "function" then
error("Cfn chunk 1 did not return a function")
end
cmt_fns[1] = fn
end
do
local chunk, load_err = load_chunk("return function(p, value)\n if type(value) == \"table\" then\n value[-1] = p\n end\n return value\n end", "pgen Cfn 2")
if not chunk then
error("Failed to load Cfn callback 2: " .. tostring(load_err))
end
local run_ok, fn = pcall(chunk)
if not run_ok then
error("Failed to run Cfn chunk 2: " .. tostring(fn))
end
if type(fn) ~= "function" then
error("Cfn chunk 2 did not return a function")
end
cmt_fns[2] = fn
end
do
local chunk, load_err = load_chunk(" local tree = require(\"moonscript.parse.tree\")\n return function(lhs, assign)\n return tree.format_assign(lhs, assign)\n end", "pgen Cfn 3")
if not chunk then
error("Failed to load Cfn callback 3: " .. tostring(load_err))
end
local run_ok, fn = pcall(chunk)
if not run_ok then
error("Failed to run Cfn chunk 3: " .. tostring(fn))
end
if type(fn) ~= "function" then
error("Cfn chunk 3 did not return a function")
end
cmt_fns[3] = fn
end
do
local chunk, load_err = load_chunk("return function(name, p)\n return {\n {\"key_literal\", name},\n {\"ref\", name, [-1] = p},\n }\n end", "pgen Cfn 4")
if not chunk then
error("Failed to load Cfn callback 4: " .. tostring(load_err))
end
local run_ok, fn = pcall(chunk)
if not run_ok then
error("Failed to run Cfn chunk 4: " .. tostring(fn))
end
if type(fn) ~= "function" then
error("Cfn chunk 4 did not return a function")
end
cmt_fns[4] = fn
end
do
local chunk, load_err = load_chunk(" local tree = require(\"moonscript.parse.tree\")\n return function(callee, args)\n return tree.join_chain(callee, args)\n end", "pgen Cfn 5")
if not chunk then
error("Failed to load Cfn callback 5: " .. tostring(load_err))
end
local run_ok, fn = pcall(chunk)
if not run_ok then
error("Failed to run Cfn chunk 5: " .. tostring(fn))
end
if type(fn) ~= "function" then
error("Cfn chunk 5 did not return a function")
end
cmt_fns[5] = fn
end
do
local chunk, load_err = load_chunk("return function(...)\n if select(\"#\", ...) == 1 then\n return ...\n end\n return {\"exp\", ...}\n end", "pgen Cfn 6")
if not chunk then
error("Failed to load Cfn callback 6: " .. tostring(load_err))
end
local run_ok, fn = pcall(chunk)
if not run_ok then
error("Failed to run Cfn chunk 6: " .. tostring(fn))
end
if type(fn) ~= "function" then
error("Cfn chunk 6 did not return a function")
end
cmt_fns[6] = fn
end
do
local chunk, load_err = load_chunk("return function(eq_start, eq_end, content)\n return {\"string\", \"[\" .. (\"=\"):rep(eq_end - eq_start) .. \"[\", content}\n end", "pgen Cfn 7")
if not chunk then
error("Failed to load Cfn callback 7: " .. tostring(load_err))
end
local run_ok, fn = pcall(chunk)
if not run_ok then
error("Failed to run Cfn chunk 7: " .. tostring(fn))
end
if type(fn) ~= "function" then
error("Cfn chunk 7 did not return a function")
end
cmt_fns[7] = fn
end
do
local chunk, load_err = load_chunk(" local subject, pos, node = ...\n local last = node[#node]\n local t = type(last) == \"table\" and last[1]\n if t == \"dot\" or t == \"index\" or t == \"slice\" then\n return pos, node\n end\n return false\n ", "pgen Cmt 8")
if not chunk then
error("Failed to load Cmt callback 8: " .. tostring(load_err))
end
cmt_fns[8] = chunk
end
end
-- Character set lookup tables (byte -> true)
sets[1] = { [46] = true, [92] = true } -- ".\\"
sets[2] = { [43] = true, [45] = true, [42] = true, [47] = true, [37] = true, [94] = true, [62] = true, [60] = true, [124] = true, [38] = true } -- "+-*/%^><|&"
sets[3] = { [13] = true, [10] = true } -- "\r\n"
sets[4] = { [117] = true, [85] = true } -- "uU"
sets[5] = { [108] = true, [76] = true } -- "lL"
sets[6] = { [101] = true, [69] = true } -- "eE"
sets[7] = { [32] = true, [9] = true } -- " \t"
sets[8] = { [32] = true, [9] = true, [13] = true, [10] = true } -- " \t\r\n"
-- FIRST-byte dispatch tables
do -- dispatch tables for choice 1
local dmask1 = { [1] = true, s = { }, full = false }
local dmask2 = { [1] = true, [2] = true, [3] = true, [4] = true, s = { }, full = true }
local dmask3 = { [1] = true, [4] = true, s = { [4] = true }, full = false }
local dmask4 = { [1] = true, [3] = true, s = { [3] = true }, full = false }
local dmask5 = { [1] = true, [2] = true, s = { }, full = false }
local bytes = {}
for b = 0, 255 do bytes[b] = dmask1 end
bytes[9] = dmask2
bytes[32] = dmask2
bytes[40] = dmask3
bytes[45] = dmask2
bytes[46] = dmask4
bytes[64] = dmask5
disp[1] = { bytes = bytes, eof = dmask1 }
end
do -- dispatch tables for choice 2
local dmask1 = { [1] = true, s = { }, full = false }
local dmask2 = { [1] = true, [2] = true, s = { }, full = false }
local dmask3 = { [1] = true, [3] = true, [4] = true, s = { [3] = true, [4] = true }, full = false }
local bytes = {}
for b = 0, 255 do bytes[b] = dmask1 end
bytes[46] = dmask2
bytes[91] = dmask3
disp[2] = { bytes = bytes, eof = dmask1 }
end
do -- dispatch tables for choice 3
local dmask1 = { [4] = true, s = { [4] = true }, full = false }
local dmask2 = { [1] = true, [2] = true, [3] = true, [4] = true, s = { }, full = true }
local dmask3 = { [2] = true, [4] = true, s = { [2] = true, [4] = true }, full = false }
local dmask4 = { [3] = true, [4] = true, s = { [3] = true, [4] = true }, full = false }
local dmask5 = { [1] = true, [4] = true, s = { [4] = true }, full = false }
local bytes = {}
for b = 0, 255 do bytes[b] = dmask1 end
bytes[9] = dmask2
bytes[32] = dmask2
bytes[42] = dmask3
bytes[45] = dmask2
bytes[94] = dmask4
bytes[99] = dmask5
disp[3] = { bytes = bytes, eof = dmask1 }
end
do -- dispatch tables for choice 4
local dmask1 = { [4] = true, s = { [4] = true }, full = false }
local dmask2 = { [1] = true, [4] = true, s = { [4] = true }, full = false }
local dmask3 = { [3] = true, [4] = true, s = { [3] = true, [4] = true }, full = false }
local dmask4 = { [2] = true, [4] = true, s = { [2] = true, [4] = true }, full = false }
local bytes = {}
for b = 0, 255 do bytes[b] = dmask1 end
bytes[9] = dmask2
bytes[32] = dmask2
bytes[33] = dmask2
bytes[34] = dmask3
bytes[39] = dmask4
bytes[40] = dmask2
bytes[45] = dmask2
disp[4] = { bytes = bytes, eof = dmask1 }
end
do -- dispatch tables for choice 5
local dmask1 = { s = { }, full = false }
local dmask2 = { [1] = true, [2] = true, [3] = true, [4] = true, s = { }, full = true }
local dmask3 = { [3] = true, s = { [3] = true }, full = false }
local dmask4 = { [4] = true, s = { [4] = true }, full = false }
local dmask5 = { [1] = true, s = { }, full = false }
local dmask6 = { [2] = true, s = { [2] = true }, full = false }
local bytes = {}
for b = 0, 255 do bytes[b] = dmask1 end
bytes[9] = dmask2
bytes[32] = dmask2
bytes[34] = dmask3
bytes[39] = dmask4
bytes[45] = dmask2
bytes[64] = dmask5
bytes[65] = dmask5
bytes[66] = dmask5
bytes[67] = dmask5
bytes[68] = dmask5
bytes[69] = dmask5
bytes[70] = dmask5
bytes[71] = dmask5
bytes[72] = dmask5
bytes[73] = dmask5
bytes[74] = dmask5
bytes[75] = dmask5
bytes[76] = dmask5
bytes[77] = dmask5
bytes[78] = dmask5
bytes[79] = dmask5
bytes[80] = dmask5
bytes[81] = dmask5
bytes[82] = dmask5
bytes[83] = dmask5
bytes[84] = dmask5
bytes[85] = dmask5
bytes[86] = dmask5
bytes[87] = dmask5
bytes[88] = dmask5
bytes[89] = dmask5
bytes[90] = dmask5
bytes[91] = dmask6
bytes[95] = dmask5
bytes[97] = dmask5
bytes[98] = dmask5
bytes[99] = dmask5
bytes[100] = dmask5
bytes[101] = dmask5
bytes[102] = dmask5
bytes[103] = dmask5
bytes[104] = dmask5
bytes[105] = dmask5
bytes[106] = dmask5
bytes[107] = dmask5
bytes[108] = dmask5
bytes[109] = dmask5
bytes[110] = dmask5
bytes[111] = dmask5
bytes[112] = dmask5
bytes[113] = dmask5
bytes[114] = dmask5
bytes[115] = dmask5
bytes[116] = dmask5
bytes[117] = dmask5
bytes[118] = dmask5
bytes[119] = dmask5
bytes[120] = dmask5
bytes[121] = dmask5
bytes[122] = dmask5
disp[5] = { bytes = bytes, eof = dmask1 }
end
do -- dispatch tables for choice 6
local dmask1 = { [9] = true, s = { [9] = true }, full = false }
local dmask2 = { [1] = true, [2] = true, [3] = true, [4] = true, [5] = true, [6] = true, [7] = true, [8] = true, [9] = true, [10] = true, [11] = true, [12] = true, [13] = true, [14] = true, [15] = true, [16] = true, [17] = true, [18] = true, s = { }, full = true }
local dmask3 = { [9] = true, [11] = true, s = { [9] = true, [11] = true }, full = false }
local dmask4 = { [9] = true, [17] = true, s = { [9] = true, [17] = true }, full = false }
local dmask5 = { [9] = true, [18] = true, s = { [9] = true, [18] = true }, full = false }
local dmask6 = { [9] = true, [16] = true, s = { [9] = true, [16] = true }, full = false }
local dmask7 = { [5] = true, [9] = true, s = { [5] = true, [9] = true }, full = false }
local dmask8 = { [6] = true, [7] = true, [9] = true, s = { [6] = true, [7] = true, [9] = true }, full = false }
local dmask9 = { [1] = true, [9] = true, s = { [9] = true }, full = false }
local dmask10 = { [9] = true, [13] = true, s = { [9] = true, [13] = true }, full = false }
local dmask11 = { [3] = true, [9] = true, s = { [3] = true, [9] = true }, full = false }
local dmask12 = { [2] = true, [9] = true, s = { [2] = true, [9] = true }, full = false }
local dmask13 = { [4] = true, [8] = true, [9] = true, s = { [4] = true, [8] = true, [9] = true }, full = false }
local dmask14 = { [9] = true, [14] = true, [15] = true, s = { [9] = true, [14] = true, [15] = true }, full = false }
local dmask15 = { [9] = true, [12] = true, s = { [9] = true, [12] = true }, full = false }
local bytes = {}
for b = 0, 255 do bytes[b] = dmask1 end
bytes[9] = dmask2
bytes[32] = dmask2
bytes[35] = dmask3
bytes[40] = dmask4
bytes[45] = dmask2
bytes[46] = dmask5
bytes[48] = dmask5
bytes[49] = dmask5
bytes[50] = dmask5
bytes[51] = dmask5
bytes[52] = dmask5
bytes[53] = dmask5
bytes[54] = dmask5
bytes[55] = dmask5
bytes[56] = dmask5
bytes[57] = dmask5
bytes[61] = dmask4
bytes[91] = dmask6
bytes[99] = dmask7
bytes[102] = dmask8
bytes[105] = dmask9
bytes[110] = dmask10
bytes[115] = dmask11
bytes[117] = dmask12
bytes[119] = dmask13
bytes[123] = dmask14
bytes[126] = dmask15
disp[6] = { bytes = bytes, eof = dmask1 }
end
do -- dispatch tables for choice 7
local dmask1 = { [11] = true, s = { [11] = true }, full = false }
local dmask2 = { [1] = true, [2] = true, [3] = true, [4] = true, [5] = true, [6] = true, [7] = true, [8] = true, [9] = true, [10] = true, [11] = true, s = { }, full = true }
local dmask3 = { [10] = true, [11] = true, s = { [10] = true, [11] = true }, full = false }
local dmask4 = { [9] = true, [11] = true, s = { [9] = true, [11] = true }, full = false }
local dmask5 = { [4] = true, [5] = true, [11] = true, s = { [4] = true, [5] = true, [11] = true }, full = false }
local dmask6 = { [1] = true, [11] = true, s = { [11] = true }, full = false }
local dmask7 = { [8] = true, [11] = true, s = { [8] = true, [11] = true }, full = false }
local dmask8 = { [7] = true, [11] = true, s = { [7] = true, [11] = true }, full = false }
local dmask9 = { [6] = true, [11] = true, s = { [6] = true, [11] = true }, full = false }
local dmask10 = { [2] = true, [3] = true, [11] = true, s = { [2] = true, [3] = true, [11] = true }, full = false }
local bytes = {}
for b = 0, 255 do bytes[b] = dmask1 end
bytes[9] = dmask2
bytes[32] = dmask2
bytes[45] = dmask2
bytes[98] = dmask3
bytes[99] = dmask3
bytes[101] = dmask4
bytes[102] = dmask5
bytes[105] = dmask6
bytes[108] = dmask7
bytes[114] = dmask8
bytes[115] = dmask9
bytes[119] = dmask10
disp[7] = { bytes = bytes, eof = dmask1 }
end
do -- dispatch tables for choice 8
local dmask1 = { [1] = true, [3] = true, s = { [3] = true }, full = false }
local dmask2 = { [1] = true, [2] = true, [3] = true, [4] = true, s = { }, full = true }
local dmask3 = { [1] = true, [2] = true, [3] = true, s = { }, full = false }
local bytes = {}
for b = 0, 255 do bytes[b] = dmask1 end
bytes[9] = dmask2
bytes[32] = dmask2
bytes[34] = dmask2
bytes[39] = dmask2
bytes[45] = dmask2
bytes[58] = dmask3
bytes[64] = dmask3
bytes[65] = dmask3
bytes[66] = dmask3
bytes[67] = dmask3
bytes[68] = dmask3
bytes[69] = dmask3
bytes[70] = dmask3
bytes[71] = dmask3
bytes[72] = dmask3
bytes[73] = dmask3
bytes[74] = dmask3
bytes[75] = dmask3
bytes[76] = dmask3
bytes[77] = dmask3
bytes[78] = dmask3
bytes[79] = dmask3
bytes[80] = dmask3
bytes[81] = dmask3
bytes[82] = dmask3
bytes[83] = dmask3
bytes[84] = dmask3
bytes[85] = dmask3
bytes[86] = dmask3
bytes[87] = dmask3
bytes[88] = dmask3
bytes[89] = dmask3
bytes[90] = dmask3
bytes[91] = dmask2
bytes[95] = dmask3
bytes[97] = dmask3
bytes[98] = dmask3
bytes[99] = dmask3
bytes[100] = dmask3
bytes[101] = dmask3
bytes[102] = dmask3
bytes[103] = dmask3
bytes[104] = dmask3
bytes[105] = dmask3
bytes[106] = dmask3
bytes[107] = dmask3
bytes[108] = dmask3
bytes[109] = dmask3
bytes[110] = dmask3
bytes[111] = dmask3
bytes[112] = dmask3
bytes[113] = dmask3
bytes[114] = dmask3
bytes[115] = dmask3
bytes[116] = dmask3
bytes[117] = dmask3
bytes[118] = dmask3
bytes[119] = dmask3
bytes[120] = dmask3
bytes[121] = dmask3
bytes[122] = dmask3
disp[8] = { bytes = bytes, eof = dmask1 }
end
do -- dispatch tables for choice 9
local dmask1 = { s = { }, full = false }
local dmask2 = { [1] = true, [2] = true, [3] = true, [4] = true, [5] = true, [6] = true, [7] = true, [8] = true, [9] = true, [10] = true, [11] = true, s = { }, full = true }
local dmask3 = { [6] = true, s = { [6] = true }, full = false }
local dmask4 = { [8] = true, s = { [8] = true }, full = false }
local dmask5 = { [11] = true, s = { [11] = true }, full = false }
local dmask6 = { [3] = true, [9] = true, s = { [3] = true, [9] = true }, full = false }
local dmask7 = { [7] = true, s = { [7] = true }, full = false }
local dmask8 = { [4] = true, [10] = true, s = { [4] = true, [10] = true }, full = false }
local dmask9 = { [2] = true, s = { [2] = true }, full = false }
local dmask10 = { [1] = true, s = { }, full = false }
local dmask11 = { [5] = true, s = { [5] = true }, full = false }
local bytes = {}
for b = 0, 255 do bytes[b] = dmask1 end
bytes[9] = dmask2
bytes[32] = dmask2
bytes[33] = dmask3
bytes[45] = dmask2
bytes[46] = dmask4
bytes[47] = dmask5
bytes[60] = dmask6
bytes[61] = dmask7
bytes[62] = dmask8
bytes[97] = dmask9
bytes[111] = dmask10
bytes[126] = dmask11
disp[9] = { bytes = bytes, eof = dmask1 }
end
-- Rule functions
rules["Root"] = function(parser)
local depth = parser.depth + 1
parser.depth = depth
if depth > MAX_DEPTH then
-- A hard Lua error (rather than a match failure) so the overflow can't
-- be silently converted into a successful parse by a predicate or choice
error("pgen: max recursion depth (" .. MAX_DEPTH .. ") exceeded at position " .. (parser.pos + 1))
end
do -- sequence with 4 patterns
local pp_pos, pp_cap, pp_trail = parser.pos, parser.cap_n, parser.trail_n
rules["White"](parser)
if parser.success then
rules["File"](parser)
end
if parser.success then
rules["White"](parser)
end
if parser.success then
do -- negate (only match if pattern fails)
local pp_pos = parser.pos
-- match any 1 characters
if parser.pos + 1 <= parser.input_len then
parser.pos = parser.pos + 1
else
parser.success = false
record_furthest(parser)
end
if parser.success then
-- Pattern matched, so negate fails
parser.pos = pp_pos
parser.success = false
record_furthest(parser)
else
-- Pattern failed, so negate succeeds
parser.success = true
-- Swallow labeled failures inside predicates (LPegLabel behavior)
if parser.throw_label then
parser.throw_label = nil
parser.throw_pos = 0
end
parser.pos = pp_pos
end
end
end
if not parser.success then
parser.pos = pp_pos parser.cap_n = pp_cap ind_trail_rewind(parser, pp_trail)
end
end
parser.depth = depth - 1
return parser.success
end
rules["Advance"] = function(parser)
local depth = parser.depth + 1
parser.depth = depth
if depth > MAX_DEPTH then
-- A hard Lua error (rather than a match failure) so the overflow can't
-- be silently converted into a successful parse by a predicate or choice
error("pgen: max recursion depth (" .. MAX_DEPTH .. ") exceeded at position " .. (parser.pos + 1))
end
do -- indenter advance (stack 0): push width if deeper than top, consume nothing
local ind_width = ind_measure(parser, 4)
local ind_s = parser.ind_stacks[1]
if ind_s.n > 0 and ind_width > ind_s[ind_s.n] then
ind_push(parser, 1, ind_width)
else
parser.success = false
record_furthest(parser)
end
end
parser.depth = depth - 1
return parser.success
end
rules["ArgBlock"] = function(parser)
local depth = parser.depth + 1
parser.depth = depth
if depth > MAX_DEPTH then
-- A hard Lua error (rather than a match failure) so the overflow can't
-- be silently converted into a successful parse by a predicate or choice
error("pgen: max recursion depth (" .. MAX_DEPTH .. ") exceeded at position " .. (parser.pos + 1))
end
do -- sequence with 3 patterns
local pp_pos, pp_cap, pp_trail = parser.pos, parser.cap_n, parser.trail_n
rules["ArgLine"](parser)
if parser.success then
do -- zero or more repetitions
while true do
do -- sequence with 4 patterns
local pp_pos, pp_cap, pp_trail = parser.pos, parser.cap_n, parser.trail_n
rules["Space"](parser)
if parser.success then
-- match single character ","
if byte(parser.input, parser.pos + 1) == 44 then
parser.pos = parser.pos + 1
else
parser.success = false
end
end
if parser.success then
rules["SpaceBreak"](parser)
end
if parser.success then
rules["ArgLine"](parser)
end
if not parser.success then
parser.pos = pp_pos parser.cap_n = pp_cap ind_trail_rewind(parser, pp_trail)
end
end
if not parser.success then
break
end
end
-- Only recover from ordinary failure, not labeled failure from T()
if not parser.throw_label then
parser.success = true
end
end
end
if parser.success then
rules["PopIndent"](parser)
end
if not parser.success then
parser.pos = pp_pos parser.cap_n = pp_cap ind_trail_rewind(parser, pp_trail)
end
end
parser.depth = depth - 1
return parser.success
end
rules["ArgLine"] = function(parser)
local depth = parser.depth + 1
parser.depth = depth
if depth > MAX_DEPTH then
-- A hard Lua error (rather than a match failure) so the overflow can't
-- be silently converted into a successful parse by a predicate or choice
error("pgen: max recursion depth (" .. MAX_DEPTH .. ") exceeded at position " .. (parser.pos + 1))
end
do -- sequence with 2 patterns
local pp_pos, pp_cap, pp_trail = parser.pos, parser.cap_n, parser.trail_n
rules["CheckIndent"](parser)
if parser.success then
rules["ExpList"](parser)
end
if not parser.success then
parser.pos = pp_pos parser.cap_n = pp_cap ind_trail_rewind(parser, pp_trail)
end
end
parser.depth = depth - 1
return parser.success
end
rules["Assign"] = function(parser)
local depth = parser.depth + 1
parser.depth = depth
if depth > MAX_DEPTH then
-- A hard Lua error (rather than a match failure) so the overflow can't
-- be silently converted into a successful parse by a predicate or choice
error("pgen: max recursion depth (" .. MAX_DEPTH .. ") exceeded at position " .. (parser.pos + 1))
end
do -- capture table
local ct_cap_start = parser.cap_n
cap_push(parser, CAP_TBL_OPEN, nil, 0, 0)
do -- sequence with 4 patterns
local pp_pos, pp_cap, pp_trail = parser.pos, parser.cap_n, parser.trail_n
do -- constant capture (1 values)
cap_push(parser, CAP_CONST, "assign", 0, 0)
end
if parser.success then
rules["Space"](parser)
end
if parser.success then
-- match single character "="
if byte(parser.input, parser.pos + 1) == 61 then
parser.pos = parser.pos + 1