aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--code_obj.lua29
-rw-r--r--code_obj.moon21
-rw-r--r--core/metaprogramming.nom6
-rw-r--r--lib/file_hash.nom2
-rw-r--r--nomsu.lua2
-rwxr-xr-xnomsu.moon2
-rw-r--r--utils.lua3
7 files changed, 16 insertions, 49 deletions
diff --git a/code_obj.lua b/code_obj.lua
index ab0f1ac..f0440ca 100644
--- a/code_obj.lua
+++ b/code_obj.lua
@@ -101,20 +101,21 @@ do
end,
append = function(self, ...)
local n = select("#", ...)
- local bits = self.bits
+ local bits, indents = self.bits, self.indents
+ local match = string.match
for i = 1, n do
local b = select(i, ...)
assert(b ~= self, "No recursion please.")
bits[#bits + 1] = b
if type(b) == 'string' then
do
- local spaces = b:match("\n([ ]*)[^\n]*$")
+ local spaces = match(b, "\n([ ]*)[^\n]*$")
if spaces then
self.current_indent = #spaces
end
end
elseif self.current_indent ~= 0 then
- self.indents[#bits] = self.current_indent
+ indents[#bits] = self.current_indent
end
end
self.__str = nil
@@ -151,26 +152,8 @@ do
_class_0 = setmetatable({
__init = function(self, source, ...)
self.source = source
- self.bits = {
- ...
- }
- local indent, indents = 0, { }
- local match = string.match
- for i, b in ipairs(self.bits) do
- if type(b) == 'string' then
- do
- local spaces = match(b, "\n([ ]*)[^\n]*$")
- if spaces then
- indent = #spaces
- end
- end
- elseif indent ~= 0 then
- indents[i] = indent
- end
- end
- self.current_indent = indent
- self.indents = indents
- self.__str = nil
+ self.bits, self.indents, self.current_indent = { }, { }, 0
+ self:append(...)
if type(self.source) == 'string' then
local filename, start, stop = self.source:match("^(.-)%[(%d+):(%d+)%]$")
if not (filename) then
diff --git a/code_obj.moon b/code_obj.moon
index fbe202c..66b7978 100644
--- a/code_obj.moon
+++ b/code_obj.moon
@@ -62,18 +62,8 @@ Source = immutable {"filename","start","stop"}, {
class Code
new: (@source, ...)=>
- @bits = {...}
- indent, indents = 0, {}
- match = string.match
- for i,b in ipairs @bits
- if type(b) == 'string'
- if spaces = match(b, "\n([ ]*)[^\n]*$")
- indent = #spaces
- elseif indent != 0
- indents[i] = indent
- @current_indent = indent
- @indents = indents
- @__str = nil
+ @bits, @indents, @current_indent = {}, {}, 0
+ @append(...)
if type(@source) == 'string'
filename,start,stop = @source\match("^(.-)%[(%d+):(%d+)%]$")
unless filename
@@ -91,16 +81,17 @@ class Code
append: (...)=>
n = select("#",...)
- bits = @bits
+ bits, indents = @bits, @indents
+ match = string.match
for i=1,n
b = select(i, ...)
assert(b != self, "No recursion please.")
bits[#bits+1] = b
if type(b) == 'string'
- if spaces = b\match("\n([ ]*)[^\n]*$")
+ if spaces = match(b, "\n([ ]*)[^\n]*$")
@current_indent = #spaces
elseif @current_indent != 0
- @indents[#bits] = @current_indent
+ indents[#bits] = @current_indent
@__str = nil
prepend: (...)=>
diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom
index 9d6e1e6..6c5221c 100644
--- a/core/metaprogramming.nom
+++ b/core/metaprogramming.nom
@@ -101,11 +101,7 @@ immediately
return t.type.."("..make_tree(t.value)..")"
end
end
- lua:append([[)
- local tree = ]], make_tree(\%longhand), [[
-
- return nomsu:tree_to_lua(tree)
- end);]])
+ lua:append(")\n local tree = ", make_tree(\%longhand), "\n return nomsu:tree_to_lua(tree)\nend);")
return lua
action [remove action %stub]
diff --git a/lib/file_hash.nom b/lib/file_hash.nom
index 9a707c3..1f263de 100644
--- a/lib/file_hash.nom
+++ b/lib/file_hash.nom
@@ -3,7 +3,7 @@ use "core"
action [file with hash %hash]
lua> ".."
local Hash = require("openssl.digest")
- for filename in io.popen('find -L . -type f -name "*.nom"'):lines() do
+ for filename in io.popen('find -L . -not -path "*/\\\\.*" -type f -name "*.nom"'):lines() do
local file = io.open(filename)
local contents = file:read("*a")
file:close()
diff --git a/nomsu.lua b/nomsu.lua
index 10a3b66..4d80357 100644
--- a/nomsu.lua
+++ b/nomsu.lua
@@ -89,7 +89,7 @@ all_files = function(path)
end
path = path:gsub("\\", "\\\\"):gsub("`", ""):gsub('"', '\\"'):gsub("$", "")
return coroutine.wrap(function()
- local f = io.popen('find -L "' .. path .. '" -type f -name "*.nom"')
+ local f = io.popen('find -L "' .. path .. '" -not -path "*/\\.*" -type f -name "*.nom"')
for line in f:lines() do
coroutine.yield(line)
end
diff --git a/nomsu.moon b/nomsu.moon
index 50a95d9..d8ae4e0 100755
--- a/nomsu.moon
+++ b/nomsu.moon
@@ -78,7 +78,7 @@ all_files = (path)->
-- TODO: improve sanitization
path = path\gsub("\\","\\\\")\gsub("`","")\gsub('"','\\"')\gsub("$","")
return coroutine.wrap ->
- f = io.popen('find -L "'..path..'" -type f -name "*.nom"')
+ f = io.popen('find -L "'..path..'" -not -path "*/\\.*" -type f -name "*.nom"')
for line in f\lines!
coroutine.yield(line)
success = f\close!
diff --git a/utils.lua b/utils.lua
index d9d64c3..c78a0c8 100644
--- a/utils.lua
+++ b/utils.lua
@@ -49,9 +49,6 @@ local function repr(x, depth)
return "{"..table.concat(ret, ", ").."}"
end
elseif x_type == 'string' then
- if x == "\n" then
- return "'\\n'"
- end
local escaped = x:gsub("\\", "\\\\"):gsub("\n","\\n"):gsub('"', '\\"')
return '"'..escaped..'"'
else