Consolidating code obj code and expunging all [[..]]-style lua strings.

This commit is contained in:
Bruce Hill 2018-05-24 16:13:23 -07:00
parent 0c07968e07
commit 446892d11e
7 changed files with 16 additions and 49 deletions

View File

@ -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

View File

@ -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: (...)=>

View File

@ -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]

View File

@ -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()

View File

@ -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

View File

@ -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!

View File

@ -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