diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-09-10 15:55:34 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-09-10 15:56:00 -0700 |
| commit | 43e6523fd42f736acfcd0c32d82246c262e07a1d (patch) | |
| tree | 5a2d6b5250528dc42ce7433374cac6c0c65859a9 /nomsu_compiler.lua | |
| parent | 603c5b12451d6c68b1e41906e10117da4d99e362 (diff) | |
Shifting towards more text methods instead of text global functions.
Also fixed a bug with method call parenthesizing.
Diffstat (limited to 'nomsu_compiler.lua')
| -rw-r--r-- | nomsu_compiler.lua | 28 |
1 files changed, 8 insertions, 20 deletions
diff --git a/nomsu_compiler.lua b/nomsu_compiler.lua index 02460b3..215617f 100644 --- a/nomsu_compiler.lua +++ b/nomsu_compiler.lua @@ -4,10 +4,10 @@ local utils = require('utils') local Files = require('files') local repr, stringify, equivalent repr, stringify, equivalent = utils.repr, utils.stringify, utils.equivalent -local List, Dict +local List, Dict, Text do local _obj_0 = require('containers') - List, Dict = _obj_0.List, _obj_0.Dict + List, Dict, Text = _obj_0.List, _obj_0.Dict, _obj_0.Text end colors = require('consolecolors') colored = setmetatable({ }, { @@ -74,23 +74,6 @@ table.copy = function(t) return _tbl_0 end)(), getmetatable(t)) end -do - local STRING_METATABLE = getmetatable("") - STRING_METATABLE.__add = function(self, other) - return self .. stringify(other) - end - STRING_METATABLE.__index = function(self, i) - local ret = string[i] - if ret ~= nil then - return ret - end - if type(i) == 'number' then - return sub(self, i, i) - elseif type(i) == 'table' then - return sub(self, i[1], i[2]) - end - end -end local MAX_LINE = 80 local NomsuCompiler = setmetatable({ name = "Nomsu" @@ -531,7 +514,12 @@ do end local lua = LuaCode.Value(tree.source) if tree.target then - lua:append(self:compile(tree.target), ":") + local target_lua = self:compile(tree.target) + if tostring(target_lua):match("^%(.*%)$") or tostring(target_lua):match("^[_a-zA-Z][_a-zA-Z0-9]*$") then + lua:append(target_lua, ":") + else + lua:append("(", target_lua, "):") + end end lua:append(string.as_lua_id(stub), "(") local args = { } |
