diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-07-10 17:34:39 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-07-10 17:34:50 -0700 |
| commit | 194146d36591e6c3a964667ead9109bbc6e00524 (patch) | |
| tree | fa2801b488f55f48bbd9a41f49585d125a54b180 /nomsu_compiler.lua | |
| parent | 26a6174f28191fe3364e30c76c1c7a5814e7c5ab (diff) | |
Improving codegen line wrapping.
Diffstat (limited to 'nomsu_compiler.lua')
| -rw-r--r-- | nomsu_compiler.lua | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/nomsu_compiler.lua b/nomsu_compiler.lua index 103a31e..3c1102f 100644 --- a/nomsu_compiler.lua +++ b/nomsu_compiler.lua @@ -150,7 +150,7 @@ local NomsuCompiler = setmetatable({ }, { end }) do - NomsuCompiler.NOMSU_COMPILER_VERSION = 3 + NomsuCompiler.NOMSU_COMPILER_VERSION = 4 NomsuCompiler.NOMSU_SYNTAX_VERSION = Parser.version NomsuCompiler._ENV = NomsuCompiler NomsuCompiler.nomsu = NomsuCompiler @@ -259,20 +259,14 @@ do end local add_lua_string_bits add_lua_string_bits = function(self, val_or_stmt, code) - local line_len = 0 local cls_str = val_or_stmt == "value" and "LuaCode.Value(" or "LuaCode(" if code.type ~= "Text" then return LuaCode(code.source, cls_str, repr(tostring(code.source)), ", ", self:compile(code), ")") end local add_bit_lua add_bit_lua = function(lua, bit_lua) - line_len = line_len + #tostring(bit_lua) - if line_len > MAX_LINE then - lua:append(",\n ") - line_len = 4 - else - lua:append(", ") - end + local bit_leading_len = #(tostring(bit_lua):match("^[^\n]*")) + lua:append(lua.trailing_line_len + bit_leading_len > MAX_LINE and ",\n " or ", ") return lua:append(bit_lua) end local operate_on_text |
