aboutsummaryrefslogtreecommitdiff
path: root/core/metaprogramming.nom
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-05-27 18:28:23 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-05-27 18:29:23 -0700
commit2e15c0fd5067318601e2f3b70ee6fc16ef58200d (patch)
tree0006e0825b2680d457bb531c3d079661b16d6bc8 /core/metaprogramming.nom
parent6ce32bdd25694d71dc232c50a008f8824f8a75ce (diff)
Some tweaks/cleanup on the nomsu code as well as adding variable
mangling to 'parse % as %' to make almost hygienic macros.
Diffstat (limited to 'core/metaprogramming.nom')
-rw-r--r--core/metaprogramming.nom19
1 files changed, 12 insertions, 7 deletions
diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom
index 76ba731..717690d 100644
--- a/core/metaprogramming.nom
+++ b/core/metaprogramming.nom
@@ -86,11 +86,14 @@ immediately
lua:append(", ", lua_var)
end
end
+ MANGLE_INDEX = (MANGLE_INDEX or 0) + 1
local function make_tree(t)
if type(t) ~= 'table' and type(t) ~= 'userdata' then
return repr(t)
elseif t.type == 'Var' and replacements[t.value] then
return replacements[t.value]
+ elseif t.type == 'Var' then
+ return t.type.."("..repr(t.value.."#"..tostring(MANGLE_INDEX))..", "..repr(t.source)..")"
elseif t.is_multi then
local bits = {}
for i, entry in ipairs(t.value) do
@@ -104,14 +107,16 @@ immediately
lua:append(")\n local tree = ", make_tree(\%longhand), "\n return nomsu:tree_to_lua(tree)\nend);")
return lua
-action [remove action %stub]
- lua> ".."
- local fn = ACTIONS[\%stub]
- local stubs = ARG_ORDERS[fn]
- for stub in pairs(stubs) do
- ACTIONS[stub] = nil
+compile [remove action %action] to
+ Lua ".."
+ do
+ local fn = ACTIONS[\(=lua "repr(\%action:get_stub())")]
+ local stubs = ARG_ORDERS[fn]
+ for stub in pairs(stubs) do
+ ACTIONS[stub] = nil
+ end
+ ARG_ORDERS[fn] = nil
end
- ARG_ORDERS[fn] = nil
immediately
action [%tree as nomsu]