aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/control_flow.nom24
-rw-r--r--core/math.nom8
-rw-r--r--core/metaprogramming.nom40
-rw-r--r--core/operators.nom28
-rw-r--r--core/text.nom6
5 files changed, 53 insertions, 53 deletions
diff --git a/core/control_flow.nom b/core/control_flow.nom
index 6d93e8a..5eabefd 100644
--- a/core/control_flow.nom
+++ b/core/control_flow.nom
@@ -188,14 +188,14 @@ immediately
%body has subtree % where
(%.type = "Action") and
((%'s stub) is "do next %") and
- %.3 = %var
+ %.value.3.value = %var.value
..: to %lua write (Lua "\n ::continue_\(%var as lua identifier)::;")
to %lua write "\nend --foreach-loop"
if
%body has subtree % where
(%.type = "Action") and
((%'s stub) is "stop %") and
- %.2 = %var
+ %.value.2.value = %var.value
..
%lua <-
Lua ".."
@@ -219,14 +219,14 @@ immediately
%body has subtree % where
(%.type = "Action") and
((%'s stub) is "do next %") and
- %.3 = %key
+ %.value.3.value = %key.value
..: to %lua write (Lua "\n ::continue_\(%key as lua identifier)::;")
if
%body has subtree % where
(%.type = "Action") and
((%'s stub) is "do next %") and
- %.3 = %value
+ %.value.3.value = %value.value
..: to %lua write (Lua "\n ::continue_\(%value as lua identifier)::;")
to %lua write "\nend --foreach-loop"
@@ -235,14 +235,14 @@ immediately
%body has subtree % where
(%.type = "Action") and
((%'s stub) is "stop %") and
- %.2 = %key
+ %.value.2.value = %key.value
..: to %stop_labels write "\n::stop_\(%key as lua identifier)::;"
if
%body has subtree % where
(%.type = "Action") and
((%'s stub) is "stop %") and
- %.2 = %value
+ %.value.2.value = %value.value
..: to %stop_labels write "\n::stop_\(%value as lua identifier)::;"
if: (length of %stop_labels) > 0
@@ -262,14 +262,14 @@ immediately
%is_first <- (yes)
%seen_else <- (no)
%branches <-
- %body if (%body.type = "Block") else [%body]
+ %body.value if (%body.type = "Block") else [%body]
for %func_call in %branches
assume (%func_call.type is "Action") or barf ".."
Invalid format for 'when' statement. Only '*' blocks are allowed.
with {..}
- %star: %func_call.1
- %condition: %func_call.2
- %action: %func_call.3
+ %star: %func_call.value.1
+ %condition: %func_call.value.2
+ %action: %func_call.value.3
..
assume (%star = "*") or barf ".."
Invalid format for 'when' statement. Lines must begin with '*'
@@ -310,11 +310,11 @@ immediately
%is_first <- (yes)
%seen_else <- (no)
%branches <-
- %body if (%body.type = "Block") else [%body]
+ %body.value if (%body.type = "Block") else [%body]
for %func_call in %branches
assume (%func_call.type is "Action") or barf ".."
Invalid format for 'when' statement. Only '*' blocks are allowed.
- with {%star:%func_call.1, %condition:%func_call.2, %action:%func_call.3}
+ with {%star:%func_call.value.1, %condition:%func_call.value.2, %action:%func_call.value.3}
assume (%star = "*") or barf ".."
Invalid format for 'when' statement. Lines must begin with '*'
assume %condition or barf ".."
diff --git a/core/math.nom b/core/math.nom
index 8d484b4..ed2cdb6 100644
--- a/core/math.nom
+++ b/core/math.nom
@@ -42,7 +42,7 @@ compile [all of %items, all %items] to
unless: (%items' "type") is "List"
return: Lua value "utils.all(\(%items as lua expr))"
%clauses <- []
- for % in %items
+ for % in %items.value
lua> "table.insert(\%clauses, \(% as lua expr));"
return: Lua value "(\(%clauses joined with " and "))"
parse [not all of %items, not all %items] as: not (all of %items)
@@ -50,7 +50,7 @@ compile [any of %items, any %items] to
unless: (%items' "type") is "List"
return: Lua value "utils.any(\(%items as lua expr))"
%clauses <- []
- for % in %items
+ for % in %items.value
lua> "table.insert(\%clauses, \(% as lua expr));"
return: Lua value "(\(%clauses joined with " or "))"
parse [none of %items, none %items] as: not (any of %items)
@@ -58,14 +58,14 @@ compile [sum of %items, sum %items] to
unless: (%items' "type") is "List"
return: Lua value "utils.sum(\(%items as lua expr))"
%clauses <- []
- for % in %items
+ for % in %items.value
lua> "table.insert(\%clauses, \(% as lua expr));"
return: Lua value "(\(%clauses joined with " + "))"
compile [product of %items, product %items] to
unless: (%items' "type") is "List"
return: Lua value "utils.product(\(%items as lua expr))"
%clauses <- []
- for % in %items
+ for % in %items.value
lua> "table.insert(\%clauses, \(% as lua expr));"
return: Lua value "(\(%clauses joined with " * "))"
action [avg of %items, average of %items]
diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom
index 6c5221c..76ba731 100644
--- a/core/metaprogramming.nom
+++ b/core/metaprogramming.nom
@@ -6,9 +6,9 @@
immediately
lua> ".."
nomsu:define_compile_action("compile %actions to %lua", function(tree, \%actions, \%lua)
- local lua = Lua(nil, "nomsu:define_compile_action(")
+ local lua = Lua(tree.source, "nomsu:define_compile_action(")
local stubs = {}
- for i, action in ipairs(\%actions) do
+ for i, action in ipairs(\%actions.value) do
stubs[i] = action:get_stub(true)
end
stubs = repr(stubs)
@@ -19,7 +19,7 @@ immediately
end
lua:append("function(tree")
local args = {}
- for i,tok in ipairs(\%actions[1]) do
+ for i,tok in ipairs(\%actions.value[1].value) do
if tok.type == "Var" then args[#args+1] = tok end
end
for i, arg in ipairs(args) do
@@ -36,9 +36,9 @@ immediately
immediately
compile [action %actions %body] to
lua> ".."
- local lua = Lua(nil, "nomsu:define_action(")
+ local lua = Lua(tree.source, "nomsu:define_action(")
local stubs = {}
- for i, action in ipairs(\%actions) do
+ for i, action in ipairs(\%actions.value) do
stubs[i] = action:get_stub(true)
end
stubs = repr(stubs)
@@ -49,7 +49,7 @@ immediately
end
lua:append("function(")
local args = {}
- for i,tok in ipairs(\%actions[1]) do
+ for i,tok in ipairs(\%actions.value[1].value) do
if tok.type == "Var" then args[#args+1] = tok end
end
for i, arg in ipairs(args) do
@@ -66,9 +66,9 @@ immediately
immediately
compile [parse %shorthand as %longhand] to
lua> ".."
- local lua = Lua(nil, "nomsu:define_compile_action(")
+ local lua = Lua(tree.source, "nomsu:define_compile_action(")
local stubs = {}
- for i, action in ipairs(\%shorthand) do
+ for i, action in ipairs(\%shorthand.value) do
stubs[i] = action:get_stub(true)
end
stubs = repr(stubs)
@@ -79,26 +79,26 @@ immediately
end
lua:append("function(tree")
local replacements = {}
- for i,tok in ipairs(\%shorthand[1]) do
+ for i,tok in ipairs(\%shorthand.value[1].value) do
if tok.type == "Var" then
local lua_var = tostring(nomsu:tree_to_lua(tok))
- replacements[tok] = lua_var
+ replacements[tok.value] = lua_var
lua:append(", ", lua_var)
end
end
local function make_tree(t)
- if replacements[t] then
- return replacements[t]
- elseif type(t) ~= 'table' and type(t) ~= 'userdata' then
+ 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.is_multi then
local bits = {}
- for i, entry in ipairs(t) do
+ for i, entry in ipairs(t.value) do
bits[i] = make_tree(entry)
end
- return t.type.."("..table.concat(bits, ", ")..")"
+ return t.type.."(Tuple("..table.concat(bits, ", ").."), "..repr(t.source)..")"
else
- return t.type.."("..make_tree(t.value)..")"
+ return t.type.."("..repr(t.value)..", "..repr(t.source)..")"
end
end
lua:append(")\n local tree = ", make_tree(\%longhand), "\n return nomsu:tree_to_lua(tree)\nend);")
@@ -169,21 +169,21 @@ immediately
# Compiler tools
immediately
compile [run %code] to
- Lua value "nomsu:run(Nomsu(nil, \(%code as lua expr)))"
+ Lua "nomsu:run(Nomsu(\(%code.source as text), \(%code as lua expr)))"
immediately
compile [show lua %block] to
lua> ".."
local \%lua = nomsu:tree_to_lua(\%block);
- return Lua(nil, "print(", repr(tostring(\%lua)), ");");
+ return Lua(tree.source, "print(", repr(tostring(\%lua)), ");");
immediately
compile [say %message] to
lua> ".."
if \%message.type == "Text" then
- return Lua(nil, "print(", \(%message as lua expr), ");");
+ return Lua(tree.source, "print(", \(%message as lua expr), ");");
else
- return Lua(nil, "print(stringify(", \(%message as lua expr), "));");
+ return Lua(tree.source, "print(stringify(", \(%message as lua expr), "));");
end
# Return
diff --git a/core/operators.nom b/core/operators.nom
index 62a3225..7f5c772 100644
--- a/core/operators.nom
+++ b/core/operators.nom
@@ -28,18 +28,18 @@ immediately
local safe = {Text=true, Number=true}
local a_lua, b_lua = \(%a as lua), \(%b as lua)
if safe[\%a.type] or safe[\%b.type] then
- return Lua.Value(nil, "(", a_lua, " == ", b_lua, ")")
+ return Lua.Value(tree.source, "(", a_lua, " == ", b_lua, ")")
else
- return Lua.Value(nil, "utils.equivalent(", a_lua, ", ", b_lua, ")")
+ return Lua.Value(tree.source, "utils.equivalent(", a_lua, ", ", b_lua, ")")
end
compile [%a isn't %b, %a is not %b, %a not= %b, %a != %b] to
lua> ".."
local safe = {Text=true, Number=true}
local a_lua, b_lua = \(%a as lua), \(%b as lua)
if safe[\%a.type] or safe[\%b.type] then
- return Lua.Value(nil, "(", a_lua, " ~= ", b_lua, ")")
+ return Lua.Value(tree.source, "(", a_lua, " ~= ", b_lua, ")")
else
- return Lua.Value(nil, "(not utils.equivalent(", a_lua, ", ", b_lua, "))")
+ return Lua.Value(tree.source, "(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: Lua value "nomsu.ids[\(% as lua expr)]"
@@ -52,7 +52,7 @@ immediately
lua> "local \%value_lua = \(%value as lua);"
assume %value_lua.is_value or barf "Invalid value for assignment: \%value"
lua> ".."
- local lua = Lua(nil, \%var_lua, ' = ', \%value_lua, ';')
+ local lua = Lua(tree.source, \%var_lua, ' = ', \%value_lua, ';')
if \%var.type == 'Var' then
lua:add_free_vars({\%var})
end
@@ -64,9 +64,9 @@ immediately
assume ((%assignments' "type") is "Dict") or barf ".."
Expected a Dict for the assignments part of '<- %' statement, not \%assignments
lua> ".."
- local lhs, rhs = Lua(), Lua()
- for i, item in ipairs(\%assignments) do
- local \%target, \%value = item[1], item[2]
+ local lhs, rhs = Lua(tree.source), Lua(tree.source)
+ for i, item in ipairs(\%assignments.value) do
+ local \%target, \%value = item.value[1], item.value[2]
local target_lua = \(%target as lua)
if not target_lua.is_value then error("Invalid target for assignment: "..\(%target as text)) end
local value_lua = \(%value as lua)
@@ -81,7 +81,7 @@ immediately
lhs:append(target_lua)
rhs:append(value_lua)
end
- return Lua(nil, lhs, " = ", rhs, ";")
+ return Lua(tree.source, lhs, " = ", rhs, ";")
immediately
compile [external %var <- %value] to
@@ -89,20 +89,20 @@ immediately
assume %var_lua.is_value or barf "Invalid target for assignment: \%var"
%value_lua <- (%value as lua)
assume %value_lua.is_value or barf "Invalid value for assignment: \%value"
- return: Lua "\(%var_lua) = \(%value_lua);"
+ return: Lua "\%var_lua = \%value_lua;"
compile [with external %externs %body] to
%body_lua <- (%body as lua statements)
- lua> "\%body_lua:remove_free_vars(\(%externs));"
+ lua> "\%body_lua:remove_free_vars(\%externs.value);"
return %body_lua
compile [with %assignments %body] to
%lua <- (%body as lua statements)
lua> ".."
- local lhs, rhs = Lua(), Lua()
+ local lhs, rhs = Lua(tree.source), Lua(tree.source)
local vars = {}
- for i, item in ipairs(\%assignments) do
- local \%target, \%value = item[1], item[2]
+ for i, item in ipairs(\%assignments.value) do
+ local \%target, \%value = item.value[1], item.value[2]
if not \%target.type == "Var" then
error("Invalid target for 'with' assignment: "..tostring(\%target))
end
diff --git a/core/text.nom b/core/text.nom
index b7fd2cf..95451ee 100644
--- a/core/text.nom
+++ b/core/text.nom
@@ -27,7 +27,7 @@ lua> ".."
};
for name, e in pairs(escapes) do
local lua = "'"..e.."'";
- nomsu:define_compile_action(name, function(tree) return Lua.Value(nil, lua); end);
+ nomsu:define_compile_action(name, function(tree) return Lua.Value(tree.value, lua); end);
end
local colors = {
["reset color"]="\\\\27[0m", bright="\\\\27[1m", dim="\\\\27[2m", underscore="\\\\27[4m",
@@ -42,9 +42,9 @@ lua> ".."
for name, c in pairs(colors) do
local color = "'"..c.."'";
local reset = "'"..colors["reset color"].."'";
- nomsu:define_compile_action(name, function(tree) return Lua.Value(nil, color); end);
+ nomsu:define_compile_action(name, function(tree) return Lua.Value(tree.value, color); end);
nomsu:define_compile_action(name.." %", function(\%)
- return Lua.Value(nil, color, "..", \(% as lua), "..", reset);
+ return Lua.Value(tree.value, color, "..", \(% as lua), "..", reset);
end);
end
end