-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoonscript.lua
More file actions
6441 lines (6405 loc) · 156 KB
/
Copy pathmoonscript.lua
File metadata and controls
6441 lines (6405 loc) · 156 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
package.preload["moonscript.cmd.moonc"] = function()
local lfs = require("lfs")
local split
split = require("moonscript.util").split
local dirsep, dirsep_chars, mkdir, normalize_dir, parse_dir, parse_file, convert_path, format_time, gettime, compile_file_text, write_file, compile_and_write, is_abs_path, path_to_target
dirsep = package.config:sub(1, 1)
if dirsep == "\\" then
dirsep_chars = "\\/"
else
dirsep_chars = dirsep
end
mkdir = function(path)
local chunks = split(path, dirsep)
local accum
for _index_0 = 1, #chunks do
local dir = chunks[_index_0]
accum = accum and tostring(accum) .. tostring(dirsep) .. tostring(dir) or dir
lfs.mkdir(accum)
end
return lfs.attributes(path, "mode")
end
normalize_dir = function(path)
return path:match("^(.-)[" .. tostring(dirsep_chars) .. "]*$") .. dirsep
end
parse_dir = function(path)
return (path:match("^(.-)[^" .. tostring(dirsep_chars) .. "]*$"))
end
parse_file = function(path)
return (path:match("^.-([^" .. tostring(dirsep_chars) .. "]*)$"))
end
convert_path = function(path)
local new_path = path:gsub("%.moon$", ".lua")
if new_path == path then
new_path = path .. ".lua"
end
return new_path
end
format_time = function(time)
return ("%.3fms"):format(time * 1000)
end
do
local socket
gettime = function()
if socket == nil then
pcall(function()
socket = require("socket")
end)
if not (socket) then
socket = false
end
end
if socket then
return socket.gettime()
else
return nil, "LuaSocket needed for benchmark"
end
end
end
compile_file_text = function(text, opts)
if opts == nil then
opts = { }
local parse = require("moonscript.parse")
local compile = require("moonscript.compile")
local parse_time
if opts.benchmark then
parse_time = assert(gettime())
end
local tree, err = parse.string(text)
if not (tree) then
return nil, err
end
if parse_time then
parse_time = gettime() - parse_time
end
if opts.show_parse_tree then
local dump = require("moonscript.dump")
dump.tree(tree)
return true
end
local compile_time
if opts.benchmark then
compile_time = gettime()
end
local code, posmap_or_err, err_pos = compile.tree(tree)
if not (code) then
return nil, compile.format_error(posmap_or_err, err_pos, text)
end
if compile_time then
compile_time = gettime() - compile_time
end
if opts.show_posmap then
local debug_posmap
debug_posmap = require("moonscript.util").debug_posmap
print("Pos", "Lua", ">>", "Moon")
print(debug_posmap(posmap_or_err, text, code))
return true
end
if opts.benchmark then
print(table.concat({
opts.fname or "stdin",
"Parse time \t" .. format_time(parse_time),
"Compile time\t" .. format_time(compile_time),
""
}, "\n"))
return true
end
return code
end
write_file = function(fname, code)
mkdir(parse_dir(fname))
local f, err = io.open(fname, "w")
if not (f) then
return nil, err
end
assert(f:write(code))
assert(f:write("\n"))
f:close()
return "build"
end
compile_and_write = function(src, dest, opts)
if opts == nil then
opts = { }
end
local f = io.open(src)
if not (f) then
return nil, "Can't find file"
end
local text = assert(f:read("*a"))
f:close()
local code, err = compile_file_text(text, opts)
if not code then
return nil, err
end
if code == true then
return true
end
if opts.print then
print(code)
return true
end
return write_file(dest, code)
end
is_abs_path = function(path)
local first = path:sub(1, 1)
if dirsep == "\\" then
return first == "/" or first == "\\" or path:sub(2, 1) == ":"
else
return first == dirsep
end
end
path_to_target = function(path, target_dir, base_dir)
if target_dir == nil then
target_dir = nil
end
if base_dir == nil then
base_dir = nil
end
local target = convert_path(path)
if target_dir then
target_dir = normalize_dir(target_dir)
end
if base_dir and target_dir then
local head = base_dir:match("^(.-)[^" .. tostring(dirsep_chars) .. "]*[" .. tostring(dirsep_chars) .. "]?$")
if head then
local start, stop = target:find(head, 1, true)
if start == 1 then
target = target:sub(stop + 1)
end
end
end
if target_dir then
if is_abs_path(target) then
target = parse_file(target)
end
target = target_dir .. target
end
return target
end
return {
dirsep = dirsep,
mkdir = mkdir,
normalize_dir = normalize_dir,
parse_dir = parse_dir,
parse_file = parse_file,
convert_path = convert_path,
gettime = gettime,
format_time = format_time,
path_to_target = path_to_target,
compile_file_text = compile_file_text,
compile_and_write = compile_and_write
}
end
package.preload["moonscript.data"] = function()
local concat, remove, insert
do
local _obj_0 = table
concat, remove, insert = _obj_0.concat, _obj_0.remove, _obj_0.insert
end
local Set
Set = function(items)
local _tbl_0 = { }
for _index_0 = 1, #items do
local k = items[_index_0]
_tbl_0[k] = true
end
return _tbl_0
end
local Stack
do
local _class_0
local _base_0 = {
__tostring = function(self)
return "<Stack {" .. concat(self, ", ") .. "}>"
end,
pop = function(self)
return remove(self)
end,
push = function(self, value, ...)
insert(self, value)
if ... then
return self:push(...)
else
return value
end
end,
top = function(self)
return self[#self]
end
}
_base_0.__index = _base_0
_class_0 = setmetatable({
__init = function(self, ...)
self:push(...)
return nil
end,
__base = _base_0,
__name = "Stack"
}, {
__index = _base_0,
__call = function(cls, ...)
local _self_0 = setmetatable({}, _base_0)
cls.__init(_self_0, ...)
return _self_0
end
})
_base_0.__class = _class_0
Stack = _class_0
end
local lua_keywords = Set({
'and',
'break',
'do',
'else',
'elseif',
'end',
'false',
'for',
'function',
'if',
'in',
'local',
'nil',
'not',
'or',
'repeat',
'return',
'then',
'true',
'until',
'while'
})
return {
Set = Set,
Stack = Stack,
lua_keywords = lua_keywords
}
end
package.preload["moonscript.base"] = function()
local compile = require("moonscript.compile")
local parse = require("moonscript.parse")
local concat, insert, remove
do
local _obj_0 = table
concat, insert, remove = _obj_0.concat, _obj_0.insert, _obj_0.remove
end
local split, dump, get_options, unpack
do
local _obj_0 = require("moonscript.util")
split, dump, get_options, unpack = _obj_0.split, _obj_0.dump, _obj_0.get_options, _obj_0.unpack
end
local lua = {
loadstring = loadstring,
load = load
}
local dirsep, line_tables, create_moonpath, to_lua, moon_loader, loadstring, loadfile, dofile, insert_loader, remove_loader
dirsep = "/"
line_tables = require("moonscript.line_tables")
create_moonpath = function(package_path)
local moonpaths
do
local _accum_0 = { }
local _len_0 = 1
local _list_0 = split(package_path, ";")
for _index_0 = 1, #_list_0 do
local _continue_0 = false
repeat
local path = _list_0[_index_0]
local prefix = path:match("^(.-)%.lua$")
if not (prefix) then
_continue_0 = true
break
end
local _value_0 = prefix .. ".moon"
_accum_0[_len_0] = _value_0
_len_0 = _len_0 + 1
_continue_0 = true
until true
if not _continue_0 then
break
end
end
moonpaths = _accum_0
end
return concat(moonpaths, ";")
end
to_lua = function(text, options)
if options == nil then
options = { }
end
if "string" ~= type(text) then
local t = type(text)
return nil, "expecting string (got " .. t .. ")"
end
if string.sub(text,1,3)=="\239\187\191" then text=string.sub(text,4) end
local tree, err = parse.string(text)
if not tree then
return nil, err
end
local code, ltable, pos = compile.tree(tree, options)
if not code then
return nil, compile.format_error(ltable, pos, text)
end
return code, ltable
end
moon_loader = function(name)
local name_path = name:gsub("%.", dirsep)
local file, file_path
for path in package.moonpath:gmatch("[^;]+") do
file_path = path:gsub("?", name_path)
file = io.open(file_path)
if file then
break
end
end
if file then
local text = file:read("*a")
file:close()
local res, err = loadstring(text, "@" .. tostring(file_path))
if not res then
error(file_path .. ": " .. err)
end
return res
end
return nil, "Could not find moon file"
end
loadstring = function(...)
local options, str, chunk_name, mode, env = get_options(...)
chunk_name = chunk_name or "=(moonscript.loadstring)"
local code, ltable_or_err = to_lua(str, options)
if not (code) then
return nil, ltable_or_err
end
if chunk_name then
line_tables[chunk_name] = ltable_or_err
end
return (lua.loadstring or lua.load)(code, chunk_name, unpack({
mode,
env
}))
end
loadfile = function(fname, ...)
local file, err = io.open(fname)
if not (file) then
return nil, err
end
local text = assert(file:read("*a"))
file:close()
return loadstring(text, "@" .. tostring(fname), ...)
end
dofile = function(...)
local f = assert(loadfile(...))
return f()
end
insert_loader = function(pos)
if pos == nil then
pos = 2
end
if not package.moonpath then
package.moonpath = create_moonpath(package.path)
end
local loaders = package.loaders or package.searchers
for _index_0 = 1, #loaders do
local loader = loaders[_index_0]
if loader == moon_loader then
return false
end
end
insert(loaders, pos, moon_loader)
return true
end
remove_loader = function()
local loaders = package.loaders or package.searchers
for i, loader in ipairs(loaders) do
if loader == moon_loader then
remove(loaders, i)
return true
end
end
return false
end
return {
_NAME = "moonscript",
insert_loader = insert_loader,
remove_loader = remove_loader,
to_lua = to_lua,
moon_loader = moon_loader,
dirsep = dirsep,
dofile = dofile,
loadfile = loadfile,
loadstring = loadstring,
create_moonpath = create_moonpath
}
end
package.preload["moonscript.transform.comprehension"] = function()
local is_value
is_value = require("moonscript.types").is_value
local construct_comprehension
construct_comprehension = function(inner, clauses)
local current_stms = inner
for i = #clauses, 1, -1 do
local clause = clauses[i]
local t = clause[1]
local _exp_0 = t
if "for" == _exp_0 then
local _, name, bounds
_, name, bounds = clause[1], clause[2], clause[3]
current_stms = {
"for",
name,
bounds,
current_stms
}
elseif "foreach" == _exp_0 then
local _, names, iter
_, names, iter = clause[1], clause[2], clause[3]
current_stms = {
"foreach",
names,
{
iter
},
current_stms
}
elseif "when" == _exp_0 then
local _, cond
_, cond = clause[1], clause[2]
current_stms = {
"if",
cond,
current_stms
}
else
current_stms = error("Unknown comprehension clause: " .. t)
end
current_stms = {
current_stms
}
end
return current_stms[1]
end
local comprehension_has_value
comprehension_has_value = function(comp)
return is_value(comp[2])
end
return {
construct_comprehension = construct_comprehension,
comprehension_has_value = comprehension_has_value
}
end
package.preload["moonscript.cmd.lint"] = function()
local insert
insert = table.insert
local Set
Set = require("moonscript.data").Set
local Block
Block = require("moonscript.compile").Block
local mtype
mtype = require("moonscript.util").moon.type
local default_whitelist = Set({
'_G',
'_VERSION',
'assert',
'bit32',
'collectgarbage',
'coroutine',
'debug',
'dofile',
'error',
'getfenv',
'getmetatable',
'io',
'ipairs',
'load',
'loadfile',
'loadstring',
'math',
'module',
'next',
'os',
'package',
'pairs',
'pcall',
'print',
'rawequal',
'rawget',
'rawlen',
'rawset',
'require',
'select',
'setfenv',
'setmetatable',
'string',
'table',
'tonumber',
'tostring',
'type',
'unpack',
'xpcall',
"nil",
"true",
"false"
})
local LinterBlock
do
local _class_0
local _parent_0 = Block
local _base_0 = {
lint_mark_used = function(self, name)
if self.lint_unused_names and self.lint_unused_names[name] then
self.lint_unused_names[name] = false
return
end
if self.parent then
return self.parent:lint_mark_used(name)
end
end,
lint_check_unused = function(self)
if not (self.lint_unused_names and next(self.lint_unused_names)) then
return
end
local names_by_position = { }
for name, pos in pairs(self.lint_unused_names) do
local _continue_0 = false
repeat
if not (pos) then
_continue_0 = true
break
end
names_by_position[pos] = names_by_position[pos] or { }
insert(names_by_position[pos], name)
_continue_0 = true
until true
if not _continue_0 then
break
end
end
local tuples
do
local _accum_0 = { }
local _len_0 = 1
for pos, names in pairs(names_by_position) do
_accum_0[_len_0] = {
pos,
names
}
_len_0 = _len_0 + 1
end
tuples = _accum_0
end
table.sort(tuples, function(a, b)
return a[1] < b[1]
end)
for _index_0 = 1, #tuples do
local _des_0 = tuples[_index_0]
local pos, names
pos, names = _des_0[1], _des_0[2]
insert(self:get_root_block().lint_errors, {
"assigned but unused " .. tostring(table.concat((function()
local _accum_0 = { }
local _len_0 = 1
for _index_1 = 1, #names do
local n = names[_index_1]
_accum_0[_len_0] = "`" .. tostring(n) .. "`"
_len_0 = _len_0 + 1
end
return _accum_0
end)(), ", ")),
pos
})
end
end,
render = function(self, ...)
self:lint_check_unused()
return _class_0.__parent.__base.render(self, ...)
end,
block = function(self, ...)
do
local _with_0 = _class_0.__parent.__base.block(self, ...)
_with_0.block = self.block
_with_0.render = self.render
_with_0.get_root_block = self.get_root_block
_with_0.lint_check_unused = self.lint_check_unused
_with_0.lint_mark_used = self.lint_mark_used
_with_0.value_compilers = self.value_compilers
_with_0.statement_compilers = self.statement_compilers
return _with_0
end
end
}
_base_0.__index = _base_0
setmetatable(_base_0, _parent_0.__base)
_class_0 = setmetatable({
__init = function(self, whitelist_globals, ...)
if whitelist_globals == nil then
whitelist_globals = default_whitelist
end
_class_0.__parent.__init(self, ...)
self.get_root_block = function()
return self
end
self.lint_errors = { }
local vc = self.value_compilers
self.value_compilers = setmetatable({
ref = function(block, val)
local name = val[2]
if not (block:has_name(name) or whitelist_globals[name] or name:match("%.")) then
insert(self.lint_errors, {
"accessing global `" .. tostring(name) .. "`",
val[-1]
})
end
block:lint_mark_used(name)
return vc.ref(block, val)
end
}, {
__index = vc
})
local sc = self.statement_compilers
self.statement_compilers = setmetatable({
assign = function(block, node)
local names = node[2]
for _index_0 = 1, #names do
local _continue_0 = false
repeat
local name = names[_index_0]
if type(name) == "table" and name[1] == "temp_name" then
_continue_0 = true
break
end
local real_name, is_local = block:extract_assign_name(name)
if not (is_local or real_name and not block:has_name(real_name, true)) then
_continue_0 = true
break
end
if real_name == "_" then
_continue_0 = true
break
end
block.lint_unused_names = block.lint_unused_names or { }
block.lint_unused_names[real_name] = node[-1] or 0
_continue_0 = true
until true
if not _continue_0 then
break
end
end
return sc.assign(block, node)
end
}, {
__index = sc
})
end,
__base = _base_0,
__name = "LinterBlock",
__parent = _parent_0
}, {
__index = function(cls, name)
local val = rawget(_base_0, name)
if val == nil then
local parent = rawget(cls, "__parent")
if parent then
return parent[name]
end
else
return val
end
end,
__call = function(cls, ...)
local _self_0 = setmetatable({}, _base_0)
cls.__init(_self_0, ...)
return _self_0
end
})
_base_0.__class = _class_0
if _parent_0.__inherited then
_parent_0.__inherited(_parent_0, _class_0)
end
LinterBlock = _class_0
end
local format_lint
format_lint = function(errors, code, header)
if not (next(errors)) then
return
end
local pos_to_line, get_line
do
local _obj_0 = require("moonscript.util")
pos_to_line, get_line = _obj_0.pos_to_line, _obj_0.get_line
end
local formatted
do
local _accum_0 = { }
local _len_0 = 1
for _index_0 = 1, #errors do
local _des_0 = errors[_index_0]
local msg, pos
msg, pos = _des_0[1], _des_0[2]
if pos then
local line = pos_to_line(code, pos)
msg = "line " .. tostring(line) .. ": " .. tostring(msg)
local line_text = "> " .. get_line(code, line)
local sep_len = math.max(#msg, #line_text)
_accum_0[_len_0] = table.concat({
msg,
("="):rep(sep_len),
line_text
}, "\n")
else
_accum_0[_len_0] = msg
end
_len_0 = _len_0 + 1
end
formatted = _accum_0
end
if header then
table.insert(formatted, 1, header)
end
return table.concat(formatted, "\n\n")
end
local whitelist_for_file
do
local lint_config
whitelist_for_file = function(fname)
if not (lint_config) then
lint_config = { }
pcall(function()
lint_config = require("lint_config")
end)
end
if not (lint_config.whitelist_globals) then
return default_whitelist
end
local final_list = { }
for pattern, list in pairs(lint_config.whitelist_globals) do
if fname:match(pattern) then
for _index_0 = 1, #list do
local item = list[_index_0]
insert(final_list, item)
end
end
end
return setmetatable(Set(final_list), {
__index = default_whitelist
})
end
end
local lint_code
lint_code = function(code, name, whitelist_globals)
if name == nil then
name = "string input"
end
local parse = require("moonscript.parse")
local tree, err = parse.string(code)
if not (tree) then
return nil, err
end
local scope = LinterBlock(whitelist_globals)
scope:stms(tree)
scope:lint_check_unused()
return format_lint(scope.lint_errors, code, name)
end
local lint_file
lint_file = function(fname)
local f, err = io.open(fname)
if not (f) then
return nil, err
end
return lint_code(f:read("*a"), fname, whitelist_for_file(fname))
end
return {
lint_code = lint_code,
lint_file = lint_file
}
end
package.preload["moonscript.transform.names"] = function()
local build
build = require("moonscript.types").build
local unpack
unpack = require("moonscript.util").unpack
local LocalName
do
local _class_0
local _base_0 = {
get_name = function(self)
return self.name
end
}
_base_0.__index = _base_0
_class_0 = setmetatable({
__init = function(self, name)
self.name = name
self[1] = "temp_name"
end,
__base = _base_0,
__name = "LocalName"
}, {
__index = _base_0,
__call = function(cls, ...)
local _self_0 = setmetatable({}, _base_0)
cls.__init(_self_0, ...)
return _self_0
end
})
_base_0.__class = _class_0
LocalName = _class_0
end
local NameProxy
do
local _class_0
local _base_0 = {
get_name = function(self, scope, dont_put)
if dont_put == nil then
dont_put = true
end
if not self.name then
self.name = scope:free_name(self.prefix, dont_put)
end
return self.name
end,
chain = function(self, ...)
local items = {
base = self,
...
}
for k, v in ipairs(items) do
if type(v) == "string" then
items[k] = {
"dot",
v
}
else
items[k] = v
end
end
return build.chain(items)
end,
index = function(self, key)
if type(key) == "string" then
key = {
"ref",
key
}
end
return build.chain({
base = self,
{
"index",
key
}
})
end,
__tostring = function(self)
if self.name then
return ("name<%s>"):format(self.name)
else
return ("name<prefix(%s)>"):format(self.prefix)
end
end
}
_base_0.__index = _base_0
_class_0 = setmetatable({
__init = function(self, prefix)
self.prefix = prefix
self[1] = "temp_name"
end,
__base = _base_0,
__name = "NameProxy"
}, {
__index = _base_0,
__call = function(cls, ...)
local _self_0 = setmetatable({}, _base_0)
cls.__init(_self_0, ...)
return _self_0
end
})
_base_0.__class = _class_0
NameProxy = _class_0
end
local is_name_proxy
is_name_proxy = function(v)
if not (type(v) == "table") then
return false
end
local _exp_0 = v.__class
if LocalName == _exp_0 or NameProxy == _exp_0 then
return true
end
end
return {
NameProxy = NameProxy,
LocalName = LocalName,
is_name_proxy = is_name_proxy
}
end
package.preload["moonscript.util"] = function()
local concat
concat = table.concat
local unpack = unpack or table.unpack
local type = type
local moon = {
is_object = function(value)
return type(value) == "table" and value.__class
end,
is_a = function(thing, t)
if not (type(thing) == "table") then
return false
end
local cls = thing.__class
while cls do
if cls == t then
return true
end
cls = cls.__parent
end
return false
end,
type = function(value)
local base_type = type(value)
if base_type == "table" then
local cls = value.__class
if cls then
return cls
end
end
return base_type
end
}
local pos_to_line
pos_to_line = function(str, pos)
local line = 1
for _ in str:sub(1, pos):gmatch("\n") do
line = line + 1
end
return line
end
local trim
trim = function(str)
return str:match("^%s*(.-)%s*$")
end
local get_line
get_line = function(str, line_num)
for line in str:gmatch("([^\n]*)\n?") do
if line_num == 1 then
return line
end
line_num = line_num - 1
end
end
local get_closest_line
get_closest_line = function(str, line_num)
local line = get_line(str, line_num)
if (not line or trim(line) == "") and line_num > 1 then
return get_closest_line(str, line_num - 1)