aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/control/exception.lux
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/library/lux/control/exception.lux86
1 files changed, 41 insertions, 45 deletions
diff --git a/stdlib/source/library/lux/control/exception.lux b/stdlib/source/library/lux/control/exception.lux
index 834f8afe8..8d39a9daf 100644
--- a/stdlib/source/library/lux/control/exception.lux
+++ b/stdlib/source/library/lux/control/exception.lux
@@ -1,6 +1,6 @@
(.require
[library
- [lux (.except except with when)
+ [lux (.except except with when def)
[abstract
[monad (.only do)]]
[control
@@ -19,9 +19,7 @@
["<[1]>" \\parser (.only Parser)]]
["[0]" macro (.only)
[syntax (.only syntax)
- ["|[0]|" input]
- ["[0]" type
- ["|[1]_[0]|" variable]]]]]]]
+ ["[0]" export]]]]]]
[//
["//" try (.only Try)]])
@@ -30,11 +28,11 @@
[#label Text
#constructor (-> a Text)]))
-(def .public (match? exception error)
+(.def .public (match? exception error)
(All (_ e) (-> (Exception e) Text Bit))
(text.starts_with? (the #label exception) error))
-(def .public (when exception then try)
+(.def .public (when exception then try)
(All (_ e a)
(-> (Exception e) (-> Text a) (Try a)
(Try a)))
@@ -51,7 +49,7 @@
then)}
{//.#Failure error}))))
-(def .public (otherwise else try)
+(.def .public (otherwise else try)
(All (_ a)
(-> (-> Text a) (Try a) a))
(.when try
@@ -61,52 +59,50 @@
{//.#Failure error}
(else error)))
-(def .public (error exception message)
+(.def .public (error exception message)
(All (_ e) (-> (Exception e) e Text))
((the ..#constructor exception) message))
-(def .public (except exception message)
+(.def .public (except exception message)
(All (_ e a) (-> (Exception e) e (Try a)))
{//.#Failure (..error exception message)})
-(def .public (assertion exception message test)
+(.def .public (assertion exception message test)
(All (_ e) (-> (Exception e) e Bit (Try Any)))
(if test
{//.#Success []}
(..except exception message)))
-(def exceptionP
- (Parser [Code (List |type_variable|.Variable) [Text (List |input|.Input)] (Maybe Code)])
- (let [private (is (Parser [(List |type_variable|.Variable) [Text (List |input|.Input)] (Maybe Code)])
- (all <>.and
- (<>.else (list) (<code>.tuple (<>.some |type_variable|.parser)))
- (<>.either (<code>.form (<>.and <code>.local |input|.parser))
- (<>.and <code>.local (<>#in (list))))
- (<>.maybe <code>.any)
- ))]
- (all <>.either
- (<>.and <code>.any private)
- (<>.and (<>#in (` .private)) private)
- )))
-
-(def .public exception
- (syntax (_ [[export_policy t_vars [name inputs] body] ..exceptionP])
- (macro.with_symbols [g!_ g!descriptor]
+(.def exceptionP
+ (Parser [export.Policy [[Text Code] Code Code]])
+ (export.parser
+ (all <>.either
+ (all <>.and
+ (<code>.form (<>.and <code>.local <code>.any))
+ <code>.any
+ <code>.any)
+ (do <>.monad
+ [name <code>.local]
+ (in [[name (code.local name)]
+ (` (Exception Any))
+ (` "")])))))
+
+(.def .public def
+ (syntax (_ [[export_policy [[name input] type body]] ..exceptionP])
+ (macro.with_symbols [g!descriptor]
(do meta.monad
- [current_module meta.current_module_name
- .let [descriptor (all text#composite "{" current_module "." name "}" text.new_line)
- g!self (code.local name)]]
- (in (list (` (def (, export_policy)
- (, g!self)
- (All ((, g!_) (,* (list#each |type_variable|.format t_vars)))
- (..Exception [(,* (list#each (the |input|.#type) inputs))]))
- (let [(, g!descriptor) (, (code.text descriptor))]
- [..#label (, g!descriptor)
- ..#constructor (function ((, g!self) [(,* (list#each (the |input|.#binding) inputs))])
- (at text.monoid (,' composite) (, g!descriptor)
- (, (maybe.else (' "") body))))])))))))))
-
-(def .public (report entries)
+ [current_module meta.current_module_name]
+ (let [descriptor (all text#composite "{" current_module "." name "}" text.new_line)
+ g!self (code.local name)]
+ (in (list (` (.def (, export_policy)
+ (, g!self)
+ (, type)
+ (let [(, g!descriptor) (, (code.text descriptor))]
+ [..#label (, g!descriptor)
+ ..#constructor (function ((, g!self) (, input))
+ (at text.monoid (,' composite) (, g!descriptor) (, body)))]))))))))))
+
+(.def .public (report entries)
(-> (List [Text Text]) Text)
(let [header_separator ": "
largest_header_size (list#mix (function (_ [header _] max)
@@ -137,7 +133,7 @@
(on_entry head)
tail))))
-(def .public (listing format entries)
+(.def .public (listing format entries)
(All (_ a)
(-> (-> a Text) (List a) Text))
(|> entries
@@ -150,7 +146,7 @@
list.reversed
..report))
-(def separator
+(.def separator
(let [gap (all "lux text concat" text.new_line text.new_line)
horizontal_line (|> "-" (list.repeated 64) text.together)]
(all "lux text concat"
@@ -158,14 +154,14 @@
horizontal_line
gap)))
-(def (decorated prelude error)
+(.def (decorated prelude error)
(-> Text Text Text)
(all "lux text concat"
prelude
..separator
error))
-(def .public (with exception message computation)
+(.def .public (with exception message computation)
(All (_ e a) (-> (Exception e) e (Try a) (Try a)))
(.when computation
{//.#Failure error}