aboutsummaryrefslogtreecommitdiff
path: root/lib/metaprogramming.nom
diff options
context:
space:
mode:
Diffstat (limited to 'lib/metaprogramming.nom')
-rw-r--r--lib/metaprogramming.nom33
1 files changed, 17 insertions, 16 deletions
diff --git a/lib/metaprogramming.nom b/lib/metaprogramming.nom
index d396ac3..1286412 100644
--- a/lib/metaprogramming.nom
+++ b/lib/metaprogramming.nom
@@ -1,8 +1,8 @@
#..
- This File contains rules for making rules and macros and some helper functions to make
+ This File contains actions for making actions and macros and some helper functions to make
that easier.
-# Rule to make macros:
+# Helper function
immediately:
lua> ".."
nomsu.parse_spec = function(nomsu, spec)
@@ -17,6 +17,7 @@ immediately:
return signature, args;
end
+# Macro to make macros:
immediately:
lua> ".."
nomsu:defmacro("compile %macro_def to %body", \(__line_no__), function(nomsu, \%macro_def, \%body)
@@ -60,14 +61,14 @@ immediately:
return {statements=lua};
end, \(__src__ 1));
-# Rule to make rules:
+# Macro to make actions:
immediately:
- compile [rule %signature = %body] to code:
+ compile [action %signature %body] to code:
lua> ".."
nomsu:assert(\%signature.type == "List",
- "Invalid type for rule definition signature. Expected List, but got: "..tostring(\%signature.type));
+ "Invalid type for action definition signature. Expected List, but got: "..tostring(\%signature.type));
nomsu:assert(\%body.type == "Block",
- "Invalid type for rule definition body. Expected Block, but got: "..tostring(\%body.type));
+ "Invalid type for action definition body. Expected Block, but got: "..tostring(\%body.type));
local signature, args = nomsu:parse_spec(\%signature);
local body_lua = nomsu:tree_to_lua(\%body);
body_lua = body_lua.statements or ("return "..body_lua.expr..";");
@@ -78,7 +79,7 @@ immediately:
end, %s);]]):format(signature, args, body_lua, nomsu:repr(src));
return def_lua;
-# Rule to make nomsu macros:
+# Macro to make nomsu macros:
immediately:
lua> ".."
nomsu:defmacro("parse %shorthand as %longhand", \(__line_no__), (function(nomsu, \%shorthand, \%longhand)
@@ -106,7 +107,7 @@ immediately:
return {statements=lua_code};
end), \(__src__ 1));
-rule [remove rule %stub] =:
+action [remove action %stub]:
lua> ".."
local def = nomsu.defs[\%stub];
for _, alias in ipairs(def.aliases) do
@@ -114,13 +115,13 @@ rule [remove rule %stub] =:
end
immediately:
- rule [%tree as lua] =:
+ action [%tree as lua]:
=lua "nomsu:tree_to_lua(\%tree).expr"
- rule [%tree as lua statements] =:
+ action [%tree as lua statements]:
lua> ".."
local lua = nomsu:tree_to_lua(\%tree);
return lua.statements or (lua.expr..";");
- rule [%tree as value] =:
+ action [%tree as value]:
=lua "nomsu:tree_to_value(\%tree)"
compile [repr %obj] to:
"nomsu:repr(\(%obj as lua))"
@@ -144,22 +145,22 @@ compile [nomsu %method %args] to: "nomsu[\(%method as lua)](nomsu, unpack(\(%arg
compile [tree %tree with %replacements] to: ".."
nomsu:replaced_vars(\(%tree as lua), \(%replacements as lua))
-parse [rule %signature] as:
+parse [action %signature] as:
(nomsu's "defs")->(nomsu "get_stub" [\%signature])
# Get the source code for a function
-rule [help %rule] =:
+action [help %action]:
lua> ".."
- local fn_def = nomsu.defs[nomsu:get_stub(\%rule)]
+ local fn_def = nomsu.defs[nomsu:get_stub(\%action)]
if not fn_def then
- nomsu:writeln("Rule not found: "..nomsu:repr(\%rule));
+ nomsu:writeln("Action not found: "..nomsu:repr(\%action));
else
nomsu:writeln(fn_def.src or "<unknown source code>");
end
# Compiler tools
parse [eval %code, run %code] as: nomsu "run" [%code]
-rule [source code from tree %tree] =:
+action [source code from tree %tree]:
lua> ".."
local _,_,leading_space = \%tree.src:find("\\n(%s*)%S");
if leading_space then