From 36ebdebb6bc0064c904f069b77e66fce98d704c5 Mon Sep 17 00:00:00 2001
From: Arun Isaac
Date: Tue, 3 Aug 2021 16:31:46 +0530
Subject: ccwl: Define input objects using a macro instead of a function.
This allows us to do sophisticated syntax checking at an early stage,
very close to the user interface. That way error messages from ccwl
will make a lot more sense.
* ccwl/ccwl.scm (input): Re-implement as macro.
(): Add new functional setters set-input-position and
set-input-prefix.
(input-spec-id, run-arg-position, run-arg-prefix): New functions.
(command, workflow): Use the new macro interface.
* doc/capture-output-file-with-parameter-reference.scm,
doc/capture-output-file.scm, doc/capture-stdout.scm, doc/checksum.scm,
doc/decompress-compile-run.scm, doc/hello-world.scm,
doc/pass-stdin.scm: Use new quoting syntax for input types.
---
ccwl/ccwl.scm | 190 +++++++++++----------
...apture-output-file-with-parameter-reference.scm | 2 +-
doc/capture-output-file.scm | 2 +-
doc/capture-stdout.scm | 2 +-
doc/checksum.scm | 6 +-
doc/decompress-compile-run.scm | 4 +-
doc/hello-world.scm | 2 +-
doc/pass-stdin.scm | 2 +-
8 files changed, 112 insertions(+), 98 deletions(-)
diff --git a/ccwl/ccwl.scm b/ccwl/ccwl.scm
index 09c590c..48c2d50 100644
--- a/ccwl/ccwl.scm
+++ b/ccwl/ccwl.scm
@@ -45,17 +45,29 @@
(type input-type)
(label input-label)
(default input-default)
- (position input-position)
- (prefix input-prefix)
+ (position input-position set-input-position)
+ (prefix input-prefix set-input-prefix)
(other input-other))
(define-immutable-record-type
(make-unspecified-default)
unspecified-default?)
-(define* (input id #:key (type 'File) label (default (make-unspecified-default)) position prefix (other '()))
- "Build and return an object."
- (make-input id type label default position prefix other))
+(define (input input-spec)
+ "Return syntax to build an object from INPUT-SPEC."
+ (syntax-case input-spec ()
+ ((id args ...) (identifier? #'id)
+ (apply (syntax-lambda** (id #:key (type #'File) label (default (make-unspecified-default)) #:key* other)
+ (let ((position #f)
+ (prefix #f))
+ #`(make-input '#,id '#,type #,label
+ #,(if (unspecified-default? default)
+ #'(make-unspecified-default)
+ default)
+ #,position #,prefix '#,other)))
+ #'(id args ...)))
+ (id (identifier? #'id) (input #'(id)))
+ (_ (error "Invalid input:" (syntax->datum input-spec)))))
(define-immutable-record-type