mirror of
https://github.com/leafo/moonscript.git
synced 2025-01-09 00:04:22 +00:00
fixed bug with assigning the names of statements
This commit is contained in:
parent
64fd33c089
commit
035b18cfff
@ -1,6 +1,7 @@
|
||||
module("moonscript.compile", package.seeall)
|
||||
local util = require("moonscript.util")
|
||||
require("moonscript.compile.format")
|
||||
local dump = require("moonscript.dump")
|
||||
local reversed = util.reversed
|
||||
local ntype, smart_node
|
||||
do
|
||||
@ -40,20 +41,13 @@ line_compile = {
|
||||
end,
|
||||
assign = function(self, node)
|
||||
local _, names, values = unpack(node)
|
||||
if #values == 1 and cascading[ntype(values[1])] then
|
||||
return self:stm({
|
||||
"assign",
|
||||
names,
|
||||
values[1]
|
||||
})
|
||||
end
|
||||
local undeclared = self:declare(names)
|
||||
local declare = "local " .. concat(undeclared, ", ")
|
||||
if self:is_stm(values) then
|
||||
if #values == 1 and self:is_stm(values[1]) and cascading[ntype(values[1])] then
|
||||
local stm = values[1]
|
||||
if #undeclared > 0 then
|
||||
self:add(declare)
|
||||
end
|
||||
if cascading[ntype(values)] then
|
||||
local decorate
|
||||
decorate = function(value)
|
||||
return {
|
||||
@ -64,10 +58,7 @@ line_compile = {
|
||||
}
|
||||
}
|
||||
end
|
||||
return self:stm(values, decorate)
|
||||
else
|
||||
return error("Assigning unsupported statement")
|
||||
end
|
||||
return self:stm(stm, decorate)
|
||||
else
|
||||
local has_fndef = false
|
||||
local i = 1
|
||||
|
@ -3,6 +3,7 @@ module "moonscript.compile", package.seeall
|
||||
util = require "moonscript.util"
|
||||
|
||||
require "moonscript.compile.format"
|
||||
dump = require "moonscript.dump"
|
||||
|
||||
import reversed from util
|
||||
import ntype, smart_node from require "moonscript.types"
|
||||
@ -27,22 +28,17 @@ line_compile =
|
||||
assign: (node) =>
|
||||
_, names, values = unpack node
|
||||
|
||||
-- can we extract single cascading value
|
||||
if #values == 1 and cascading[ntype values[1]]
|
||||
return @stm {"assign", names, values[1]}
|
||||
|
||||
undeclared = @declare names
|
||||
declare = "local "..concat(undeclared, ", ")
|
||||
|
||||
if @is_stm values
|
||||
-- todo: tree transformation
|
||||
if #values == 1 and @is_stm(values[1]) and cascading[ntype(values[1])]
|
||||
stm = values[1]
|
||||
@add declare if #undeclared > 0
|
||||
if cascading[ntype(values)]
|
||||
decorate = (value) ->
|
||||
{"assign", names, {value}}
|
||||
|
||||
@stm values, decorate
|
||||
else
|
||||
error "Assigning unsupported statement"
|
||||
@stm stm, decorate
|
||||
else
|
||||
has_fndef = false
|
||||
i = 1
|
||||
|
@ -308,7 +308,7 @@ local build_grammar = wrap(function()
|
||||
CompFor = key"for" * Ct(NameList) * key"in" * (sym"*" * Exp / mark"unpack" + Exp) / mark"for",
|
||||
CompClause = CompFor + key"when" * Exp / mark"when",
|
||||
|
||||
Assign = Ct(AssignableList) * sym"=" * (With + If + Ct(TableBlock + ExpListLow)) / mark"assign",
|
||||
Assign = Ct(AssignableList) * sym"=" * (Ct(With + If) + Ct(TableBlock + ExpListLow)) / mark"assign",
|
||||
Update = Assignable * ((sym"..=" + sym"+=" + sym"-=" + sym"*=" + sym"/=" + sym"%=")/trim) * Exp / mark"update",
|
||||
|
||||
-- we can ignore precedence for now
|
||||
|
Loading…
Reference in New Issue
Block a user