From 7cc6abe4b5d1af4a05a58705279f6172cf270825 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Mon, 16 Oct 2023 17:27:50 +0100 Subject: 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. --- ccwl/ccwl.scm | 49 +++++++++++++++++++++++++++---------------------- tests/ccwl.scm | 3 +++ 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") -- cgit v1.2.3