aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nomsu_compiler.lua24
-rw-r--r--nomsu_compiler.moon20
2 files changed, 22 insertions, 22 deletions
diff --git a/nomsu_compiler.lua b/nomsu_compiler.lua
index 0b7de81..7e562ea 100644
--- a/nomsu_compiler.lua
+++ b/nomsu_compiler.lua
@@ -194,16 +194,23 @@ compile = function(self, tree)
end
return lua
elseif "Text" == _exp_0 then
- local lua = LuaCode:from(tree.source)
+ if #tree == 0 then
+ return LuaCode:from(tree.source, '""')
+ end
+ if #tree == 1 and type(tree[1]) == 'string' then
+ return LuaCode:from(tree.source, tree[1]:as_lua())
+ end
+ local lua = LuaCode:from(tree.source, "Text(")
local added = 0
local string_buffer = ""
local add_bit
add_bit = function(bit)
if added > 0 then
if lua:trailing_line_len() + #bit > MAX_LINE then
- lua:add("\n ")
+ lua:add(",\n ")
+ else
+ lua:add(", ")
end
- lua:add("..")
end
lua:add(bit)
added = added + 1
@@ -223,13 +230,8 @@ compile = function(self, tree)
string_buffer = ""
end
local bit_lua = self:compile(bit)
- if bit.type == "Block" and #bit == 1 then
- bit = bit[1]
- end
if bit.type == "Block" then
bit_lua = LuaCode:from(bit.source, "a_List(function(add)", "\n ", bit_lua, "\nend):joined()")
- elseif bit.type ~= "Text" then
- bit_lua = LuaCode:from(bit.source, "tostring(", bit_lua, ")")
end
add_bit(bit_lua)
_continue_0 = true
@@ -245,11 +247,9 @@ compile = function(self, tree)
string_buffer = ""
end
if added == 0 then
- add_bit('""')
- end
- if added > 1 then
- lua:parenthesize()
+ return LuaCode:from(tree.source, '""')
end
+ lua:add(")")
return lua
elseif "List" == _exp_0 or "Dict" == _exp_0 then
local typename = "a_" .. tree.type
diff --git a/nomsu_compiler.moon b/nomsu_compiler.moon
index b224fad..1b3e952 100644
--- a/nomsu_compiler.moon
+++ b/nomsu_compiler.moon
@@ -155,14 +155,19 @@ compile = (tree)=>
return lua
when "Text"
- lua = LuaCode\from(tree.source)
+ if #tree == 0
+ return LuaCode\from(tree.source, '""')
+ if #tree == 1 and type(tree[1]) == 'string'
+ return LuaCode\from(tree.source, tree[1]\as_lua!)
+ lua = LuaCode\from(tree.source, "Text(")
added = 0
string_buffer = ""
add_bit = (bit)->
if added > 0
if lua\trailing_line_len! + #bit > MAX_LINE
- lua\add "\n "
- lua\add ".."
+ lua\add ",\n "
+ else
+ lua\add ", "
lua\add bit
added += 1
@@ -176,14 +181,10 @@ compile = (tree)=>
string_buffer = ""
bit_lua = @compile(bit)
- if bit.type == "Block" and #bit == 1
- bit = bit[1]
if bit.type == "Block"
bit_lua = LuaCode\from bit.source, "a_List(function(add)",
"\n ", bit_lua,
"\nend):joined()"
- elseif bit.type != "Text"
- bit_lua = LuaCode\from(bit.source, "tostring(",bit_lua,")")
add_bit bit_lua
if string_buffer != ""
@@ -192,9 +193,8 @@ compile = (tree)=>
string_buffer = ""
if added == 0
- add_bit '""'
- if added > 1
- lua\parenthesize!
+ return LuaCode\from(tree.source, '""')
+ lua\add ")"
return lua
when "List", "Dict"