aboutsummaryrefslogtreecommitdiff
path: root/lib/core/errors.nom
diff options
context:
space:
mode:
Diffstat (limited to 'lib/core/errors.nom')
-rw-r--r--lib/core/errors.nom137
1 files changed, 75 insertions, 62 deletions
diff --git a/lib/core/errors.nom b/lib/core/errors.nom
index 6be7e7f..a05c7d4 100644
--- a/lib/core/errors.nom
+++ b/lib/core/errors.nom
@@ -18,65 +18,79 @@ use "core/control_flow"
if ($condition.type == "Action"):
when $condition.stub is:
"1 ==":
- return
- LuaCode ("
- do
- local _a, _b = \($condition.1 as lua expr), \($condition.3 as lua expr)
- if _a ~= _b then
- _a = type_of(_a) == 'Text' and _a:as_lua() or _1_as_text(_a)
- _b = type_of(_b) == 'Text' and _b:as_lua() or _1_as_text(_b)
- at_1_fail(\(quote "\($condition.1.source)"),
- "Assumption failed: This value was ".._a.." but it was expected to be ".._b..".")
- end
+ return Lua ("
+ do -- Assumption:
+ local _a, _b = \($condition.1 as lua expr), \($condition.3 as lua expr)
+ if _a ~= _b then
+ _a = type_of(_a) == 'Text' and _a:as_lua() or _1_as_text(_a)
+ _b = type_of(_b) == 'Text' and _b:as_lua() or _1_as_text(_b)
+ at_1_fail(\(quote "\($condition.1.source)"),
+ "Assumption failed: This value was ".._a.." but it was expected to be ".._b..".")
end
- ")
+ end
+ ")
+
"1 !=":
- return
- LuaCode ("
- do
- local _a, _b = \($condition.1 as lua expr), \($condition.3 as lua expr)
- if _a == _b then
- _a = type_of(_a) == 'Text' and _a:as_lua() or _1_as_text(_a)
- at_1_fail(\(quote "\($condition.1.source)"),
- "Assumption failed: This value was ".._a.." but it wasn't expected to be.")
- end
+ return Lua ("
+ do -- Assumption:
+ local _a, _b = \($condition.1 as lua expr), \($condition.3 as lua expr)
+ if _a == _b then
+ _a = type_of(_a) == 'Text' and _a:as_lua() or _1_as_text(_a)
+ at_1_fail(\(quote "\($condition.1.source)"),
+ "Assumption failed: This value was ".._a.." but it wasn't expected to be.")
end
- ")
+ end
+ ")
+
"1 >" "1 <" "1 >=" "1 <=":
- return
- LuaCode ("
- do
- local _a, _b = \($condition.1 as lua expr), \($condition.3 as lua expr)
- if _a ~= _b then
- _a = type_of(_a) == 'Text' and _a:as_lua() or _1_as_text(_a)
- _b = type_of(_b) == 'Text' and _b:as_lua() or _1_as_text(_b)
- at_1_fail(\(quote "\($condition.1.source)"),
- "Assumption failed: This value was ".._a..", but it was expected to be \($condition.3)".._b..".")
- end
+ return Lua ("
+ do -- Assumption:
+ local _a, _b = \($condition.1 as lua expr), \($condition.3 as lua expr)
+ if _a ~= _b then
+ _a = type_of(_a) == 'Text' and _a:as_lua() or _1_as_text(_a)
+ _b = type_of(_b) == 'Text' and _b:as_lua() or _1_as_text(_b)
+ at_1_fail(\(quote "\($condition.1.source)"),
+ "Assumption failed: This value was ".._a..", but it was expected to be \
+ ..\($condition.3)".._b..".")
end
- ")
+ end
+ ")
+
"1 is":
- return
- LuaCode ("
- do
- local _ta, _tb = type_of(\($condition.1 as lua expr)), \($condition.3 as lua expr)
- if _ta ~= _tb then
- at_1_fail(\(quote "\($condition.1.source)"),
- "Assumption failed: This value was ".._ta.." but it was expected to be ".._tb..".")
- end
+ return Lua ("
+ do -- Assumption:
+ local _a, _b = \($condition.1 as lua expr), \($condition.3 as lua expr)
+ if not _1_is(_a, _b) then
+ _a = type_of(_a) == 'Text' and _a:as_lua() or _1_as_text(_a)
+ at_1_fail(\(quote "\($condition.1.source)"),
+ "Assumption failed: This value (".._a..") was expected to be "..\
+ .._b..", but wasn't.")
end
- ")
- return
- LuaCode ("
- if not \($condition as lua expr) then
- at_1_fail(\(quote "\($condition.source)"), "Assumption failed: This assumption did not hold.")
- end
- ")
+ end
+ ")
+
+ "1 isn ' t" "1 is not":
+ return Lua ("
+ do -- Assumption:
+ local _a, _b = \($condition.1 as lua expr), \($condition.(#$condition) as lua expr)
+ if _1_is(_a, _b) then
+ _a = type_of(_a) == 'Text' and _a:as_lua() or _1_as_text(_a)
+ at_1_fail(\(quote "\($condition.1.source)"),
+ "Assumption failed: This value (".._a..") was expected to not be \
+ ..".._b..", but it was.")
+ end
+ end
+ ")
+
+ return Lua ("
+ if not \($condition as lua expr) then
+ at_1_fail(\(quote "\($condition.source)"), "Assumption failed: This assumption did not hold.")
+ end
+ ")
(assume $a == $b) parses as (assume ($a == $b))
(assume $a != $b) parses as (assume ($a != $b))
(test that $condition) parses as (assume $condition)
-
test:
try: fail
$worked = (no)
@@ -109,21 +123,20 @@ test:
if ($msg_lua, text, is lua id):
$fallback_lua, add free vars [($msg_lua, text)]
$fallback_lua, prepend "-- Failure:\n"
- return
- Lua ("
- do
- local _fell_through = false
- local _result = {xpcall(function()
- \($action as lua)
- _fell_through = true
- end, enhance_error)}
- if _result[1] then
- \$success_lua
- else
- \$fallback_lua
- end
+ return Lua ("
+ do
+ local _fell_through = false
+ local _result = {xpcall(function()
+ \($action as lua)
+ _fell_through = true
+ end, enhance_error)}
+ if _result[1] then
+ \$success_lua
+ else
+ \$fallback_lua
end
- ")
+ end
+ ")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~