From 60a979e224f26117f5be82bfca757a2483cef0fd Mon Sep 17 00:00:00 2001 From: Li Jin Date: Tue, 12 Oct 2021 10:04:44 +0800 Subject: fix test. --- spec/outputs/ambiguous.lua | 30 ++ spec/outputs/assign.lua | 44 ++ spec/outputs/attrib.lua | 63 +++ spec/outputs/backcall.lua | 130 +++++ spec/outputs/bubbling.lua | 123 +++++ spec/outputs/class.lua | 1057 ++++++++++++++++++++++++++++++++++++++ spec/outputs/comprehension.lua | 277 ++++++++++ spec/outputs/cond.lua | 272 ++++++++++ spec/outputs/destructure.lua | 357 +++++++++++++ spec/outputs/do.lua | 48 ++ spec/outputs/existential.lua | 156 ++++++ spec/outputs/export.lua | 307 +++++++++++ spec/outputs/export_default.lua | 19 + spec/outputs/funcs.lua | 222 ++++++++ spec/outputs/global.lua | 89 ++++ spec/outputs/goto.lua | 67 +++ spec/outputs/import.lua | 92 ++++ spec/outputs/lists.lua | 282 ++++++++++ spec/outputs/literals.lua | 28 + spec/outputs/local.lua | 151 ++++++ spec/outputs/loops.lua | 352 +++++++++++++ spec/outputs/macro-export.lua | 2 + spec/outputs/macro-teal.tl | 2 + spec/outputs/macro.lua | 233 +++++++++ spec/outputs/metatable.lua | 113 ++++ spec/outputs/multiline_chain.lua | 91 ++++ spec/outputs/operators.lua | 29 ++ spec/outputs/pipe.lua | 116 +++++ spec/outputs/plus.lua | 69 +++ spec/outputs/return.lua | 102 ++++ spec/outputs/string.lua | 42 ++ spec/outputs/stub.lua | 26 + spec/outputs/switch.lua | 71 +++ spec/outputs/syntax.lua | 360 +++++++++++++ spec/outputs/tables.lua | 351 +++++++++++++ spec/outputs/teal-lang.lua | 49 ++ spec/outputs/teal-lang.tl | 60 +++ spec/outputs/unless_else.lua | 7 + spec/outputs/using.lua | 23 + spec/outputs/vararg.lua | 218 ++++++++ spec/outputs/whitespace.lua | 98 ++++ spec/outputs/with.lua | 164 ++++++ 42 files changed, 6392 insertions(+) create mode 100644 spec/outputs/ambiguous.lua create mode 100644 spec/outputs/assign.lua create mode 100644 spec/outputs/attrib.lua create mode 100644 spec/outputs/backcall.lua create mode 100644 spec/outputs/bubbling.lua create mode 100644 spec/outputs/class.lua create mode 100644 spec/outputs/comprehension.lua create mode 100644 spec/outputs/cond.lua create mode 100644 spec/outputs/destructure.lua create mode 100644 spec/outputs/do.lua create mode 100644 spec/outputs/existential.lua create mode 100644 spec/outputs/export.lua create mode 100644 spec/outputs/export_default.lua create mode 100644 spec/outputs/funcs.lua create mode 100644 spec/outputs/global.lua create mode 100644 spec/outputs/goto.lua create mode 100644 spec/outputs/import.lua create mode 100644 spec/outputs/lists.lua create mode 100644 spec/outputs/literals.lua create mode 100644 spec/outputs/local.lua create mode 100644 spec/outputs/loops.lua create mode 100644 spec/outputs/macro-export.lua create mode 100644 spec/outputs/macro-teal.tl create mode 100644 spec/outputs/macro.lua create mode 100644 spec/outputs/metatable.lua create mode 100644 spec/outputs/multiline_chain.lua create mode 100644 spec/outputs/operators.lua create mode 100644 spec/outputs/pipe.lua create mode 100644 spec/outputs/plus.lua create mode 100644 spec/outputs/return.lua create mode 100644 spec/outputs/string.lua create mode 100644 spec/outputs/stub.lua create mode 100644 spec/outputs/switch.lua create mode 100644 spec/outputs/syntax.lua create mode 100644 spec/outputs/tables.lua create mode 100644 spec/outputs/teal-lang.lua create mode 100644 spec/outputs/teal-lang.tl create mode 100644 spec/outputs/unless_else.lua create mode 100644 spec/outputs/using.lua create mode 100644 spec/outputs/vararg.lua create mode 100644 spec/outputs/whitespace.lua create mode 100644 spec/outputs/with.lua (limited to 'spec') diff --git a/spec/outputs/ambiguous.lua b/spec/outputs/ambiguous.lua new file mode 100644 index 0000000..6039d73 --- /dev/null +++ b/spec/outputs/ambiguous.lua @@ -0,0 +1,30 @@ +local bind = grasp.bind; +(bind(stmt))({ + color = "Red" +}) +local a = 'b' +local c = d; +(a(b))(c(d)) +c = d.c; +(a(b))(c(d)); +(c(d))(a(b)) +local b +a, b = c, d; +(d(a))(c) +for i = 1, 10 do + a = function() end + (print)(1) + a = f; + (print)(2) + if cond then + (print)(3) + end + ::abc::; + (print)(4) + goto abc; + (print)(5) +end +do + print(123) +end +return nil diff --git a/spec/outputs/assign.lua b/spec/outputs/assign.lua new file mode 100644 index 0000000..628f763 --- /dev/null +++ b/spec/outputs/assign.lua @@ -0,0 +1,44 @@ +local _ +_ = function() + local joop = 2302 + return function(hi) + local d = 100 + hi = 1021 + local a, b, c + a, b, c, d = 1, 2, 3, 4 + local hello + hello[232], (5 + 5)[121], hello, x[99] = 100, 200, 300 + joop = 12 + end +end +local joop = 2345 +local a, b +if hello then + a, b = "hello" +else + a, b = "nothing", "yeah" +end +if hello then + if yeah then + a, b = "one", "two" + else + a, b = "mmhh" + end +else + print("the other") + a, b = "nothing", "yeah" +end +local c, d +if true then + c, d = 1, 2 +end +local x +do + local f = getHandler() + if f then + x = ((function() + f() + return 123 + end)()) + end +end diff --git a/spec/outputs/attrib.lua b/spec/outputs/attrib.lua new file mode 100644 index 0000000..d9ac3f2 --- /dev/null +++ b/spec/outputs/attrib.lua @@ -0,0 +1,63 @@ +do + local a , b = setmetatable({ }, { + __close = function(self) + return print("closed") + end + }) + local c , d = 123, 'abc' + close(a, b) + const(c, d) +end +do + local v = (function() + if flag then + return func() + else + return setmetatable({ }, { + __close = function(self) end + }) + end + end)() + local f = (function() + local _with_0 = io.open("file.txt") + _with_0:write("Hello") + return _with_0 + end)() +end +do + local _ = (function() + local _with_0 = io.open("file.txt") + _with_0:write("Hello") + return _with_0 + end)(); + local _ = setmetatable({ }, { + __close = function(self) + return print("second") + end + }); + local _ = setmetatable({ }, { + __close = function() + return print("first") + end + }) +end +local _defers = setmetatable({ }, { + __close = function(self) + self[#self]() + self[#self] = nil + end +}) +do + _defers[#_defers + 1] = function() + return print(3) + end + local _ = _defers; + _defers[#_defers + 1] = function() + return print(2) + end + local _ = _defers; + _defers[#_defers + 1] = function() + return print(1) + end + local _ = _defers +end diff --git a/spec/outputs/backcall.lua b/spec/outputs/backcall.lua new file mode 100644 index 0000000..9f7ec29 --- /dev/null +++ b/spec/outputs/backcall.lua @@ -0,0 +1,130 @@ +do + map({ + 1, + 2, + 3 + }, function(x) + return x * 2 + end) +end +do + map(function(x) + return x * 2 + end, { + 1, + 2, + 3 + }) +end +do + filter(function(x) + return x > 2 + end, (function() + return map(function(x) + return x * 2 + end, { + 1, + 2, + 3, + 4 + }) + end)()) +end +do + if http ~= nil then + http.get("ajaxtest", function(data) + body[".result"]:html(data) + return http.post("ajaxprocess", data, function(processed) + body[".result"]:append(processed) + return setTimeout(1000, function() + return print("done") + end) + end) + end) + end +end +do + syncStatus(function() + return loadAsync("file.yue", function(err, data) + if data == nil then + data = "nil" + end + if err then + print(err) + return + end + return compileAsync(data, function(codes) + local func = loadstring(codes) + return func() + end) + end) + end) +end +do + f1(function() + return f2(function() + do + f3(function() + return f4(function() end) + end) + end + return f5(function() + return f6(function() + return f7() + end) + end) + end) + end) +end +do + local result, msg + do + do + local _obj_0 = receiveAsync("filename.txt", function(data) + print(data) + return processAsync(data, function(info) + return check(info) + end) + end) + result, msg = _obj_0.result, _obj_0.msg + end + end + print(result, msg) + local totalSize = reduce(((function() + local _accum_0 = { } + local _len_0 = 1 + local _list_0 = files + for _index_0 = 1, #_list_0 do + local file = _list_0[_index_0] + _accum_0[_len_0] = loadAsync(file, function(data) + return addToCache(file, data) + end) + _len_0 = _len_0 + 1 + end + return _accum_0 + end)()), 0, function(a, b) + return a + b + end) +end +local propA +do + propA = property(function(self) + return self._value + end, function(self, value) + print("old value: " .. tostring(self._value)) + print("new value: " .. tostring(value)) + self._value = value + end) +end +local propB +do + propB = property(function(self) + return self._value + end, function(self, value) + print("old value: " .. tostring(self._value)) + print("new value: " .. tostring(value)) + self._value = value + end) +end +alert("hi") +return nil diff --git a/spec/outputs/bubbling.lua b/spec/outputs/bubbling.lua new file mode 100644 index 0000000..7cb93c7 --- /dev/null +++ b/spec/outputs/bubbling.lua @@ -0,0 +1,123 @@ +local f +f = function(...) + return #{ + ... + } +end +local dont_bubble +dont_bubble = function() + local _accum_0 = { } + local _len_0 = 1 + for x in (function(...) + return print(...) + end)("hello") do + _accum_0[_len_0] = x + _len_0 = _len_0 + 1 + end + return _accum_0 +end +local k +do + local _accum_0 = { } + local _len_0 = 1 + for x in (function(...) + return print(...) + end)("hello") do + _accum_0[_len_0] = x + _len_0 = _len_0 + 1 + end + k = _accum_0 +end +local j +do + local _accum_0 = { } + local _len_0 = 1 + for i = 1, 10 do + _accum_0[_len_0] = function(...) + return print(...) + end + _len_0 = _len_0 + 1 + end + j = _accum_0 +end +local m +m = function(...) + local _accum_0 = { } + local _len_0 = 1 + local _list_0 = { + ... + } + for _index_0 = 1, #_list_0 do + local x = _list_0[_index_0] + if f(...) > 4 then + _accum_0[_len_0] = x + _len_0 = _len_0 + 1 + end + end + return _accum_0 +end +local _ +_ = function(...) + local x + do + local _accum_0 = { } + local _len_0 = 1 + local _list_0 = { + ... + } + for _index_0 = 1, #_list_0 do + local i = _list_0[_index_0] + _accum_0[_len_0] = i + _len_0 = _len_0 + 1 + end + x = _accum_0 + end + local y + do + local _accum_0 = { } + local _len_0 = 1 + local _list_0 = { + ... + } + for _index_0 = 1, #_list_0 do + local x = _list_0[_index_0] + _accum_0[_len_0] = x + _len_0 = _len_0 + 1 + end + y = _accum_0 + end + local z + do + local _accum_0 = { } + local _len_0 = 1 + for x in hallo do + if f(...) > 4 then + _accum_0[_len_0] = x + _len_0 = _len_0 + 1 + end + end + z = _accum_0 + end + local a + do + local _accum_0 = { } + local _len_0 = 1 + for i = 1, 10 do + _accum_0[_len_0] = ... + _len_0 = _len_0 + 1 + end + a = _accum_0 + end + local b + do + local _accum_0 = { } + local _len_0 = 1 + for i = 1, 10 do + _accum_0[_len_0] = function(...) + return print(...) + end + _len_0 = _len_0 + 1 + end + b = _accum_0 + end +end diff --git a/spec/outputs/class.lua b/spec/outputs/class.lua new file mode 100644 index 0000000..20b18ea --- /dev/null +++ b/spec/outputs/class.lua @@ -0,0 +1,1057 @@ +local Hello +do + local _class_0 + local _base_0 = { + hello = function(self) + return print(self.test, self.world) + end, + __tostring = function(self) + return "hello world" + end + } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function(self, test, world) + self.test = test + self.world = world + return print("creating object..") + end, + __base = _base_0, + __name = "Hello" + }, { + __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 + Hello = _class_0 +end +local x = Hello(1, 2) +x:hello() +print(x) +local Simple +do + local _class_0 + local _base_0 = { + cool = function(self) + return print("cool") + end + } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "Simple" + }, { + __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 + Simple = _class_0 +end +local Yikes +do + local _class_0 + local _parent_0 = Simple + local _base_0 = { } + _base_0.__index = _base_0 + setmetatable(_base_0, _parent_0.__base) + _class_0 = setmetatable({ + __init = function(self) + return print("created hello") + end, + __base = _base_0, + __name = "Yikes", + __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 + Yikes = _class_0 +end +x = Yikes() +x:cool() +local Hi +do + local _class_0 + local _base_0 = { + cool = function(self, num) + return print("num", num) + end + } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function(self, arg) + return print("init arg", arg) + end, + __base = _base_0, + __name = "Hi" + }, { + __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 + Hi = _class_0 +end +do + local _class_0 + local _parent_0 = Hi + local _base_0 = { + cool = function(self) + return _class_0.__parent.__base.cool(self, 120302) + end + } + _base_0.__index = _base_0 + setmetatable(_base_0, _parent_0.__base) + _class_0 = setmetatable({ + __init = function(self) + return _class_0.__parent.__init(self, "man") + end, + __base = _base_0, + __name = "Simple", + __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 + Simple = _class_0 +end +x = Simple() +x:cool() +print(x.__class == Simple) +local Okay +do + local _class_0 + local _base_0 = { + something = 20323 + } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "Okay" + }, { + __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 + Okay = _class_0 +end +local Biggie +do + local _class_0 + local _parent_0 = Okay + local _base_0 = { + something = function(self) + _class_0.__parent.__base.something(self, 1, 2, 3, 4) + _class_0.__parent.something(another_self, 1, 2, 3, 4) + return assert(_class_0.__parent == Okay) + end + } + _base_0.__index = _base_0 + setmetatable(_base_0, _parent_0.__base) + _class_0 = setmetatable({ + __init = function(self, ...) + return _class_0.__parent.__init(self, ...) + end, + __base = _base_0, + __name = "Biggie", + __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 + Biggie = _class_0 +end +local Yeah +do + local _class_0 + local _base_0 = { + okay = function(self) + return _class_0.__parent.something(self, 1, 2, 3, 4) + end + } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "Yeah" + }, { + __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 + Yeah = _class_0 +end +local What +do + local _class_0 + local _base_0 = { + something = function(self) + return print("val:", self.val) + end + } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "What" + }, { + __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 + What = _class_0 +end +do + local _class_0 + local _parent_0 = What + local _base_0 = { + val = 2323, + something = function(self) + local _base_1 = _class_0.__parent + local _fn_0 = _base_1.something + return _fn_0 and function(...) + return _fn_0(_base_1, ...) + end + end + } + _base_0.__index = _base_0 + setmetatable(_base_0, _parent_0.__base) + _class_0 = setmetatable({ + __init = function(self, ...) + return _class_0.__parent.__init(self, ...) + end, + __base = _base_0, + __name = "Hello", + __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 + Hello = _class_0 +end +do + local _with_0 = Hello() + x = _with_0:something() + print(x) + x() +end +local CoolSuper +do + local _class_0 + local _base_0 = { + hi = function(self) + _class_0.__parent.__base.hi(self, 1, 2, 3, 4)(1, 2, 3, 4) + _class_0.__parent.something(1, 2, 3, 4) + local _ = _class_0.__parent.something(1, 2, 3, 4).world + _class_0.__parent.yeah(self, "world").okay(hi, hi, hi) + _ = something.super + _ = _class_0.__parent.super.super.super + do + local _base_1 = _class_0.__parent + local _fn_0 = _base_1.hello + _ = _fn_0 and function(...) + return _fn_0(_base_1, ...) + end + end + return nil + end + } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "CoolSuper" + }, { + __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 + CoolSuper = _class_0 +end +x = self.hello +x = self.__class.hello +self:hello("world") +self.__class:hello("world") +self.__class:one(self.__class:two(4, 5)(self.three, self.four)) +local xx +xx = function(hello, world, cool) + self.hello = hello + self.__class.world = world +end +local ClassMan +do + local _class_0 + local _base_0 = { + blue = function(self) end, + green = function(self) end + } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "ClassMan" + }, { + __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 + local self = _class_0; + self.yeah = 343 + self.hello = 3434 + self.world = 23423 + self.red = function(self) end + ClassMan = _class_0 +end +x = self +local y = self.__class +self(something) +self.__class(something) +local self = self + self / self +self = 343 +self.hello(2, 3, 4) +local _ = hello[self].world +local Whacko +do + local _class_0 + local hello + local _base_0 = { } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "Whacko" + }, { + __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 + local self = _class_0; + _ = self.hello + if something then + print("hello world") + end + hello = "world" + self.another = "day" + if something then + print("yeah") + end + Whacko = _class_0 +end +print("hello") +local yyy +yyy = function() + local Cool + do + local _class_0 + local _base_0 = { } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "Cool" + }, { + __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 + local self = _class_0; + _ = nil + Cool = _class_0 + return _class_0 + end +end +do + local _class_0 + local _base_0 = { } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "D" + }, { + __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 + local self = _class_0; + _ = nil + a.b.c.D = _class_0 +end +do + local _class_0 + local _base_0 = { } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "hello" + }, { + __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 + local self = _class_0; + _ = nil + a.b["hello"] = _class_0 +end +do + local _class_0 + local _parent_0 = Hello.World + local _base_0 = { } + _base_0.__index = _base_0 + setmetatable(_base_0, _parent_0.__base) + _class_0 = setmetatable({ + __init = function(self, ...) + return _class_0.__parent.__init(self, ...) + end, + __base = _base_0, + __name = "Something", + __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 + local self = _class_0; + _ = nil + if _parent_0.__inherited then + _parent_0.__inherited(_parent_0, _class_0) + end + (function() + return require("moon") + end)().Something = _class_0 +end +local a +do + local _class_0 + local _base_0 = { } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "a" + }, { + __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 + a = _class_0 +end +local b +local Something +do + local _class_0 + local _base_0 = { } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "Something" + }, { + __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 + Something = _class_0 + b = _class_0 +end +local c +do + local _class_0 + local _parent_0 = Hello + local _base_0 = { } + _base_0.__index = _base_0 + setmetatable(_base_0, _parent_0.__base) + _class_0 = setmetatable({ + __init = function(self, ...) + return _class_0.__parent.__init(self, ...) + end, + __base = _base_0, + __name = "Something", + __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 + Something = _class_0 + c = _class_0 +end +local d +do + local _class_0 + local _parent_0 = World + local _base_0 = { } + _base_0.__index = _base_0 + setmetatable(_base_0, _parent_0.__base) + _class_0 = setmetatable({ + __init = function(self, ...) + return _class_0.__parent.__init(self, ...) + end, + __base = _base_0, + __name = "d", + __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 + d = _class_0 +end +print(((function() + local WhatsUp + do + local _class_0 + local _base_0 = { } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "WhatsUp" + }, { + __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 + WhatsUp = _class_0 + return _class_0 + end +end)()).__name) +do + local _class_0 + local _base_0 = { } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "Something" + }, { + __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 + local self = _class_0; + _ = nil + Something = _class_0 +end +do + local _class_0 + local val, insert + local _base_0 = { } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function(self) + return print(insert, val) + end, + __base = _base_0, + __name = "Something" + }, { + __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 + local self = _class_0; + val = 23 + insert = table.insert + Something = _class_0 +end +do + local _class_0 + local _base_0 = { } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = hi, + __base = _base_0, + __name = "X" + }, { + __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 + X = _class_0 +end +do + local _class_0 + local _parent_0 = Thing + local _base_0 = { + dang = function(self) + return { + hello = function() + return _class_0.__parent.__base.dang(self) + end, + world = function() + return _class_0.__parent.one + end + } + end + } + _base_0.__index = _base_0 + setmetatable(_base_0, _parent_0.__base) + _class_0 = setmetatable({ + __init = function(self, ...) + return _class_0.__parent.__init(self, ...) + end, + __base = _base_0, + __name = "Cool", + __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 + Cool = _class_0 +end +do + local _class_0 + local _parent_0 = Thing + local _base_0 = { + dang = do_something(function(self) + return _class_0.__parent.__base.dang(self) + end) + } + _base_0.__index = _base_0 + setmetatable(_base_0, _parent_0.__base) + _class_0 = setmetatable({ + __init = function(self, ...) + return _class_0.__parent.__init(self, ...) + end, + __base = _base_0, + __name = "Whack", + __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 + Whack = _class_0 +end +do + local _class_0 + local _parent_0 = Thing + local _base_0 = { } + _base_0.__index = _base_0 + setmetatable(_base_0, _parent_0.__base) + _class_0 = setmetatable({ + __init = function(self, ...) + return _class_0.__parent.__init(self, ...) + end, + __base = _base_0, + __name = "Wowha", + __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 + local self = _class_0; + self.butt = function() + _class_0.__parent.butt(self) + _ = _class_0.__parent.hello + _class_0.__parent.hello(self) + local _base_1 = _class_0.__parent + local _fn_0 = _base_1.hello + return _fn_0 and function(...) + return _fn_0(_base_1, ...) + end + end + self.zone = cool({ + function() + _class_0.__parent.zone(self) + _ = _class_0.__parent.hello + _class_0.__parent.hello(self) + local _base_1 = _class_0.__parent + local _fn_0 = _base_1.hello + return _fn_0 and function(...) + return _fn_0(_base_1, ...) + end + end + }) + if _parent_0.__inherited then + _parent_0.__inherited(_parent_0, _class_0) + end + Wowha = _class_0 +end +do + local Test + do + local _class_0 + local _base_0 = { + test = function(self) + return self.__class["if"] and self.__class["do"](self.__class) + end + } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function(self) + self.__class["if"] = true + end, + __base = _base_0, + __name = "Test" + }, { + __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 + local self = _class_0; + self["do"] = function(self) + return 1 + end + Test = _class_0 + end + local test = Test() + test:test() +end +do + local Test + do + local _class_0 + local _base_0 = { + ["do"] = function(self) + return 1 + end, + test = function(self) + return self["if"] and self["do"](self) + end + } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function(self) + self["if"] = true + end, + __base = _base_0, + __name = "Test" + }, { + __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 + Test = _class_0 + end + local test = Test() + test:test() +end +do + local _class_0 + local _parent_0 = lapis.Application + local _base_0 = { + ["/"] = function(self) + return { + json = { + status = true + } + } + end + } + _base_0.__index = _base_0 + setmetatable(_base_0, _parent_0.__base) + _class_0 = setmetatable({ + __init = function(self, ...) + return _class_0.__parent.__init(self, ...) + end, + __base = _base_0, + __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 +end +do + local _class_0 + local _base_0 = { } + local _list_0 = { + B, + C, + D + } + for _index_0 = 1, #_list_0 do + local _mixin_0 = _list_0[_index_0] + for _key_0, _val_0 in pairs(_mixin_0.__base) do + if not _key_0:match("^__") then + _base_0[_key_0] = _val_0 + end + end + end + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "A" + }, { + __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 + A = _class_0 +end +return nil diff --git a/spec/outputs/comprehension.lua b/spec/outputs/comprehension.lua new file mode 100644 index 0000000..9a7c478 --- /dev/null +++ b/spec/outputs/comprehension.lua @@ -0,0 +1,277 @@ +local items = { + 1, + 2, + 3, + 4, + 5, + 6 +} +local out +do + local _tbl_0 = { } + for k in items do + _tbl_0[k] = k * 2 + end + out = _tbl_0 +end +local x = { + hello = "world", + okay = 2323 +} +local copy +do + local _tbl_0 = { } + for k, v in pairs(x) do + if k ~= "okay" then + _tbl_0[k] = v + end + end + copy = _tbl_0 +end +local _ +do + local _tbl_0 = { } + for x in yes do + local _key_0, _val_0 = unpack(x) + _tbl_0[_key_0] = _val_0 + end + _ = _tbl_0 +end +do + local _tbl_0 = { } + local _list_0 = yes + for _index_0 = 1, #_list_0 do + local x = _list_0[_index_0] + local _key_0, _val_0 = unpack(x) + _tbl_0[_key_0] = _val_0 + end + _ = _tbl_0 +end +do + local _tbl_0 = { } + for x in yes do + local _key_0, _val_0 = xxxx + _tbl_0[_key_0] = _val_0 + end + _ = _tbl_0 +end +do + local _tbl_0 = { } + local _list_0 = { + { + 1, + 2 + }, + { + 3, + 4 + } + } + for _index_0 = 1, #_list_0 do + local x = _list_0[_index_0] + local _key_0, _val_0 = unpack((function() + local _accum_0 = { } + local _len_0 = 1 + for i, a in ipairs(x) do + _accum_0[_len_0] = a * i + _len_0 = _len_0 + 1 + end + return _accum_0 + end)()) + _tbl_0[_key_0] = _val_0 + end + _ = _tbl_0 +end +local n1 +do + local _accum_0 = { } + local _len_0 = 1 + for i = 1, 10 do + _accum_0[_len_0] = i + _len_0 = _len_0 + 1 + end + n1 = _accum_0 +end +local n2 +do + local _accum_0 = { } + local _len_0 = 1 + for i = 1, 10 do + if i % 2 == 1 then + _accum_0[_len_0] = i + _len_0 = _len_0 + 1 + end + end + n2 = _accum_0 +end +local aa +do + local _accum_0 = { } + local _len_0 = 1 + for x = 1, 10 do + for y = 5, 14 do + _accum_0[_len_0] = { + x, + y + } + _len_0 = _len_0 + 1 + end + end + aa = _accum_0 +end +local bb +do + local _accum_0 = { } + local _len_0 = 1 + for thing in y do + for i = 1, 10 do + _accum_0[_len_0] = y + _len_0 = _len_0 + 1 + end + end + bb = _accum_0 +end +local cc +do + local _accum_0 = { } + local _len_0 = 1 + for i = 1, 10 do + for thing in y do + _accum_0[_len_0] = y + _len_0 = _len_0 + 1 + end + end + cc = _accum_0 +end +local dd +do + local _accum_0 = { } + local _len_0 = 1 + for i = 1, 10 do + if cool then + for thing in y do + if x > 3 then + if c + 3 then + _accum_0[_len_0] = y + _len_0 = _len_0 + 1 + end + end + end + end + end + dd = _accum_0 +end +do + local _tbl_0 = { } + for i = 1, 10 do + _tbl_0["hello"] = "world" + end + _ = _tbl_0 +end +local j +do + local _accum_0 = { } + local _len_0 = 1 + for _des_0 in things do + local a, b, c = _des_0[1], _des_0[2], _des_0[3] + _accum_0[_len_0] = a + _len_0 = _len_0 + 1 + end + j = _accum_0 +end +local k +do + local _accum_0 = { } + local _len_0 = 1 + local _list_0 = things + for _index_0 = 1, #_list_0 do + local _des_0 = _list_0[_index_0] + local a, b, c = _des_0[1], _des_0[2], _des_0[3] + _accum_0[_len_0] = a + _len_0 = _len_0 + 1 + end + k = _accum_0 +end +local i +do + local _accum_0 = { } + local _len_0 = 1 + local _list_0 = things + for _index_0 = 1, #_list_0 do + local _des_0 = _list_0[_index_0] + local hello, world = _des_0.hello, _des_0.world + _accum_0[_len_0] = hello + _len_0 = _len_0 + 1 + end + i = _accum_0 +end +local hj +do + local _tbl_0 = { } + for _des_0 in things do + local a, b, c = _des_0[1], _des_0[2], _des_0[3] + _tbl_0[a] = c + end + hj = _tbl_0 +end +local hk +do + local _tbl_0 = { } + local _list_0 = things + for _index_0 = 1, #_list_0 do + local _des_0 = _list_0[_index_0] + local a, b, c = _des_0[1], _des_0[2], _des_0[3] + _tbl_0[a] = c + end + hk = _tbl_0 +end +local hi +do + local _tbl_0 = { } + local _list_0 = things + for _index_0 = 1, #_list_0 do + local _des_0 = _list_0[_index_0] + local hello, world = _des_0.hello, _des_0.world + _tbl_0[hello] = world + end + hi = _tbl_0 +end +for _des_0 in things do + local a, b, c = _des_0[1], _des_0[2], _des_0[3] + ok(a, b, c) +end +do + local _accum_0 = { } + local _len_0 = 1 + local _max_0 = 3 + 4 + for _index_0 = 1 + 2, _max_0 < 0 and #items + _max_0 or _max_0 do + local item = items[_index_0] + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 + end + _ = _accum_0 +end +do + local _accum_0 = { } + local _len_0 = 1 + local _max_0 = 2 - thing[4] + for _index_0 = hello() * 4, _max_0 < 0 and #items + _max_0 or _max_0 do + local item = items[_index_0] + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 + end + _ = _accum_0 +end +local list +do + local _accum_0 = { } + local _len_0 = 1 + for item in items do + if item ~= nil then + _accum_0[_len_0] = item:invoke(123) + end + _len_0 = _len_0 + 1 + end + list = _accum_0 +end +return nil diff --git a/spec/outputs/cond.lua b/spec/outputs/cond.lua new file mode 100644 index 0000000..5efa237 --- /dev/null +++ b/spec/outputs/cond.lua @@ -0,0 +1,272 @@ +local you_cool = false +local _ +if cool then + if you_cool then + _ = one + else + if eatdic then + _ = yeah + else + _ = two + _ = three + end + end +else + _ = no +end +if cool then + _ = no +end +if cool then + _ = no +else + _ = yes +end +if cool then + wow(cool) +else + noso(cool) +end +if working then + if cool then + if cool then + _ = okay + else + _ = what + end + else + _ = nah + end +end +if yeah then + no(day) +elseif cool(me) then + okay(ya) +else + u(way) +end +if yeah then + no(dad) +else + if cool(you) then + okay(bah) + else + p(way) + end +end +if (function() end)() then + what(ever) +end +if nil then + flip(me) +else + it(be, rad) +end +if things(great) then + no(way) +elseif okay(sure) then + what(here) +end +if things then + no(chance) +elseif okay then + what(now) +end +if things then + yes(man) +elseif okay(person) then + hi(there) +else + hmm(sure) +end +if lets(go) then + print("greetings") +elseif "just us" then + print("will smith") +else + show(5555555) +end +do + local something = 10 + if something then + print(something) + else + print("else") + end +end +local hello +do + local something = 10 + if something then + hello = print(something) + else + hello = print("else") + end +end +hello = 5 + (function() + local something = 10 + if something then + return print(something) + end +end)() +local z = false +if false then + _ = one +else + do + local x = true + if x then + _ = two + else + z = true + if z then + _ = three + else + _ = four + end + end + end +end +local out +if false then + out = one +else + do + local x = true + if x then + out = two + else + z = true + if z then + out = three + else + out = four + end + end + end +end +local kzy +kzy = function() + do + local something = true + if something then + return 1 + else + do + local another = false + if another then + return 2 + end + end + end + end +end +if not true then + print("cool!") +end +if not (true and false) then + print("cool!") +end +if not false then + print("cool!") +end +if not false then + print("cool!") +else + print("no way!") +end +if not nil then + print("hello") +else + print("world") +end +local x +if not true then + x = print("cool!") +end +if not (true and false) then + x = print("cool!") +end +local y +if not false then + y = print("cool!") +end +if not false then + y = print("cool!") +else + y = print("no way!") +end +if not nil then + z = print("hello") +else + z = print("world") +end +print((function() + if not true then + return print("cool!") + end +end)()) +print((function() + if not (true and false) then + return print("cool!") + end +end)()) +print((function() + if not false then + return print("cool!") + end +end)()) +print((function() + if not false then + return print("cool!") + else + return print("no way!") + end +end)()) +print((function() + if not nil then + return print("hello") + else + return print("world") + end +end)()) +if not value then + print("hello") +end +local dddd +if not value then + dddd = { + 1, + 2, + 3 + } +end +do + local j = 100 + j = hi() + if not j then + error("not j!") + end +end +local a = 12 +local c, b +if something then + a, c, b = "cool" +end +local j +if 1 then + if 2 then + j = 3 + end +else + j = 6 +end +local m +if 1 then + if 2 then + m = 3 + end +else + m = 6 +end +return nil diff --git a/spec/outputs/destructure.lua b/spec/outputs/destructure.lua new file mode 100644 index 0000000..9ca13c8 --- /dev/null +++ b/spec/outputs/destructure.lua @@ -0,0 +1,357 @@ +do + local a, b + do + local _obj_0 = hello + a, b = _obj_0[1], _obj_0[2] + end + local c + do + local _obj_0 = hello + a, b, c = _obj_0[1][1], _obj_0[2], _obj_0[3][1] + end + local hello, world + do + local _obj_0 = value + hello, world = _obj_0.hello, _obj_0.world + end +end +do + local no, thing + do + local _obj_0 = world + no, thing = _obj_0.yes, _obj_0[1] + end + local a, b, c, d + do + local _obj_0 = yeah + a, b, c, d = _obj_0.a, _obj_0.b, _obj_0.c, _obj_0.d + end + local _ = two + a = one[1] + c = nil + b = one[1] + local e = two + d = one[1] + local x = one + local y = two[1] + local xx, yy = 1, 2 + do + local _obj_0 = { + xx, + yy + } + yy, xx = _obj_0[1], _obj_0[2] + end + local f, g + do + local _obj_0 = tbl + a, b, c, d, e, f, g = _obj_0[1], _obj_0.b, _obj_0[2], _obj_0.d, _obj_0[3], _obj_0.f, _obj_0[4] + end + do + c = nil + do + local _obj_0 = tbl + a, b = _obj_0.a, _obj_0.b + end + end + do + a = tbl + b, c = _.b, _.c + end + do + b = _ + a = tbl.a + c = _.c + end +end +do + local futurists = { + sculptor = "Umberto Boccioni", + painter = "Vladimir Burliuk", + poet = { + name = "F.T. Marinetti", + address = { + "Via Roma 42R", + "Bellagio, Italy 22021" + } + } + } + do + local name, street, city = futurists.poet.name, futurists.poet.address[1], futurists.poet.address[2] + end + do + local sculptor, painter, name, street, city = futurists.sculptor, futurists.painter, futurists.poet.name, futurists.poet.address[1], futurists.poet.address[2] + end +end +do + local c, e + do + local _obj_0 = tb + c, e = _obj_0.a.b, _obj_0.a.d + end +end +do + local c, e, f + do + local _obj_0 = tb + c, e, f = _obj_0.a[1].b, _obj_0.a[2].d, _obj_0.a[3] + end +end +do + self.world = x[1] + do + local _obj_0 = x + a.b, c.y, func().z = _obj_0[1], _obj_0[2], _obj_0[3] + end + self.world = x.world +end +do + local thing = { + { + 1, + 2 + }, + { + 3, + 4 + } + } + for _index_0 = 1, #thing do + local _des_0 = thing[_index_0] + local x, y = _des_0[1], _des_0[2] + print(x, y) + end +end +do + do + local _with_0 = thing + local a, b = _with_0[1], _with_0[2] + print(a, b) + end +end +do + local thing = nil + if thing then + local a = thing[1] + print(a) + else + print("nothing") + end + local thang = { + 1, + 2 + } + if thang then + local a, b = thang[1], thang[2] + print(a, b) + end + if thing then + local a, b = thing[1], thing[2] + print(a, b) + else + if thang then + local c, d = thang[1], thang[2] + print(c, d) + else + print("NO") + end + end +end +do + local z = "yeah" + local a, b, c = z[1], z[2], z[3] +end +do + local a, b, c + do + local _obj_0 = z + a, b, c = _obj_0[1], _obj_0[2], _obj_0[3] + end +end +local _ +_ = function(z) + local a, b, c = z[1], z[2], z[3] +end +do + local z = "oo" + _ = function(k) + local a, b, c = z[1], z[2], z[3] + end +end +do + local endVar = thing["function"]["end"] +end +do + local a, b, c + do + local _obj_0 = thing + a, b, c = _obj_0["if"][1], _obj_0["if"][2], _obj_0["if"][3] + end +end +do + local a, b + if true then + do + local _obj_0 = { + a = "Hello", + b = "World" + } + a, b = _obj_0.a, _obj_0.b + end + end + local days, hours, mins, secs + do + local _accum_0 = { } + local _len_0 = 1 + local _list_0 = { + string.match("1 2 3 4", "(.+)%s(.+)%s(.+)%s(.+)") + } + for _index_0 = 1, #_list_0 do + local a = _list_0[_index_0] + _accum_0[_len_0] = tonumber(a) + _len_0 = _len_0 + 1 + end + days, hours, mins, secs = _accum_0[1], _accum_0[2], _accum_0[3], _accum_0[4] + end + local one, two, three + do + local _tbl_0 = { } + for w in foo:gmatch("%S+") do + _tbl_0[w] = true + end + one, two, three = _tbl_0.one, _tbl_0.two, _tbl_0.three + end + b = 123 + a = (a["if"](a, 123) + t).a +end +do + local name, job + do + local _obj_0 = person + name, job = _obj_0.name, _obj_0.job + end + if name == nil then + name = "nameless" + end + if job == nil then + job = "jobless" + end + local request + request = function(url, options) + if options == nil then + options = { } + end + local method, headers, parameters, payload, ok, err, final = options.method, options.headers, options.parameters, options.payload, options.ok, options.err, options.final + if method == nil then + method = "GET" + end + if headers == nil then + headers = { } + end + if parameters == nil then + parameters = { } + end + if payload == nil then + payload = "" + end + local res = makeRequest(url, method, parameters, payload, ok, err, final) + return res + end + local value1, key3 + do + local _obj_0 = tb + value1, key3 = _obj_0.key1.key2, _obj_0.key3 + end + if value1 == nil then + value1 = 123 + end + if key3 == nil then + key3 = "abc" + end + local mt, call, add + do + local _obj_0 = getmetatable(tb) + mt, call, add = _obj_0, getmetatable(_obj_0).__call, getmetatable(_obj_0).__add + end + if mt == nil then + mt = { + __index = { + abc = 123 + } + } + end + if call == nil then + call = (function() + return { } + end) + end + local _obj_0 = tb + local mtx, y, zItem = getmetatable(_obj_0.x), _obj_0.y, _obj_0.z + if mtx == nil then + mtx = { } + end + local index = getmetatable(_obj_0).__index + if index == nil then + index = function() + return nil + end + end + local _obj_1 = getmetatable(tb).func + if _obj_1 == nil then + if item ~= nil then + _obj_1 = item.defVal + end + end + a.b(function() + return 123 + end).c = _obj_1 +end +do + local mt, subFunc + do + local _obj_0 = getmetatable(tb.x) + mt, subFunc = _obj_0, _obj_0.__sub + end + if mt == nil then + mt = { } + end +end +do + local mt, subFunc + do + local _obj_0 = tb + mt, subFunc = getmetatable(_obj_0.x), getmetatable(_obj_0.x).__sub + end + if mt == nil then + mt = { } + end +end +do + local a, b, _obj_0 + do + local _obj_1 = tb + a, b, _obj_0 = _obj_1[1], _obj_1[2], _obj_1.c[1] + end + if a == nil then + a = 1 + end + if b == nil then + b = 2 + end + if _obj_0 == nil then + _obj_0 = 3 + end + d.e = _obj_0 + local _list_0 = tuples + for _index_0 = 1, #_list_0 do + local _des_0 = _list_0[_index_0] + local left, right = _des_0[1], _des_0[2] + if left == nil then + left = "null" + end + if right == nil then + right = false + end + print(left, right) + end +end diff --git a/spec/outputs/do.lua b/spec/outputs/do.lua new file mode 100644 index 0000000..96d1022 --- /dev/null +++ b/spec/outputs/do.lua @@ -0,0 +1,48 @@ +do + print("hello") + print("world") +end +local x +do + print("hello") + x = print("world") +end +local y +do + local things = "shhh" + y = function() + return "hello: " .. things + end +end +local _ +_ = function() + if something then + do + return "yeah" + end + end +end +local t = { + y = (function() + local number = 100 + return function(x) + return x + number + end + end)() +} +return function(y, k) + if y == nil then + y = ((function() + x = 10 + 2 + return x + end)()) + end + if k == nil then + do + k = "nothing" + end + end + do + return "uhhh" + end +end diff --git a/spec/outputs/existential.lua b/spec/outputs/existential.lua new file mode 100644 index 0000000..4a64c49 --- /dev/null +++ b/spec/outputs/existential.lua @@ -0,0 +1,156 @@ +if f1 ~= nil then + f1() +end +if f2 ~= nil then + f2("arg0", 123) +end +local x +if tab ~= nil then + x = tab.value +end +print((function() + if abc ~= nil then + local _obj_0 = abc["hello world"] + if _obj_0 ~= nil then + return _obj_0.xyz + end + return nil + end + return nil +end)()) +if print and (x ~= nil) then + print(x) +end +if self ~= nil then + self:func(998) +end +do + local _with_0 + if abc ~= nil then + local _obj_0 = abc() + local _obj_1 = _obj_0.func + if _obj_1 ~= nil then + _with_0 = _obj_1(_obj_0) + end + end + if (function() + local _obj_0 = _with_0.p + if _obj_0 ~= nil then + return _obj_0(_with_0, "abc") + end + return nil + end)() then + return 123 + end +end +do + local _des_0 + if a ~= nil then + local _obj_0 = a["if"] + if _obj_0 ~= nil then + local _obj_1 = _obj_0["then"] + if _obj_1 ~= nil then + local _obj_2 = _obj_1(_obj_0, 123) + if _obj_2 ~= nil then + _des_0 = _obj_2((function() + if self ~= nil then + return self["function"](self, 998) + end + return nil + end)()) + end + end + end + end + if _des_0 then + x = _des_0.x + print(x) + end +end +local res = ((function() + local _call_0 = b["function"] + local _obj_0 = _call_0["do"](_call_0) + local _obj_1 = _obj_0["while"] + if _obj_1 ~= nil then + local _call_1 = _obj_1(_obj_0, "OK") + local _base_0 = _call_1["if"](_call_1, "def", 998) + local _fn_0 = _base_0.f + return _fn_0 and function(...) + return _fn_0(_base_0, ...) + end + end + return nil +end)() ~= nil) +print(res) +local solipsism +if (mind ~= nil) and not (world ~= nil) then + solipsism = true +end +local speed = 0 +speed = speed or 15 +local footprints = yeti or "bear" +local major = 'Computer Science' +if not (major ~= nil) then + signUpForClass('Introduction to Wines') +end +if (window ~= nil) then + local environment = 'browser (probably)' +end +local zip +local _obj_0 = lottery.drawWinner +if _obj_0 ~= nil then + local _obj_1 = _obj_0().address + if _obj_1 ~= nil then + zip = _obj_1.zipcode + end +end +local len = (function() + if utf8 ~= nil then + return utf8.len + end + return nil +end)() or (function() + if string ~= nil then + return string.len + end + return nil +end)() or function(o) + return #o +end +local a +if tb1 ~= nil then + local _obj_1 = tb1["end"] + if _obj_1 ~= nil then + a = _obj_1(tb1, 123 + (function() + if tb2 ~= nil then + return tb2["then"](tb2, 456) + end + return nil + end)()) + end +end +local b = ((function() + if tb1 ~= nil then + local _base_0 = tb1 + local _fn_0 = _base_0["end"] + return _fn_0 and function(...) + return _fn_0(_base_0, ...) + end + end + return nil +end)() ~= nil) or (function() + if tb2 ~= nil then + local _base_0 = tb2 + local _fn_0 = _base_0["then"] + return _fn_0 and function(...) + return _fn_0(_base_0, ...) + end + end + return nil +end)() +local _with_0 = io.open("test.txt", "w") +if _with_0 ~= nil then + _with_0:write("hello") + _with_0:close() +end +return _with_0 diff --git a/spec/outputs/export.lua b/spec/outputs/export.lua new file mode 100644 index 0000000..02546ec --- /dev/null +++ b/spec/outputs/export.lua @@ -0,0 +1,307 @@ +local _module_0 = { } +local a, b, c = 223, 343, 123 +_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c +local cool = "dad" +_module_0["cool"] = cool +local d, e, f = 3, 2, 1 +_module_0[#_module_0 + 1] = d +_module_0[#_module_0 + 1] = e +_module_0[#_module_0 + 1] = f +local Something +do + local _class_0 + local _base_0 = { + umm = "cool" + } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "Something" + }, { + __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 + Something = _class_0 +end +_module_0["Something"] = Something +if this then + _module_0[#_module_0 + 1] = 232 +else + _module_0[#_module_0 + 1] = 4343 +end +local What +if this then + What = 232 +else + What = 4343 +end +_module_0["What"] = What +local y +y = function() + local hallo = 3434 +end +_module_0["y"] = y +do + local _with_0 = tmp + local j = 2000 + _module_0[#_module_0 + 1] = _with_0 +end +local cbVal +do + local h = 100 + cbVal = f(function(x) + return x(h) + end) +end +_module_0["cbVal"] = cbVal +y = function() + local h = 100 + local k = 100 +end +_module_0["y"] = y +local _exp_0 = h +if 100 == _exp_0 or 150 == _exp_0 then + _module_0[#_module_0 + 1] = 200 +elseif 200 == _exp_0 then + _module_0[#_module_0 + 1] = 300 +else + _module_0[#_module_0 + 1] = 0 +end +local Constant +local _exp_1 = value +if "good" == _exp_1 then + Constant = 1 +elseif "better" == _exp_1 then + Constant = 2 +elseif "best" == _exp_1 then + Constant = 3 +end +_module_0["Constant"] = Constant +local item = func(123) +_module_0["item"] = item +_module_0[#_module_0 + 1] = x +f((function() + if a then + return b + end +end)()) +f((function() + return 123 +end)()) +f((function() + if b == a then + return c + end +end)()) +f((function() + local _accum_0 = { } + local _len_0 = 1 + for i = 1, 10 do + _accum_0[_len_0] = i + _len_0 = _len_0 + 1 + end + return _accum_0 +end)()) +f((function() + local _accum_0 = { } + local _len_0 = 1 + for i = 1, 10 do + _accum_0[_len_0] = i + _len_0 = _len_0 + 1 + end + return _accum_0 +end)()) +f((function() + local _tbl_0 = { } + for k, v in pairs(tb) do + _tbl_0[k] = v + end + return _tbl_0 +end)()) +f((function() + local _accum_0 = { } + local _len_0 = 1 + for k, v in pairs(tb) do + _accum_0[_len_0] = k, v + _len_0 = _len_0 + 1 + end + return _accum_0 +end)()) +f((function() + local _accum_0 = { } + local _len_0 = 1 + while a do + _accum_0[_len_0] = true + _len_0 = _len_0 + 1 + end + return _accum_0 +end)()) +f((function() + a.b = 123 + return a +end)()) +f((function() + if a ~= nil then + return a.b + end + return nil +end)()) +f((function() + local _base_0 = a + local _fn_0 = _base_0.b + return _fn_0 and function(...) + return _fn_0(_base_0, ...) + end +end)()) +f((function() + local A + do + local _class_0 + local _base_0 = { } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "A" + }, { + __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 + A = _class_0 + return _class_0 + end +end)()) +local _ = tostring((function() + if a then + return b + end +end)()) +_ = tostring((function() + return 123 +end)()) +_ = tostring((function() + if b == a then + return c + end +end)()) +_ = tostring((function() + local _accum_0 = { } + local _len_0 = 1 + for i = 1, 10 do + _accum_0[_len_0] = i + _len_0 = _len_0 + 1 + end + return _accum_0 +end)()) +_ = tostring((function() + local _accum_0 = { } + local _len_0 = 1 + for i = 1, 10 do + _accum_0[_len_0] = i + _len_0 = _len_0 + 1 + end + return _accum_0 +end)()) +_ = tostring((function() + local _tbl_0 = { } + for k, v in pairs(tb) do + _tbl_0[k] = v + end + return _tbl_0 +end)()) +_ = tostring((function() + local _accum_0 = { } + local _len_0 = 1 + for k, v in pairs(tb) do + _accum_0[_len_0] = k, v + _len_0 = _len_0 + 1 + end + return _accum_0 +end)()) +_ = tostring((function() + local _accum_0 = { } + local _len_0 = 1 + while a do + _accum_0[_len_0] = true + _len_0 = _len_0 + 1 + end + return _accum_0 +end)()) +_ = tostring((function() + a.b = 123 + return a +end)()) +_ = tostring((function() + if a ~= nil then + return a.b + end + return nil +end)()) +_ = tostring((function() + local _base_0 = a + local _fn_0 = _base_0.b + return _fn_0 and function(...) + return _fn_0(_base_0, ...) + end +end)()) +_ = tostring((function() + local A + do + local _class_0 + local _base_0 = { } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "A" + }, { + __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 + A = _class_0 + return _class_0 + end +end)()) +local v1, v2, v3, v4, v5 +v1 = 1 +v2 = 2 +_module_0["v2"] = v2 +do + local _class_0 + local _base_0 = { } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "v4" + }, { + __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 + v4 = _class_0 + v3 = _class_0 +end +_module_0["v3"] = v3 +v5 = 5 +return _module_0 diff --git a/spec/outputs/export_default.lua b/spec/outputs/export_default.lua new file mode 100644 index 0000000..a9c787f --- /dev/null +++ b/spec/outputs/export_default.lua @@ -0,0 +1,19 @@ +local _module_0 = nil +print("OK") +_module_0 = function() + print("hello") + return 123 +end +if not isOff then + f(123, "abc", function(x, fy) + print(x) + return fy(function(y, res) + if res then + return abc + y + else + return abc + end + end) + end) +end +return _module_0 diff --git a/spec/outputs/funcs.lua b/spec/outputs/funcs.lua new file mode 100644 index 0000000..03281e4 --- /dev/null +++ b/spec/outputs/funcs.lua @@ -0,0 +1,222 @@ +local x +x = function() + return print(what) +end +local _ +_ = function() end +_ = function() + return function() + return function() end + end +end +go(to(the(barn))) +open(function() + return the(function() + return door + end) +end) +open(function() + the(door) + local hello + hello = function() + return my(func) + end +end) +local h +h = function() + return hi +end +eat(function() end, world); +(function() end)() +x = function(...) end +hello() +hello.world() +_ = hello().something +_ = what()["ofefe"] +what()(the()(heck())) +_ = function(a, b, c, d, e) end +_ = function(a, a, a, a, a) + return print(a) +end +_ = function(x) + if x == nil then + x = 23023 + end +end +_ = function(x) + if x == nil then + x = function(y) + if y == nil then + y = function() end + end + end + end +end +_ = function(x) + if x == nil then + if something then + x = yeah + else + x = no + end + end +end +local something +something = function(hello, world) + if hello == nil then + hello = 100 + end + if world == nil then + world = function(x) + if x == nil then + x = [[yeah cool]] + end + return print("eat rice") + end + end + return print(hello) +end +_ = function(self) end +_ = function(self, x, y) end +_ = function(self, x, y) + self.x = x + self.y = y +end +_ = function(self, x) + if x == nil then + x = 1 + end +end +_ = function(self, x, y, z) + if x == nil then + x = 1 + end + if z == nil then + z = "hello world" + end + self.x = x + self.z = z +end +x(function() + return +end) +y(function() + return 1 +end) +z(function() + return 1, "hello", "world" +end) +k(function() + if yes then + return + else + return + end +end) +_ = function() + if something then + return real_name + end +end +d(function() + return print("hello world") +end, 10) +d(1, 2, 3, 4, 5, 6, (function() + if something then + print("okay") + return 10 + end +end)(), 10, 20) +f()()(what)(function() + return print("srue") +end, 123) +x = function(a, b) + return print("what") +end +local y +y = function(a, b) + if a == nil then + a = "hi" + end + if b == nil then + b = 23 + end + return print("what") +end +local z +z = function(a, b) + if a == nil then + a = "hi" + end + if b == nil then + b = 23 + end + return print("what") +end +local j +j = function(f, g, m, a, b) + if a == nil then + a = "hi" + end + if b == nil then + b = 23 + end + return print("what") +end +y = function(a, b, ...) + if a == nil then + a = "hi" + end + if b == nil then + b = 23 + end + return print("what") +end +y = function(a, b, ...) + if a == nil then + a = "hi" + end + if b == nil then + b = 23 + end + return print("what") +end +local args +args = function(a, b) + return print("what") +end +args = function(a, b) + if a == nil then + a = "hi" + end + if b == nil then + b = 23 + end + return print("what") +end +args = function(a, b) + if a == nil then + a = "hi" + end + if b == nil then + b = 23 + end + return print("what") +end +args = function(f, g, m, a, b) + if a == nil then + a = "hi" + end + if b == nil then + b = 23 + end + return print("what") +end +local self +self = function(n) + if n == 0 then + return 1 + end + return n * self(n - 1) +end +return nil diff --git a/spec/outputs/global.lua b/spec/outputs/global.lua new file mode 100644 index 0000000..1c9a3cf --- /dev/null +++ b/spec/outputs/global.lua @@ -0,0 +1,89 @@ +do + a, b, c = 223, 343 + cool = "dad" +end +do + do + local _class_0 + local _base_0 = { + umm = "cool" + } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "Something" + }, { + __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 + Something = _class_0 + end +end +do + local d + a, b, c, d = "hello" +end +do + local What + if this then + What = 232 + else + What = 4343 + end + local another = 3434 + Another = 7890 + if inner then + local Yeah = "10000" + end + if this then + What = 232 + else + What = 4343 + end +end +do + if this then + What = 232 + else + What = 4343 + end + x, y, z = 1, 2, 3 + y = function() + local hallo = 3434 + end + do + local _with_0 = tmp + local j = 2000 + end +end +do + x = 3434 + if y then + x = 10 + end +end +do + if y then + local x = 10 + end + x = 3434 +end +do + do + k = 1212 + do + local h = 100 + end + y = function() + local h = 100 + k = 100 + end + end + local h = 100 +end diff --git a/spec/outputs/goto.lua b/spec/outputs/goto.lua new file mode 100644 index 0000000..d1f7b77 --- /dev/null +++ b/spec/outputs/goto.lua @@ -0,0 +1,67 @@ +do + local a = 0 + ::start:: + a = a + 1 + if a == 5 then + goto done + end + goto start + ::done:: +end +do + for z = 1, 10 do + for y = 1, 10 do + for x = 1, 10 do + if x ^ 2 + y ^ 2 == z ^ 2 then + print('found a Pythagorean triple:', x, y, z) + goto done + end + end + end + end + ::done:: +end +do + for z = 1, 10 do + for y = 1, 10 do + for x = 1, 10 do + if x ^ 2 + y ^ 2 == z ^ 2 then + print('found a Pythagorean triple:', x, y, z) + print('now trying next z...') + goto zcontinue + end + end + end + ::zcontinue:: + end +end +do + ::redo:: + for x = 1, 10 do + for y = 1, 10 do + if not f(x, y) then + goto continue + end + if not g(x, y) then + goto skip + end + if not h(x, y) then + goto redo + end + ::continue:: + end + end + ::skip:: +end +do + local _list_0 = t + for _index_0 = 1, #_list_0 do + local x = _list_0[_index_0] + if x % 2 == 0 then + print('list has even number') + goto has + end + end + print('list lacks even number') + ::has:: +end diff --git a/spec/outputs/import.lua b/spec/outputs/import.lua new file mode 100644 index 0000000..02e210b --- /dev/null +++ b/spec/outputs/import.lua @@ -0,0 +1,92 @@ +local hello = yeah.hello +local world +do + local _obj_0 = table["cool"] + hello, world = _obj_0.hello, _obj_0.world +end +local a, b, c = items.a, (function() + local _base_0 = items + local _fn_0 = _base_0.b + return _fn_0 and function(...) + return _fn_0(_base_0, ...) + end +end)(), items.c +local master, ghost +do + local _obj_0 = find("mytable") + master, ghost = _obj_0.master, (function() + local _base_0 = _obj_0 + local _fn_0 = _base_0.ghost + return _fn_0 and function(...) + return _fn_0(_base_0, ...) + end + end)() +end +local yumm +a, yumm = 3434, "hello" +local _table_0 = 232 +local something +do + local _obj_0 = a(table) + something = _obj_0.something +end +if indent then + local okay, well + do + local _obj_0 = tables[100] + okay, well = _obj_0.okay, (function() + local _base_0 = _obj_0 + local _fn_0 = _base_0.well + return _fn_0 and function(...) + return _fn_0(_base_0, ...) + end + end)() + end +end +do + a, b, c = z.a, z.b, z.c +end +do + a, b, c = z.a, z.b, z.c +end +do + a, b, c = z.a, z.b, z.c +end +do + a, b, c = z.a, z.b, z.c +end +do + a, b, c = z.a, z.b, z.c +end +do + local module = require('module') + local module_x = require('module_x') + local d_a_s_h_e_s = require("d-a-s-h-e-s") + local part = require("module.part") +end +do + local Player = require("player") + local C, Ct, Cmt + do + local _obj_0 = require("lpeg") + C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt + end + local one, two, ch + do + local _obj_0 = require("export") + one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] + end + local Another = require("export").Another +end +do + module = require('module') + module_x = require('module_x') + module_y = require("org.package.module-y") +end +do + local func, ifVar + do + local _obj_0 = require("org.package.module") + func, ifVar = _obj_0["function"], _obj_0["if"] + end +end diff --git a/spec/outputs/lists.lua b/spec/outputs/lists.lua new file mode 100644 index 0000000..581cc23 --- /dev/null +++ b/spec/outputs/lists.lua @@ -0,0 +1,282 @@ +local hi +do + local _accum_0 = { } + local _len_0 = 1 + for _, x in ipairs({ + 1, + 2, + 3, + 4 + }) do + _accum_0[_len_0] = x * 2 + _len_0 = _len_0 + 1 + end + hi = _accum_0 +end +local items = { + 1, + 2, + 3, + 4, + 5, + 6 +} +local _ +do + local _accum_0 = { } + local _len_0 = 1 + for z in ipairs(items) do + if z > 4 then + _accum_0[_len_0] = z + _len_0 = _len_0 + 1 + end + end + _ = _accum_0 +end +local rad +do + local _accum_0 = { } + local _len_0 = 1 + for a in ipairs({ + 1, + 2, + 3, + 4, + 5, + 6 + }) do + if good_number(a) then + _accum_0[_len_0] = { + a + } + _len_0 = _len_0 + 1 + end + end + rad = _accum_0 +end +do + local _accum_0 = { } + local _len_0 = 1 + for z in items do + for j in list do + if z > 4 then + _accum_0[_len_0] = z + _len_0 = _len_0 + 1 + end + end + end + _ = _accum_0 +end +require("util") +local dump +dump = function(x) + return print(util.dump(x)) +end +local range +range = function(count) + local i = 0 + return coroutine.wrap(function() + while i < count do + coroutine.yield(i) + i = i + 1 + end + end) +end +dump((function() + local _accum_0 = { } + local _len_0 = 1 + for x in range(10) do + _accum_0[_len_0] = x + _len_0 = _len_0 + 1 + end + return _accum_0 +end)()) +dump((function() + local _accum_0 = { } + local _len_0 = 1 + for x in range(5) do + if x > 2 then + for y in range(5) do + _accum_0[_len_0] = { + x, + y + } + _len_0 = _len_0 + 1 + end + end + end + return _accum_0 +end)()) +local things +do + local _accum_0 = { } + local _len_0 = 1 + for x in range(10) do + if x > 5 then + for y in range(10) do + if y > 7 then + _accum_0[_len_0] = x + y + _len_0 = _len_0 + 1 + end + end + end + end + things = _accum_0 +end +for x in ipairs({ + 1, + 2, + 4 +}) do + for y in ipairs({ + 1, + 2, + 3 + }) do + if x ~= 2 then + print(x, y) + end + end +end +for x in items do + print("hello", x) +end +do + local _accum_0 = { } + local _len_0 = 1 + for x in x do + _accum_0[_len_0] = x + _len_0 = _len_0 + 1 + end + _ = _accum_0 +end +local x +do + local _accum_0 = { } + local _len_0 = 1 + for x in x do + _accum_0[_len_0] = x + _len_0 = _len_0 + 1 + end + x = _accum_0 +end +for x in ipairs({ + 1, + 2, + 4 +}) do + for y in ipairs({ + 1, + 2, + 3 + }) do + if x ~= 2 then + print(x, y) + end + end +end +local double +do + local _accum_0 = { } + local _len_0 = 1 + for _index_0 = 1, #items do + local x = items[_index_0] + _accum_0[_len_0] = x * 2 + _len_0 = _len_0 + 1 + end + double = _accum_0 +end +for _index_0 = 1, #double do + local x = double[_index_0] + print(x) +end +local cut +do + local _accum_0 = { } + local _len_0 = 1 + for _index_0 = 1, #items do + local x = items[_index_0] + if x > 3 then + _accum_0[_len_0] = x + _len_0 = _len_0 + 1 + end + end + cut = _accum_0 +end +local hello +do + local _accum_0 = { } + local _len_0 = 1 + for _index_0 = 1, #items do + local x = items[_index_0] + for _index_1 = 1, #items do + local y = items[_index_1] + _accum_0[_len_0] = x + y + _len_0 = _len_0 + 1 + end + end + hello = _accum_0 +end +for _index_0 = 1, #hello do + local z = hello[_index_0] + print(z) +end +x = { + 1, + 2, + 3, + 4, + 5, + 6, + 7 +} +local _max_0 = -5 +for _index_0 = 2, _max_0 < 0 and #x + _max_0 or _max_0, 2 do + local y = x[_index_0] + print(y) +end +local _max_1 = 3 +for _index_0 = 1, _max_1 < 0 and #x + _max_1 or _max_1 do + local y = x[_index_0] + print(y) +end +for _index_0 = 2, #x do + local y = x[_index_0] + print(y) +end +for _index_0 = 1, #x, 2 do + local y = x[_index_0] + print(y) +end +for _index_0 = 2, #x, 2 do + local y = x[_index_0] + print(y) +end +local a, b, c = 1, 5, 2 +local _max_2 = b +for _index_0 = a, _max_2 < 0 and #x + _max_2 or _max_2, c do + local y = x[_index_0] + print(y) +end +local normal +normal = function(hello) + local _accum_0 = { } + local _len_0 = 1 + for x in yeah do + _accum_0[_len_0] = x + _len_0 = _len_0 + 1 + end + return _accum_0 +end +local test = x(1, 2, 3, 4, 5) +for _index_0 = 1, #test do + local thing = test[_index_0] + print(thing) +end +return function() + local _list_0 = rows + for _index_0 = 1, #_list_0 do + local row = _list_0[_index_0] + a = b + end +end diff --git a/spec/outputs/literals.lua b/spec/outputs/literals.lua new file mode 100644 index 0000000..1ffadc8 --- /dev/null +++ b/spec/outputs/literals.lua @@ -0,0 +1,28 @@ +local _ = { + 121, + 121.2323, + 121.2323e-1, + 121.2323e13434, + 2323E34, + 0x12323, + 0xfF2323, + 0xabcdef, + 0xABCDEF, + .2323, + .2323e-1, + .2323e13434, + 1LL, + 1ULL, + 9332LL, + 9332, + 0x2aLL, + 0x2aULL, + [[ hello world ]], + [=[ hello world ]=], + [====[ hello world ]====], + "another world", + 'what world', + "\n hello world\n ", + 'yeah\n what is going on\n here is something cool' +} +return nil diff --git a/spec/outputs/local.lua b/spec/outputs/local.lua new file mode 100644 index 0000000..288764a --- /dev/null +++ b/spec/outputs/local.lua @@ -0,0 +1,151 @@ +do + local a + local a, b, c + local g + b, g = 23232 +end +do + local x = 1212 + local something + something = function() + local x + x = 1212 + end +end +do + local y, z + y = 2323 + z = 2323 +end +do + print("Nothing Here!") +end +do + local X, Y + local x = 3434 + local y = 3434 + X = 3434 + Y = "yeah" +end +do + local x, y = "a", "b" +end +do + local x, y + x, y = "a", "b" +end +do + if something then + local x = 2323 + end +end +do + local x + do + x = "one" + end + x = 100 + do + x = "two" + end +end +do + local k, x, a, b, c + if what then + k = 10 + end + x = 100 + do + local _obj_0 = y + a, b, c = _obj_0.a, _obj_0.b, _obj_0.c + end +end +do + local a, b, c, d + a = 100 + print("hi") + b = 200 + c = 100 + print("hi") + d = 200 + d = 2323 +end +do + local Uppercase, One, Two + local lowercase = 5 + Uppercase = 3 + do + local _class_0 + local Five + local _base_0 = { } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "One" + }, { + __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 + local self = _class_0; + Five = 6 + One = _class_0 + end + do + local _class_0 + local No + local _base_0 = { } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "Two" + }, { + __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 + local self = _class_0; + do + local _class_1 + local _base_1 = { } + _base_1.__index = _base_1 + _class_1 = setmetatable({ + __init = function() end, + __base = _base_1, + __name = "No" + }, { + __index = _base_1, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_1) + cls.__init(_self_0, ...) + return _self_0 + end + }) + _base_1.__class = _class_1 + No = _class_1 + end + Two = _class_0 + end +end +do + local _list_0 = { } + for _index_0 = 1, #_list_0 do + local a = _list_0[_index_0] + local _ = a + end +end +do + local x + x = a or b +end +local g = 2323 diff --git a/spec/outputs/loops.lua b/spec/outputs/loops.lua new file mode 100644 index 0000000..a905e4e --- /dev/null +++ b/spec/outputs/loops.lua @@ -0,0 +1,352 @@ +for x = 1, 10 do + print("yeah") +end +for x = 1, #something do + print("yeah") +end +for y = 100, 60, -3 do + print("count down", y) +end +for a = 1, 10 do + print("okay") +end +for a = 1, 10 do + for b = 2, 43 do + print(a, b) + end +end +for i in iter do + for j in yeah do + local x = 343 + i + j + print(i, j) + end +end +local _list_0 = something +for _index_0 = 1, #_list_0 do + local x = _list_0[_index_0] + print(x) +end +for k, v in pairs(hello) do + print(k, v) +end +for x in y, z do + print(x) +end +for x in y, z, k do + print(x) +end +local _list_1 = modules +for _index_0 = 1, #_list_1 do + local name, members = _list_1[_index_0] + print(name, member) +end +local x +x = function() + for x in y do + local _ = y + end +end +local hello = { + 1, + 2, + 3, + 4, + 5 +} +do + local _accum_0 = { } + local _len_0 = 1 + for _index_0 = 1, #hello do + local y = hello[_index_0] + if y % 2 == 0 then + _accum_0[_len_0] = y + end + _len_0 = _len_0 + 1 + end + x = _accum_0 +end +x = function() + for _index_0 = 1, #hello do + local x = hello[_index_0] + local _ = y + end +end +local t +do + local _accum_0 = { } + local _len_0 = 1 + for i = 10, 20 do + _accum_0[_len_0] = i * 2 + _len_0 = _len_0 + 1 + end + t = _accum_0 +end +local hmm = 0 +local y +do + local _accum_0 = { } + local _len_0 = 1 + for j = 3, 30, 8 do + hmm = hmm + 1 + _accum_0[_len_0] = j * hmm + _len_0 = _len_0 + 1 + end + y = _accum_0 +end +local _ +_ = function() + for k = 10, 40 do + _ = "okay" + end +end +_ = function() + local _accum_0 = { } + local _len_0 = 1 + for k = 10, 40 do + _accum_0[_len_0] = "okay" + _len_0 = _len_0 + 1 + end + return _accum_0 +end +while true do + print("name") +end +while 5 + 5 do + print("okay world") + working(man) +end +while also do + i(work(too)) + _ = "okay" +end +local i = 0 +do + local _accum_0 = { } + local _len_0 = 1 + while i < 10 do + i = i + 1 + _len_0 = _len_0 + 1 + end + x = _accum_0 +end +do + local _accum_0 = { } + local _len_0 = 1 + local _list_2 = 3 + for _index_0 = 1, #_list_2 do + local thing = _list_2[_index_0] + y = "hello" + _len_0 = _len_0 + 1 + end + x = _accum_0 +end +do + local _accum_0 = { } + local _len_0 = 1 + for x = 1, 2 do + y = "hello" + _len_0 = _len_0 + 1 + end + x = _accum_0 +end +while true do + local _continue_0 = false + repeat + if false then + _continue_0 = true + break + end + print("yes") + if true then + break + end + print("no") + _continue_0 = true + until true + if not _continue_0 then + break + end +end +for i = 1, 10 do + while true do + local _continue_0 = false + repeat + if not true then + _continue_0 = true + break + end + break + _continue_0 = true + until true + if not _continue_0 then + break + end + end +end +local a = 1 +repeat + local _continue_0 = false + repeat + a = a + 1 + if a == 5 then + _continue_0 = true + break + end + if a == 6 then + break + end + print(a) + _continue_0 = true + until true + if not _continue_0 then + break + end +until a == 10 +a = 3 +while not (a == 0) do + a = a - 1 +end +local done = false +while not done do + done = true +end +repeat + print("hello") +until true +while not done do + x = 10 + repeat + x = x - 1 + until x == 0 +end +while not cond do + print("okay") +end +for x = 1, 10 do + local _continue_0 = false + repeat + if x > 3 and x < 7 then + _continue_0 = true + break + end + print(x) + _continue_0 = true + until true + if not _continue_0 then + break + end +end +local list +do + local _accum_0 = { } + local _len_0 = 1 + for x = 1, 10 do + local _continue_0 = false + repeat + if x > 3 and x < 7 then + _continue_0 = true + break + end + _accum_0[_len_0] = x + _len_0 = _len_0 + 1 + _continue_0 = true + until true + if not _continue_0 then + break + end + end + list = _accum_0 +end +local _list_2 = { + 1, + 2, + 3, + 4, + 5, + 6 +} +for _index_0 = 1, #_list_2 do + local a = _list_2[_index_0] + local _continue_0 = false + repeat + if a == 1 then + _continue_0 = true + break + end + if a == 3 then + _continue_0 = true + break + end + print(a) + _continue_0 = true + until true + if not _continue_0 then + break + end +end +for x = 1, 10 do + local _continue_0 = false + repeat + if x % 2 == 0 then + _continue_0 = true + break + end + for y = 2, 12 do + local _continue_1 = false + repeat + if y % 3 == 0 then + _continue_1 = true + break + end + _continue_1 = true + until true + if not _continue_1 then + break + end + end + _continue_0 = true + until true + if not _continue_0 then + break + end +end +while true do + local _continue_0 = false + repeat + if false then + _continue_0 = true + break + end + break + _continue_0 = true + until true + if not _continue_0 then + break + end +end +while true do + local _continue_0 = false + repeat + if false then + _continue_0 = true + break + end + return 22 + _continue_0 = true + until true + if not _continue_0 then + break + end +end +do + local xxx = { + 1, + 2, + 3, + 4 + } + for _index_0 = 1, #xxx do + local thing = xxx[_index_0] + print(thing) + end +end diff --git a/spec/outputs/macro-export.lua b/spec/outputs/macro-export.lua new file mode 100644 index 0000000..b5a63f8 --- /dev/null +++ b/spec/outputs/macro-export.lua @@ -0,0 +1,2 @@ +local _module_0 = { } +return _module_0 diff --git a/spec/outputs/macro-teal.tl b/spec/outputs/macro-teal.tl new file mode 100644 index 0000000..b5a63f8 --- /dev/null +++ b/spec/outputs/macro-teal.tl @@ -0,0 +1,2 @@ +local _module_0 = { } +return _module_0 diff --git a/spec/outputs/macro.lua b/spec/outputs/macro.lua new file mode 100644 index 0000000..a2430a2 --- /dev/null +++ b/spec/outputs/macro.lua @@ -0,0 +1,233 @@ +assert(item == nil); +local v = (item == nil) +if f1() then + print("OK") +end +if (f1() and f2() and f3()) then + print("OK") +end +if (x == "Apple" or x == "Pig" or x == "Dog") then + print("exist") +end +local _list_0 = (function() + local _accum_0 = { } + local _len_0 = 1 + local _list_0 = (function() + local _accum_1 = { } + local _len_1 = 1 + local _list_0 = { + 1, + 2, + 3 + } + for _index_0 = 1, #_list_0 do + local _ = _list_0[_index_0] + _accum_1[_len_1] = _ * 2 + _len_1 = _len_1 + 1 + end + return _accum_1 + end)() + for _index_0 = 1, #_list_0 do + local _ = _list_0[_index_0] + if _ > 4 then + _accum_0[_len_0] = _ + _len_0 = _len_0 + 1 + end + end + return _accum_0 +end)() +for _index_0 = 1, #_list_0 do + local _ = _list_0[_index_0] + print(_) +end +local _list_1 = (function() + local _accum_0 = { } + local _len_0 = 1 + local _list_1 = (function() + local _accum_1 = { } + local _len_1 = 1 + local _list_1 = { + 1, + 2, + 3 + } + for _index_0 = 1, #_list_1 do + local _ = _list_1[_index_0] + _accum_1[_len_1] = _ * 2 + _len_1 = _len_1 + 1 + end + return _accum_1 + end)() + for _index_0 = 1, #_list_1 do + local _ = _list_1[_index_0] + if _ > 4 then + _accum_0[_len_0] = _ + _len_0 = _len_0 + 1 + end + end + return _accum_0 +end)() +for _index_0 = 1, #_list_1 do + local _ = _list_1[_index_0] + print(_) +end +local val +do + local _2 + do + local _accum_0 = { } + local _len_0 = 1 + local _list_2 = { + 1, + 2, + 3 + } + for _index_0 = 1, #_list_2 do + local _ = _list_2[_index_0] + _accum_0[_len_0] = _ * 2 + _len_0 = _len_0 + 1 + end + _2 = _accum_0 + end + local _3 + do + local _accum_0 = { } + local _len_0 = 1 + for _index_0 = 1, #_2 do + local _ = _2[_index_0] + if _ > 4 then + _accum_0[_len_0] = _ + _len_0 = _len_0 + 1 + end + end + _3 = _accum_0 + end + local _4 + if #_3 == 0 then + _4 = 0 + else + local _1 = 0 + for _index_0 = 1, #_3 do + local _2 = _3[_index_0] + _1 = _1 + _2 + end + _4 = _1 + end + val = _4 +end +(1 + 2):call(123) +local res = (1 + 2) +local f +f = function(x) + return function(y) + return function(z) + return print(x, y, z) + end + end +end +do + local a = 8 + do + a = 1 + a = a + 1 + end + a = a + (function() + a = 1 + return a + 1 + end)() + print(a) +end +do + local a = 8 + a = (function() + local a + a = 1 + return a + 1 + end)() + a = a + (function() + local a + a = 1 + return a + 1 + end)() + print(a) +end +local x = 0; +local function f(a) + return a + 1 +end +x = x + f(3); +function tb:func() + print(123) +end +print(x) +local sel +sel = function(a, b, c) + if a then + return b + else + return c + end +end +local function sel(a, b, c) + if a then + return b + else + return c + end +end +local function dummy() + +end +-- a comment here +local _ = require('underscore') +local a = ((((_({ + 1, + 2, + 3, + 4, + -2, + 3 +})):chain()):map(function(self) + return self * 2 +end)):filter(function(self) + return self > 3 +end)):value(); +((((_({ + 1, + 2, + 3, + 4, + -2, + 3 +})):chain()):map(function(self) + return self * 2 +end)):filter(function(self) + return self > 3 +end)):each(function(self) + return print(self) +end) +local result = ((((((origin.transform.root.gameObject:Parents()):Descendants()):SelectEnable()):SelectVisible()):TagEqual("fx")):Where(function(x) + return x.name:EndsWith("(Clone)") +end)):Destroy() +do + local _1 + _1 = origin.transform.root.gameObject:Parents() + local _2 + _2 = _1:Descendants() + local _3 + _3 = _2:SelectEnable() + local _4 + _4 = _3:SelectVisible() + local _5 + _5 = _4:TagEqual("fx") + local _6 + _6 = _5:Where(function(x) + return x.name:EndsWith("(Clone)") + end) + _6:Destroy() +end +origin.transform.root.gameObject:Parents():Descendants():SelectEnable():SelectVisible():TagEqual("fx"):Where(function(x) + return x.name:EndsWith("(Clone)") +end):Destroy() +print('abc') +return 123 diff --git a/spec/outputs/metatable.lua b/spec/outputs/metatable.lua new file mode 100644 index 0000000..16ae86c --- /dev/null +++ b/spec/outputs/metatable.lua @@ -0,0 +1,113 @@ +local a = setmetatable({ + close = true, +}, { + __close = function(self) + return print("out of scope") + end +}) +local b = setmetatable({ }, { + __add = function(left, right) + return right - left + end +}) +local c = setmetatable({ + key1 = true, + key2 = true +}, { + __add = add +}) +local w = setmetatable({ }, { + [name] = 123, + ["new"] = function(self, val) + return { + val + } + end +}) +getmetatable(w)["new"](getmetatable(w)[name]) +local _ = setmetatable({ }, { + __close = function() + return print("out of scope") + end +}) +local d, e = a.close, getmetatable(a).__close +local f = getmetatable(a):__close(1) +getmetatable(a).__add = function(x, y) + return x + y +end +do + local _obj_0 = a + local new = _obj_0.new + local close, closeA + do + local _obj_1 = getmetatable(_obj_0) + close, closeA = _obj_1.__close, _obj_1.__close + end + print(new, close, closeA) +end +do + local x, new, var, close, closeA, num, add, sub + local _obj_0, _obj_1 + x, _obj_0, _obj_1 = 123, a.b.c, func() + new, var = _obj_0.new, _obj_0.var + do + local _obj_2 = getmetatable(_obj_0) + close, closeA = _obj_2.__close, _obj_2.__close + end + num = _obj_1.num + do + local _obj_2 = getmetatable(_obj_1) + add, sub = _obj_2.__add, _obj_2.__sub + end +end +setmetatable(a.b, { }) +x.abc = 123 +setmetatable(func(), mt) +_ = extra +setmetatable(b.c, mt) +a, d, e = 1, "abc" +local is_same = getmetatable(a).__index == getmetatable(a).__index +setmetatable(a, { + __index = tb +}) +getmetatable(a).__index = tb +getmetatable(a).__index = tb +local mt = getmetatable(a) +tb:func(#list) +getmetatable(tb):__func(list) +getmetatable(tb):__func(list) +local index, setFunc +do + local _obj_0 = getmetatable(require("module")) + index, setFunc = _obj_0.__index, _obj_0.__newindex +end +do + local _with_0 = tb + print(getmetatable(_with_0).__add, getmetatable(_with_0.x):__index("key")) + a = getmetatable(getmetatable(getmetatable(_with_0).__index).__add):__new(123) + b = t(#getmetatable(_with_0).__close.test) + c = t(#getmetatable(_with_0).__close(_with_0.test)) +end +mt = getmetatable(a) +a = setmetatable({ }, mt) +a = setmetatable({ }, { + __index = mt +}) +local index +index = getmetatable(a).__index +index = getmetatable(a).__index +do + local ctor, update + do + local _obj_0 = getmetatable(a) + ctor, update = _obj_0.new, _obj_0.update + end +end +do + local ctor, update + do + local _obj_0 = getmetatable(a) + ctor, update = _obj_0.new, _obj_0.update + end +end +return nil diff --git a/spec/outputs/multiline_chain.lua b/spec/outputs/multiline_chain.lua new file mode 100644 index 0000000..fea7bc6 --- /dev/null +++ b/spec/outputs/multiline_chain.lua @@ -0,0 +1,91 @@ +local x = a.b.c.d +x.y = a.b:c() +func(1, arg2.value:get(), arg3.value:get(), { + 1, + ((function() + if x ~= nil then + local _obj_0 = x.y + if _obj_0 ~= nil then + return _obj_0.z + end + return nil + end + return nil + end)() ~= nil), + 3 +}) +local tbb = { + k1 = a:b(123).c(), + k2 = { + w1 = a().b:c() + } +} +local tb +if f2 ~= nil then + tb = f2("abc", f1({ }).a) +end +local f +f = function() + local _accum_0 = { } + local _len_0 = 1 + local _list_0 = vals + for _index_0 = 1, #_list_0 do + local _des_0 = _list_0[_index_0] + local a = _des_0[1] + _accum_0[_len_0] = a.b:c(123) + _len_0 = _len_0 + 1 + end + return _accum_0 +end +local f1 +f1 = function() + return x, a:b(123).c("abc") +end +local result = origin.transform.root.gameObject:Parents():Descendants():SelectEnable():SelectVisible():TagEqual("fx"):Where(function(x) + if x:IsTargeted() then + return false + end + return x.name:EndsWith("(Clone)") +end):Destroy() +origin.transform.root.gameObject:Parents():Descendants():SelectEnable():SelectVisible():TagEqual("fx"):Where(function(x) + return x.name:EndsWith("(Clone)") +end):Destroy() +do + local _with_0 = item + _with_0.itemFieldA = 123 + _with_0:callMethod():chainCall() + _with_0:callMethod():chainCall() + _with_0:chainCall() + local _exp_0 = _with_0.itemFieldB:getValue() + if "Valid" == _exp_0 or _with_0:getItemState() == _exp_0 then + _with_0:itemMethodA():getValue() + else + _with_0:itemMethodB():getValue() + end + local a + if _with_0.itemFieldC then + a = _with_0.itemFieldD + else + a = _with_0.itemFieldE + end + local _list_0 = values + for _index_0 = 1, #_list_0 do + local v = _list_0[_index_0] + _with_0:itemMethodC(v) + end + for i = 1, counter do + _with_0:itemMethodC(i) + end + if not _with_0.b then + do + local _accum_0 = { } + local _len_0 = 1 + while _with_0.itemFieldD do + _accum_0[_len_0] = _with_0:itemNext():get() + _len_0 = _len_0 + 1 + end + _with_0.c = _accum_0 + end + end +end +return nil diff --git a/spec/outputs/operators.lua b/spec/outputs/operators.lua new file mode 100644 index 0000000..d782f5c --- /dev/null +++ b/spec/outputs/operators.lua @@ -0,0 +1,29 @@ +local x = 1 + 3 +local y = 1 + 3 +local z = 1 + 3 + 4 +local k = b and c and g +local h = thing and function() + return print("hello world") +end +local i = thing or function() + return print("hello world") +end +local p = thing and function() end +print("hello world") +local s = thing or function() end and 234 +local u = { + color = 1 and 2 and 3, + 4, + 4 +} +local v = { + color = 1 and function() + return "yeah" + end, + "great", + oksy = 3 ^ 2 +} +local nno = (yeah + 2) +local nn = (yeah + 2) +local n = hello(b)(function() end) +return hello(a, (yeah + 2) - okay) diff --git a/spec/outputs/pipe.lua b/spec/outputs/pipe.lua new file mode 100644 index 0000000..bf517ae --- /dev/null +++ b/spec/outputs/pipe.lua @@ -0,0 +1,116 @@ +foreach({ + "abc", + 123, + 998 +}, print) +print(reduce(filter(map({ + 1, + 2, + 3 +}, function(x) + return x * 2 +end), function(x) + return x > 4 +end), 0, function(a, b) + return a + b +end)) +print(table.concat((function() + local _accum_0 = { } + local _len_0 = 1 + for i = 0, 10 do + _accum_0[_len_0] = tostring(i) + _len_0 = _len_0 + 1 + end + return _accum_0 +end)(), ",")) +local b = 1 + 2 + (print(tostring(4), 1) or 123) +do + local x = math.max(233, 998) + if x then + print(x) + end +end +do + local _with_0 + if create ~= nil then + _with_0 = create(b, "new") + end + _with_0.value = 123 + print(_with_0:work()) +end +if f ~= nil then + f(123) +end +if f2 ~= nil then + f2((function() + if f1 ~= nil then + return f1("abc") + end + return nil + end)()) +end +local c +if f2 ~= nil then + c = f2((function() + if f1 ~= nil then + return f1("abc") + end + return nil + end)()) +end +local f +f = function() + local _obj_0 = x.y + if _obj_0 ~= nil then + return _obj_0["if"](_obj_0, arg) + end + return nil +end +func2(998, "abc", func1(func0(233))) +func2(func1(func0(998, "abc", 233))) +f(1, 2, 3, 4, 5) +f(1, val(2), 3, 4, 5) +f(1, 2, arr[3], 4, 5) +local a = f2(1, f1(1, 2, 3, tonumber(table.concat({ + "1", + "2", + "3" +}, ""))), 3) +print(render(emit(parse(extract(readFile("example.txt"), language, { }), language)))) +print(render(emit(parse(extract(readFile("example.txt"), language, { }), language)))) +print(render(emit(parse(extract(readFile("example.txt"), language, { }), language)))) +f(not func(123)) +do + local _1 = abc(123, -func(list({ + "abc", + "xyz", + "123" + }):map("#"):value()), "x") + _2, _3, _4 = 1, 2, f(3) + local _5 + _5 = f4(f3(f2(f1(v, 1), 2), 3), 4) +end +local x = b(a(123)) or d(c(456)) or (function() + local _call_0 = a["if"] + return _call_0["then"](_call_0, "abc") +end)() or (function() + if a ~= nil then + local _obj_0 = a.b + local _obj_1 = _obj_0.c + if _obj_1 ~= nil then + return _obj_1(_obj_0, 123) + end + return nil + end + return nil +end)() or (function() + local _base_0 = x + local _fn_0 = _base_0.y + return _fn_0 and function(...) + return _fn_0(_base_0, ...) + end +end)() +local x1 = 3 * f(-4) +local x2 = 3 * f(-2 ^ 2) +local y = 1 + b(3, (a ^ c)(not #2)) * f1(f(4 ^ -123)) or 123 +return nil diff --git a/spec/outputs/plus.lua b/spec/outputs/plus.lua new file mode 100644 index 0000000..749e830 --- /dev/null +++ b/spec/outputs/plus.lua @@ -0,0 +1,69 @@ +x["do"](x, "work") +func((function() + local _call_0 = a["do"](a) + local _call_1 = _call_0["end"](_call_0, "OK") + return _call_1["if"](_call_1, "abc", 123) +end)()) +local _call_0 = b["function"] +local _call_1 = _call_0["do"](_call_0) +local _call_2 = _call_1["while"](_call_1, "OK") +local res = _call_2["if"](_call_2, "def", 998) +local _call_3 = c["repeat"]["if"] +local _call_4 = _call_3["then"](_call_3, "xyz") +_call_4["else"](_call_4, res) +print(self["for"], self.__class["function"](self.__class, 123)) +do + local fcolor = message:match("<%w*>") + if fcolor then + local message = message:gsub("<%->", fcolor) + end +end +local message +do + local fcolor = message:match("<%w*>") + if fcolor then + message = message:gsub("<%->", fcolor) + end +end +local valA +do + local func = getfunc() + if func then + valA = func() + end +end +local valA +do + local func = getfunc() + if func then + valA = func() + end +end +local valB +do + local func = getfunc() + if func ~= nil then + valB = func() + end +end +backpack = { + something = { + yeah = 200, + they = function() + print("hello") + return yor_feet("small") + end, + pretty = hair, + gold = hmm + }, + yow = 1000, + eat = goo, + yeah = dudd +} +local start = { + something = "cold" +} +local bathe +bathe = { + on = "fire" +} diff --git a/spec/outputs/return.lua b/spec/outputs/return.lua new file mode 100644 index 0000000..0735b23 --- /dev/null +++ b/spec/outputs/return.lua @@ -0,0 +1,102 @@ +local _ +_ = function() + local _list_0 = things + for _index_0 = 1, #_list_0 do + local x = _list_0[_index_0] + _ = x + end +end +_ = function() + local _accum_0 = { } + local _len_0 = 1 + local _list_0 = things + for _index_0 = 1, #_list_0 do + local x = _list_0[_index_0] + _accum_0[_len_0] = x + _len_0 = _len_0 + 1 + end + return _accum_0 +end +do + local _list_0 = things + for _index_0 = 1, #_list_0 do + local x = _list_0[_index_0] + return x + end +end +do + local _accum_0 = { } + local _len_0 = 1 + local _list_0 = things + for _index_0 = 1, #_list_0 do + local x = _list_0[_index_0] + _accum_0[_len_0] = x + _len_0 = _len_0 + 1 + end + return _accum_0 +end +do + local _tbl_0 = { } + local _list_0 = things + for _index_0 = 1, #_list_0 do + local x, y = _list_0[_index_0] + _tbl_0[x] = y + end + return _tbl_0 +end +_ = function() + if a then + if a then + return a + else + return b + end + elseif b then + if a then + return a + else + return b + end + else + if a then + return a + else + return b + end + end +end +do + if a then + if a then + return a + else + return b + end + elseif b then + if a then + return a + else + return b + end + else + if a then + return a + else + return b + end + end +end +_ = function() + local _base_0 = a + local _fn_0 = _base_0.b + return _fn_0 and function(...) + return _fn_0(_base_0, ...) + end +end +do + local _base_0 = a + local _fn_0 = _base_0.b + return _fn_0 and function(...) + return _fn_0(_base_0, ...) + end +end diff --git a/spec/outputs/string.lua b/spec/outputs/string.lua new file mode 100644 index 0000000..84b6700 --- /dev/null +++ b/spec/outputs/string.lua @@ -0,0 +1,42 @@ +local hi = "hello" +local hello = "what the heckyes" +print(hi) +local umm = 'umm' +local here, another = "yeah", 'world' +local aye = "YU'M" +you('"hmmm" I said') +print(aye, you) +another = [[ hello world ]] +local hi_there = [[ hi there +]] +local well = [==[ "helo" ]==] +local hola = [===[ eat noots]===] +local mm = [[well trhere]] +local txt = [[ + +nil +Fail to compile +]] +local oo = "" +local x = "\\" +x = "a\\b" +x = "\\\n" +x = "\"" +local a = "hello " .. tostring(hello) .. " hello" +local b = tostring(hello) .. " hello" +local c = "hello " .. tostring(5 + 1) +local d = tostring(hello(world)) +local e = tostring(1) .. " " .. tostring(2) .. " " .. tostring(3) +local f = [[hello #{world} world]] +a = 'hello #{hello} hello' +b = '#{hello} hello' +c = 'hello #{hello}' +local _ = "hello"; +("hello"):format(1); +("hello"):format(1, 2, 3); +("hello"):format(1, 2, 3)(1, 2, 3); +("hello"):world(); +("hello"):format().hello(1, 2, 3); +("hello"):format(1, 2, 3) +something("hello"):world() +return something(("hello"):world()) diff --git a/spec/outputs/stub.lua b/spec/outputs/stub.lua new file mode 100644 index 0000000..ff867ba --- /dev/null +++ b/spec/outputs/stub.lua @@ -0,0 +1,26 @@ +local x = { + val = 100, + hello = function(self) + return print(self.val) + end +} +local fn +do + local _base_0 = x + local _fn_0 = _base_0.val + fn = _fn_0 and function(...) + return _fn_0(_base_0, ...) + end +end +print(fn()) +print(x:val()); +(function(...) + do + local _base_0 = hello(...) + local _fn_0 = _base_0.world + x = _fn_0 and function(...) + return _fn_0(_base_0, ...) + end + end +end)() +return nil diff --git a/spec/outputs/switch.lua b/spec/outputs/switch.lua new file mode 100644 index 0000000..1c8839f --- /dev/null +++ b/spec/outputs/switch.lua @@ -0,0 +1,71 @@ +local _exp_0 = value +if "cool" == _exp_0 then + print("hello world") +end +local _exp_1 = value +if "cool" == _exp_1 then + print("hello world") +else + print("okay rad") +end +local _exp_2 = value +if "cool" == _exp_2 then + print("hello world") +elseif "yeah" == _exp_2 then + local _ = [[FFFF]] + [[MMMM]] +elseif (2323 + 32434) == _exp_2 then + print("okay") +else + print("okay rad") +end +local out +local _exp_3 = value +if "cool" == _exp_3 then + out = print("hello world") +else + out = print("okay rad") +end +local _exp_4 = value +if "cool" == _exp_4 then + out = xxxx +elseif "umm" == _exp_4 then + out = 34340 +else + out = error("this failed big time") +end +do + local _with_0 = something + local _exp_5 = _with_0:value() + if _with_0.okay == _exp_5 then + local _ = "world" + else + local _ = "yesh" + end +end +fix(this) +call_func((function() + local _exp_5 = something + if 1 == _exp_5 then + return "yes" + else + return "no" + end +end)()) +local _exp_5 = hi +if (hello or world) == _exp_5 then + local _ = greene +end +local _exp_6 = hi +if "one" == _exp_6 or "two" == _exp_6 then + print("cool") +elseif "dad" == _exp_6 then + local _ = no +end +local _exp_7 = hi +if (3 + 1) == _exp_7 or hello() == _exp_7 or (function() + return 4 +end)() == _exp_7 then + return yello +else + return print("cool") +end diff --git a/spec/outputs/syntax.lua b/spec/outputs/syntax.lua new file mode 100644 index 0000000..3187898 --- /dev/null +++ b/spec/outputs/syntax.lua @@ -0,0 +1,360 @@ +local a = 1 + 2 * 3 / 6 +local bunch, go, here +a, bunch, go, here = another, world +func(arg1, arg2, another, arg3) +local we +here, we = function() end, yeah +local the, different +the, different = function() + return approach +end, yeah +dad() +dad(lord) +hello(one, two)(); +(5 + 5)(world) +fun(a)(b) +fun(a)(b) +fun(a)(b, bad(hello)) +hello(world(what(are(you(doing(here)))))) +what(the)[3243](world, yeck(heck)) +hairy[hands][are](gross)(okay(okay[world])) +local _ = (get[something] + 5)[years] +local i, x = 200, 300 +local yeah = (1 + 5) * 3 +yeah = ((1 + 5) * 3) / 2 +yeah = ((1 + 5) * 3) / 2 + i % 100 +local whoa = (1 + 2) * (3 + 4) * (4 + 5) +_ = function() + if something then + return 1, 2, 4 + end + return print("hello") +end +_ = function() + if hello then + return "heloo", "world" + else + return no, way + end +end +_ = function() + return 1, 2, 34 +end +return 5 + function() + return 4 + 2 +end +return 5 + (function() + return 4 +end) + 2 +print(5 + function() + _ = 34 + return good(nads) +end) +something('else', "ya") +something('else') +something("else") +_ = something([[hey]]) * 2 +_ = something([======[hey]======]) * 2 +_ = something[ [======[hey]======]] * 2 +_ = something('else'), 2 +_ = something("else"), 2 +_ = something([[else]]), 2 +_ = something[ [[else]]], 2 +something('else', 2) +something("else", 2) +something([[else]], 2) +_ = here(we)("go")[12123] +split("abc xyz 123"):map("#"):printAll() +_ = f("")[a] +_ = f(""):b() +_ = f("").c() +f(("")[a]) +f((""):b()) +f(("").c()) +list({ + "abc", + "xyz", + "123" +}):map("#"):printAll() +_ = f({ })[a] +_ = f({ }):b() +_ = f({ }).c() +local something = { + test = 12323, + what = function() + return print("hello world") + end +} +print(something.test) +local frick = { + hello = "world" +} +local argon = { + num = 100, + world = function(self) + print(self.num) + return { + something = function() + return print("hi from something") + end + } + end, + somethin = function(self, str) + print("string is", str) + return { + world = function(a, b) + return print("sum", a + b) + end + } + end +} +something.what() +argon:world().something() +argon:somethin("200").world(1, 2) +x = -434 +x = -hello(world(one(two))) +local hi = -"herfef" +x = -(function() + local _accum_0 = { } + local _len_0 = 1 + for x in x do + _accum_0[_len_0] = x + _len_0 = _len_0 + 1 + end + return _accum_0 +end)() +if cool then + print("hello") +end +if not cool then + print("hello") +end +if not (1212 and 3434) then + print("hello") +end +for i = 1, 10 do + print("hello") +end +print("nutjob") +if hello then + _ = 343 +end +if cool then + print("what") +end +(function(...) + local arg = { + ... + } +end)() +x = function(...) + return dump({ + ... + }) +end +x = not true +local y = not (5 + 5) +y = #"hello" +x = #{ + #{ }, + #{ + 1 + }, + #{ + 1, + 2 + } +} +_ = hello, world +something:hello(what)(a, b) +something:hello(what) +something.hello:world(a, b) +something.hello:world(1, 2, 3)(a, b) +something.hello:world(1, 2, 3)(a, b) +x = 1232 +x = x + (10 + 3) +local j = j - "hello" +y = y * 2 +y = y / 100 +local m = m % 2 +local hello = hello .. "world" +self.__class.something = self.__class.something + 10 +self.something = self.something + 10 +local _update_0 = "hello" +a[_update_0] = a[_update_0] + 10 +local _update_1 = "hello" .. tostring(tostring(ff)) +a[_update_1] = a[_update_1] + 10 +a[four].x = a[four].x + 10 +x = 0 +local _list_0 = values +for _index_0 = 1, #_list_0 do + local v = _list_0[_index_0] + _ = ((function() + if ntype(v) == "fndef" then + x = x + 1 + end + end)()) +end +hello = { + something = world, + ["if"] = "hello", + ["else"] = 3434, + ["function"] = "okay", + good = 230203 +} +local tb = { + ["do"] = b, + (function() + return { + b = b + } + end)() +} +div({ + class = "cool" +}) +_ = 5 + what(wack) +what(whack + 5) +_ = 5 - what(wack) +what(whack - 5) +x = hello - world - something; +(function(something) + if something == nil then + do + local _with_0 = what + _with_0:cool(100) + something = _with_0 + end + end + return print(something) +end)() +if something then + _ = 03589 +else + _ = 3434 +end +if something then + _ = yeah +elseif "ymmm" then + print("cool") +else + _ = okay +end +x = notsomething +y = ifsomething +local z = x and b +z = x(andb) +while 10 > something({ + something = "world" + }) do + print("yeah") +end +x = { + okay = sure +} +yeah({ + okay = man, + sure = sir +}) +hello("no comma", { + yeah = dada, + another = world +}) +hello("comma", { + something = hello_world, + frick = you +}) +another(hello, one, two, three, four, { + yeah = man, + okay = yeah, + fine = alright +}) +another(hello, one, two, three, four, { + yeah = man, + okay = yeah, + { + fine = alright, + okay = 1 + }, + { + fine = alright, + okay = 2 + } +}) +another(hello, one, two, three, four, { + yeah = man, + okay = yeah +}) +another(hello, one, two, three, four, { + yeah = man({ + okay = yeah + }) +}) +ajax(url, function(data) + return process(data) +end, function(error) + return print(error) +end) +a = a + (3 - 5) +a = a * (3 + 5) +a = a * 3 +a = a >> 3 +a = a << 3 +a = a / func("cool") +x["then"] = "hello" +x["while"]["true"] = "hello" +x["while"]["true"] = "hello" +x = x or "hello" +x = x and "hello" +z = a - b +z = a(-b) +z = a - b +z = a - b +local str = strA .. strB .. strC +func(3000, "192.168.1.1") +local f +f = function() + return a, b, c, d, e, f +end +f = function() + return a, b, c, d, e, f +end +do + local _with_0 = obj + invoke(_with_0:func(), 123, "abc") +end +invokeA(invokeB(invokeC(123))) +invokeA(invokeB(invokeC(123))) +local v = { + a(-1), + a(-1), + a - 1, + a - 1, + a - 1, + a - 1, + a - 1, + a - 1, + a(~1), + a(~1), + a ~ 1, + a ~ 1, + a ~ 1, + a ~ 1, + a ~ 1, + a ~ 1 +} +do + a = 1 + 2 * 3 / 4 + local _1 = f1(-1 + 2 + 3) + local _2 = f1 - 1 + 2 + 3 + local f2 + f2 = function(x) + return print(x + 1) + end + a = f2() + f2(-1) + a = f2() - f2(1) + local _3, _4 + _1, _2, _3, _4 = 1, f(2, 3, f(4, 4)) +end +return nil diff --git a/spec/outputs/tables.lua b/spec/outputs/tables.lua new file mode 100644 index 0000000..086e8b3 --- /dev/null +++ b/spec/outputs/tables.lua @@ -0,0 +1,351 @@ +local backpack = { + something = { + yeah = 200, + they = function() + print("hello") + return yor_feet("small") + end, + pretty = hair, + gold = hmm + }, + yow = 1000, + eat = goo, + yeah = dudd +} +local start = { + something = "cold" +} +local bathe = { + on = "fire" +} +local another = { + [4] = 232, + ["good food"] = "is the best" +} +local fwip = { + something = hello("what"), + number = 2323, + what = yo("momma", "yeah"), + fruit = basket, + nuts = day +} +local frick = { + hello = "world" +} +local frack, best = { + hello = "world", + rice = 3434 +}, "what" +local ya = { + 1, + 2, + 3, + key = 100, + 343, + "hello", + umm = 232 +} +local x = { + 1, + 2, + 4343, + 343, + 343 +} +local g, p = { + 1, + 2, + nowy = "yes", + 3, + 4, + hey = 232, + another = "day" +}, 234 +local annother = { + 1, + 2, + 3, + 3, + 4, + 5, + 6, + 7, + 8 +} +local yeah = { + [232] = 3434, + "helo", + ice = "cake" +} +local whatabout = { + hello(world, another), + what, + about, + now, + hello("world"), + yeah, + hello("world", yeah) +} +x = { + something = function(self) + return "hello" + end, + cool = { + bed = { + 2323, + 2323 + }, + red = 2343 + }, + name = function(self, node) + return self:value(node) + end +} +x = { + something = something, + something = something +} +local y = { + hi = hi, + there = there, + how = how, + you = you, + thing = thing +} +call_me("hello", { + x = x, + y = y, + z = z +}) +local t = { + a = 'a', + [b] = 'b' +} +local xam = { + hello = 1234, + ["hello"] = 12354, + [ [[hello]]] = 12354, + ["hello"] = 12354, + [ [[hello]]] = 12354 +} +local kam = { + hello = 12, + goodcheese = "mmm", + yeah = 12 + 232, + lets = keepit({ + going = true, + okay = "yeah" + }), + more = { + 1, + (function() + local _accum_0 = { } + local _len_0 = 1 + for x = 1, 10 do + _accum_0[_len_0] = x + _len_0 = _len_0 + 1 + end + return _accum_0 + end)() + }, + [{ + "one", + "two" + }] = one_thing(function(self) end) +} +keepit({ + going = true, + okay = "yeah", + workd = "okay" +}) +thing({ + what = "great", + no = "more", + okay = 123 +}) +thing({ + what = "great", + no = "more" +}) +local _ = { + okay = 123 +} +local k = { + ["hello"] = "world" +} +k = { + ['hello'] = 'world' +} +k = { + ["hello"] = 'world', + ["hat"] = "zat" +} +please({ + ["hello"] = "world" +}) +k = { + ["hello"] = "world", + ["one"] = "zone" +} +local f = "one", { + ["two"] = three +}, "four" +f = { + ["two"] = three +}, "four" +f = { + "one", + ["two"] = three, + "four" +} +local j = "one", { + ["two"] = three, + ["four"] = five +}, 6, 7 +local heroine = { + name = "Christina", + age = 18, + job = "Princess", + likes = { + { + name = "kittens", + img = "/image/kittens.png" + }, + { + name = "flower", + img = "/image/flower.png" + } + }, + items = { + { + name = "ring", + amount = 2 + }, + { + name = "necklace", + amount = 1 + } + }, + status = { + desc = "weak", + { + attribute = "health", + value = 50 + }, + { + attribute = "mana", + value = 100 + } + } +} +local inventory = { + equipment = { + "sword", + "shield" + }, + items = { + { + name = "potion", + count = 10 + }, + { + name = "bread", + count = 3 + } + } +} +local items = { + func(), + (function() + local _with_0 = tb + _with_0.abc = 123 + return _with_0 + end)(), + { + 1, + 2, + 3 + }, + f({ + 1, + 2, + 3 + }), + f({ + 1, + 2, + 3 + }), + (function() + local _accum_0 = { } + local _len_0 = 1 + for i = 1, 3 do + _accum_0[_len_0] = i + _len_0 = _len_0 + 1 + end + return _accum_0 + end)(), + tostring((function() + if a then + return b + end + end)()) +} +local pairs = { + { + "king", + "queen" + }, + { + "hero", + "princess" + } +} +items = { + { + name = "ring", + amount = 2 + }, + { + name = "necklace", + amount = 1 + } +} +local menus = { + { + text = "Save", + sub = { + { + text = "Slot 1: " .. (slots[1].name or "None"), + click = function() end + }, + { + text = { + "Slot 2" + }, + click = function() end + }, + { + text = [[Slot 3]], + click = function() end + }, + { + text = ("Slot 4"):name(), + click = function() end + }, + { + text = ({ + { + "slot5" + } + })[1]:name(), + click = function() end + }, + [6] = { + text = ("Slot 6"), + click = function() end + } + } + } +} +return nil diff --git a/spec/outputs/teal-lang.lua b/spec/outputs/teal-lang.lua new file mode 100644 index 0000000..0e627f4 --- /dev/null +++ b/spec/outputs/teal-lang.lua @@ -0,0 +1,49 @@ +local a = { + value = 123 +}; +local b = a.value; +local add = function(a, b) + return a + b +end +local s = add(a.value, b) +print(s); +local Point = {}; +Point.new = function(x, y) +local point = setmetatable({ }, { + __index = Point +}) + point.x = x or 0 + point.y = y or 0 + return point +end +Point.move = function(self, dx, dy) + self.x = self.x + dx + self.y = self.y + dy +end +local p = Point.new(100, 100) +p:move(50, 50); +local filter = function(tab, handler) + local _accum_0 = { } + local _len_0 = 1 + for _index_0 = 1, #tab do + local item = tab[_index_0] + if handler(item) then + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 + end + end + return _accum_0 +end +local cond = function(item) + return item ~= "a" +end +local res = filter({ + "a", + "b", + "c", + "a" +}, cond) +for _index_0 = 1, #res do + local s = res[_index_0] + print(s) +end diff --git a/spec/outputs/teal-lang.tl b/spec/outputs/teal-lang.tl new file mode 100644 index 0000000..8f0bf36 --- /dev/null +++ b/spec/outputs/teal-lang.tl @@ -0,0 +1,60 @@ +local a:{string:number} = { + value = 123 +}; +local b:number = a.value; +local function add(a:number, b:number):number + + return a + b + +end +local s = add(a.value, b) +print(s); +local record Point + x: number + y: number +end +function Point.new(x:number, y:number):Point +local point:Point = setmetatable({ }, { + __index = Point +}) + point.x = x or 0 + point.y = y or 0 + return point + +end +function Point:move(dx:number, dy:number) + self.x = self.x + dx + self.y = self.y + dy + +end +local p:Point = Point.new(100, 100) +p:move(50, 50); +local function filter(tab:{string}, handler:function(item:string):boolean):{string} + + local _accum_0 = { } + local _len_0 = 1 + for _index_0 = 1, #tab do + local item = tab[_index_0] + if handler(item) then + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 + end + end + return _accum_0 + +end +local function cond(item:string):boolean + + return item ~= "a" + +end +local res = filter({ + "a", + "b", + "c", + "a" +}, cond) +for _index_0 = 1, #res do + local s = res[_index_0] + print(s) +end diff --git a/spec/outputs/unless_else.lua b/spec/outputs/unless_else.lua new file mode 100644 index 0000000..c85d4bf --- /dev/null +++ b/spec/outputs/unless_else.lua @@ -0,0 +1,7 @@ +if a then + if not b then + return print("hi") + elseif c then + return print("not hi") + end +end diff --git a/spec/outputs/using.lua b/spec/outputs/using.lua new file mode 100644 index 0000000..6d0d888 --- /dev/null +++ b/spec/outputs/using.lua @@ -0,0 +1,23 @@ +local hello = "hello" +local world = "world" +local _ +_ = function() + local hello = 3223 +end +_ = function(a) + local hello = 3223 + a = 323 +end +_ = function(a, b, c) + a, b, c = 1, 2, 3 + local world = 12321 +end +_ = function(a, e, f) + local b, c + a, b, c = 1, 2, 3 + hello = 12321 + local world = "yeah" +end +_ = function() + local hello = hello or 2 +end diff --git a/spec/outputs/vararg.lua b/spec/outputs/vararg.lua new file mode 100644 index 0000000..e799a94 --- /dev/null +++ b/spec/outputs/vararg.lua @@ -0,0 +1,218 @@ +local join +join = function(...) + f_with((function() + local _with_0 = a + _with_0:func() + return _with_0 + end)()) + f_with((function(...) + local _with_0 = a + _with_0:func(...) + return _with_0 + end)(...)) + f_listcomp((function() + local _accum_0 = { } + local _len_0 = 1 + for i = 1, 10 do + _accum_0[_len_0] = items[i] + _len_0 = _len_0 + 1 + end + return _accum_0 + end)()) + f_listcomp((function(...) + local _accum_0 = { } + local _len_0 = 1 + for i = 1, 10 do + _accum_0[_len_0] = items[i](...) + _len_0 = _len_0 + 1 + end + return _accum_0 + end)(...)) + f_listcomp((function() + local _accum_0 = { } + local _len_0 = 1 + local _list_0 = items + for _index_0 = 1, #_list_0 do + local item = _list_0[_index_0] + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 + end + return _accum_0 + end)()) + f_listcomp((function(...) + local _accum_0 = { } + local _len_0 = 1 + local _list_0 = items + for _index_0 = 1, #_list_0 do + local item = _list_0[_index_0] + _accum_0[_len_0] = item(...) + _len_0 = _len_0 + 1 + end + return _accum_0 + end)(...)) + f_class((function() + local A + do + local _class_0 + local _base_0 = { } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "A" + }, { + __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 + local self = _class_0; + func() + A = _class_0 + return _class_0 + end + end)()) + f_class((function(...) + local A + do + local _class_0 + local _base_0 = { } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "A" + }, { + __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 + local self = _class_0; + func(...) + A = _class_0 + return _class_0 + end + end)(...)) + f_tblcomp((function() + local _tbl_0 = { } + for k, v in pairs(tb) do + _tbl_0[k] = v + end + return _tbl_0 + end)()) + f_tblcomp((function(...) + local _tbl_0 = { } + for k, v in pairs(tb) do + _tbl_0[k] = v(...) + end + return _tbl_0 + end)(...)) + f_tblcomp((function() + local _tbl_0 = { } + local _list_0 = items + for _index_0 = 1, #_list_0 do + local item = _list_0[_index_0] + _tbl_0[item] = true + end + return _tbl_0 + end)()) + f_tblcomp((function(...) + local _tbl_0 = { } + local _list_0 = items + for _index_0 = 1, #_list_0 do + local item = _list_0[_index_0] + _tbl_0[item(...)] = true + end + return _tbl_0 + end)(...)) + f_do((function() + return func() + end)()) + f_do((function(...) + return func(...) + end)(...)) + f_while((function() + local _accum_0 = { } + local _len_0 = 1 + while false do + _accum_0[_len_0] = func() + _len_0 = _len_0 + 1 + end + return _accum_0 + end)()) + f_while((function(...) + local _accum_0 = { } + local _len_0 = 1 + while false do + _accum_0[_len_0] = func(...) + _len_0 = _len_0 + 1 + end + return _accum_0 + end)(...)) + f_if((function() + if false then + return func() + end + end)()) + f_if((function(...) + if false then + return func(...) + end + end)(...)) + f_unless((function() + if not true then + return func() + end + end)()) + f_unless((function(...) + if not true then + return func(...) + end + end)(...)) + f_switch((function() + local _exp_0 = x + if "abc" == _exp_0 then + return func() + end + end)()) + f_switch((function(...) + local _exp_0 = x + if "abc" == _exp_0 then + return func(...) + end + end)(...)) + f_eop((function() + if func ~= nil then + return func() + end + return nil + end)()) + f_eop((function(...) + if func ~= nil then + return func(...) + end + return nil + end)(...)) + f_colon((function() + local _base_0 = f() + local _fn_0 = _base_0.func + return _fn_0 and function(...) + return _fn_0(_base_0, ...) + end + end)()) + f_colon((function(...) + local _base_0 = f(...) + local _fn_0 = _base_0.func + return _fn_0 and function(...) + return _fn_0(_base_0, ...) + end + end)(...)) + return nil +end diff --git a/spec/outputs/whitespace.lua b/spec/outputs/whitespace.lua new file mode 100644 index 0000000..1bc4503 --- /dev/null +++ b/spec/outputs/whitespace.lua @@ -0,0 +1,98 @@ +local _ = { + 1, + 2 +} +_ = { + 1, + 2 +} +_ = { + 1, + 2 +} +_ = { + 1, + 2 +} +_ = { + 1, + 2 +} +_ = { + something(1, 2, 4, 5, 6), + 3, + 4, + 5 +} +_ = { + a(1, 2, 3), + 4, + 5, + 6, + 1, + 2, + 3 +} +_ = { + b(1, 2, 3, 4, 5, 6), + 1, + 2, + 3, + 1, + 2, + 3 +} +_ = { + 1, + 2, + 3 +} +_ = { + c(1, 2, 3) +} +hello(1, 2, 3, 4, 1, 2, 3, 4, 4, 5) +x(1, 2, 3, 4, 5, 6) +hello(1, 2, 3, world(4, 5, 6, 5, 6, 7, 8)) +hello(1, 2, 3, world(4, 5, 6, 5, 6, 7, 8), 9, 9) +_ = { + hello(1, 2), + 3, + 4, + 5, + 6 +} +local x = { + hello(1, 2, 3, 4, 5, 6, 7), + 1, + 2, + 3, + 4 +} +if hello(1, 2, 3, world, world) then + print("hello") +end +if hello(1, 2, 3, world, world) then + print("hello") +end +a(one, two, three) +b(one, two, three) +c(one, two, three, four) +local v +v = function() + return a, b, c +end +local v1, v2, v3 +v1, v2, v3 = function() + return a +end, b, c +local a, b, c, d, e, f = 1, f2({ + abc = abc +}), 3, 4, f5(abc), 6 +for a, b, c in pairs(tb) do + print(a, b, c) +end +for i = 1, 10, -1 do + print(i) +end +local a, b, c +return nil diff --git a/spec/outputs/with.lua b/spec/outputs/with.lua new file mode 100644 index 0000000..e1497c6 --- /dev/null +++ b/spec/outputs/with.lua @@ -0,0 +1,164 @@ +do + local a + a = function() + local _with_0 = something + print(_with_0.hello) + print(hi) + print("world") + return _with_0 + end +end +do + do + local _with_0 = leaf + _with_0.world() + _with_0.world(1, 2, 3) + local g = _with_0.what.is.this + _with_0.hi(1, 2, 3) + _with_0:hi(1, 2).world(2323) + _with_0:hi("yeah", "man") + _with_0.world = 200 + end +end +do + local zyzyzy + do + local _with_0 = something + _with_0.set_state("hello world") + zyzyzy = _with_0 + end +end +do + local x = 5 + (function() + local _with_0 = Something() + _with_0:write("hello world") + return _with_0 + end)() +end +do + local x = { + hello = (function() + local _with_0 = yeah + _with_0:okay() + return _with_0 + end)() + } +end +do + do + local _with_0 = foo + local _ = _with_0:prop("something").hello + _with_0.prop:send(one) + _with_0.prop:send(one) + end +end +do + do + local _with_0 = a, b + print(_with_0.world) + end + local mod + do + local _M = { } + _M.Thing = "hi" + mod = _M + end + do + local a, b = something, pooh + print(a.world) + end + local x + do + local a, b = 1, 2 + print(a + b) + x = a + end + print((function() + local a, b = 1, 2 + print(a + b) + return a + end)()) + local p + do + local _with_0 = 1 + hello().x, world().y = _with_0, 2 + print(a + b) + p = _with_0 + end +end +do + local x = "hello" + x:upper() +end +do + do + local k = "jo" + print(k:upper()) + end +end +do + do + local a, b, c = "", "", "" + print(a:upper()) + end +end +do + local a = "bunk" + do + local b, c + a, b, c = "", "", "" + print(a:upper()) + end +end +do + do + local _with_0 = j + print(_with_0:upper()) + end +end +do + do + local _with_0 = "jo" + k.j = _with_0 + print(_with_0:upper()) + end +end +do + do + local _with_0 = a + print(_with_0.b) + do + local _with_1 = _with_0.c + print(_with_1.d) + end + end +end +do + do + local _with_0 = a + do + local _with_1 = 2 + _with_0.b = _with_1 + print(_with_1.c) + end + end +end +do + local _ + _ = function() + local _with_0 = hi + return _with_0.a, _with_0.b + end +end +do + do + local _with_0 = tb + _with_0.x = item.field:func(123) + end +end +do + local _with_0 = dad + _with_0["if"]("yes") + local y = _with_0["end"].of["function"] + return _with_0 +end -- cgit v1.2.3-55-g6feb