aboutsummaryrefslogtreecommitdiff
path: root/nomsu.lua
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2017-09-18 22:41:50 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2017-09-18 22:41:50 -0700
commit2c4acdfe67e05fba88d4c48509c8767d2dce358b (patch)
treed72f52122d4b372d832c69bd9a21d0da34323de5 /nomsu.lua
parent15886aa57978cbd236ff6ac3bc16adf0941ca299 (diff)
More major overhaulage.
Diffstat (limited to 'nomsu.lua')
-rw-r--r--nomsu.lua50
1 files changed, 48 insertions, 2 deletions
diff --git a/nomsu.lua b/nomsu.lua
index 443b663..6a4793d 100644
--- a/nomsu.lua
+++ b/nomsu.lua
@@ -203,7 +203,43 @@ do
self.defs[invocation] = fn_info
end
end,
+ get_invocations_from_definition = function(self, def, vars)
+ if def.type == "String" or def.type == "List" then
+ return self:tree_to_value(def, vars)
+ end
+ if def.type ~= "Thunk" then
+ self:error("Trying to get invocations from " .. tostring(def.type) .. ", but expected Thunk.")
+ end
+ local invocations = { }
+ local _list_0 = def.value.value
+ for _index_0 = 1, #_list_0 do
+ local statement = _list_0[_index_0]
+ if statement.value.type ~= "FunctionCall" then
+ self:error("Invalid statement type: " .. tostring(statement.value.type) .. ", expected FunctionCall")
+ end
+ local name_bits = { }
+ local _list_1 = statement.value.value
+ for _index_1 = 1, #_list_1 do
+ local token = _list_1[_index_1]
+ if token.type == "Word" then
+ table.insert(name_bits, token.value)
+ elseif token.value.type == "Var" then
+ table.insert(name_bits, token.value.src)
+ else
+ self:error("Unexpected token type in definition: " .. tostring(token.value.type) .. " (expected Word or Var)")
+ end
+ end
+ table.insert(invocations, table.concat(name_bits, " "))
+ end
+ return invocations
+ end,
get_invocations = function(self, text)
+ if not text then
+ self:error("No text provided!")
+ end
+ if type(text) == 'function' then
+ error("Function passed to get_invocations")
+ end
if type(text) == 'string' then
text = {
text
@@ -764,11 +800,21 @@ do
if kind == "Expression" then
error("Expected to be in statement.")
end
- return "do\n" .. self:tree_to_value(vars.lua_code, vars) .. "\nend", true
+ local inner_vars = setmetatable({ }, {
+ __index = function(_, key)
+ return "vars[" .. tostring(utils.repr(key, true)) .. "]"
+ end
+ })
+ return "do\n" .. self:tree_to_value(vars.lua_code, inner_vars) .. "\nend", true
end)
self:defmacro([[lua expr %lua_code]], function(self, vars, kind)
local lua_code = vars.lua_code.value
- return self:tree_to_value(vars.lua_code, vars)
+ local inner_vars = setmetatable({ }, {
+ __index = function(_, key)
+ return "vars[" .. tostring(utils.repr(key, true)) .. "]"
+ end
+ })
+ return self:tree_to_value(vars.lua_code, inner_vars)
end)
return self:def("run file %filename", function(self, vars)
local file = io.open(vars.filename)