From f746ba34d799e6560df1aad1cad15a70b34914d1 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Tue, 22 Jan 2019 16:15:25 -0800 Subject: Moved all the text method stuff into text.moon instead of splitting across string2/containers. Modified the type stuff to output better type names and use (a Dict) and (a List) instead of (Dict) and (List). (Text) now also has a proper constructor. (assume) now also handles a bunch of different assumptions with smart error messages. --- lib/core/errors.nom | 84 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 60 insertions(+), 24 deletions(-) (limited to 'lib/core/errors.nom') diff --git a/lib/core/errors.nom b/lib/core/errors.nom index a84b580..e24c012 100644 --- a/lib/core/errors.nom +++ b/lib/core/errors.nom @@ -14,31 +14,67 @@ use "core/control_flow" )) ") -(assume $condition) compiles to (" - if not \($condition as lua expr) then - at_1_fail(\(quote "\($condition.source)"), "Assumption failed: This was not true.") - end -") - -(assume $a == $b) compiles to (" - do - local _a, _b = \($a as lua expr), \($b as lua expr) - if _a ~= _b then - at_1_fail(\(quote "\($a.source)"), - "Assumption failed: This value was "..tostring(_a).." but it was expected to be "..tostring(_b)..".") - end - end -") +(assume $condition) compiles to: + 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 tostring(_a) + _b = type_of(_b) == 'Text' and _b:as_lua() or tostring(_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 tostring(_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 tostring(_a) + _b = type_of(_b) == 'Text' and _b:as_lua() or tostring(_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 + end + ") + return + LuaCode (" + if not \($condition as lua expr) then + at_1_fail(\(quote "\($condition.source)"), "Assumption failed: This assumption did not hold.") + end + ") -(assume $a != $b) compiles to (" - do - local _a, _b = \($a as lua expr), \($b as lua expr) - if _a == _b then - at_1_fail(\(quote "\($a.source)"), - "Assumption failed: This value was "..tostring(_a).." but it wasn't expected to be.") - end - end -") +(assume $a == $b) parses as (assume ($a == $b)) +(assume $a != $b) parses as (assume ($a != $b)) test: try: fail -- cgit v1.2.3