diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2019-01-22 16:15:25 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2019-01-22 16:16:53 -0800 |
| commit | f746ba34d799e6560df1aad1cad15a70b34914d1 (patch) | |
| tree | 3829ce9bd8469e59d1a51470823d510dc808e1c7 /lib/core/errors.nom | |
| parent | a596195f6cfb6731f1e778e4bc304028ecd9bf08 (diff) | |
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.
Diffstat (limited to 'lib/core/errors.nom')
| -rw-r--r-- | lib/core/errors.nom | 84 |
1 files changed, 60 insertions, 24 deletions
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 |
