aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nomsu.lua10
-rwxr-xr-xnomsu.moon11
2 files changed, 18 insertions, 3 deletions
diff --git a/nomsu.lua b/nomsu.lua
index 9663a9e..d79c8ab 100644
--- a/nomsu.lua
+++ b/nomsu.lua
@@ -412,7 +412,7 @@ do
end
end
for k, v in pairs(scope["#vars"] or { }) do
- insert(buff, "<@" .. tostring(k) .. "> = " .. tostring(self:value_to_nomsu(v)))
+ insert(buff, "<%" .. tostring(k) .. "> = " .. tostring(self:value_to_nomsu(v)))
end
return concat(buff, "\n")
end,
@@ -853,6 +853,14 @@ end);]]):format(concat(buffer, "\n"))
return _accum_0
end)(), "; ")) .. "})"
end
+ elseif "string" == _exp_0 then
+ if value == "\n" then
+ return "'\\n'"
+ elseif not value:find([["]]) and not value:find("\n") and not value:find("\\") then
+ return "\"" .. value .. "\""
+ else
+ return '".."\n ' .. (self:indent(value))
+ end
else
return error("Unsupported value_to_nomsu type: " .. tostring(type(value)))
end
diff --git a/nomsu.moon b/nomsu.moon
index 9ca17e0..e9907bd 100755
--- a/nomsu.moon
+++ b/nomsu.moon
@@ -37,7 +37,6 @@ if _VERSION == "Lua 5.1"
-- type checking?
-- Fix compiler bug that breaks when file ends with a block comment
-- Add compiler options for optimization level (compile-fast vs. run-fast, etc.)
--- Change longstrings to be "..\n content\n.."
-- Change precompiling from producing lua code to producing lua> "code" nomsu files
lpeg.setmaxstack 10000 -- whoa
@@ -309,7 +308,7 @@ class NomsuCompiler
insert buff, "using:\n #{@indent @serialize_defs(_using)}\n..do:\n #{@indent concat(_using_do, "\n")}"
for k,v in pairs(scope["#vars"] or {})
- insert buff, "<@#{k}> = #{@value_to_nomsu v}"
+ insert buff, "<%#{k}> = #{@value_to_nomsu v}"
return concat buff, "\n"
@@ -591,6 +590,14 @@ end);]])\format(concat(buffer, "\n"))
return "[#{concat [@value_to_nomsu(v) for v in *value], ", "}]"
else
return "(d{#{concat ["#{@value_to_nomsu(k)}=#{@value_to_nomsu(v)}" for k,v in pairs(value)], "; "}})"
+ when "string"
+ if value == "\n"
+ return "'\\n'"
+ elseif not value\find[["]] and not value\find"\n" and not value\find"\\"
+ return "\""..value.."\""
+ else
+ -- TODO: This might fail if it's being put inside a list or something
+ return '".."\n '..(@indent value)
else
error("Unsupported value_to_nomsu type: #{type(value)}")