mirror of
https://github.com/leafo/moonscript.git
synced 2024-11-22 02:44:23 +00:00
allow multiple name proxy of same type in names of for in loop
This commit is contained in:
parent
25b997e71f
commit
252e875833
@ -436,8 +436,8 @@ do
|
|||||||
local t = ntype(node)
|
local t = ntype(node)
|
||||||
return value_compilers[t] ~= nil or t == "value"
|
return value_compilers[t] ~= nil or t == "value"
|
||||||
end,
|
end,
|
||||||
name = function(self, node)
|
name = function(self, node, ...)
|
||||||
return self:value(node)
|
return self:value(node, ...)
|
||||||
end,
|
end,
|
||||||
value = function(self, node, ...)
|
value = function(self, node, ...)
|
||||||
node = self.transform.value(node)
|
node = self.transform.value(node)
|
||||||
|
@ -279,7 +279,8 @@ class Block
|
|||||||
value_compilers[t] != nil or t == "value"
|
value_compilers[t] != nil or t == "value"
|
||||||
|
|
||||||
-- line wise compile functions
|
-- line wise compile functions
|
||||||
name: (node) => @value node
|
name: (node, ...) => @value node, ...
|
||||||
|
|
||||||
value: (node, ...) =>
|
value: (node, ...) =>
|
||||||
node = @transform.value node
|
node = @transform.value node
|
||||||
action = if type(node) != "table"
|
action = if type(node) != "table"
|
||||||
|
@ -185,19 +185,23 @@ local statement_compilers = {
|
|||||||
do
|
do
|
||||||
local _with_0 = self:line()
|
local _with_0 = self:line()
|
||||||
_with_0:append("for ")
|
_with_0:append("for ")
|
||||||
_with_0:append_list((function()
|
loop = _with_0
|
||||||
|
end
|
||||||
|
do
|
||||||
|
local _with_0 = self:block(loop)
|
||||||
|
loop:append_list((function()
|
||||||
local _accum_0 = { }
|
local _accum_0 = { }
|
||||||
local _len_0 = 0
|
local _len_0 = 0
|
||||||
local _list_0 = names
|
local _list_0 = names
|
||||||
for _index_0 = 1, #_list_0 do
|
for _index_0 = 1, #_list_0 do
|
||||||
local name = _list_0[_index_0]
|
local name = _list_0[_index_0]
|
||||||
_len_0 = _len_0 + 1
|
_len_0 = _len_0 + 1
|
||||||
_accum_0[_len_0] = self:name(name)
|
_accum_0[_len_0] = _with_0:name(name, false)
|
||||||
end
|
end
|
||||||
return _accum_0
|
return _accum_0
|
||||||
end)(), ", ")
|
end)(), ", ")
|
||||||
_with_0:append(" in ")
|
loop:append(" in ")
|
||||||
_with_0:append_list((function()
|
loop:append_list((function()
|
||||||
local _accum_0 = { }
|
local _accum_0 = { }
|
||||||
local _len_0 = 0
|
local _len_0 = 0
|
||||||
local _list_0 = exps
|
local _list_0 = exps
|
||||||
@ -208,11 +212,7 @@ local statement_compilers = {
|
|||||||
end
|
end
|
||||||
return _accum_0
|
return _accum_0
|
||||||
end)(), ",")
|
end)(), ",")
|
||||||
_with_0:append(" do")
|
loop:append(" do")
|
||||||
loop = _with_0
|
|
||||||
end
|
|
||||||
do
|
|
||||||
local _with_0 = self:block(loop)
|
|
||||||
_with_0:declare(names)
|
_with_0:declare(names)
|
||||||
_with_0:stms(block)
|
_with_0:stms(block)
|
||||||
return _with_0
|
return _with_0
|
||||||
|
@ -100,12 +100,13 @@ statement_compilers =
|
|||||||
|
|
||||||
loop = with @line!
|
loop = with @line!
|
||||||
\append "for "
|
\append "for "
|
||||||
\append_list [@name name for name in *names], ", "
|
|
||||||
\append " in "
|
|
||||||
\append_list [@value exp for exp in *exps], ","
|
|
||||||
\append " do"
|
|
||||||
|
|
||||||
with @block loop
|
with @block loop
|
||||||
|
loop\append_list [\name name, false for name in *names], ", "
|
||||||
|
loop\append " in "
|
||||||
|
loop\append_list [@value exp for exp in *exps], ","
|
||||||
|
loop\append " do"
|
||||||
|
|
||||||
\declare names
|
\declare names
|
||||||
\stms block
|
\stms block
|
||||||
|
|
||||||
|
@ -266,8 +266,8 @@ local value_compilers = {
|
|||||||
minus = function(self, node)
|
minus = function(self, node)
|
||||||
return self:line("-", self:value(node[2]))
|
return self:line("-", self:value(node[2]))
|
||||||
end,
|
end,
|
||||||
temp_name = function(self, node)
|
temp_name = function(self, node, ...)
|
||||||
return node:get_name(self)
|
return node:get_name(self, ...)
|
||||||
end,
|
end,
|
||||||
number = function(self, node)
|
number = function(self, node)
|
||||||
return node[2]
|
return node[2]
|
||||||
|
@ -150,8 +150,8 @@ value_compilers =
|
|||||||
minus: (node) =>
|
minus: (node) =>
|
||||||
@line "-", @value node[2]
|
@line "-", @value node[2]
|
||||||
|
|
||||||
temp_name: (node) =>
|
temp_name: (node, ...) =>
|
||||||
node\get_name self
|
node\get_name self, ...
|
||||||
|
|
||||||
number: (node) =>
|
number: (node) =>
|
||||||
node[2]
|
node[2]
|
||||||
|
@ -48,9 +48,12 @@ local NameProxy
|
|||||||
do
|
do
|
||||||
local _parent_0 = nil
|
local _parent_0 = nil
|
||||||
local _base_0 = {
|
local _base_0 = {
|
||||||
get_name = function(self, scope)
|
get_name = function(self, scope, dont_put)
|
||||||
|
if dont_put == nil then
|
||||||
|
dont_put = true
|
||||||
|
end
|
||||||
if not self.name then
|
if not self.name then
|
||||||
self.name = scope:free_name(self.prefix, true)
|
self.name = scope:free_name(self.prefix, dont_put)
|
||||||
end
|
end
|
||||||
return self.name
|
return self.name
|
||||||
end,
|
end,
|
||||||
|
@ -11,9 +11,9 @@ class NameProxy
|
|||||||
new: (@prefix) =>
|
new: (@prefix) =>
|
||||||
self[1] = "temp_name"
|
self[1] = "temp_name"
|
||||||
|
|
||||||
get_name: (scope) =>
|
get_name: (scope, dont_put=true) =>
|
||||||
if not @name
|
if not @name
|
||||||
@name = scope\free_name @prefix, true
|
@name = scope\free_name @prefix, dont_put
|
||||||
@name
|
@name
|
||||||
|
|
||||||
chain: (...) =>
|
chain: (...) =>
|
||||||
|
Loading…
Reference in New Issue
Block a user