From 664e02d1b5e5aa479869c4e17ec4128f5cfd04e2 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 29 Jun 2022 03:15:23 -0400 Subject: New "parser" hierarchy. [Part 6] --- stdlib/source/parser/lux/world/environment.lux | 44 ++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 stdlib/source/parser/lux/world/environment.lux (limited to 'stdlib/source/parser') 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))) -- cgit v1.2.3