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 +++++++++++++++++++++++++++++++ stdlib/source/program/aedifex/local.lux | 4 +-- stdlib/source/program/aedifex/profile.lux | 3 -- stdlib/source/program/aedifex/project.lux | 3 ++ 4 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 stdlib/source/program/aedifex/input.lux (limited to 'stdlib/source/program/aedifex') 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)]))))) diff --git a/stdlib/source/program/aedifex/local.lux b/stdlib/source/program/aedifex/local.lux index bc2dbfb91..c7c72c827 100644 --- a/stdlib/source/program/aedifex/local.lux +++ b/stdlib/source/program/aedifex/local.lux @@ -137,13 +137,13 @@ [pom (encoding.from-utf8 pom) pom (:: xml.codec decode pom) profile (.run //pom.parser pom)] - (wrap [pom (set.to-list (get@ #/.dependencies profile))]))) + (wrap [pom (get@ #/.dependencies profile)]))) library (..read! system (format prefix (//artifact/extension.extension type))) sha1 (..read! system (format prefix //artifact/extension.sha1)) md5 (..read! system (format prefix //artifact/extension.md5))] (wrap {#//dependency/resolution.library library #//dependency/resolution.pom pom - #//dependency/resolution.dependencies dependencies + #//dependency/resolution.dependencies (set.to-list dependencies) #//dependency/resolution.sha1 (|> sha1 (:coerce (//hash.Hash //hash.SHA-1)) (:: //hash.sha1-codec encode)) diff --git a/stdlib/source/program/aedifex/profile.lux b/stdlib/source/program/aedifex/profile.lux index d8ebf9b18..190ed3714 100644 --- a/stdlib/source/program/aedifex/profile.lux +++ b/stdlib/source/program/aedifex/profile.lux @@ -24,9 +24,6 @@ ["." artifact (#+ Artifact)] ["." dependency]]) -(def: #export file - "project.lux") - (type: #export Distribution #Repo #Manual) diff --git a/stdlib/source/program/aedifex/project.lux b/stdlib/source/program/aedifex/project.lux index 071f54b12..9bc80c462 100644 --- a/stdlib/source/program/aedifex/project.lux +++ b/stdlib/source/program/aedifex/project.lux @@ -17,6 +17,9 @@ ["." // #_ ["#" profile (#+ Name Profile)]]) +(def: #export file + "project.lux") + (type: #export Project (Dictionary Name Profile)) -- cgit v1.2.3