aboutsummaryrefslogtreecommitdiff
path: root/core/control_flow.nom
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-06-12 13:56:15 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-06-12 13:56:35 -0700
commit0c9973ff0363e400d3d284339b77197c40c3f60c (patch)
tree00c51a0cea933b1cec28f45561e3ba74dde466ff /core/control_flow.nom
parent7cd512d15e5bc22c529d5b4e3e02a41fe1e84208 (diff)
Tidying up exceptions and error reporting. Also simplified the grammar a
tiny bit.
Diffstat (limited to 'core/control_flow.nom')
-rw-r--r--core/control_flow.nom42
1 files changed, 30 insertions, 12 deletions
diff --git a/core/control_flow.nom b/core/control_flow.nom
index f5c61e3..73a0f43 100644
--- a/core/control_flow.nom
+++ b/core/control_flow.nom
@@ -49,13 +49,13 @@ immediately
To see why this is necessary consider: (random()<.5 and false or 99)
return
Lua value ".."
- (function()
+ ((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
immediately
@@ -361,31 +361,46 @@ immediately
# Try/except
immediately
compile [..]
- try %action and if it succeeds %success or if it barfs %fallback
- try %action and if it barfs %fallback or if it succeeds %success
+ 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
local fell_through = false
- local ok, ret = pcall(function()
+ local err, erred = nil, false
+ local ok, ret = xpcall(function()
\(%action as lua statements)
fell_through = true
+ end, function(\(%msg as lua expr))
+ local ok, ret = pcall(function()
+ \(%fallback as lua statements)
+ end)
+ if not ok then err, erred = ret, true end
end)
if ok then
\(%success as lua statements)
if not fell_through then
return ret
end
- else
- \(%fallback as lua statements)
+ elseif erred then
+ error(err, 0)
end
end
+immediately
+ parse [..]
+ try %action and if it succeeds %success or if it barfs %fallback
+ try %action and if it barfs %fallback or if it succeeds %success
+ ..as: try %action and if it succeeds %success or if it barfs (=lua "") %fallback
+immediately
parse [try %action] as
try %action and if it succeeds: do nothing
..or if it barfs: do nothing
parse [try %action and if it barfs %fallback] as
try %action and if it succeeds: do nothing
..or if it barfs %fallback
+ parse [try %action and if it barfs %msg %fallback] as
+ try %action and if it succeeds: do nothing
+ ..or if it barfs %msg %fallback
parse [try %action and if it succeeds %success] as
try %action and if it succeeds %success or if it barfs: do nothing
@@ -406,17 +421,20 @@ immediately
fell_through = true
end)
\(%final_action as lua statements)
- if not ok then error(ret) end
+ if not ok then error(ret, 0) end
if not fell_through then return ret end
end
# Inline thunk:
immediately
compile [result of %body] to
- Lua value ".."
- (function()
- \(%body as lua statements)
- end)()
+ %body <- (%body as lua statements)
+ declare locals in %body
+ return
+ Lua value ".."
+ ((function()
+ \%body
+ end)())
# Coroutines:
immediately