diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/library/lux/control/parser/environment.lux | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/stdlib/source/library/lux/control/parser/environment.lux b/stdlib/source/library/lux/control/parser/environment.lux index c0ced37c2..ea3370c0a 100644 --- a/stdlib/source/library/lux/control/parser/environment.lux +++ b/stdlib/source/library/lux/control/parser/environment.lux @@ -13,32 +13,38 @@ ["." //]) (type: #export Property + {#.doc (doc "A property in the environment.")} Text) (type: #export Environment + {#.doc (doc "An abstraction for environment variables of a program.")} (Dictionary Property Text)) -(exception: #export (unknown {property Property}) +(exception: #export (unknown_property {property Property}) (exception.report ["Property" (%.text property)])) (type: #export (Parser a) + {#.doc (doc "A parser of environment variables of a program.")} (//.Parser Environment a)) (def: #export empty + {#.doc (doc "An empty environment.")} Environment (dictionary.new text.hash)) (def: #export (property name) - (-> Text (Parser Text)) + (-> Property (Parser Text)) (function (_ environment) (case (dictionary.get name environment) (#.Some value) (exception.return [environment value]) #.None - (exception.throw ..unknown name)))) + (exception.except ..unknown_property [name])))) (def: #export (run parser environment) + {#.doc (doc "Executes a parser against the given environment variables." + "Does not check whether all environment variables were parsed, since they're usually an open set.")} (All [a] (-> (Parser a) Environment (Try a))) (\ try.monad map product.right (parser environment))) |