diff options
Diffstat (limited to 'nomsu_compiler.moon')
| -rw-r--r-- | nomsu_compiler.moon | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/nomsu_compiler.moon b/nomsu_compiler.moon index bae3f11..7a637f4 100644 --- a/nomsu_compiler.moon +++ b/nomsu_compiler.moon @@ -14,7 +14,7 @@ re = require 're' utils = require 'utils' Files = require 'files' {:repr, :stringify, :equivalent} = utils -{:List, :Dict} = require 'containers' +{:List, :Dict, :Text} = require 'containers' export colors, colored colors = require 'consolecolors' colored = setmetatable({}, {__index:(_,color)-> ((msg)-> colors[color]..tostring(msg or '')..colors.reset)}) @@ -57,18 +57,6 @@ table.copy = (t)-> setmetatable({k,v for k,v in pairs(t)}, getmetatable(t)) -- consider non-linear codegen, rather than doing thunks for things like comprehensions -- Re-implement nomsu-to-lua comment translation? --- Use + operator for string coercive concatenation (note: "asdf" + 3 == "asdf3") --- Use [] for accessing string characters, or s[{3,4}] for s:sub(3,4) --- Note: This globally affects all strings in this instance of Lua! -do - STRING_METATABLE = getmetatable("") - STRING_METATABLE.__add = (other)=> @ .. stringify(other) - STRING_METATABLE.__index = (i)=> - ret = string[i] - if ret != nil then return ret - if type(i) == 'number' then return sub(@, i, i) - elseif type(i) == 'table' then return sub(@, i[1], i[2]) - MAX_LINE = 80 -- For beautification purposes, try not to make lines much longer than this value NomsuCompiler = setmetatable {name:"Nomsu"}, __index: (k)=> if _self = rawget(@, "self") then _self[k] else nil @@ -339,8 +327,12 @@ with NomsuCompiler return ret lua = LuaCode.Value(tree.source) - if tree.target - lua\append @compile(tree.target), ":" + if tree.target -- Method call + target_lua = @compile tree.target + if tostring(target_lua)\match("^%(.*%)$") or tostring(target_lua)\match("^[_a-zA-Z][_a-zA-Z0-9]*$") + lua\append target_lua, ":" + else + lua\append "(", target_lua, "):" lua\append(string.as_lua_id(stub),"(") args = {} for i, tok in ipairs tree |
