From 0759cd640e36be5f4fffd1d01d16708f7ef04e9b Mon Sep 17 00:00:00 2001 From: leaf corcoran Date: Sat, 12 Jan 2013 10:33:12 -0800 Subject: [PATCH] local glob tests and local ^ --- moonscript/compile.lua | 2 +- moonscript/compile.moon | 2 +- moonscript/compile/statement.lua | 25 +++++++++++++++++++++---- moonscript/compile/statement.moon | 20 +++++++++++++++++--- tests/inputs/local.moon | 24 ++++++++++++++++++++++++ tests/outputs/local.lua | 25 +++++++++++++++++++++++++ 6 files changed, 89 insertions(+), 9 deletions(-) diff --git a/moonscript/compile.lua b/moonscript/compile.lua index 57fd30b..36a4c10 100644 --- a/moonscript/compile.lua +++ b/moonscript/compile.lua @@ -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 diff --git a/moonscript/compile.moon b/moonscript/compile.moon index c6249c8..3eab635 100644 --- a/moonscript/compile.moon +++ b/moonscript/compile.moon @@ -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 diff --git a/moonscript/compile/statement.lua b/moonscript/compile/statement.lua index 49b4812..77c17d1 100644 --- a/moonscript/compile/statement.lua +++ b/moonscript/compile/statement.lua @@ -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 diff --git a/moonscript/compile/statement.moon b/moonscript/compile/statement.moon index 704aaad..72ce9ae 100644 --- a/moonscript/compile/statement.moon +++ b/moonscript/compile/statement.moon @@ -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 " diff --git a/tests/inputs/local.moon b/tests/inputs/local.moon index 8f30e86..ba1a800 100644 --- a/tests/inputs/local.moon +++ b/tests/inputs/local.moon @@ -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" + diff --git a/tests/outputs/local.lua b/tests/outputs/local.lua index b76663c..830b7b0 100644 --- a/tests/outputs/local.lua +++ b/tests/outputs/local.lua @@ -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 \ No newline at end of file