aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/parser
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/parser')
-rw-r--r--stdlib/source/parser/lux/world/environment.lux44
1 files changed, 44 insertions, 0 deletions
diff --git a/stdlib/source/parser/lux/world/environment.lux b/stdlib/source/parser/lux/world/environment.lux
new file mode 100644
index 000000000..33089f2a3
--- /dev/null
+++ b/stdlib/source/parser/lux/world/environment.lux
@@ -0,0 +1,44 @@
+(.require
+ [library
+ [lux (.except)
+ [control
+ ["//" parser]
+ ["[0]" try (.only Try)]
+ ["[0]" exception (.only exception)]]
+ [data
+ ["[0]" product]
+ ["[0]" text (.only)
+ ["%" \\format (.only format)]]
+ [collection
+ ["[0]" dictionary (.only Dictionary)]]]]])
+
+(type .public Property
+ Text)
+
+(type .public Environment
+ (Dictionary Property Text))
+
+(exception .public (unknown_property [property Property])
+ (exception.report
+ "Property" (%.text property)))
+
+(type .public (Parser a)
+ (//.Parser Environment a))
+
+(def .public empty
+ Environment
+ (dictionary.empty text.hash))
+
+(def .public (property name)
+ (-> Property (Parser Text))
+ (function (_ environment)
+ (case (dictionary.value name environment)
+ {.#Some value}
+ {try.#Success [environment value]}
+
+ {.#None}
+ (exception.except ..unknown_property [name]))))
+
+(def .public (result parser environment)
+ (All (_ a) (-> (Parser a) Environment (Try a)))
+ (at try.monad each product.right (parser environment)))