aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/collections.nom22
-rw-r--r--lib/control_flow.nom24
-rw-r--r--lib/math.nom18
-rw-r--r--lib/metaprogramming.nom52
-rw-r--r--lib/operators.nom4
-rw-r--r--lib/text.nom4
6 files changed, 62 insertions, 62 deletions
diff --git a/lib/collections.nom b/lib/collections.nom
index 52e6675..376b861 100644
--- a/lib/collections.nom
+++ b/lib/collections.nom
@@ -16,7 +16,7 @@ parse [..]
compile [..]
%index st to last in %list, %index nd to last in %list, %index rd to last in %list
%index th to last in %list
-..to: "nomsu.utils.nth_to_last(\(%list as lua), \(%index as lua))"
+..to: "utils.nth_to_last(\(%list as lua), \(%index as lua))"
parse [first in %list, first %list] as: 1 st in %list
parse [last in %list, last %list] as: 1 st to last in %list
@@ -45,7 +45,7 @@ compile [..]
..to: "((\(%list as lua))[\(%index as lua)] ~= nil)"
compile [length of %list, size of %list, size %list, number of %list, len %list] to:
- "nomsu.utils.size(\(%list as lua))"
+ "utils.size(\(%list as lua))"
# Chained lookup
compile [%list ->* %indices] to:
@@ -99,13 +99,13 @@ immediately:
assume ((%item's "type") is "Var") or barf ".."
List comprehension has the wrong type for the loop variable. Expected Var, but got: \(%item's "type")
return ".."
- (function(nomsu);
+ (function();
local comprehension = {};
for i,\(%item as lua) in ipairs(\(%iterable as lua)) do;
comprehension[i] = \(%expression as lua);
end;
return comprehension;
- end)(nomsu)
+ end)()
parse [%expression for all %iterable] as: %expression for % in %iterable
compile [%expression for %key = %value in %iterable] to:
@@ -114,13 +114,13 @@ immediately:
assume ((%value's "type") is "Var") or barf ".."
List comprehension has the wrong type for the value loop variable. Expected Var, but got: \(%value's "type")
return ".."
- (function(nomsu);
+ (function();
local comprehension = {};
for \(%key as lua), \(%value as lua) in pairs(\(%iterable as lua)) do;
comprehension[i] = \(%expression as lua);
end;
return comprehension;
- end)(nomsu)
+ end)()
# Dict comprehensions
immediately:
@@ -128,13 +128,13 @@ immediately:
assume ((%item's "type") is "Var") or barf ".."
Dict comprehension has the wrong type for the loop variable. Expected Var, but got: \(%item's "type")
return ".."
- (function(nomsu);
+ (function();
local comprehension = {};
for i,\(%item as lua) in ipairs(\(%iterable as lua)) do;
comprehension[\(%key as lua)] = \(%value as lua);
end;
return comprehension;
- end)(nomsu)
+ end)()
parse [%key = %value for all %iterable] as: %key = %value for % in %iterable
compile [%key = %value for %src_key = %src_value in %iterable] to:
@@ -143,18 +143,18 @@ immediately:
assume ((%src_value's "type") is "Var") or barf ".."
Dict comprehension has the wrong type for the value loop variable. Expected Var, but got: \(%src_value's "type")
return ".."
- (function(nomsu);
+ (function();
local comprehension = {};
for \(%src_key as lua), \(%src_value as lua) in pairs(\(%iterable as lua)) do;
comprehension[\(%key as lua)] = \(%value as lua);
end;
return comprehension;
- end)(nomsu)
+ end)()
# Sorting:
compile [sort %items] to: "table.sort(\(%items as lua))"
compile [sort %items by %key_expr] to: ".."
- nomsu.utils.sort(\(%items as lua), function(\(\% as lua))
+ utils.sort(\(%items as lua), function(\(\% as lua))
return \(%key_expr as lua);
end)
diff --git a/lib/control_flow.nom b/lib/control_flow.nom
index f2500c5..1510903 100644
--- a/lib/control_flow.nom
+++ b/lib/control_flow.nom
@@ -50,13 +50,13 @@ immediately:
doesn't have a proper ternary operator!)
To see why this is necessary consider: (random()<.5 and false or 99)
return ".."
- (function(nomsu)
+ (function()
if \(%condition as lua) then
return \(%when_true_expr as lua);
else
return \(%when_false_expr as lua);
end
- end)(nomsu)
+ end)()
# GOTOs
immediately:
@@ -344,10 +344,10 @@ immediately:
..to code: ".."
do
local fell_through = false;
- local ok, ret = pcall(function(nomsu)
+ local ok, ret = pcall(function()
\(%action as lua statements)
fell_through = true;
- end, nomsu);
+ end);
if ok then
\(%success as lua statements)
end
@@ -375,15 +375,15 @@ immediately:
compile [do %action then always %final_action] to code: ".."
do
local fell_through = false;
- local ok, ret1 = pcall(function(nomsu)
+ local ok, ret1 = pcall(function()
\(%action as lua statements)
fell_through = true;
- end, nomsu);
- local ok2, ret2 = pcall(function(nomsu)
+ end);
+ local ok2, ret2 = pcall(function()
\(%final_action as lua statements)
- end, nomsu);
- if not ok then nomsu:error(ret1); end
- if not ok2 then nomsu:error(ret2); end
+ end);
+ if not ok then error(ret1); end
+ if not ok2 then error(ret2); end
if not fell_through then
return ret1;
end
@@ -402,12 +402,12 @@ immediately:
local \(join %temp_vars with ", ") = \(join %old_vals with ", ");
\(join %old_vals with ", ") = \(join %new_vals with ", ");
local fell_through = false;
- local ok, ret = pcall(function(nomsu)
+ local ok, ret = pcall(function()
do
\(%action as lua statements)
end
fell_through = true;
- end, nomsu);
+ end);
\(join %old_vals with ", ") = \(join %temp_vars with ", ");
if not ok then error(ret, 0); end
if not fell_through then return ret end
diff --git a/lib/math.nom b/lib/math.nom
index 85e8ac5..9e9af98 100644
--- a/lib/math.nom
+++ b/lib/math.nom
@@ -38,30 +38,30 @@ action [%n to the nearest %rounder]:
# Any/all/none
compile [all of %items, all %items] to:
"(\(join ((% as lua) for all (%items' "value")) with " and "))"
- ..if ((%items' "type") is "List") else "nomsu.utils.all(\(%items as lua))"
+ ..if ((%items' "type") is "List") else "utils.all(\(%items as lua))"
parse [not all of %items, not all %items] as: not (all of %items)
compile [any of %items, any %items] to:
"(\(join ((% as lua) for all (%items' "value")) with " or "))"
- ..if ((%items' "type") is "List") else "nomsu.utils.any(\(%items as lua))"
+ ..if ((%items' "type") is "List") else "utils.any(\(%items as lua))"
parse [none of %items, none %items] as: not (any of %items)
compile [sum of %items, sum %items] to:
"(\(join ((% as lua) for all (%items' "value")) with " + "))"
- ..if ((%items' "type") is "List") else "nomsu.utils.sum(\(%items as lua))"
+ ..if ((%items' "type") is "List") else "utils.sum(\(%items as lua))"
compile [product of %items, product %items] to:
"(\(join ((% as lua) for all (%items' "value")) with " * "))"
- ..if ((%items' "type") is "List") else "nomsu.utils.product(\(%items as lua))"
+ ..if ((%items' "type") is "List") else "utils.product(\(%items as lua))"
action [avg of %items, average of %items]:
- =lua "(nomsu.utils.sum(\%items)/#\%items)"
+ =lua "(utils.sum(\%items)/#\%items)"
compile [min of %items, smallest of %items, lowest of %items] to:
- "nomsu.utils.min(\(%items as lua))"
+ "utils.min(\(%items as lua))"
compile [max of %items, biggest of %items, largest of %items, highest of %items] to:
- "nomsu.utils.max(\(%items as lua))"
+ "utils.max(\(%items as lua))"
compile [min of %items by %value_expr] to: ".."
- nomsu.utils.min(\(%items as lua), function(\(\% as lua))
+ utils.min(\(%items as lua), function(\(\% as lua))
return \(%value_expr as lua)
end)
compile [max of %items by %value_expr] to: ".."
- nomsu.utils.max(\(%items as lua), function(\(\% as lua))
+ utils.max(\(%items as lua), function(\(\% as lua))
return \(%value_expr as lua)
end)
diff --git a/lib/metaprogramming.nom b/lib/metaprogramming.nom
index 55e9bea..aee5b67 100644
--- a/lib/metaprogramming.nom
+++ b/lib/metaprogramming.nom
@@ -11,19 +11,19 @@ immediately:
names[i] = alias.src;
end
local _, arg_names, _ = nomsu:get_stub(spec.value[1]);
- local args = {"nomsu"};
- for i, a in ipairs(arg_names) do args[i+1] = "_"..nomsu:var_to_lua_identifier(a); end
- names, args = nomsu:repr(names), table.concat(args, ", ");
+ local args = {};
+ for i, a in ipairs(arg_names) do args[i] = "_"..nomsu:var_to_lua_identifier(a); end
+ names, args = repr(names), table.concat(args, ", ");
return names, args;
end
# Compile-time action to make compile-time actions:
immediately:
lua> ".."
- nomsu:define_compile_action("compile %names to %body", \(__line_no__), function(nomsu, \%names, \%body)
- nomsu:assert(\%names.type == "List",
+ nomsu:define_compile_action("compile %names to %body", \(__line_no__), function(\%names, \%body)
+ assert(\%names.type == "List",
"Invalid type for compile definition names. Expected List, but got: "..tostring(\%names.type));
- nomsu:assert(\%body.type == "Block",
+ assert(\%body.type == "Block",
"Invalid type for compile definition body. Expected Block, but got: "..tostring(\%body.type));
local names, args = nomsu:parse_spec(\%names);
local body_lua = nomsu:tree_to_lua(\%body);
@@ -35,16 +35,16 @@ immediately:
end
local function compile_action_wrapper(...) return {expr=compile_action(...)}; end
nomsu:define_compile_action(%s, %s, compile_action_wrapper, %s);
- end]]):format(args, body_lua, names, nomsu:repr(\%names:get_line_no()),
- nomsu:repr(("compile %s\\n..to code %s"):format(\%names.src, \%body.src)));
+ end]]):format(args, body_lua, names, repr(\%names:get_line_no()),
+ repr(("compile %s\\n..to code %s"):format(\%names.src, \%body.src)));
return {statements=lua};
end, \(__src__ 1));
lua> ".."
- nomsu:define_compile_action("compile %names to code %body", \(__line_no__), function(nomsu, \%names, \%body)
- nomsu:assert(\%names.type == "List",
+ nomsu:define_compile_action("compile %names to code %body", \(__line_no__), function(\%names, \%body)
+ assert(\%names.type == "List",
"Invalid type for compile definition names. Expected List, but got: "..tostring(\%names.type));
- nomsu:assert(\%body.type == "Block",
+ assert(\%body.type == "Block",
"Invalid type for compile definition body. Expected Block, but got: "..tostring(\%body.type));
local names, args = nomsu:parse_spec(\%names);
local body_lua = nomsu:tree_to_lua(\%body);
@@ -56,8 +56,8 @@ immediately:
end
local function compile_action_wrapper(...) return {statements=compile_action(...)}; end
nomsu:define_compile_action(%s, %s, compile_action_wrapper, %s);
- end]]):format(args, body_lua, names, nomsu:repr(\%names:get_line_no()),
- nomsu:repr(("compile %s\\n..to code %s"):format(\%names.src, \%body.src)));
+ end]]):format(args, body_lua, names, repr(\%names:get_line_no()),
+ repr(("compile %s\\n..to code %s"):format(\%names.src, \%body.src)));
return {statements=lua};
end, \(__src__ 1));
@@ -65,9 +65,9 @@ immediately:
immediately:
compile [action %names %body] to code:
lua> ".."
- nomsu:assert(\%names.type == "List",
+ assert(\%names.type == "List",
"Invalid type for action definition names. Expected List, but got: "..tostring(\%names.type));
- nomsu:assert(\%body.type == "Block",
+ assert(\%body.type == "Block",
"Invalid type for action definition body. Expected Block, but got: "..tostring(\%body.type));
local names, args = nomsu:parse_spec(\%names);
local body_lua = nomsu:tree_to_lua(\%body);
@@ -76,34 +76,34 @@ immediately:
local def_lua = ([[
nomsu:define_action(%s, \(__line_no__), function(%s)
%s
- end, %s);]]):format(names, args, body_lua, nomsu:repr(src));
+ end, %s);]]):format(names, args, body_lua, repr(src));
return def_lua;
# Macro to make nomsu macros:
immediately:
lua> ".."
- nomsu:define_compile_action("parse %shorthand as %longhand", \(__line_no__), (function(nomsu, \%shorthand, \%longhand)
- nomsu:assert(\%shorthand.type == "List",
+ nomsu:define_compile_action("parse %shorthand as %longhand", \(__line_no__), (function(\%shorthand, \%longhand)
+ assert(\%shorthand.type == "List",
"Invalid type for parse definition shorthand. Expected List, but got: "..tostring(\%shorthand.type));
- nomsu:assert(\%longhand.type == "Block",
+ assert(\%longhand.type == "Block",
"Invalid type for parse definition body. Expected Block, but got: "..tostring(\%longhand.type));
local names, args = nomsu:parse_spec(\%shorthand);
local template = {};
for i, line in ipairs(\%longhand.value) do
template[i] = nomsu:dedent(line.src);
end
- template = nomsu:repr(table.concat(template, "\\n"));
+ template = repr(table.concat(template, "\\n"));
local _, arg_names, _ = nomsu:get_stub(\%shorthand.value[1]);
local replacements = {};
- for i, a in ipairs(arg_names) do replacements[i] = "["..nomsu:repr(a).."]=_"..nomsu:var_to_lua_identifier(a); end
+ for i, a in ipairs(arg_names) do replacements[i] = "["..repr(a).."]=_"..nomsu:var_to_lua_identifier(a); end
replacements = "{"..table.concat(replacements, ", ").."}";
local lua_code = ([[
nomsu:define_compile_action(%s, %s, (function(%s)
local template = nomsu:parse(%s, %s);
local replacement = nomsu:replaced_vars(template, %s);
return nomsu:tree_to_lua(replacement);
- end), %s)]]):format(names, nomsu:repr(\%shorthand:get_line_no()), args, template,
- nomsu:repr(\%shorthand:get_line_no()), replacements, nomsu:repr(nomsu:source_code(0)));
+ end), %s)]]):format(names, repr(\%shorthand:get_line_no()), args, template,
+ repr(\%shorthand:get_line_no()), replacements, repr(nomsu:source_code(0)));
return {statements=lua_code};
end), \(__src__ 1));
@@ -124,7 +124,7 @@ immediately:
action [%tree as value]:
=lua "nomsu:tree_to_value(\%tree)"
compile [repr %obj] to:
- "nomsu:repr(\(%obj as lua))"
+ "repr(\(%obj as lua))"
compile [indented %obj] to:
"nomsu:indent(\(%obj as lua))"
compile [dedented %obj] to:
@@ -153,7 +153,7 @@ action [help %action]:
lua> ".."
local fn_def = nomsu.defs[nomsu:get_stub(\%action)]
if not fn_def then
- nomsu:writeln("Action not found: "..nomsu:repr(\%action));
+ nomsu:writeln("Action not found: "..repr(\%action));
else
nomsu:writeln(fn_def.src or "<unknown source code>");
end
@@ -182,7 +182,7 @@ compile [say %str] to:
if \%str.type == "Text" then
return "nomsu:writeln("..\(%str as lua)..")";
else
- return "nomsu:writeln(nomsu:stringify("..\(%str as lua).."))";
+ return "nomsu:writeln(stringify("..\(%str as lua).."))";
end
# Error functions
diff --git a/lib/operators.nom b/lib/operators.nom
index 89f940e..b697aad 100644
--- a/lib/operators.nom
+++ b/lib/operators.nom
@@ -20,7 +20,7 @@ immediately:
if safe[\%a.type] or safe[\%b.type] then
return "("..a_lua.." == "..b_lua..")";
else
- return "nomsu.utils.equivalent("..a_lua..", "..b_lua..")";
+ return "utils.equivalent("..a_lua..", "..b_lua..")";
end
compile [%a isn't %b, %a is not %b, %a not= %b, %a != %b] to:
lua> ".."
@@ -29,7 +29,7 @@ immediately:
if safe[\%a.type] or safe[\%b.type] then
return "("..a_lua.." ~= "..b_lua..")";
else
- return "(not nomsu.utils.equivalent("..a_lua..", "..b_lua.."))";
+ return "(not utils.equivalent("..a_lua..", "..b_lua.."))";
end
# For strict identity checking, use (%x's id) is (%y's id)
compile [%'s id, id of %] to: "nomsu.ids[\(% as lua)]"
diff --git a/lib/text.nom b/lib/text.nom
index 7c06d07..a1331ef 100644
--- a/lib/text.nom
+++ b/lib/text.nom
@@ -8,7 +8,7 @@ use "lib/metaprogramming.nom"
action [join %strs with %glue]:
lua> ".."
local str_bits = {}
- for i,bit in ipairs(\%strs) do str_bits[i] = nomsu:stringify(bit) end
+ for i,bit in ipairs(\%strs) do str_bits[i] = stringify(bit) end
return table.concat(str_bits, \%glue)
parse [join %strs] as: join %strs with ""
@@ -49,7 +49,7 @@ lua do> ".."
local color = "'"..c.."'";
local reset = "'"..colors["reset color"].."'";
nomsu:define_compile_action(name, \(__line_no__), function() return {expr=color}; end, \(__src__ 1));
- nomsu:define_compile_action(name.." %", \(__line_no__), function(nomsu, _)
+ nomsu:define_compile_action(name.." %", \(__line_no__), function(_)
return {expr=color..".."..nomsu:tree_to_lua(_).expr..".."..reset};
end, \(__src__ 1));
end