mirror of
https://github.com/leafo/moonscript.git
synced 2024-11-22 02:44:23 +00:00
local glob tests and local ^
This commit is contained in:
parent
19032214a8
commit
0759cd640e
@ -404,7 +404,7 @@ do
|
||||
if self.export_all then
|
||||
return true
|
||||
end
|
||||
if self.export_proper and name:match("^[A-Z]") then
|
||||
if self.export_proper and name:match("^%u") then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
@ -234,7 +234,7 @@ class Block
|
||||
has_name: (name, skip_exports) =>
|
||||
if not skip_exports
|
||||
return true if @export_all
|
||||
return true if @export_proper and name\match"^[A-Z]"
|
||||
return true if @export_proper and name\match"^%u"
|
||||
|
||||
yes = @_names[name]
|
||||
if yes == nil and @parent
|
||||
|
@ -40,11 +40,28 @@ local statement_compilers = {
|
||||
end
|
||||
end,
|
||||
declare_glob = function(self, node)
|
||||
local kind = node[2]
|
||||
local names = { }
|
||||
self:set("name_glob", function(name)
|
||||
insert(names, name)
|
||||
return true
|
||||
end)
|
||||
local fn
|
||||
local _exp_0 = node[2]
|
||||
if "*" == _exp_0 then
|
||||
fn = function(name)
|
||||
if type(name) == "string" then
|
||||
insert(names, name)
|
||||
return true
|
||||
end
|
||||
end
|
||||
elseif "^" == _exp_0 then
|
||||
fn = function(name)
|
||||
if type(name) == "string" and name:match("^%u") then
|
||||
insert(names, name)
|
||||
return true
|
||||
end
|
||||
end
|
||||
else
|
||||
fn = error("unknown glob")
|
||||
end
|
||||
self:set("name_glob", fn)
|
||||
return data.DelayedLine(function(buff)
|
||||
insert(buff, "local ")
|
||||
local _list_0 = names
|
||||
|
@ -21,10 +21,24 @@ statement_compilers =
|
||||
\append_list [@name name for name in *undeclared], ", "
|
||||
|
||||
declare_glob: (node) =>
|
||||
kind = node[2]
|
||||
|
||||
names = {}
|
||||
@set "name_glob", (name) ->
|
||||
insert names, name
|
||||
true
|
||||
fn = switch node[2]
|
||||
when "*"
|
||||
(name) ->
|
||||
if type(name) == "string"
|
||||
insert names, name
|
||||
true
|
||||
when "^"
|
||||
(name) ->
|
||||
if type(name) == "string" and name\match "^%u"
|
||||
insert names, name
|
||||
true
|
||||
else
|
||||
error "unknown glob"
|
||||
|
||||
@set "name_glob", fn
|
||||
|
||||
data.DelayedLine (buff) ->
|
||||
insert buff, "local "
|
||||
|
@ -9,3 +9,27 @@ something = ->
|
||||
x = 1212
|
||||
|
||||
|
||||
do
|
||||
local *
|
||||
y = 2323
|
||||
z = 2323
|
||||
|
||||
do
|
||||
local *
|
||||
print "Nothing Here!"
|
||||
|
||||
do
|
||||
local ^
|
||||
x = 3434
|
||||
y = 3434
|
||||
X = 3434
|
||||
Y = "yeah"
|
||||
|
||||
do
|
||||
local ^
|
||||
x,y = "a", "b"
|
||||
|
||||
do
|
||||
local *
|
||||
x,y = "a", "b"
|
||||
|
||||
|
@ -5,4 +5,29 @@ local something
|
||||
something = function()
|
||||
local x
|
||||
x = 1212
|
||||
end
|
||||
do
|
||||
local y, z
|
||||
y = 2323
|
||||
z = 2323
|
||||
end
|
||||
do
|
||||
|
||||
print("Nothing Here!")
|
||||
end
|
||||
do
|
||||
local X, Y
|
||||
x = 3434
|
||||
local y = 3434
|
||||
X = 3434
|
||||
Y = "yeah"
|
||||
end
|
||||
do
|
||||
|
||||
local y
|
||||
x, y = "a", "b"
|
||||
end
|
||||
do
|
||||
local x, y
|
||||
x, y = "a", "b"
|
||||
end
|
Loading…
Reference in New Issue
Block a user