aboutsummaryrefslogtreecommitdiff
path: root/nomsu_compiler.moon
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2018-11-29 14:23:02 -0800
committerBruce Hill <bruce@bruce-hill.com>2018-11-29 14:23:17 -0800
commit7a7dcefc447c4a4b20755fb6fb919a2f6328eafd (patch)
tree7fd40f9cb9d610ea60a444172f78763ecbc17d55 /nomsu_compiler.moon
parent04c80440fb503a604cd0cfd6b316add7d9b99f7a (diff)
Added text comprehensions (in the style of the list/dict ones)
Diffstat (limited to 'nomsu_compiler.moon')
-rw-r--r--nomsu_compiler.moon10
1 files changed, 10 insertions, 0 deletions
diff --git a/nomsu_compiler.moon b/nomsu_compiler.moon
index a818c99..0266dab 100644
--- a/nomsu_compiler.moon
+++ b/nomsu_compiler.moon
@@ -227,7 +227,17 @@ compile = setmetatable({
lua\append string_buffer
added += 1
string_buffer = ""
+
bit_lua = compile(bit)
+ if bit.type == "Block"
+ bit_lua = LuaCode\from bit.source, "(function()",
+ "\n local _buffer = List{}",
+ "\n local function add(bit) _buffer:add(bit) end",
+ "\n local function join_with(glue) _buffer = _buffer:joined_with(glue) end",
+ "\n ", bit_lua,
+ "\n if lua_type_of(_buffer) == 'table' then _buffer = _buffer:joined() end",
+ "\n return _buffer",
+ "\nend)()"
if lua\trailing_line_len! + #bit_lua\text! > MAX_LINE
lua\append "\n "
if added > 0 then lua\append ".."