From 0fe039a41571328a29b7a620643fc5e30e32b9a3 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 11 Aug 2018 10:59:38 -0400 Subject: Moved CLI machinery to stdlib. --- stdlib/source/lux/compiler/cli.lux | 53 ++++++++++++++++++++++++++++++++++ stdlib/source/lux/compiler/default.lux | 7 ++--- 2 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 stdlib/source/lux/compiler/cli.lux (limited to 'stdlib/source') diff --git a/stdlib/source/lux/compiler/cli.lux b/stdlib/source/lux/compiler/cli.lux new file mode 100644 index 000000000..a73eb5a15 --- /dev/null +++ b/stdlib/source/lux/compiler/cli.lux @@ -0,0 +1,53 @@ +(.module: + [lux #* + [control + ["p" parser]] + ["." cli (#+ CLI)] + [world + [file (#+ File)]]]) + +(type: #export Configuration + {#sources (List File) + #target File}) + +(type: #export Build + [Configuration Text]) + +(type: #export REPL + Configuration) + +(type: #export Service + (#Build Build) + (#REPL REPL)) + +(do-template [ ] + [(def: #export + (CLI Text) + (cli.parameter [ ]))] + + [source "-s" "--source"] + [target "-t" "--target"] + [program "-p" "--program"] + ) + +(def: #export configuration + (CLI Configuration) + ($_ p.and + (p.some ..source) + ..target)) + +(def: #export build + (CLI Build) + ($_ p.and + configuration + ..program)) + +(def: #export repl + (CLI REPL) + ..configuration) + +(def: #export service + (CLI Service) + ($_ p.or + (p.after (cli.this "build") ..build) + (p.after (cli.this "repl") ..repl))) diff --git a/stdlib/source/lux/compiler/default.lux b/stdlib/source/lux/compiler/default.lux index f06a235de..cb93fdba4 100644 --- a/stdlib/source/lux/compiler/default.lux +++ b/stdlib/source/lux/compiler/default.lux @@ -16,6 +16,7 @@ [world ["." file (#+ File)]]] [// + ["." cli (#+ Configuration)] [meta [io ["." context]]]] @@ -64,10 +65,6 @@ ## ## (format module-name "/" cache.descriptor-name) ## ## (encoding.to-utf8 (%code (cache/description.write file-name module)))))) -(type: #export Configuration - {#sources (List File) - #target File}) - (type: #export (Platform fs anchor expression statement) {#host (Host expression statement) #phase (translation.Phase anchor expression statement) @@ -126,7 +123,7 @@ (-> Configuration Text (fs ))) (do (:: (get@ #file-system platform) &monad) [source (context.read (get@ #file-system platform) - (get@ #sources configuration) + (get@ #cli.sources configuration) module-name) ## _ (&io.prepare-module target-dir module-name) ## _ (write-module target-dir file-name module-name module artifacts) -- cgit v1.2.3