diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2019-01-22 16:54:56 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2019-01-22 16:55:21 -0800 |
| commit | c59401c8ffb1d99bfeb72ba249865e6ef0d95845 (patch) | |
| tree | 00ebc5105a5c264e9bfa808dcdacbea588c5b3ce /nomsu_compiler.moon | |
| parent | f746ba34d799e6560df1aad1cad15a70b34914d1 (diff) | |
Switched compiler to produce Text("hello ", name) instead of ("hello
"..tostring(name))
Diffstat (limited to 'nomsu_compiler.moon')
| -rw-r--r-- | nomsu_compiler.moon | 20 |
1 files changed, 10 insertions, 10 deletions
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" |
