aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/control_flow.nom34
-rw-r--r--core/coroutines.nom4
-rw-r--r--core/errors.nom6
-rw-r--r--core/metaprogramming.nom13
-rw-r--r--core/operators.nom4
-rw-r--r--core/scopes.nom2
-rw-r--r--core/text.nom2
7 files changed, 29 insertions, 36 deletions
diff --git a/core/control_flow.nom b/core/control_flow.nom
index 236c9a8..cba0777 100644
--- a/core/control_flow.nom
+++ b/core/control_flow.nom
@@ -20,7 +20,7 @@ test:
barf "conditional fail"
(if %condition %if_body) compiles to "\
..if \(%condition as lua expr) then
- \(%if_body as lua statements)
+ \(%if_body as lua)
end"
test:
@@ -31,9 +31,9 @@ test:
if %condition %if_body else %else_body, unless %condition %else_body else %if_body
..all compile to "\
..if \(%condition as lua expr) then
- \(%if_body as lua statements)
+ \(%if_body as lua)
else
- \(%else_body as lua statements)
+ \(%else_body as lua)
end"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -137,7 +137,7 @@ test:
%lua = (..)
Lua "\
..while \(%condition as lua expr) do
- \(%body as lua statements)"
+ \(%body as lua)"
if (%body has subtree \(do next)):
%lua::append "\n ::continue::"
@@ -165,7 +165,7 @@ test:
define mangler
%lua = (..)
Lua "for \(mangle "i")=1,\(%n as lua expr) do\n "
- %lua::append (%body as lua statements)
+ %lua::append (%body as lua)
if (%body has subtree \(do next)):
%lua::append "\n ::continue::"
if (%body has subtree \(do next repeat)):
@@ -216,7 +216,7 @@ test:
%step as lua expr
.. do"
- %lua::append "\n " (%body as lua statements)
+ %lua::append "\n " (%body as lua)
if (%body has subtree \(do next)):
%lua::append "\n ::continue::"
if (%body has subtree \(do next %var)):
@@ -256,7 +256,7 @@ test:
# This uses Lua's approach of only allowing loop-scoped variables in a loop
%lua = (..)
Lua "for \(mangle "i"),\(%var as lua identifier) in ipairs(\(%iterable as lua expr)) do\n "
- %lua::append (%body as lua statements)
+ %lua::append (%body as lua)
if (%body has subtree \(do next)):
%lua::append "\n ::continue::"
if (%body has subtree \(do next %var)):
@@ -277,7 +277,7 @@ test:
# This uses Lua's approach of only allowing loop-scoped variables in a loop
%lua = (..)
Lua "for \(%i as lua identifier),\(%var as lua identifier) in ipairs(\(%iterable as lua expr)) do\n "
- %lua::append (%body as lua statements)
+ %lua::append (%body as lua)
if (%body has subtree \(do next)):
%lua::append "\n ::continue::"
if (%body has subtree \(do next %var)):
@@ -318,7 +318,7 @@ test:
%iterable as lua expr
..) do"
- %lua::append "\n " (%body as lua statements)
+ %lua::append "\n " (%body as lua)
if (%body has subtree \(do next)):
%lua::append "\n ::continue::"
if (%body has subtree \(do next %key)):
@@ -387,7 +387,7 @@ test:
..need a conditional block around it. Otherwise, make sure the 'else' \
..block comes last."
- %code::append "\nelse\n " (%action as lua statements)
+ %code::append "\nelse\n " (%action as lua)
%else_allowed = (no)
..else:
%code::append %clause " "
@@ -396,7 +396,7 @@ test:
%code::append " or "
%code::append (%line.%i as lua expr)
- %code::append " then\n " (%action as lua statements)
+ %code::append " then\n " (%action as lua)
%clause = "\nelseif"
if ((size of "\%code") == 0):
@@ -445,7 +445,7 @@ test:
..need a conditional block around it. Otherwise, make sure the 'else' \
..block comes last."
- %code::append "\nelse\n " (%action as lua statements)
+ %code::append "\nelse\n " (%action as lua)
%else_allowed = (no)
..else:
%code::append %clause " "
@@ -454,7 +454,7 @@ test:
%code::append " or "
%code::append "\(mangle "branch value") == " (%line.%i as lua expr)
- %code::append " then\n " (%action as lua statements)
+ %code::append " then\n " (%action as lua)
%clause = "\nelseif"
if ((size of "\%code") == 0):
@@ -471,7 +471,7 @@ test:
# Do/finally
(do %action) compiles to "\
..do
- \(%action as lua statements)
+ \(%action as lua)
end -- do"
test:
@@ -489,10 +489,10 @@ test:
..do
local \(mangle "fell_through") = false
local \(mangle "ok"), \(mangle "ret") = pcall(function()
- \(%action as lua statements)
+ \(%action as lua)
\(mangle "fell_through") = true
end)
- \(%final_action as lua statements)
+ \(%final_action as lua)
if not \(mangle "ok") then error(ret, 0) end
if not \(mangle "fell_through") then return ret end
end"
@@ -525,7 +525,7 @@ test:
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)"
if (%body has subtree \(do next)):
%lua::append "\n ::continue::"
if (%body has subtree \(do next %var)):
diff --git a/core/coroutines.nom b/core/coroutines.nom
index 782c20e..27797fa 100644
--- a/core/coroutines.nom
+++ b/core/coroutines.nom
@@ -18,11 +18,11 @@ test:
assume (%nums == [4, 5, 6, 6, 6]) or barf "Coroutine iteration failed"
[coroutine %body, generator %body] all compile to "\
..(function()
- \(%body as lua statements)
+ \(%body as lua)
end)"
(-> %) compiles to "coroutine.yield(true, \((% as lua expr) if % else "nil"))"
(for % in coroutine %co %body) compiles to "\
..for _junk,\(% as lua expr) in coroutine.wrap(\(%co as lua expr)) do
- \(%body as lua statements)
+ \(%body as lua)
end"
diff --git a/core/errors.nom b/core/errors.nom
index b2222ee..7cec344 100644
--- a/core/errors.nom
+++ b/core/errors.nom
@@ -63,16 +63,16 @@ test:
local fell_through = false
local err, erred = nil, false
local ok, ret = xpcall(function()
- \(%action as lua statements)
+ \(%action as lua)
fell_through = true
end, function(\(=lua "\%fallback and \(%msg as lua expr) or ''"))
local ok, ret = pcall(function()
- \((=lua "\%fallback or \%msg") as lua statements)
+ \((=lua "\%fallback or \%msg") as lua)
end)
if not ok then err, erred = ret, true end
end)
if ok then
- \(%success as lua statements)
+ \(%success as lua)
if not fell_through then
return ret
end
diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom
index 2ae8b1b..1f787c2 100644
--- a/core/metaprogramming.nom
+++ b/core/metaprogramming.nom
@@ -233,17 +233,10 @@ test:
[%action parses as %body] all parse as ([%action] all parse as %body)
(%tree as lua expr) compiles to "\
- ..compile(\(=lua "compile(\%tree, nil, true)"), nil, true)"
+ ..compile(\(=lua "compile(\%tree, true)"), true)"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-(%tree as lua) compiles to "compile(\(%tree as lua expr))"
-(%tree as lua statements) compiles to "\
- ..compile(\(%tree as lua expr)):as_statements()"
-
-(%tree as lua return) compiles to "\
- ..compile(\(%tree as lua expr)):as_statements('return ')"
-
externally [%var as lua identifier, %var as lua id] all mean:
lua> "\
..if lua_type_of(\%var) == 'string' then return \%var:as_lua_id()
@@ -265,7 +258,7 @@ externally (% is %kind syntax tree) means (..)
(%tree with %t -> %replacement) compiles to "\
..\(%tree as lua expr):map(function(\(%t as lua expr))
- \(%replacement as lua return)
+ \((%replacement as lua) if (%replacement.type == "Block") else ("return \(%replacement as lua expr)"))
end)"
externally (%tree with vars %replacements) means (..)
@@ -393,7 +386,7 @@ test:
--local compile = _1_forked(compile)
local old_action = compile.action
compile.action = _1_forked(old_action)
- \(%body as lua statements)
+ \(%body as lua)
compile.action = old_action
end"
diff --git a/core/operators.nom b/core/operators.nom
index 66185f7..38fc9a8 100644
--- a/core/operators.nom
+++ b/core/operators.nom
@@ -94,7 +94,7 @@ test:
assume ((%foozle == "inner") and (%y == "outer")) or barf "\
..'with external' failed."
(with external %externs %body) compiles to:
- %body_lua = (%body as lua statements)
+ %body_lua = (%body as lua)
lua> "\
..\%body_lua:remove_free_vars(table.map(\%externs, function(v) return compile(v):text() end))"
return %body_lua
@@ -109,7 +109,7 @@ test:
assume (%x == 1) or barf "'with' scoping failed"
assume (%z == (nil)) or barf "'with' scoping failed"
(with %assignments %body) compiles to:
- %lua = (%body as lua statements)
+ %lua = (%body as lua)
lua> "\
..local lhs, rhs = LuaCode(tree.source), LuaCode(tree.source)
local vars = {}
diff --git a/core/scopes.nom b/core/scopes.nom
index 47960d8..bd8b8a6 100644
--- a/core/scopes.nom
+++ b/core/scopes.nom
@@ -23,7 +23,7 @@ test:
assume ((foo) == "outer foo")
[with local %locals %body, with local %locals do %body] all compile to:
- %body_lua = (%body as lua statements)
+ %body_lua = (%body as lua)
if %locals.type is:
"Dict":
%body_lua = (..)
diff --git a/core/text.nom b/core/text.nom
index 1e297aa..2d72f01 100644
--- a/core/text.nom
+++ b/core/text.nom
@@ -38,7 +38,7 @@ test:
for \(%match as lua expr) in (\(%text as lua expr)):gmatch(\(..)
%patt as lua expr
..) do
- \(mangle "comprehension")[#\(mangle "comprehension")+1] = \(%expr as lua statements)
+ \(mangle "comprehension")[#\(mangle "comprehension")+1] = \(%expr as lua)
end
return \(mangle "comprehension")
end)()"