aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program/aedifex/input.lux
diff options
context:
space:
mode:
authorEduardo Julian2020-10-25 05:10:08 -0400
committerEduardo Julian2020-10-25 05:10:08 -0400
commit72b4eecdc514387ab3b1c105cfd49436c9eb1e8d (patch)
tree20d8e52d5769b00be003dea58754b5bea79bb9e3 /stdlib/source/program/aedifex/input.lux
parente153b011bb94ba95474505c307873616bb493b6d (diff)
Some improvements to the Lux syntax parser.
Diffstat (limited to 'stdlib/source/program/aedifex/input.lux')
-rw-r--r--stdlib/source/program/aedifex/input.lux59
1 files changed, 59 insertions, 0 deletions
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
+ ["<c>" 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) (<c>.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)])))))