From c4e928e5805054aa12da40baaeccbb9c522b52d0 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 14 Nov 2017 23:57:34 -0400 Subject: - Small refactoring. --- stdlib/source/lux/control/exception.lux | 30 +++++------ stdlib/source/lux/control/parser.lux | 92 ++++++++++++++++----------------- 2 files changed, 61 insertions(+), 61 deletions(-) diff --git a/stdlib/source/lux/control/exception.lux b/stdlib/source/lux/control/exception.lux index abc729129..9732cd185 100644 --- a/stdlib/source/lux/control/exception.lux +++ b/stdlib/source/lux/control/exception.lux @@ -1,7 +1,7 @@ (;module: {#;doc "Exception-handling functionality built on top of the Error type."} lux (lux (control monad) - (data ["E" error] + (data ["e" error] [maybe] [text "text/" Monoid]) [meta] @@ -30,41 +30,41 @@ If no exception was detected, or a different one from the one being checked, then pass along the original value."} (All [a] - (-> Exception (-> Text a) (E;Error a) - (E;Error a))) + (-> Exception (-> Text a) (e;Error a) + (e;Error a))) (case try - (#E;Success output) - (#E;Success output) + (#e;Success output) + (#e;Success output) - (#E;Error error) + (#e;Error error) (let [reference (exception "")] (if (text;starts-with? reference error) - (#E;Success (|> error + (#e;Success (|> error (text;clip (text;size reference) (text;size error)) maybe;assume then)) - (#E;Error error))))) + (#e;Error error))))) (def: #export (otherwise to-do try) {#;doc "If no handler could be found to catch the exception, then run a function as a last-resort measure."} (All [a] - (-> (-> Text a) (E;Error a) a)) + (-> (-> Text a) (e;Error a) a)) (case try - (#E;Success output) + (#e;Success output) output - (#E;Error error) + (#e;Error error) (to-do error))) (def: #export (return value) {#;doc "A way to lift normal values into the error-handling context."} - (All [a] (-> a (E;Error a))) - (#E;Success value)) + (All [a] (-> a (e;Error a))) + (#e;Success value)) (def: #export (throw exception message) {#;doc "Decorate an error message with an Exception and lift it into the error-handling context."} - (All [a] (-> Exception Text (E;Error a))) - (#E;Error (exception message))) + (All [a] (-> Exception Text (e;Error a))) + (#e;Error (exception message))) (syntax: #export (exception: [_ex-lev csr;export] [name s;local-symbol]) {#;doc (doc "Define a new exception type." diff --git a/stdlib/source/lux/control/parser.lux b/stdlib/source/lux/control/parser.lux index 166826519..1b91a0248 100644 --- a/stdlib/source/lux/control/parser.lux +++ b/stdlib/source/lux/control/parser.lux @@ -6,43 +6,43 @@ [codec]) (data (coll [list "list/" Functor Monoid]) [product] - ["E" error]))) + ["e" error]))) (type: #export (Parser s a) {#;doc "A generic parser."} - (-> s (E;Error [s a]))) + (-> s (e;Error [s a]))) ## [Structures] (struct: #export Functor (All [s] (Functor (Parser s))) (def: (map f ma) (function [input] (case (ma input) - (#E;Error msg) - (#E;Error msg) + (#e;Error msg) + (#e;Error msg) - (#E;Success [input' a]) - (#E;Success [input' (f a)]))))) + (#e;Success [input' a]) + (#e;Success [input' (f a)]))))) (struct: #export Applicative (All [s] (Applicative (Parser s))) (def: functor Functor) (def: (wrap x) (function [input] - (#E;Success [input x]))) + (#e;Success [input x]))) (def: (apply ff fa) (function [input] (case (ff input) - (#E;Success [input' f]) + (#e;Success [input' f]) (case (fa input') - (#E;Success [input'' a]) - (#E;Success [input'' (f a)]) + (#e;Success [input'' a]) + (#e;Success [input'' (f a)]) - (#E;Error msg) - (#E;Error msg)) + (#e;Error msg) + (#e;Error msg)) - (#E;Error msg) - (#E;Error msg))))) + (#e;Error msg) + (#e;Error msg))))) (struct: #export Monad (All [s] (Monad (Parser s))) (def: applicative Applicative) @@ -50,10 +50,10 @@ (def: (join mma) (function [input] (case (mma input) - (#E;Error msg) - (#E;Error msg) + (#e;Error msg) + (#e;Error msg) - (#E;Success [input' ma]) + (#e;Success [input' ma]) (ma input'))))) ## [Parsers] @@ -62,8 +62,8 @@ (All [s] (-> Text Bool (Parser s Unit))) (function [input] (if test - (#E;Success [input []]) - (#E;Error message)))) + (#e;Success [input []]) + (#e;Error message)))) (def: #export (maybe p) {#;doc "Optionality combinator."} @@ -71,12 +71,12 @@ (-> (Parser s a) (Parser s (Maybe a)))) (function [input] (case (p input) - (#E;Error _) (#E;Success [input #;None]) - (#E;Success [input' x]) (#E;Success [input' (#;Some x)])))) + (#e;Error _) (#e;Success [input #;None]) + (#e;Success [input' x]) (#e;Success [input' (#;Some x)])))) (def: #export (run input p) (All [s a] - (-> s (Parser s a) (E;Error [s a]))) + (-> s (Parser s a) (e;Error [s a]))) (p input)) (def: #export (some p) @@ -85,8 +85,8 @@ (-> (Parser s a) (Parser s (List a)))) (function [input] (case (p input) - (#E;Error _) (#E;Success [input (list)]) - (#E;Success [input' x]) (run input' + (#e;Error _) (#e;Success [input (list)]) + (#e;Success [input' x]) (run input' (do Monad [xs (some p)] (wrap (list& x xs))) @@ -116,8 +116,8 @@ (-> (Parser s a) (Parser s b) (Parser s (| a b)))) (function [tokens] (case (p1 tokens) - (#E;Success [tokens' x1]) (#E;Success [tokens' (+0 x1)]) - (#E;Error _) (run tokens + (#e;Success [tokens' x1]) (#e;Success [tokens' (+0 x1)]) + (#e;Error _) (run tokens (do Monad [x2 p2] (wrap (+1 x2)))) @@ -129,7 +129,7 @@ (-> (Parser s a) (Parser s a) (Parser s a))) (function [tokens] (case (pl tokens) - (#E;Error _) (pr tokens) + (#e;Error _) (pr tokens) output output ))) @@ -157,10 +157,10 @@ (if (n.> +0 n) (function [input] (case (p input) - (#E;Error msg) - (#E;Success [input (list)]) + (#e;Error msg) + (#e;Success [input (list)]) - (#E;Success [input' x]) + (#e;Success [input' x]) (run input' (do Monad [xs (at-most (n.dec n) p)] @@ -195,32 +195,32 @@ (All [s a] (-> (Parser s a) (Parser s Unit))) (function [input] (case (p input) - (#E;Error msg) - (#E;Success [input []]) + (#e;Error msg) + (#e;Success [input []]) _ - (#E;Error "Expected to fail; yet succeeded.")))) + (#e;Error "Expected to fail; yet succeeded.")))) (def: #export (fail message) (All [s a] (-> Text (Parser s a))) (function [input] - (#E;Error message))) + (#e;Error message))) (def: #export (default value parser) {#;doc "If the given parser fails, returns the default value."} (All [s a] (-> a (Parser s a) (Parser s a))) (function [input] (case (parser input) - (#E;Error error) - (#E;Success [input value]) + (#e;Error error) + (#e;Success [input value]) - (#E;Success [input' output]) - (#E;Success [input' output])))) + (#e;Success [input' output]) + (#e;Success [input' output])))) (def: #export remaining (All [s] (Parser s s)) (function [inputs] - (#E;Success [inputs inputs]))) + (#e;Success [inputs inputs]))) (def: #export (rec parser) {#;doc "Combinator for recursive parser."} @@ -252,13 +252,13 @@ (All [s a z] (-> (codec;Codec a z) (Parser s a) (Parser s z))) (function [input] (case (parser input) - (#E;Error error) - (#E;Error error) + (#e;Error error) + (#e;Error error) - (#E;Success [input' to-decode]) + (#e;Success [input' to-decode]) (case (:: Codec decode to-decode) - (#E;Error error) - (#E;Error error) + (#e;Error error) + (#e;Error error) - (#E;Success value) - (#E;Success [input' value]))))) + (#e;Success value) + (#e;Success [input' value]))))) -- cgit v1.2.3