aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/collections.nom8
-rw-r--r--core/control_flow.nom166
-rw-r--r--core/coroutines.nom14
-rw-r--r--core/errors.nom34
-rw-r--r--core/id.nom5
-rw-r--r--core/io.nom14
-rw-r--r--core/math.nom12
-rw-r--r--core/metaprogramming.nom138
-rw-r--r--core/operators.nom68
-rw-r--r--core/scopes.nom14
-rw-r--r--core/text.nom31
11 files changed, 249 insertions, 255 deletions
diff --git a/core/collections.nom b/core/collections.nom
index bc58c7b..5daaa09 100644
--- a/core/collections.nom
+++ b/core/collections.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.8.7.6
+#!/usr/bin/env nomsu -V4.8.8.6
#
This file contains code that supports manipulating and using collections like lists
and dictionaries.
@@ -154,8 +154,8 @@ compile [set %dict 's metatable to %metatable] to (..)
test:
assume (({} with fallback % -> (% + 1)).10 == 11)
compile [%dict with fallback %key -> %value] to (..)
- Lua value ".."
- (function(d)
+ Lua value "\
+ ..(function(d)
local mt = {}
for k,v in pairs(getmetatable(d) or {}) do mt[k] = v end
mt.__index = function(self, \(%key as lua expr))
@@ -164,7 +164,7 @@ compile [%dict with fallback %key -> %value] to (..)
return value
end
return setmetatable(d, mt)
- end)(\(%dict as lua expr))
+ end)(\(%dict as lua expr))"
# Sorting
test:
diff --git a/core/control_flow.nom b/core/control_flow.nom
index b26b870..ee9c8c3 100644
--- a/core/control_flow.nom
+++ b/core/control_flow.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.8.7.6
+#!/usr/bin/env nomsu -V4.8.8.6
#
This file contains compile-time actions that define basic control flow structures
like "if" statements and loops.
@@ -17,10 +17,10 @@ test:
if (no):
barf "conditional fail"
compile [if %condition %if_body] to (..)
- Lua ".."
- if \(%condition as lua expr) then
+ Lua "\
+ ..if \(%condition as lua expr) then
\(%if_body as lua statements)
- end
+ end"
test:
unless (yes):
@@ -29,12 +29,12 @@ parse [unless %condition %unless_body] as (if (not %condition) %unless_body)
compile [..]
if %condition %if_body else %else_body, unless %condition %else_body else %if_body
..to (..)
- Lua ".."
- if \(%condition as lua expr) then
+ Lua "\
+ ..if \(%condition as lua expr) then
\(%if_body as lua statements)
else
\(%else_body as lua statements)
- end
+ end"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -54,23 +54,23 @@ compile [..]
equivalent of a conditional expression: (cond and if_true or if_false)
if {Text:yes, List:yes, Dict:yes, Number:yes}.(%when_true_expr.type):
return (..)
- Lua value ".."
- (\(%condition as lua expr) and \(%when_true_expr as lua expr) or \(..)
+ Lua value "\
+ ..(\(%condition as lua expr) and \(%when_true_expr as lua expr) or \(..)
%when_false_expr as lua expr
- ..)
+ ..)"
..else:
# Otherwise, need to do an anonymous inline function (yuck, too bad lua
doesn't have a proper ternary operator!)
To see why this is necessary consider: (random()<.5 and false or 99)
return (..)
- Lua value ".."
- ((function()
+ Lua value "\
+ ..((function()
if \(%condition as lua expr) then
return \(%when_true_expr as lua expr)
else
return \(%when_false_expr as lua expr)
end
- end)())
+ end)())"
# GOTOs
test:
@@ -112,9 +112,9 @@ compile [do next repeat] to (Lua "goto continue_repeat")
compile [stop repeating] to (Lua "goto stop_repeat")
compile [repeat while %condition %body] to:
%lua = (..)
- Lua ".."
- while \(%condition as lua expr) do
- \(%body as lua statements)
+ Lua "\
+ ..while \(%condition as lua expr) do
+ \(%body as lua statements)"
if (%body has subtree \(do next)):
%lua::append "\n ::continue::"
@@ -123,11 +123,11 @@ compile [repeat while %condition %body] to:
%lua::append "\nend --while-loop"
if (%body has subtree \(stop repeating)):
%lua = (..)
- Lua ".."
- do -- scope of "stop repeating" label
+ Lua "\
+ ..do -- scope of "stop repeating" label
\%lua
::stop_repeat::
- end -- end of "stop repeating" label scope
+ end -- end of "stop repeating" label scope"
return %lua
@@ -141,9 +141,9 @@ test:
compile [repeat %n times %body] to:
define mangler
%lua = (..)
- Lua ".."
- for \(mangle "i")=1,\(%n as lua expr) do
- \(%body as lua statements)
+ Lua "\
+ ..for \(mangle "i")=1,\(%n as lua expr) do
+ \(%body as lua statements)"
if (%body has subtree \(do next)):
%lua::append "\n ::continue::"
@@ -152,11 +152,11 @@ compile [repeat %n times %body] to:
%lua::append "\nend --numeric for-loop"
if (%body has subtree \(stop repeating)):
%lua = (..)
- Lua ".."
- do -- scope of "stop repeating" label
+ Lua "\
+ ..do -- scope of "stop repeating" label
\%lua
::stop_repeat::
- end -- end of "stop repeating" label scope
+ end -- end of "stop repeating" label scope"
return %lua
@@ -199,11 +199,11 @@ compile [..]
unless (%var.type is "Var"):
compile error at %var.source "Loop expected variable, not: %s"
%lua = (..)
- Lua ".."
- for \(%var as lua expr)=\(%start as lua expr),\(%stop as lua expr),\(..)
+ Lua "\
+ ..for \(%var as lua expr)=\(%start as lua expr),\(%stop as lua expr),\(..)
%step as lua expr
.. do
- \(%body as lua statements)
+ \(%body as lua statements)"
if (%body has subtree \(do next)):
%lua::append "\n ::continue::"
@@ -212,11 +212,11 @@ compile [..]
%lua::append "\nend --numeric for-loop"
if (%body has subtree \(stop %var)):
%lua = (..)
- Lua ".."
- do -- scope for stopping for-loop
+ Lua "\
+ ..do -- scope for stopping for-loop
\%lua
\(compile as (===stop %var ===))
- end -- end of scope for stopping for-loop
+ end -- end of scope for stopping for-loop"
return %lua
@@ -245,9 +245,9 @@ compile [for %var in %iterable %body] to:
compile error at %var.source "Loop expected variable, not: %s"
define mangler
%lua = (..)
- Lua ".."
- for \(mangle "i"),\(%var as lua identifier) in ipairs(\(%iterable as lua expr)) do
- \(%body as lua statements)
+ Lua "\
+ ..for \(mangle "i"),\(%var as lua identifier) in ipairs(\(%iterable as lua expr)) do
+ \(%body as lua statements)"
if (%body has subtree \(do next)):
%lua::append "\n ::continue::"
@@ -256,11 +256,11 @@ compile [for %var in %iterable %body] to:
%lua::append "\nend --foreach-loop"
if (%body has subtree \(stop %var)):
%lua = (..)
- Lua ".."
- do -- scope for stopping for-loop
+ Lua "\
+ ..do -- scope for stopping for-loop
\%lua
\(compile as (===stop %var ===))
- end -- end of scope for stopping for-loop
+ end -- end of scope for stopping for-loop"
return %lua
@@ -284,11 +284,11 @@ compile [..]
unless (%value.type is "Var"):
compile error at %value.source "Loop expected variable, not: %s"
%lua = (..)
- Lua ".."
- for \(%key as lua identifier),\(%value as lua identifier) in pairs(\(..)
+ Lua "\
+ ..for \(%key as lua identifier),\(%value as lua identifier) in pairs(\(..)
%iterable as lua expr
..) do
- \(%body as lua statements)
+ \(%body as lua statements)"
if (%body has subtree \(do next)):
%lua::append "\n ::continue::"
@@ -304,10 +304,10 @@ compile [..]
%stop_labels::append "\n\(compile as (===stop %value ===))"
if ((size of "\%stop_labels") > 0):
%lua = (..)
- Lua ".."
- do -- scope for stopping for % = % loop
+ Lua "\
+ ..do -- scope for stopping for % = % loop
\%lua\%stop_labels
- end
+ end"
return %lua
@@ -337,39 +337,39 @@ compile [if %body, when %body] to:
((%line.type is "Action") and ((size of %line) >= 2)) and (..)
%line.(size of %line) is "Block" syntax tree
..:
- compile error at %line.source ".."
- Invalid line for 'if', each line should contain conditional expressions followed by a block, or "else" followed by a block:
- %s
+ compile error at %line.source "\
+ ..Invalid line for 'if', each line should contain conditional expressions followed by a block, or "else" followed by a block:
+ %s"
%action = %line.(size of %line)
if ((%line.1 is "else") and ((size of %line) == 2)):
unless %else_allowed:
compile error at %line.source "Can't have two 'else' blocks"
unless ((size of "\%code") > 0):
- compile error at %line.source ".."
- Can't have an 'else' block without a preceeding condition
+ compile error at %line.source "\
+ ..Can't have an 'else' block without a preceeding condition"
- %code::append ".."
-
+ %code::append "\
+ ..
else
- \(%action as lua statements)
+ \(%action as lua statements)"
%else_allowed = (no)
..else:
%code::append "\%clause "
for %i in 1 to ((size of %line) - 1):
unless (%line.%i is syntax tree):
- compile error at %line.source ".."
- Invalid condition for 'if' statement:
- %s
+ compile error at %line.source "\
+ ..Invalid condition for 'if' statement:
+ %s"
if (%i > 1):
%code::append " or "
%code::append (%line.%i as lua expr)
- %code::append ".."
- then
- \(%action as lua statements)
+ %code::append "\
+ .. then
+ \(%action as lua statements)"
%clause = "\nelseif"
@@ -401,39 +401,39 @@ compile [if %branch_value is %body, when %branch_value is %body] to:
((%line.type is "Action") and ((size of %line) >= 2)) and (..)
%line.(size of %line) is "Block" syntax tree
..:
- compile error at %line.source ".."
- Invalid line for 'if % is % %', each line should contain expressions followed by a block, or "else" followed by a block:
- %s
+ compile error at %line.source "\
+ ..Invalid line for 'if % is % %', each line should contain expressions followed by a block, or "else" followed by a block:
+ %s"
%action = %line.(size of %line)
if ((%line.1 is "else") and ((size of %line) == 2)):
unless %else_allowed:
compile error at %line.source "Can't have two 'else' blocks"
unless ((size of "\%code") > 0):
- compile error at %line.source ".."
- Can't have an 'else' block without a preceeding condition
+ compile error at %line.source "\
+ ..Can't have an 'else' block without a preceeding condition"
- %code::append ".."
-
+ %code::append "\
+ ..
else
- \(%action as lua statements)
+ \(%action as lua statements)"
%else_allowed = (no)
..else:
%code::append "\%clause "
for %i in 1 to ((size of %line) - 1):
unless (%line.%i is syntax tree):
- compile error at %line.source ".."
- Invalid condition for 'if' statement:
- %s
+ compile error at %line.source "\
+ ..Invalid condition for 'if' statement:
+ %s"
if (%i > 1):
%code::append " or "
%code::append "\(mangle "branch value") == \(%line.%i as lua expr)"
- %code::append ".."
- then
- \(%action as lua statements)
+ %code::append "\
+ .. then
+ \(%action as lua statements)"
%clause = "\nelseif"
@@ -441,18 +441,18 @@ compile [if %branch_value is %body, when %branch_value is %body] to:
compile error at %body.source "'if % is % %' block has an empty body"
%code::append "\nend --when"
return (..)
- Lua ".."
- do --if % is
+ Lua "\
+ ..do --if % is
local \(mangle "branch value") = \(%branch_value as lua expr)
\%code
- end --if % is
+ end --if % is"
# Do/finally
compile [do %action] to (..)
- Lua ".."
- do
+ Lua "\
+ ..do
\(%action as lua statements)
- end --do
+ end --do"
test:
%d = {}
@@ -467,8 +467,8 @@ test:
compile [do %action then always %final_action] to:
define mangler
return (..)
- Lua ".."
- do
+ Lua "\
+ ..do
local \(mangle "fell_through") = false
local \(mangle "ok"), \(mangle "ret") = pcall(function()
\(%action as lua statements)
@@ -477,7 +477,7 @@ compile [do %action then always %final_action] to:
\(%final_action as lua statements)
if not \(mangle "ok") then error(ret, 0) end
if not \(mangle "fell_through") then return ret end
- end
+ end"
test:
assume ((result of (: return 99)) == 99)
@@ -502,12 +502,12 @@ compile [for %var in recursive %structure %body] to (..)
compile [recurse %v on %x] to (..)
Lua "table.insert(\(mangle "stack \(%v.1)"), \(%x as lua expr))"
%lua = (..)
- Lua ".."
- do
+ Lua "\
+ ..do
local \(mangle "stack \(%var.1)") = _List{\(%structure as lua expr)}
while #\(mangle "stack \(%var.1)") > 0 do
\(%var as lua expr) = table.remove(\(mangle "stack \(%var.1)"), 1)
- \(%body as lua statements)
+ \(%body as lua statements)"
if (%body has subtree \(do next)):
%lua::append "\n ::continue::"
diff --git a/core/coroutines.nom b/core/coroutines.nom
index d7d1db4..e7ec41e 100644
--- a/core/coroutines.nom
+++ b/core/coroutines.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.8.7.6
+#!/usr/bin/env nomsu -V4.8.8.6
#
This file defines the code that creates and manipulates coroutines
@@ -15,15 +15,15 @@ test:
for % in coroutine %co: %nums::add %
assume (%nums == [4, 5, 6, 6, 6]) or barf "Coroutine iteration failed"
compile [coroutine %body, generator %body] to (..)
- Lua value ".."
- (function()
+ Lua value "\
+ ..(function()
\(%body as lua statements)
- end)
+ end)"
compile [->] to (Lua value "coroutine.yield(true)")
compile [-> %] to (Lua value "coroutine.yield(true, \(% as lua expr))")
compile [for % in coroutine %co %body] to (..)
- Lua ".."
- for junk,\(% as lua expr) in coroutine.wrap(\(%co as lua expr)) do
+ Lua "\
+ ..for junk,\(% as lua expr) in coroutine.wrap(\(%co as lua expr)) do
\(%body as lua statements)
- end
+ end"
diff --git a/core/errors.nom b/core/errors.nom
index 53f88be..f5dcb8c 100644
--- a/core/errors.nom
+++ b/core/errors.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.8.7.6
+#!/usr/bin/env nomsu -V4.8.8.6
#
This file contains basic error reporting code
@@ -10,34 +10,34 @@ compile [compile error at %source %msg] to (..)
Lua "nomsu:compile_error(\(%source as lua expr), \(%msg as lua expr))"
compile [assume %condition] to:
- lua> ".."
- local \%assumption = 'Assumption failed: '..tostring(nomsu:tree_to_nomsu(\%condition))
+ lua> "\
+ ..local \%assumption = 'Assumption failed: '..tostring(nomsu:tree_to_nomsu(\%condition))"
return (..)
- Lua ".."
- if not \(%condition as lua expr) then
+ Lua "\
+ ..if not \(%condition as lua expr) then
error(\(quote "\%assumption"), 0)
- end
+ end"
compile [assume %a == %b] to:
- lua> ".."
- local \%assumption = 'Assumption failed: '..tostring(nomsu:tree_to_nomsu(\(\(%a == %b))))
+ lua> "\
+ ..local \%assumption = 'Assumption failed: '..tostring(nomsu:tree_to_nomsu(\(\(%a == %b))))"
define mangler
return (..)
- Lua ".."
- do
+ Lua "\
+ ..do
local \(mangle "a"), \(mangle "b") = \(%a as lua expr), \(%b as lua expr)
if \(mangle "a") ~= \(mangle "b") then
error(\(quote "\%assumption").."\\n"..tostring(\(mangle "a")).." != "..tostring(\(..)
mangle "b"
..), 0)
end
- end
+ end"
compile [assume %condition or barf %message] to (..)
- Lua ".."
- if not \(%condition as lua expr) then
+ Lua "\
+ ..if not \(%condition as lua expr) then
error(\(%message as lua expr), 0)
- end
+ end"
test:
try (barf) and if it succeeds: barf "try failed."
@@ -57,8 +57,8 @@ compile [..]
try %action and if it succeeds %success or if it barfs %msg %fallback
try %action and if it barfs %msg %fallback or if it succeeds %success
..to (..)
- Lua ".."
- do
+ Lua "\
+ ..do
local fell_through = false
local err, erred = nil, false
local ok, ret = xpcall(function()
@@ -78,7 +78,7 @@ compile [..]
elseif erred then
error(err, 0)
end
- end
+ end"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/core/id.nom b/core/id.nom
index 9f41cfb..9656dd0 100644
--- a/core/id.nom
+++ b/core/id.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.8.7.6
+#!/usr/bin/env nomsu -V4.8.8.6
#
A simple UUID function based on RFC 4122: http://www.ietf.org/rfc/rfc4122.txt
@@ -13,8 +13,7 @@ use "core/control_flow.nom"
set %obj_by_id's metatable to {__mode:"v"}
%id_by_obj = {}
set %id_by_obj 's metatable to {..}
- __mode:"k"
- __index: (..)
+ __mode:"k", __index: (..)
[%self, %key] ->:
if (%key == (nil)):
return %self.%nil_surrogate
diff --git a/core/io.nom b/core/io.nom
index d656419..1e87209 100644
--- a/core/io.nom
+++ b/core/io.nom
@@ -1,23 +1,23 @@
-#!/usr/bin/env nomsu -V3.8.7.6
+#!/usr/bin/env nomsu -V4.8.8.6
#
This file contains basic input/output code
use "core/metaprogramming.nom"
compile [say %message] to (..)
- lua> ".."
- if \%message.type == "Text" then
+ lua> "\
+ ..if \%message.type == "Text" then
return LuaCode(tree.source, "print(", \(%message as lua expr), ");");
else
return LuaCode(tree.source, "print(tostring(", \(%message as lua expr), "));");
- end
+ end"
compile [ask %prompt] to (..)
- lua> ".."
- if \%prompt.type == "Text" then
+ lua> "\
+ ..if \%prompt.type == "Text" then
return LuaCode.Value(tree.source, "(io.write(", \(%prompt as lua expr), ") and io.read())");
else
return LuaCode.Value(tree.source, "(io.write(tostring(", \(..)
%prompt as lua expr
.., ")) and io.read())");
- end
+ end"
diff --git a/core/math.nom b/core/math.nom
index 439b698..11282a4 100644
--- a/core/math.nom
+++ b/core/math.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.8.7.6
+#!/usr/bin/env nomsu -V4.8.8.6
#
This file defines some common math literals and functions
@@ -10,8 +10,8 @@ use "core/collections.nom"
# Literals:
test:
- assume (all of [inf, NaN, pi, tau, golden ratio, e]) or barf ".."
- math constants failed
+ assume (all of [inf, NaN, pi, tau, golden ratio, e]) or barf "\
+ ..math constants failed"
%nan = (NaN)
assume (%nan != %nan) or barf "NaN failed"
compile [infinity, inf] to (Lua value "math.huge")
@@ -127,9 +127,9 @@ parse [max of %items by %item = %value_expr] as (..)
# Random functions
action [seed random with %] (..)
- lua> ".."
- math.randomseed(\%);
- for i=1,20 do math.random(); end
+ lua> "\
+ ..math.randomseed(\%);
+ for i=1,20 do math.random(); end"
parse [seed random] as (seed random with (=lua "os.time()"))
compile [random number, random, rand] to (Lua value "math.random()")
diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom
index 5c08167..f669493 100644
--- a/core/metaprogramming.nom
+++ b/core/metaprogramming.nom
@@ -1,11 +1,11 @@
-#!/usr/bin/env nomsu -V3.8.7.6
+#!/usr/bin/env nomsu -V4.8.8.6
#
This File contains actions for making actions and compile-time actions and some helper
functions to make that easier.
lua> "NOMSU_CORE_VERSION = 8"
-lua> ".."
- do
+lua> "\
+ ..do
local mangle_index = 0
function mangler()
local my_mangle_index = mangle_index
@@ -17,10 +17,10 @@ lua> ".."
end
COMPILE_ACTIONS["define mangler"] = function(nomsu, tree)
return LuaCode(tree.source, "local mangle_1 = mangler()")
- end
+ end"
-lua> ".."
- COMPILE_ACTIONS["1 -> 2"] = function(nomsu, tree, \%args, \%body)
+lua> "\
+ ..COMPILE_ACTIONS["1 -> 2"] = function(nomsu, tree, \%args, \%body)
local lua = LuaCode.Value(tree.source, "(function(")
if AST.is_syntax_tree(\%args, "Action") then \%args = \%args:get_args() end
local lua_args = table.map(\%args, function(a) return AST.is_syntax_tree(a) and tostring(nomsu:compile(a)) or a end)
@@ -30,10 +30,10 @@ lua> ".."
body_lua:declare_locals()
lua:append(")\\n ", body_lua, "\\nend)")
return lua
- end
+ end"
-lua> ".."
- COMPILE_ACTIONS["compile as 1"] = function(nomsu, tree, \%action)
+lua> "\
+ ..COMPILE_ACTIONS["compile as 1"] = function(nomsu, tree, \%action)
local lua = LuaCode.Value(tree.source, "COMPILE_ACTIONS[", repr(\%action.stub), "](")
local lua_args = table.map(\%action:get_args(), function(a) return nomsu:compile(a) end)
table.insert(lua_args, 1, "nomsu")
@@ -41,7 +41,7 @@ lua> ".."
lua:concat_append(lua_args, ", ")
lua:append(")")
return lua
- end
+ end"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -62,8 +62,8 @@ test:
test:
asdf
assume (%tmp is (nil)) or barf "compile to is leaking variables"
-lua> ".."
- COMPILE_ACTIONS["compile 1 to 2"] = function(nomsu, tree, \%actions, \%body)
+lua> "\
+ ..COMPILE_ACTIONS["compile 1 to 2"] = function(nomsu, tree, \%actions, \%body)
local \%args = {"nomsu", "tree", unpack(table.map(\%actions[1]:get_args(), function(a) return tostring(nomsu:compile(\
..a)) end))}
local lua = LuaCode(tree.source, "COMPILE_ACTIONS[", repr(\%actions[1].stub),
@@ -84,16 +84,16 @@ lua> ".."
end
end
return lua
- end
+ end"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compile [call %fn with %args] to:
- lua> ".."
- local lua = LuaCode.Value(tree.source, nomsu:compile(\%fn), "(")
+ lua> "\
+ ..local lua = LuaCode.Value(tree.source, nomsu:compile(\%fn), "(")
lua:concat_append(table.map(\%args, function(a) return nomsu:compile(a) end), ", ")
lua:append(")")
- return lua
+ return lua"
test:
local action [foo %x]: return "outer"
@@ -108,8 +108,8 @@ test:
assume ((foo 1) == "outer")
compile [local action %actions %body] to:
- lua> ".."
- local fn_name = \%actions[1].stub:as_lua_id()
+ lua> "\
+ ..local fn_name = \%actions[1].stub:as_lua_id()
local \%args = table.map(\%actions[1]:get_args(), function(a) return tostring(nomsu:compile(a)) end)
local lua = LuaCode(tree.source, fn_name, " = ", \(compile as (%args -> %body)))
lua:add_free_vars({fn_name})
@@ -129,7 +129,7 @@ compile [local action %actions %body] to:
lua:append(")\\nend")
end
end
- return lua
+ return lua"
test:
action [baz1]: return "baz1"
@@ -138,10 +138,10 @@ test:
assume ((baz1) == "baz1")
assume ((baz2) == "baz2")
compile [action %actions %body] to (..)
- lua> ".."
- local lua = \(compile as (local action %actions %body))
+ lua> "\
+ ..local lua = \(compile as (local action %actions %body))
lua:remove_free_vars(table.map(\%actions, function(a) return a.stub:as_lua_id() end))
- return lua
+ return lua"
test:
assume ((action (say %)) == (=lua "say_1"))
@@ -156,15 +156,15 @@ test:
test:
set {%1:1, %2:2}
swap %1 and %2
- assume ((%1 == 2) and (%2 == 1)) or barf ".."
- 'parse % as %' failed on 'swap % and %'
+ assume ((%1 == 2) and (%2 == 1)) or barf "\
+ ..'parse % as %' failed on 'swap % and %'"
set {%tmp:1, %tmp2:2}
swap %tmp and %tmp2
- assume ((%tmp == 2) and (%tmp2 == 1)) or barf ".."
- 'parse % as %' variable mangling failed.
+ assume ((%tmp == 2) and (%tmp2 == 1)) or barf "\
+ ..'parse % as %' variable mangling failed."
compile [parse %actions as %body] to (..)
- lua> ".."
- local replacements = {}
+ lua> "\
+ ..local replacements = {}
for i,arg in ipairs(\%actions[1]:get_args()) do
replacements[arg[1]] = tostring(nomsu:compile(arg))
end
@@ -201,18 +201,18 @@ compile [parse %actions as %body] to (..)
"\\nlocal lua = nomsu:compile(tree)",
"\\nreturn lua")
local ret = \(compile as (compile %actions to %new_body))
- return ret
+ return ret"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
action [%tree as lua expr]:
- lua> ".."
- \%tree_lua = nomsu:compile(\%tree)
+ lua> "\
+ ..\%tree_lua = nomsu:compile(\%tree)
if not \%tree_lua.is_value then
nomsu:compile_error(\%tree.source, "Could not convert %s to a Lua expression",
nomsu:tree_to_nomsu(\%tree))
end
- return \%tree_lua
+ return \%tree_lua"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -227,8 +227,8 @@ compile [remove action %action] to (..)
Lua "\(=lua "(\(%action.stub)):as_lua_id()") = nil"
test:
- assume ("\(\(foo \%x) as nomsu)" == "foo %x") or barf ".."
- action source code failed.
+ assume ("\(\(foo \%x) as nomsu)" == "foo %x") or barf "\
+ ..action source code failed."
compile [%tree as nomsu] to (..)
Lua value "nomsu:tree_to_nomsu(\(%tree as lua expr))"
@@ -236,12 +236,12 @@ compile [%tree as inline nomsu] to (..)
Lua value "nomsu:tree_to_nomsu(\(%tree as lua expr), true)"
action [%var as lua identifier, %var as lua id] (..)
- lua> ".."
- if type(\%var) == 'string' then return \%var:as_lua_id()
+ lua> "\
+ ..if type(\%var) == 'string' then return \%var:as_lua_id()
elseif AST.is_syntax_tree(\%var, 'Var') then return \%var[1]:as_lua_id()
elseif AST.is_syntax_tree(\%var, 'Action') then return \%var.stub:as_lua_id()
else error("Unknown type: "..tostring(\%var))
- end
+ end"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -250,39 +250,39 @@ compile [% is %kind syntax tree] to (..)
Lua value "AST.is_syntax_tree(\(% as lua expr), \(%kind as lua expr))"
compile [%tree with %t -> %replacement] to (..)
- Lua value ".."
- \(%tree as lua expr):map(function(\(%t as lua expr))
+ Lua value "\
+ ..\(%tree as lua expr):map(function(\(%t as lua expr))
\(%replacement as lua return)
- end)
+ end)"
action [%tree with vars %replacements] (..)
- =lua ".."
- \%tree:map(function(\%t)
+ =lua "\
+ ..\%tree:map(function(\%t)
if \%t.type == "Var" then
return \%replacements[\%t[1]]
end
- end)
+ end)"
compile [tree %tree with vars %replacements] to (..)
- Lua value ".."
- \(=lua "repr(\%tree)"):map(function(t)
+ Lua value "\
+ ..\(=lua "repr(\%tree)"):map(function(t)
if t.type == "Var" then
return \(%replacements as lua expr)[t[1]]
end
- end)
+ end)"
compile [%tree has subtree %match_tree] to (..)
- Lua value ".."
- (function()
+ Lua value "\
+ ..(function()
local match_tree = \(%match_tree as lua expr)
for subtree in coroutine.wrap(function() \(%tree as lua expr):map(coroutine.yield) end) do
if subtree == match_tree then return true end
end
- end)()
+ end)()"
action [match %tree with %patt]:
- lua> ".."
- if \%patt.type == "Var" then return _Dict{[\%patt[1]]=\%tree} end
+ lua> "\
+ ..if \%patt.type == "Var" then return _Dict{[\%patt[1]]=\%tree} end
if \%patt.type == "Action" and \%patt.stub ~= \%tree.stub then return nil end
if #\%patt ~= #\%tree then return nil end
local matches = _Dict{}
@@ -296,11 +296,11 @@ action [match %tree with %patt]:
end
end
end
- return matches
+ return matches"
action [%tree with %patt ~> %replacement]:
- lua> ".."
- return \%tree:map(function(\%t)
+ lua> "\
+ ..return \%tree:map(function(\%t)
local \%vars = \(match %t with %patt)
if not \%vars then return nil end
for \%k,\%v in pairs(\%vars) do
@@ -311,14 +311,14 @@ action [%tree with %patt ~> %replacement]:
return \%vars[\%t[1]]
end
end)
- end)
+ end)"
test:
assume (..)
(..)
- quote ".."
- one
- "two"
+ quote "\
+ ..one
+ "two""
..== "\"one\\n\\\"two\\\"\""
compile [quote %s] to (Lua value "repr(\(%s as lua expr))")
@@ -335,10 +335,10 @@ test:
assume ((parse "\\1") == \(\(1)))
compile [parse %text] to (Lua value "nomsu:parse(\(%text as lua expr))")
compile [parse %text from %filename] to (..)
- Lua value ".."
- nomsu:parse(NomsuCode(Source(\(%filename as lua expr), 1, #\(%text as lua expr)), \(..)
+ Lua value "\
+ ..nomsu:parse(NomsuCode(Source(\(%filename as lua expr), 1, #\(%text as lua expr)), \(..)
%text as lua expr
- ..))
+ ..))"
test:
assume ((run "return (2 + 99)") == 101)
@@ -347,10 +347,10 @@ test:
\(external \%passed = \(yes))
assume %passed
compile [run %nomsu_code] to (..)
- Lua value ".."
- nomsu:run(\(%nomsu_code as lua expr), \(..)
+ Lua value "\
+ ..nomsu:run(\(%nomsu_code as lua expr), \(..)
=lua "repr(tostring(\(%nomsu_code.source)))"
- ..)
+ ..)"
test:
assume ((\(\(5) + \(5)) as value) == 10) or barf "%tree as value failed."
@@ -377,13 +377,13 @@ compile [command line args] to (Lua value "arg")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compile [with local compile actions %body] to (..)
- Lua ".."
- do
+ Lua "\
+ ..do
local nomsu = table.fork(nomsu, {COMPILE_ACTIONS=table.fork(COMPILE_ACTIONS)})
\(%body as lua statements)
- end
+ end"
action [Nomsu version]:
use "lib/version.nom"
- return ".."
- \(Nomsu syntax version).\(core version).\(Nomsu compiler version).\(lib version)
+ return "\
+ ..\(Nomsu syntax version).\(core version).\(Nomsu compiler version).\(lib version)"
diff --git a/core/operators.nom b/core/operators.nom
index 3d18275..161bf83 100644
--- a/core/operators.nom
+++ b/core/operators.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.8.7.6
+#!/usr/bin/env nomsu -V4.8.8.6
#
This file contains definitions of operators like "+" and "and".
@@ -29,21 +29,21 @@ test:
compile [%var = %value] to:
lua> "local \%var_lua = \(%var as lua)"
assume %var_lua.is_value or barf "Invalid target for assignment: \%var"
- lua> ".."
- \%value = \%value:map(function(t)
+ lua> "\
+ ..\%value = \%value:map(function(t)
if Action:is_instance(t) and t.stub == "?" then
return \%var
end
end)
- local \%value_lua = \(%value as lua)
+ local \%value_lua = \(%value as lua)"
assume %value_lua.is_value or barf "Invalid value for assignment: \%value"
- lua> ".."
- local lua = LuaCode(tree.source, \%var_lua, ' = ', \%value_lua, ';')
+ lua> "\
+ ..local lua = LuaCode(tree.source, \%var_lua, ' = ', \%value_lua, ';')
if \%var.type == 'Var' then
lua:add_free_vars({tostring(nomsu:compile(\%var))})
end
- return lua
+ return lua"
test:
set {%x:10, %y:20}
@@ -53,10 +53,10 @@ test:
# Simultaneous mutli-assignments like: x,y,z = 1,x,3;
compile [set %assignments] to:
- assume (%assignments.type is "Dict") or barf ".."
- Expected a Dict for the assignments part of '<- %' statement, not \%assignments
- lua> ".."
- local lhs, rhs = LuaCode(tree.source), LuaCode(tree.source)
+ assume (%assignments.type is "Dict") or barf "\
+ ..Expected a Dict for the assignments part of '<- %' statement, not \%assignments"
+ lua> "\
+ ..local lhs, rhs = LuaCode(tree.source), LuaCode(tree.source)
for i, item in ipairs(\%assignments) do
local \%target, \%value = item[1], item[2]
\%value = \%value:map(function(t)
@@ -82,7 +82,7 @@ compile [set %assignments] to:
lhs:append(target_lua)
rhs:append(value_lua)
end
- return LuaCode(tree.source, lhs, " = ", rhs, ";")
+ return LuaCode(tree.source, lhs, " = ", rhs, ";")"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -109,12 +109,12 @@ test:
%y = "inner"
set global x local y
- assume ((%foozle == "inner") and (%y == "outer")) or barf ".."
- 'with external' failed.
+ assume ((%foozle == "inner") and (%y == "outer")) or barf "\
+ ..'with external' failed."
compile [with external %externs %body] to:
%body_lua = (%body as lua statements)
- lua> ".."
- \%body_lua:remove_free_vars(table.map(\%externs, function(v) return tostring(nomsu:compile(v)) end))
+ lua> "\
+ ..\%body_lua:remove_free_vars(table.map(\%externs, function(v) return tostring(nomsu:compile(v)) end))"
return %body_lua
test:
@@ -128,8 +128,8 @@ test:
assume (%z == (nil)) or barf "'with' scoping failed"
compile [with %assignments %body] to:
%lua = (%body as lua statements)
- lua> ".."
- local lhs, rhs = LuaCode(tree.source), LuaCode(tree.source)
+ lua> "\
+ ..local lhs, rhs = LuaCode(tree.source), LuaCode(tree.source)
local vars = {}
for i, item in ipairs(\%assignments) do
local \%target, \%value = item[1], item[2]
@@ -152,13 +152,13 @@ compile [with %assignments %body] to:
end
end
\%lua:remove_free_vars(vars)
- \%lua:prepend("local ", lhs, " = ", rhs, ";\\n")
+ \%lua:prepend("local ", lhs, " = ", rhs, ";\\n")"
return (..)
- Lua ".."
- do
+ Lua "\
+ ..do
\%lua
- end -- 'with' block
+ end -- 'with' block"
# Math Operators
test:
@@ -175,8 +175,8 @@ test:
return 1
assume (0 <= (one) <= 2) or barf "Three-way chained comparison failed."
- assume (%calls == 1) or barf ".."
- Three-way comparison evaluated middle value multiple times
+ assume (%calls == 1) or barf "\
+ ..Three-way comparison evaluated middle value multiple times"
parse [%x < %y < %z] as (..)
call ([%a, %b, %c] -> ((%a < %b) and (%b < %c))) with [%x, %y, %z]
@@ -232,28 +232,28 @@ compile [NOT %, ~ %] to (..)
compile [%a OR %b, %a | %b] to (..)
Lua value (..)
- (%use_bitops and "bit.bor(\(%a as lua expr), \(%b as lua expr))") or ".."
- (\(%a as lua expr) | \(%b as lua expr))
+ (%use_bitops and "bit.bor(\(%a as lua expr), \(%b as lua expr))") or "\
+ ..(\(%a as lua expr) | \(%b as lua expr))"
compile [%a XOR %b, %a ~ %b] to (..)
Lua value (..)
- (%use_bitops and "bit.bxor(\(%a as lua expr), \(%b as lua expr))") or ".."
- (\(%a as lua expr) ~ \(%b as lua expr))
+ (%use_bitops and "bit.bxor(\(%a as lua expr), \(%b as lua expr))") or "\
+ ..(\(%a as lua expr) ~ \(%b as lua expr))"
compile [%a AND %b, %a & %b] to (..)
Lua value (..)
- (%use_bitops and "bit.band(\(%a as lua expr), \(%b as lua expr))") or ".."
- (\(%a as lua expr) & \(%b as lua expr))
+ (%use_bitops and "bit.band(\(%a as lua expr), \(%b as lua expr))") or "\
+ ..(\(%a as lua expr) & \(%b as lua expr))"
compile [%x LSHIFT %shift, %x << %shift] to (..)
Lua value (..)
- (%use_bitops and "bit.lshift(\(%x as lua expr), \(%shift as lua expr))") or ".."
- (\(%x as lua expr) << \(%shift as lua expr))
+ (%use_bitops and "bit.lshift(\(%x as lua expr), \(%shift as lua expr))") or "\
+ ..(\(%x as lua expr) << \(%shift as lua expr))"
compile [%x RSHIFT %shift, %x >> %shift] to (..)
Lua value (..)
- (%use_bitops and "bit.rshift(\(%x as lua expr), \(%shift as lua expr))") or ".."
- (\(%x as lua expr) >> \(%shift as lua expr))
+ (%use_bitops and "bit.rshift(\(%x as lua expr), \(%shift as lua expr))") or "\
+ ..(\(%x as lua expr) >> \(%shift as lua expr))"
# Unary operators
test:
diff --git a/core/scopes.nom b/core/scopes.nom
index 6cc79c0..216222d 100644
--- a/core/scopes.nom
+++ b/core/scopes.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.8.7.6
+#!/usr/bin/env nomsu -V4.8.8.6
#
This file contains definitions pertaining to variable scoping
@@ -25,9 +25,9 @@ compile [with local %locals %body, with local %locals do %body] to:
if %locals.type is:
"Dict":
%body_lua = (..)
- Lua ".."
- \(compile as (<- %locals))
- \%body_lua
+ Lua "\
+ ..\(compile as (<- %locals))
+ \%body_lua"
%body_lua::declare locals ("\(%.1 as lua)" for % in %locals)
@@ -39,7 +39,7 @@ compile [with local %locals %body, with local %locals do %body] to:
compile error at %locals.source "Unexpected locals: %s"
return (..)
- Lua ".."
- do
+ Lua "\
+ ..do
\%body_lua
- end
+ end"
diff --git a/core/text.nom b/core/text.nom
index da9d550..25e9c3c 100644
--- a/core/text.nom
+++ b/core/text.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V3.8.7.6
+#!/usr/bin/env nomsu -V4.8.8.6
#
This file contains some definitions of text escape sequences, including ANSI console
color codes.
@@ -8,16 +8,12 @@ use "core/metaprogramming.nom"
test:
assume "\[1, 2, 3]" == "[1, 2, 3]"
assume "foo = \(1 + 2)!" == "foo = 3!"
- assume (..)
- ".."
- one
- two
- ..== "one\ntwo"
- assume (..)
- ".."
- no\
- ..gap
- ..== "nogap"
+ assume "one\ntwo" == "\
+ ..one
+ two"
+ assume "nogap" == "\
+ ..no\
+ ..gap"
assume (["x", "y"]::joined with ",") == "x,y"
assume (["x", "y"]::joined) == "xy"
assume ("BAR"::byte 2) == 65
@@ -31,10 +27,9 @@ test:
%こんにちは = "こんにちは"
アクション [% と言う] "\(%)世界"
assume (%こんにちは と言う) == "こんにちは世界"
-
compile [%expr for %match in %text matching %patt] to (..)
- Lua value ".."
- (function()
+ Lua value "\
+ ..(function()
local ret = _List{}
for \(%match as lua expr) in (\(%text as lua expr)):gmatch(\(..)
%patt as lua expr
@@ -42,14 +37,14 @@ compile [%expr for %match in %text matching %patt] to (..)
ret[#ret+1] = \(%expr as lua statements)
end
return ret
- end)()
+ end)()"
test:
assume "\n" == (newline)
# Text literals
-lua> ".."
- do
+lua> "\
+ ..do
local escapes = {
nl="\\\\n", newline="\\\\n", tab="\\\\t", bell="\\\\a", cr="\\\\r",
["carriage return"]="\\\\r", backspace="\\\\b", ["form feed"]="\\\\f",
@@ -61,4 +56,4 @@ lua> ".."
return LuaCode.Value(tree.source, lua)
end
end
- end
+ end"