From 72b4eecdc514387ab3b1c105cfd49436c9eb1e8d Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 25 Oct 2020 05:10:08 -0400 Subject: Some improvements to the Lux syntax parser. --- stdlib/source/program/aedifex/input.lux | 59 +++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 stdlib/source/program/aedifex/input.lux (limited to 'stdlib/source/program/aedifex/input.lux') diff --git a/stdlib/source/program/aedifex/input.lux b/stdlib/source/program/aedifex/input.lux new file mode 100644 index 000000000..ffed02d28 --- /dev/null +++ b/stdlib/source/program/aedifex/input.lux @@ -0,0 +1,59 @@ +(.module: + [lux #* + [abstract + [monad (#+ Monad do)]] + [control + [pipe (#+ do>)] + ["." try (#+ Try)] + [parser + ["" code]] + [security + ["!" capability]]] + [data + [binary (#+ Binary)] + ["." text + ["." encoding]]] + [meta + ["." location]] + [tool + [compiler + [language + [lux + ["." syntax]]]]] + [world + ["." file]]] + ["." // #_ + ["#" profile (#+ Profile)] + ["#." action (#+ Action)] + ["#." project (#+ Project)] + ["#." parser]]) + +(def: (parse-lux source-code) + (-> Text (Try Code)) + (let [parse (syntax.parse "" + syntax.no-aliases + (text.size source-code))] + (case (parse [location.dummy 0 source-code]) + (#.Left [_ error]) + (#try.Failure error) + + (#.Right [_ lux-code]) + (#try.Success lux-code)))) + +(def: parse-project + (-> Binary (Try Project)) + (|>> (do> try.monad + [encoding.from-utf8] + [..parse-lux] + [(list) (.run //parser.project)]))) + +(def: #export (read monad fs profile) + (All [!] (-> (Monad !) (file.System !) Text (! (Try Profile)))) + (do (try.with monad) + [project-file (!.use (:: fs file) //project.file) + project-file (!.use (:: project-file content) [])] + (:: monad wrap + (|> project-file + (do> try.monad + [..parse-project] + [(//project.profile profile)]))))) -- cgit v1.2.3