summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2023-10-16 17:27:50 +0100
committerArun Isaac2023-10-16 17:27:50 +0100
commit7cc6abe4b5d1af4a05a58705279f6172cf270825 (patch)
tree4bd59a97fa98788ffbd16c5d3acba561d845d532
parent985f892b58a6f8b18f498d62d0ed6d4e6860b985 (diff)
downloadccwl-7cc6abe4b5d1af4a05a58705279f6172cf270825.tar.gz
ccwl-7cc6abe4b5d1af4a05a58705279f6172cf270825.tar.lz
ccwl-7cc6abe4b5d1af4a05a58705279f6172cf270825.zip
ccwl: Flatten prefixed string arguments in command definitions.
* ccwl/ccwl.scm (run-args): Flatten prefixed string arguments in command definitions. * tests/ccwl.scm ("tolerate prefixed string arguments in command definitions"): New test.
-rw-r--r--ccwl/ccwl.scm49
-rw-r--r--tests/ccwl.scm3
2 files changed, 30 insertions, 22 deletions
diff --git a/ccwl/ccwl.scm b/ccwl/ccwl.scm
index 1b1d8fe..a476406 100644
--- a/ccwl/ccwl.scm
+++ b/ccwl/ccwl.scm
@@ -286,28 +286,33 @@ identifiers defined in the commands."
(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)))
+ (append-map (lambda (x)
+ (syntax-case x ()
+ ;; Replace input symbol with quoted symbol.
+ (input (identifier? #'input)
+ (begin
+ (ensure-input-is-defined #'input)
+ (list #''input)))
+ ;; Leave string as is.
+ (string-arg (string? (syntax->datum #'string-arg))
+ (list #'string-arg))
+ ;; Replace prefixed input symbol with quoted symbol.
+ ((prefix input) (and (string? (syntax->datum #'prefix))
+ (identifier? #'input))
+ (begin
+ (ensure-input-is-defined #'input)
+ (list #''input)))
+ ;; Flatten prefixed string arguments. They have no
+ ;; special meaning.
+ ((prefix string-arg) (and (string? (syntax->datum #'prefix))
+ (string? (syntax->datum #'string-arg)))
+ (list #'prefix #'string-arg))
+ (_
+ (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
diff --git a/tests/ccwl.scm b/tests/ccwl.scm
index aef2a85..7cbb2c0 100644
--- a/tests/ccwl.scm
+++ b/tests/ccwl.scm
@@ -261,4 +261,7 @@
'(command #:run "echo" 42))
#f)))
+(test-assert "tolerate prefixed string arguments in command definitions"
+ (command #:run "echo" ("-x" "foo")))
+
(test-end "ccwl")