aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-05-03 21:56:07 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-05-03 21:56:31 -0700
commitbf60ac28c5ab128a15d1b0a2d5f1021dbe7081fd (patch)
treed76e0ade0c287f9aef91b04b0e33222cea575513 /core
parent2abaf67b66c6a967ee51e59c7802534b07706b6b (diff)
Overhaul with smaller, more concise codebase around defining
actions/macros, and deleting some dead code.
Diffstat (limited to 'core')
-rw-r--r--core/metaprogramming.nom19
-rw-r--r--core/text.nom11
2 files changed, 12 insertions, 18 deletions
diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom
index fdbae61..d4ae624 100644
--- a/core/metaprogramming.nom
+++ b/core/metaprogramming.nom
@@ -5,7 +5,7 @@
# Compile-time action to make compile-time actions:
immediately
lua> ".."
- nomsu:define_compile_action("compile %actions to %lua", \(!! code location !!), function(tree, \%actions, \%lua)
+ nomsu:define_compile_action("compile %actions to %lua", function(tree, \%actions, \%lua)
local lua = Lua(tree.source, "nomsu:define_compile_action(");
local stubs = {};
for i, action in ipairs(\%actions.value) do
@@ -17,7 +17,7 @@ immediately
else
lua:append(stubs,", ");
end
- lua:append(repr(tree.source:get_line()), ", function(tree");
+ lua:append("function(tree");
local args = {};
for i,tok in ipairs(\%actions.value[1].value) do
if tok.type == "Var" then args[#args+1] = nomsu:var_to_lua_identifier(tok.value); end
@@ -49,7 +49,7 @@ immediately
else
lua:append(stubs,", ");
end
- lua:append(repr(tree.source:get_line()), ", function(");
+ lua:append("function(");
local args = {};
for i,tok in ipairs(\%actions.value[1].value) do
if tok.type == "Var" then args[#args+1] = nomsu:var_to_lua_identifier(tok.value); end
@@ -80,7 +80,7 @@ immediately
else
lua:append(stubs,", ");
end
- lua:append(repr(tree.source:get_line()), ", function(tree");
+ lua:append("function(tree");
local args = {};
for i,tok in ipairs(\%shorthand.value[1].value) do
if tok.type == "Var" then args[#args+1] = nomsu:var_to_lua_identifier(tok.value); end
@@ -103,12 +103,11 @@ immediately
action [remove action %stub]
lua> ".."
local fn = ACTIONS[\%stub];
- local metadata = nomsu.action_metadata[fn];
- for i=#metadata.aliases,1,-1 do
- metadata.arg_orders[metadata.aliases[i]] = nil;
- table.remove(metadata.aliases, i);
+ local stubs = ARG_ORDERS[fn];
+ for stub in pairs(stubs) do
+ ACTIONS[stub] = nil;
end
- ACTIONS[\%stub] = nil;
+ ARG_ORDERS[fn] = nil;
immediately
action [%tree as lua]
@@ -142,7 +141,7 @@ immediately
action [%tree's stub]
- =lua "nomsu:tree_to_stub(\%tree)"
+ =lua "\%tree:get_stub()"
immediately
parse [%var <-write %code] as: lua> "\%var:append(\%code);"
diff --git a/core/text.nom b/core/text.nom
index 835ef87..465e3f6 100644
--- a/core/text.nom
+++ b/core/text.nom
@@ -18,11 +18,6 @@ compile [capitalized %text, %text capitalized] to
compile [%text with %sub instead of %patt, %text s/%patt/%sub] to
Lua value "((\(%text as lua expr)):gsub(\(%patt as lua expr), \(%sub as lua expr)))"
-# TODO: figure out whether indent/dedent should affect first line
-compile [indented %text, %text indented] to: Lua value "((\%text):gsub('\\n','\\n'..(' ')))"
-compile [dedented %obj, %obj dedented] to: Lua value "nomsu:dedent(\(%obj as lua expr))"
-compile [%text indented %n times] to: Lua value "((\%text):gsub('\\n','\\n'..(' '):rep(\%n)))"
-
# Text literals
lua> ".."
do
@@ -32,7 +27,7 @@ lua> ".."
};
for name, e in pairs(escapes) do
local lua = "'"..e.."'";
- nomsu:define_compile_action(name, \(!! code location !!), function(tree) return Lua.Value(tree.source, lua); end);
+ nomsu:define_compile_action(name, function(tree) return Lua.Value(tree.source, lua); end);
end
local colors = {
["reset color"]="\\\\27[0m", bright="\\\\27[1m", dim="\\\\27[2m", underscore="\\\\27[4m",
@@ -47,8 +42,8 @@ lua> ".."
for name, c in pairs(colors) do
local color = "'"..c.."'";
local reset = "'"..colors["reset color"].."'";
- nomsu:define_compile_action(name, \(!! code location !!), function(tree) return Lua.Value(tree.source, color); end);
- nomsu:define_compile_action(name.." %", \(!! code location !!), function(\%)
+ nomsu:define_compile_action(name, function(tree) return Lua.Value(tree.source, color); end);
+ nomsu:define_compile_action(name.." %", function(\%)
return Lua.Value(tree.source, color, "..", \%:as_lua(nomsu), "..", reset);
end);
end