aboutsummaryrefslogtreecommitdiff
path: root/ccwl
diff options
context:
space:
mode:
authorArun Isaac2023-10-16 17:20:37 +0100
committerArun Isaac2023-10-16 17:20:37 +0100
commit985f892b58a6f8b18f498d62d0ed6d4e6860b985 (patch)
tree4a02308876e7ef1f3f086eb07e81862dc1bd50c0 /ccwl
parentbb6b3e677cc35c8f55d8e167b2c35b915e3a8dfe (diff)
downloadccwl-985f892b58a6f8b18f498d62d0ed6d4e6860b985.tar.gz
ccwl-985f892b58a6f8b18f498d62d0ed6d4e6860b985.tar.lz
ccwl-985f892b58a6f8b18f498d62d0ed6d4e6860b985.zip
ccwl: Move run arguments construction to separate function.
* ccwl/ccwl.scm (command): Move run arguments construction to ... (run-args): ... new function.
Diffstat (limited to 'ccwl')
-rw-r--r--ccwl/ccwl.scm72
1 files changed, 38 insertions, 34 deletions
diff --git a/ccwl/ccwl.scm b/ccwl/ccwl.scm
index 695fa8d..1b1d8fe 100644
--- a/ccwl/ccwl.scm
+++ b/ccwl/ccwl.scm
@@ -272,6 +272,43 @@ RUN-ARGS. If such an input is not present in RUN-ARGS, return #f."
(_ #f)))
run-args))
+(define (run-args run defined-input-identifiers)
+ "Return a list of run arguments specified in @var{run}
+syntax. @var{defined-input-identifiers} is the list of input
+identifiers defined in the commands."
+ (let ((ensure-input-is-defined
+ ;; Ensure that specified input is defined in #:inputs of
+ ;; command definition.
+ (lambda (input)
+ (unless (memq (syntax->datum input)
+ defined-input-identifiers)
+ (raise-exception
+ (condition (ccwl-violation input)
+ (formatted-message "Undefined input ~a"
+ (syntax->datum input))))))))
+ (map (lambda (x)
+ (syntax-case x ()
+ ;; Replace input symbol with quoted symbol.
+ (input (identifier? #'input)
+ (begin
+ (ensure-input-is-defined #'input)
+ #''input))
+ ;; Leave string as is.
+ (string-arg (string? (syntax->datum #'string-arg))
+ #'string-arg)
+ ;; Replace prefixed input symbol with quoted symbol.
+ ((prefix input) (and (string? (syntax->datum #'prefix))
+ (identifier? #'input))
+ (begin
+ (ensure-input-is-defined #'input)
+ #''input))
+ (_
+ (raise-exception
+ (condition (ccwl-violation x)
+ (formatted-message "Invalid command element ~a. Command elements must either be input identifiers or literal strings."
+ (syntax->datum x)))))))
+ run)))
+
;; TODO: Add fine-grained syntax checking.
(define-syntax command
(lambda (x)
@@ -319,40 +356,7 @@ RUN-ARGS. If such an input is not present in RUN-ARGS, return #f."
#,(run-arg-prefix id run))))
inputs))
(list #,@(map output outputs))
- (list #,@(let ((ensure-input-is-defined
- ;; Ensure that specified input is
- ;; defined in #:inputs of command
- ;; definition.
- (lambda (input)
- (unless (memq (syntax->datum input)
- (map input-spec-id inputs))
- (raise-exception
- (condition (ccwl-violation input)
- (formatted-message "Undefined input ~a"
- (syntax->datum input))))))))
- (map (lambda (x)
- (syntax-case x ()
- ;; Replace input symbol with quoted symbol.
- (input (identifier? #'input)
- (begin
- (ensure-input-is-defined #'input)
- #''input))
- ;; Leave string as is.
- (string-arg (string? (syntax->datum #'string-arg))
- #'string-arg)
- ;; Replace prefixed input symbol with
- ;; quoted symbol.
- ((prefix input) (and (string? (syntax->datum #'prefix))
- (identifier? #'input))
- (begin
- (ensure-input-is-defined #'input)
- #''input))
- (_
- (raise-exception
- (condition (ccwl-violation x)
- (formatted-message "Invalid command element ~a. Command elements must either be input identifiers or literal strings."
- (syntax->datum x)))))))
- run)))
+ (list #,@(run-args run (map input-spec-id inputs)))
#,(and stdin #`'#,stdin)
#,(if (and stderr
(not (string? (syntax->datum stderr))))