aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
authorEduardo Julian2017-04-14 17:33:22 -0400
committerEduardo Julian2017-04-14 17:33:22 -0400
commit079fdb6c828bd7589ba0785ad1bb82c14b375f32 (patch)
tree701c2c978da33618b9be2bae552b7c53ebe4f851 /stdlib
parent962502e64dc170088af133470eb878d7dd0e8d4c (diff)
- Fixed the way "program:" CLI params are specified.
- Added before/after combinators to lux/cli.
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/source/lux/cli.lux29
1 files changed, 21 insertions, 8 deletions
diff --git a/stdlib/source/lux/cli.lux b/stdlib/source/lux/cli.lux
index afe784e98..d171dc899 100644
--- a/stdlib/source/lux/cli.lux
+++ b/stdlib/source/lux/cli.lux
@@ -121,6 +121,19 @@
#;Nil (#;Right [inputs []])
_ (#;Left (Text/append "Unknown parameters: " (text;join-with " " inputs))))))
+(def: #export (after param subject)
+ (All [p s] (-> (CLI p) (CLI s) (CLI s)))
+ (do Monad<CLI>
+ [_ param]
+ subject))
+
+(def: #export (before param subject)
+ (All [p s] (-> (CLI p) (CLI s) (CLI s)))
+ (do Monad<CLI>
+ [output subject
+ _ param]
+ (wrap output)))
+
(def: #export (assert message test)
{#;doc "Fails with the given message if the test is false."}
(-> Text Bool (CLI Unit))
@@ -215,15 +228,15 @@
## [Syntax]
(type: Program-Args
(#Raw-Program-Args Text)
- (#Parsed-Program-Args (List [Text AST])))
+ (#Parsed-Program-Args (List [AST AST])))
(def: program-args^
(Syntax Program-Args)
(s;alt s;local-symbol
(s;form (s;some (s;either (do s;Monad<Syntax>
[name s;local-symbol]
- (wrap [name (` any)]))
- (s;record (s;seq s;local-symbol s;any)))))))
+ (wrap [(ast;symbol ["" name]) (` any)]))
+ (s;tuple (s;seq s;any s;any)))))))
(syntax: #export (program: [args program-args^] body)
{#;doc (doc "Defines the entry-point to a program (similar to the \"main\" function/method in other programming languages)."
@@ -249,13 +262,13 @@
(#Parsed-Program-Args args)
(with-gensyms [g!args g!_ g!output g!message]
(wrap (list (` (;_lux_program (~ g!args)
- (case ((: (CLI (io;IO Unit))
- (do Monad<CLI>
+ (case ((: (;;CLI (io;IO Unit))
+ (do ;;Monad<CLI>
[(~@ (|> args
- (List/map (function [[name parser]]
- (list (ast;symbol ["" name]) parser)))
+ (List/map (function [[binding parser]]
+ (list binding parser)))
List/join))
- (~ g!_) end]
+ (~ g!_) ;;end]
((~' wrap) (~ body))))
(~ g!args))
(#;Right [(~ g!_) (~ g!output)])