Renamed replaced_vars() to be more descriptive.

This commit is contained in:
Bruce Hill 2018-01-12 16:45:36 -08:00
parent b4a0267f71
commit 90c72074db
3 changed files with 17 additions and 17 deletions

View File

@ -100,7 +100,7 @@ immediately:
local lua_code = ([[
nomsu:define_compile_action(%s, %s, (function(%s)
local template = nomsu:parse(%s, %s);
local replacement = nomsu:replaced_vars(template, %s);
local replacement = nomsu:tree_with_replaced_vars(template, %s);
return nomsu:tree_to_lua(replacement);
end), %s)]]):format(names, repr(\%shorthand:get_line_no()), args, template,
repr(\%shorthand:get_line_no()), replacements, repr(nomsu:source_code(0)));
@ -143,7 +143,7 @@ compile [nomsu] to: "nomsu"
compile [nomsu's %key] to: "nomsu[\(%key as lua)]"
compile [nomsu %method %args] to: "nomsu[\(%method as lua)](nomsu, unpack(\(%args as lua)))"
compile [tree %tree with %replacements] to: ".."
nomsu:replaced_vars(\(%tree as lua), \(%replacements as lua))
nomsu:tree_with_replaced_vars(\(%tree as lua), \(%replacements as lua))
parse [action %names] as:
(nomsu's "defs")->(nomsu "get_stub" [\%names])

View File

@ -996,17 +996,17 @@ do
end
return concat(bits, "\n")
end,
replaced_vars = function(self, tree, vars)
tree_with_replaced_vars = function(self, tree, replacements)
if type(tree) ~= 'table' then
return tree
end
local _exp_0 = tree.type
if "Var" == _exp_0 then
if vars[tree.value] ~= nil then
tree = vars[tree.value]
if replacements[tree.value] ~= nil then
tree = replacements[tree.value]
end
elseif "File" == _exp_0 or "Nomsu" == _exp_0 or "Block" == _exp_0 or "List" == _exp_0 or "FunctionCall" == _exp_0 or "Text" == _exp_0 then
local new_value = self:replaced_vars(tree.value, vars)
local new_value = self:tree_with_replaced_vars(tree.value, replacements)
if new_value ~= tree.value then
do
local _tbl_0 = { }
@ -1019,10 +1019,10 @@ do
end
elseif "Dict" == _exp_0 then
local dirty = false
local replacements = { }
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)
local new_key = self:tree_with_replaced_vars(e.dict_key, replacements)
local new_value = self:tree_with_replaced_vars(e.dict_value, replacements)
dirty = dirty or (new_key ~= e.dict_key or new_value ~= e.dict_value)
replacements[i] = {
dict_key = new_key,
@ -1043,7 +1043,7 @@ do
local new_values = { }
local any_different = false
for k, v in pairs(tree) do
new_values[k] = self:replaced_vars(v, vars)
new_values[k] = self:tree_with_replaced_vars(v, replacements)
any_different = any_different or (new_values[k] ~= tree[k])
end
if any_different then

View File

@ -677,14 +677,14 @@ class NomsuCompiler
insert bits, close
return concat(bits)
replaced_vars: (tree, vars)=>
tree_with_replaced_vars: (tree, replacements)=>
if type(tree) != 'table' then return tree
switch tree.type
when "Var"
if vars[tree.value] ~= nil
tree = vars[tree.value]
if replacements[tree.value] ~= nil
tree = replacements[tree.value]
when "File", "Nomsu", "Block", "List", "FunctionCall", "Text"
new_value = @replaced_vars tree.value, vars
new_value = @tree_with_replaced_vars tree.value, replacements
if new_value != tree.value
tree = {k,v for k,v in pairs(tree)}
tree.value = new_value
@ -692,8 +692,8 @@ class NomsuCompiler
dirty = false
replacements = {}
for i,e in ipairs tree.value
new_key = @replaced_vars e.dict_key, vars
new_value = @replaced_vars e.dict_value, vars
new_key = @tree_with_replaced_vars e.dict_key, replacements
new_value = @tree_with_replaced_vars e.dict_value, replacements
dirty or= new_key != e.dict_key or new_value != e.dict_value
replacements[i] = {dict_key:new_key, dict_value:new_value}
if dirty
@ -703,7 +703,7 @@ class NomsuCompiler
new_values = {}
any_different = false
for k,v in pairs tree
new_values[k] = @replaced_vars v, vars
new_values[k] = @tree_with_replaced_vars v, replacements
any_different or= (new_values[k] != tree[k])
if any_different
tree = new_values