aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/parser
diff options
context:
space:
mode:
authorEduardo Julian2022-06-29 03:15:23 -0400
committerEduardo Julian2022-06-29 03:15:23 -0400
commit664e02d1b5e5aa479869c4e17ec4128f5cfd04e2 (patch)
tree7111d48d8a728ea30abfb6adb104425f61d65585 /stdlib/source/parser
parent5232f0701cd95f260005a65d220a361dd71b6b96 (diff)
New "parser" hierarchy. [Part 6]
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)))