aboutsummaryrefslogtreecommitdiff
path: root/nomsu.lua
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-01-03 00:52:01 -0800
committerBruce Hill <bitbucket@bruce-hill.com>2018-01-03 00:52:01 -0800
commitcfee75b21b307b5d57c215cad5b1c089c91182fc (patch)
treee6d605892aced717a4519f7860c0b143d11819a6 /nomsu.lua
parent3bd12b5331f7e5ec939cb8130350ea68fcbd6ceb (diff)
Reworked {} a bit and added dicts to the core language. Did some more
testing on string interpolations too.
Diffstat (limited to 'nomsu.lua')
-rw-r--r--nomsu.lua57
1 files changed, 57 insertions, 0 deletions
diff --git a/nomsu.lua b/nomsu.lua
index 6a9a792..a0be840 100644
--- a/nomsu.lua
+++ b/nomsu.lua
@@ -740,6 +740,8 @@ end);]]):format(concat(buffer, "\n"))
else
return longbuff, false
end
+ elseif "Dict" == _exp_0 then
+ return error("Sorry, not yet implemented.")
elseif "Number" == _exp_0 then
return repr(tree.value), true
elseif "Var" == _exp_0 then
@@ -955,6 +957,32 @@ end)]]):format(concat(lua_bits, "\n"))
insert(items, expr)
end
return self.__class:comma_separated_items("{", items, "}"), nil
+ elseif "Dict" == _exp_0 then
+ local items = { }
+ local _list_0 = tree.value
+ for _index_0 = 1, #_list_0 do
+ local entry = _list_0[_index_0]
+ local key_expr, key_statement
+ if entry.dict_key.type == "Word" then
+ key_expr, key_statement = repr(entry.dict_key.value), nil
+ else
+ key_expr, key_statement = self:tree_to_lua(entry.dict_key, filename)
+ end
+ if key_statement then
+ self:error("Cannot use [[" .. tostring(entry.dict_key.src) .. "]] as a dict key, since it's not an expression.")
+ end
+ local value_expr, value_statement = self:tree_to_lua(entry.dict_value, filename)
+ if value_statement then
+ self:error("Cannot use [[" .. tostring(entry.dict_value.src) .. "]] as a dict value, since it's not an expression.")
+ end
+ local key_str = key_expr:match([=[["']([a-zA-Z_][a-zA-Z0-9_]*)['"]]=])
+ if key_str then
+ insert(items, tostring(key_str) .. "=" .. tostring(value_expr))
+ else
+ insert(items, "[" .. tostring(key_expr) .. "]=" .. tostring(value_expr))
+ end
+ end
+ return self.__class:comma_separated_items("{", items, "}"), nil
elseif "Number" == _exp_0 then
return repr(tree.value), nil
elseif "Var" == _exp_0 then
@@ -982,6 +1010,13 @@ end)]]):format(concat(lua_bits, "\n"))
local v = _list_0[_index_0]
self:walk_tree(v, depth + 1)
end
+ elseif "Dict" == _exp_0 then
+ local _list_0 = tree.value
+ for _index_0 = 1, #_list_0 do
+ local e = _list_0[_index_0]
+ self:walk_tree(e.dict_key, depth + 1)
+ self:walk_tree(e.dict_value, depth + 1)
+ end
else
self:walk_tree(tree.value, depth + 1)
end
@@ -1034,6 +1069,28 @@ end)]]):format(concat(lua_bits, "\n"))
end
tree.value = new_value
end
+ elseif "Dict" == _exp_0 then
+ local dirty = false
+ local replacements = { }
+ for i, e in ipairs(tree.value) do
+ local new_key = self:replaced_vars(e.dict_key, vars)
+ local new_value = self:replaced_vars(e.dict_value, vars)
+ dirty = dirty or (new_key ~= e.dict_key or new_value ~= e.dict_value)
+ replacements[i] = {
+ dict_key = new_key,
+ dict_value = new_value
+ }
+ end
+ if dirty then
+ do
+ local _tbl_0 = { }
+ for k, v in pairs(tree) do
+ _tbl_0[k] = v
+ end
+ tree = _tbl_0
+ end
+ tree.value = replacements
+ end
elseif nil == _exp_0 then
local new_values = { }
local any_different = false