mirror of
https://github.com/leafo/moonscript.git
synced 2024-11-22 02:44:23 +00:00
local *
This commit is contained in:
parent
fa06e6103d
commit
54dc8efa0b
@ -749,6 +749,17 @@ tree = function(tree, options)
|
||||
return lua_code, posmap
|
||||
end
|
||||
end
|
||||
do
|
||||
local _with_0 = require("moonscript.data")
|
||||
local data = _with_0
|
||||
for name, cls in pairs({
|
||||
Line = Line,
|
||||
Lines = Lines,
|
||||
DelayedLine = DelayedLine
|
||||
}) do
|
||||
data[name] = cls
|
||||
end
|
||||
end
|
||||
return {
|
||||
tree = tree,
|
||||
value = value,
|
||||
|
@ -411,4 +411,9 @@ tree = (tree, options={}) ->
|
||||
posmap = scope._lines\flatten_posmap!
|
||||
lua_code, posmap
|
||||
|
||||
-- mmmm
|
||||
with data = require "moonscript.data"
|
||||
for name, cls in pairs {:Line, :Lines, :DelayedLine}
|
||||
data[name] = cls
|
||||
|
||||
{ :tree, :value, :format_error, :Block, :RootBlock }
|
||||
|
@ -1,8 +1,6 @@
|
||||
local reversed, unpack
|
||||
do
|
||||
local _table_0 = require("moonscript.util")
|
||||
reversed, unpack = _table_0.reversed, _table_0.unpack
|
||||
end
|
||||
local util = require("moonscript.util")
|
||||
local data = require("moonscript.data")
|
||||
local reversed, unpack = util.reversed, util.unpack
|
||||
local ntype
|
||||
do
|
||||
local _table_0 = require("moonscript.types")
|
||||
@ -41,6 +39,23 @@ local statement_compilers = {
|
||||
end
|
||||
end
|
||||
end,
|
||||
declare_glob = function(self, node)
|
||||
local names = { }
|
||||
self:set("name_glob", function(name)
|
||||
insert(names, name)
|
||||
return true
|
||||
end)
|
||||
return data.DelayedLine(function(buff)
|
||||
insert(buff, "local ")
|
||||
local _list_0 = names
|
||||
for _index_0 = 1, #_list_0 do
|
||||
local name = _list_0[_index_0]
|
||||
insert(buff, self:name(name))
|
||||
insert(buff, ", ")
|
||||
end
|
||||
buff[#buff] = nil
|
||||
end)
|
||||
end,
|
||||
declare_with_shadows = function(self, node)
|
||||
local names = node[2]
|
||||
self:declare(names)
|
||||
|
@ -1,5 +1,8 @@
|
||||
|
||||
import reversed, unpack from require "moonscript.util"
|
||||
util = require "moonscript.util"
|
||||
data = require "moonscript.data"
|
||||
|
||||
import reversed, unpack from util
|
||||
import ntype from require "moonscript.types"
|
||||
import concat, insert from table
|
||||
|
||||
@ -17,6 +20,19 @@ statement_compilers =
|
||||
with @line "local "
|
||||
\append_list [@name name for name in *undeclared], ", "
|
||||
|
||||
declare_glob: (node) =>
|
||||
names = {}
|
||||
@set "name_glob", (name) ->
|
||||
insert names, name
|
||||
true
|
||||
|
||||
data.DelayedLine (buff) ->
|
||||
insert buff, "local "
|
||||
for name in *names
|
||||
insert buff, @name name
|
||||
insert buff, ", "
|
||||
buff[#buff] = nil -- strips local if no names
|
||||
|
||||
-- this overrides the existing names with new locals, used for local keyword
|
||||
declare_with_shadows: (node) =>
|
||||
names = node[2]
|
||||
|
@ -404,7 +404,7 @@ local build_grammar = wrap_env(function()
|
||||
PopIndent = Cmt("", pop_indent),
|
||||
InBlock = Advance * Block * PopIndent,
|
||||
|
||||
Local = key"local" * Ct(NameList) / mark"declare_with_shadows",
|
||||
Local = key"local" * ((op"*" + op"^") / mark"declare_glob" + Ct(NameList) / mark"declare_with_shadows"),
|
||||
|
||||
Import = key"import" * Ct(ImportNameList) * key"from" * Exp / mark"import",
|
||||
ImportName = (sym"\\" * Ct(Cc"colon_stub" * Name) + Name),
|
||||
|
@ -329,6 +329,18 @@ local Statement = Transformer({
|
||||
end,
|
||||
assign = function(self, node)
|
||||
local names, values = unpack(node, 2)
|
||||
do
|
||||
local globber = self:get("name_glob")
|
||||
if globber then
|
||||
local _list_0 = names
|
||||
for _index_0 = 1, #_list_0 do
|
||||
local name = _list_0[_index_0]
|
||||
if globber(name) then
|
||||
self:put_name(name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
local transformed
|
||||
if #values == 1 then
|
||||
local value = values[1]
|
||||
|
@ -158,6 +158,12 @@ Statement = Transformer {
|
||||
|
||||
assign: (node) =>
|
||||
names, values = unpack node, 2
|
||||
|
||||
if globber = @get "name_glob"
|
||||
for name in *names
|
||||
if globber name
|
||||
@put_name name
|
||||
|
||||
-- bubble cascading assigns
|
||||
transformed = if #values == 1
|
||||
value = values[1]
|
||||
|
Loading…
Reference in New Issue
Block a user