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.lux | 35 ++---------------- 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 ++ 5 files changed, 67 insertions(+), 37 deletions(-) create mode 100644 stdlib/source/program/aedifex/input.lux (limited to 'stdlib/source/program') diff --git a/stdlib/source/program/aedifex.lux b/stdlib/source/program/aedifex.lux index 327eb8902..76db24a47 100644 --- a/stdlib/source/program/aedifex.lux +++ b/stdlib/source/program/aedifex.lux @@ -33,6 +33,7 @@ [action (#+ Action)] ["#" profile] ["#." project (#+ Project)] + ["#." input] ["#." parser] ["#." pom] ["#." cli] @@ -46,26 +47,6 @@ ["#/." auto] ["#/." deploy]]]) -(def: (read-file! path) - (-> Path (IO (Try Binary))) - (do (try.with io.monad) - [project-file (!.use (:: file.system file) [path])] - (!.use (:: project-file content) []))) - -(def: (read-code source-code) - (-> Text (Try Code)) - (let [parse (syntax.parse "" - syntax.no-aliases - (text.size source-code)) - start (: Source - [["" 0 0] 0 source-code])] - (case (parse start) - (#.Left [end error]) - (#try.Failure error) - - (#.Right [end lux-code]) - (#try.Success lux-code)))) - (def: (install! profile) (-> /.Profile (Promise Any)) (do promise.monad @@ -99,20 +80,10 @@ (log! (format "Could not resolve dependencies:" text.new-line error)))))) -(def: project - (-> Binary (Try Project)) - (|>> (do> try.monad - [encoding.from-utf8] - [..read-code] - [(list) (.run /parser.project)]))) - (program: [{[profile operation] /cli.command}] (do {@ io.monad} - [data (..read-file! /.file)] - (case (do try.monad - [data data - project (..project data)] - (/project.profile profile project)) + [?profile (/input.read io.monad file.system profile)] + (case ?profile (#try.Success profile) (case operation #/cli.POM 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