From 079fdb6c828bd7589ba0785ad1bb82c14b375f32 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Fri, 14 Apr 2017 17:33:22 -0400 Subject: - Fixed the way "program:" CLI params are specified. - Added before/after combinators to lux/cli. --- stdlib/source/lux/cli.lux | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'stdlib') 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 + [_ param] + subject)) + +(def: #export (before param subject) + (All [p s] (-> (CLI p) (CLI s) (CLI s))) + (do Monad + [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 [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 + (case ((: (;;CLI (io;IO Unit)) + (do ;;Monad [(~@ (|> 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)]) -- cgit v1.2.3