aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
authorEduardo Julian2019-04-19 18:49:43 -0400
committerEduardo Julian2019-04-19 18:49:43 -0400
commit6d4950f84e4ec1d35dff95c9816d75f360d4a349 (patch)
treef48b6d793b4175316c5636878479dc348fae0394 /stdlib
parent0ed7cb3a7d07cf92be57a8f26355212bcee0325d (diff)
Moved the CLI parser under "lux/control/parser/".
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/source/lux/control/parser/cli.lux (renamed from stdlib/source/lux/control/cli.lux)52
-rw-r--r--stdlib/source/program/compositor/cli.lux10
-rw-r--r--stdlib/source/test/lux.lux5
-rw-r--r--stdlib/source/test/lux/control.lux6
-rw-r--r--stdlib/source/test/lux/control/parser/cli.lux (renamed from stdlib/source/test/lux/control/cli.lux)20
5 files changed, 48 insertions, 45 deletions
diff --git a/stdlib/source/lux/control/cli.lux b/stdlib/source/lux/control/parser/cli.lux
index ae712d644..e3ac37255 100644
--- a/stdlib/source/lux/control/cli.lux
+++ b/stdlib/source/lux/control/parser/cli.lux
@@ -14,19 +14,19 @@
[tool
[compiler
["." host]]]]
- [//
- ["." io]
- ["p" parser (#+ Parser)]
- [concurrency
- ["." process]]])
+ ["." //
+ [//
+ ["." io]
+ [concurrency
+ ["." process]]]])
-(type: #export (CLI a)
+(type: #export (Parser a)
{#.doc "A command-line interface parser."}
- (Parser (List Text) a))
+ (//.Parser (List Text) a))
(def: #export (run inputs parser)
- (All [a] (-> (List Text) (CLI a) (Error a)))
- (case (p.run inputs parser)
+ (All [a] (-> (List Text) (Parser a) (Error a)))
+ (case (//.run inputs parser)
(#error.Success [remaining output])
(case remaining
#.Nil
@@ -40,7 +40,7 @@
(def: #export any
{#.doc "Just returns the next input without applying any logic."}
- (CLI Text)
+ (Parser Text)
(function (_ inputs)
(case inputs
(#.Cons arg inputs')
@@ -51,7 +51,7 @@
(def: #export (parse parser)
{#.doc "Parses the next input with a parsing function."}
- (All [a] (-> (-> Text (Error a)) (CLI a)))
+ (All [a] (-> (-> Text (Error a)) (Parser a)))
(function (_ inputs)
(do error.monad
[[remaining raw] (any inputs)
@@ -60,7 +60,7 @@
(def: #export (this reference)
{#.doc "Checks that a token is in the inputs."}
- (-> Text (CLI Any))
+ (-> Text (Parser Any))
(function (_ inputs)
(do error.monad
[[remaining raw] (any inputs)]
@@ -70,10 +70,10 @@
(def: #export (somewhere cli)
{#.doc "Given a parser, tries to parse it somewhere in the inputs (i.e. not necessarily parsing the immediate inputs)."}
- (All [a] (-> (CLI a) (CLI a)))
+ (All [a] (-> (Parser a) (Parser a)))
(function (_ inputs)
(loop [immediate inputs]
- (case (p.run immediate cli)
+ (case (//.run immediate cli)
(#error.Success [remaining output])
(#error.Success [remaining output])
@@ -90,22 +90,22 @@
(def: #export end
{#.doc "Ensures there are no more inputs."}
- (CLI Any)
+ (Parser Any)
(function (_ inputs)
(case inputs
#.Nil (#error.Success [inputs []])
_ (#error.Failure (format "Unknown parameters: " (text.join-with " " inputs))))))
(def: #export (named name value)
- (All [a] (-> Text (CLI a) (CLI a)))
+ (All [a] (-> Text (Parser a) (Parser a)))
(|> value
- (p.after (..this name))
+ (//.after (..this name))
..somewhere))
(def: #export (parameter [short long] value)
- (All [a] (-> [Text Text] (CLI a) (CLI a)))
+ (All [a] (-> [Text Text] (Parser a) (Parser a)))
(|> value
- (p.after (p.either (..this short) (..this long)))
+ (//.after (//.either (..this short) (..this long)))
..somewhere))
(type: Program-Args
@@ -114,11 +114,11 @@
(def: program-args^
(Syntax Program-Args)
- (p.or s.local-identifier
- (s.tuple (p.some (p.either (do p.monad
- [name s.local-identifier]
- (wrap [(code.identifier ["" name]) (` any)]))
- (s.record (p.and s.any s.any)))))))
+ (//.or s.local-identifier
+ (s.tuple (//.some (//.either (do //.monad
+ [name s.local-identifier]
+ (wrap [(code.identifier ["" name]) (` any)]))
+ (s.record (//.and s.any s.any)))))))
(syntax: #export (program:
{args program-args^}
@@ -151,8 +151,8 @@
(with-gensyms [g!args g!_ g!output g!message]
(wrap (list (` ("lux def program"
(.function ((~ g!program) (~ g!args))
- (case ((: (~! (..CLI (io.IO .Any)))
- ((~! do) (~! p.monad)
+ (case ((: (~! (..Parser (io.IO .Any)))
+ ((~! do) (~! //.monad)
[(~+ (|> args
(list@map (function (_ [binding parser])
(list binding parser)))
diff --git a/stdlib/source/program/compositor/cli.lux b/stdlib/source/program/compositor/cli.lux
index 8df1cc839..4453d5d36 100644
--- a/stdlib/source/program/compositor/cli.lux
+++ b/stdlib/source/program/compositor/cli.lux
@@ -1,8 +1,8 @@
(.module:
[lux #*
[control
- ["p" parser]
- ["." cli (#+ CLI)]]
+ ["p" parser
+ ["." cli (#+ Parser)]]]
[world
[file (#+ Path)]]]
## [///
@@ -21,7 +21,7 @@
(template [<name> <long>]
[(def: #export <name>
- (CLI Text)
+ (Parser Text)
(cli.named <long> cli.any))]
[source "--source"]
@@ -30,14 +30,14 @@
)
(def: #export configuration
- (CLI Configuration)
+ (Parser Configuration)
($_ p.and
(p.some ..source)
..target
..module))
(def: #export service
- (CLI Service)
+ (Parser Service)
($_ p.or
(p.after (cli.this "build") ..configuration)
(p.after (cli.this "repl") ..configuration)))
diff --git a/stdlib/source/test/lux.lux b/stdlib/source/test/lux.lux
index ab5d2e1d4..f62a071ae 100644
--- a/stdlib/source/test/lux.lux
+++ b/stdlib/source/test/lux.lux
@@ -12,9 +12,10 @@
[monad (#+ do)]
[predicate (#+ Predicate)]]
[control
- [cli (#+ program:)]
["." io (#+ io)]
- ["." function]]
+ ["." function]
+ [parser
+ [cli (#+ program:)]]]
[data
["." name]
[number
diff --git a/stdlib/source/test/lux/control.lux b/stdlib/source/test/lux/control.lux
index bacb4cb24..61d69459f 100644
--- a/stdlib/source/test/lux/control.lux
+++ b/stdlib/source/test/lux/control.lux
@@ -2,7 +2,6 @@
[lux #*
["_" test (#+ Test)]]
["." / #_
- ["#." cli]
["#." continuation]
["#." exception]
["#." io]
@@ -20,7 +19,8 @@
["#." actor]
["#." stm]]
["#." parser #_
- ["#/." text]]
+ ["#/." text]
+ ["#/." cli]]
[security
["#." privacy]
["#." integrity]]
@@ -40,6 +40,7 @@
Test
($_ _.and
/parser/text.test
+ /parser/cli.test
))
(def: security
@@ -52,7 +53,6 @@
(def: #export test
Test
($_ _.and
- /cli.test
/continuation.test
/exception.test
/io.test
diff --git a/stdlib/source/test/lux/control/cli.lux b/stdlib/source/test/lux/control/parser/cli.lux
index ff7a3abb3..a476c97c6 100644
--- a/stdlib/source/test/lux/control/cli.lux
+++ b/stdlib/source/test/lux/control/parser/cli.lux
@@ -1,6 +1,8 @@
(.module:
[lux #*
- data/text/format
+ [data
+ text/format
+ ["." name]]
["M" abstract/monad (#+ Monad do)]
["_" test (#+ Test)]
["r" math/random]
@@ -10,8 +12,8 @@
[data
["." error]
[number
- ["." nat ("#;." decimal)]]
- ["." text ("#;." equivalence)]
+ ["." nat ("#@." decimal)]]
+ ["." text ("#@." equivalence)]
[collection
["." list]]]]
{1
@@ -19,12 +21,12 @@
(def: #export test
Test
- (<| (_.context (%name (name-of /.CLI)))
+ (<| (_.context (name.module (name-of /._)))
(do r.monad
[num-args (|> r.nat (:: @ map (n/% 10)))
- #let [gen-arg (:: @ map nat;encode r.nat)]
+ #let [gen-arg (:: @ map nat@encode r.nat)]
yes gen-arg
- #let [gen-ignore (r.filter (|>> (text;= yes) not)
+ #let [gen-ignore (r.filter (|>> (text@= yes) not)
(r.unicode 5))]
no gen-ignore
pre-ignore (r.list 5 gen-ignore)
@@ -36,7 +38,7 @@
#0
(#error.Success arg)
- (text;= arg yes))))
+ (text@= arg yes))))
(_.test "Can test tokens."
(and (|> (/.run (list yes) (/.this yes))
(case> (#error.Failure _)
@@ -51,12 +53,12 @@
(#error.Success _)
#0))))
(_.test "Can use custom token parsers."
- (|> (/.run (list yes) (/.parse nat;decode))
+ (|> (/.run (list yes) (/.parse nat@decode))
(case> (#error.Failure _)
#0
(#error.Success parsed)
- (text;= (nat;encode parsed)
+ (text@= (nat@encode parsed)
yes))))
(_.test "Can query if there are any more inputs."
(and (|> (/.run (list) /.end)