aboutsummaryrefslogtreecommitdiff
path: root/nomsu.lua
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-05-10 22:47:03 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-05-10 22:47:18 -0700
commit4126589afef1c3c14cfa5a3a0f43cc6e98569f1d (patch)
tree3a6aee67f531c76f2b979f4b81cba5fc53b3fc6e /nomsu.lua
parent77c11a2443adb883621b4253d63fe40db048bd85 (diff)
Cleanup: removed "File" type trees (now just Block), overhauled
how_do_i.nom, added "result of %" macro, which allowed comprehensions to be way more concisely defined. Moved len() operator into the nomsu environment.
Diffstat (limited to 'nomsu.lua')
-rw-r--r--nomsu.lua32
1 files changed, 30 insertions, 2 deletions
diff --git a/nomsu.lua b/nomsu.lua
index 3a29261..43fafab 100644
--- a/nomsu.lua
+++ b/nomsu.lua
@@ -375,7 +375,6 @@ do
end
local tree = self:parse(nomsu_code)
assert(tree, "Failed to parse: " .. tostring(nomsu_code))
- assert(tree.type == "File", "Attempt to run non-file: " .. tostring(tree.type))
local lua = tree:as_lua(self)
lua:convert_to_statements()
lua:declare_locals()
@@ -492,7 +491,7 @@ do
return
end
local _exp_0 = tree.type
- if "List" == _exp_0 or "File" == _exp_0 or "Block" == _exp_0 or "Action" == _exp_0 or "Text" == _exp_0 or "IndexChain" == _exp_0 then
+ if "List" == _exp_0 or "Block" == _exp_0 or "Action" == _exp_0 or "Text" == _exp_0 or "IndexChain" == _exp_0 then
local _list_0 = tree.value
for _index_0 = 1, #_list_0 do
local v = _list_0[_index_0]
@@ -543,6 +542,18 @@ do
return tree:map(fn)
end,
tree_with_replaced_vars = function(self, tree, replacements)
+ if not (next(replacements)) then
+ return tree
+ end
+ if next(replacements).type == "Var" then
+ do
+ local _tbl_0 = { }
+ for k, v in pairs(replacements) do
+ _tbl_0[self:var_to_lua_identifier(k)] = v
+ end
+ replacements = _tbl_0
+ end
+ end
return tree:map(function(t)
if t.type == "Var" then
local id = tostring(t:as_lua(self))
@@ -737,6 +748,23 @@ do
load = load,
ipairs = ipairs
}
+ if jit then
+ self.environment.len = function(x)
+ do
+ local mt = getmetatable(x)
+ if mt then
+ if mt.__len then
+ return mt.__len(x)
+ end
+ end
+ end
+ return #x
+ end
+ else
+ self.environment.len = (function(x)
+ return #x
+ end)
+ end
for k, v in pairs(Types) do
self.environment[k] = v
end