diff options
author | Arun Isaac | 2024-09-11 22:57:44 +0100 |
---|---|---|
committer | Arun Isaac | 2024-09-12 17:08:55 +0100 |
commit | 90454030fbaa3f5709f496fa850223b833498286 (patch) | |
tree | daa896ac7a2554125c32c5c8855ce43364b9918b | |
parent | 312aa98445154dd1440ee6dd583e379ca1ec966d (diff) | |
download | ravanan-90454030fbaa3f5709f496fa850223b833498286.tar.gz ravanan-90454030fbaa3f5709f496fa850223b833498286.tar.lz ravanan-90454030fbaa3f5709f496fa850223b833498286.zip |
command-line-tool: Support interpolation with parameter references.
* ravanan/command-line-tool.scm (javascript-expression?): Return #t
even for parameter references mixed with literals.
(interpolate-parameter-references): New function.
(strip-javascript-expression): Delete function.
(coerce-expression): Use interpolate-parameter-references instead of
strip-javascript-expression.
-rw-r--r-- | ravanan/command-line-tool.scm | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/ravanan/command-line-tool.scm b/ravanan/command-line-tool.scm index 4c1b085..cfca932 100644 --- a/ravanan/command-line-tool.scm +++ b/ravanan/command-line-tool.scm @@ -162,17 +162,38 @@ class. Else, return @code{#f}." supplementary-requirements))) (define (javascript-expression? str) - "Return @code{#t} if @var{str} is a CWL javascript expression. Else, return + "Return @code{#t} if @var{str} contains a CWL javascript expression. Else, return @code{#f}." - (and (string-prefix? "$(" str) - (string-suffix? ")" str))) + (string-contains str "$(")) -(define (strip-javascript-expression expression) - "Strip $(…) around javascript @var{expression}." - (substring expression - (string-length "$(") - (- (string-length expression) - (string-length ")")))) +(define (interpolate-parameter-references str) + "Interpolate @var{str} with one or more parameter references into a javascript +expression suitable for evaluation." + (define (tokenize str) + "Split @var{str} into alternating tokens of parameter reference and literal +strings." + (let ((end (if (string-prefix? "$(" str) + (1+ (string-index str #\))) + (string-index str #\$)))) + (if end + (cons (substring str 0 end) + (tokenize (substring str end))) + (if (string-null? str) + (list) + (list str))))) + + (string-join (map (lambda (token) + (if (and (string-prefix? "$(" token) + (string-suffix? ")" token)) + ;; Strip $(…). + (substring token + (string-length "$(") + (- (string-length token) + (string-length ")"))) + ;; Surround with double quotes. + (string-append "\"" token "\""))) + (tokenize str)) + " + ")) (define (coerce-expression expression) "Coerce @var{expression} into a scheme JSON tree. @@ -185,7 +206,7 @@ evaluates it. This G-expression references variables @code{inputs} and (javascript-expression? expression)) #~(evaluate-parameter-reference #$%worker-node - #$(strip-javascript-expression expression) + #$(interpolate-parameter-references expression) inputs 'null runtime |