diff --git a/WDL/StdLib.py b/WDL/StdLib.py index ef79a789..d437b1da 100644 --- a/WDL/StdLib.py +++ b/WDL/StdLib.py @@ -77,6 +77,10 @@ def sub(input: Value.String, pattern: Value.String, replace: Value.String) -> Va def defined(v: Value.Base): return Value.Boolean(not isinstance(v, Value.Null)) + @static([Type.String(), Type.Array(Type.String())], Type.String()) + def sep(sep: Value.String, iterable: Value.Array) -> Value.String: + return Value.String(sep.value.join(v.value for v in iterable.value)) + # write_* static([Type.Array(Type.String())], Type.File(), "write_lines")( self._write(_serialize_lines) diff --git a/WDL/_grammar.py b/WDL/_grammar.py index caf63589..d04fe024 100644 --- a/WDL/_grammar.py +++ b/WDL/_grammar.py @@ -321,12 +321,7 @@ output_decls: "output" "{" bound_decl* "}" // WDL task commands: with {} and <<< >>> command and ${} and ~{} placeholder styles -!?placeholder_key: "default" | "false" | "true" | "sep" -?placeholder_value: string_literal - | INT -> int - | FLOAT -> float -placeholder_option: placeholder_key "=" placeholder_value -placeholder: placeholder_option* expr +placeholder: expr ?command: command1 | command2 diff --git a/tests/test_5stdlib.py b/tests/test_5stdlib.py index 4a6b86cf..4ffd74a9 100644 --- a/tests/test_5stdlib.py +++ b/tests/test_5stdlib.py @@ -713,6 +713,50 @@ def test_zip_cross(self): } """, expected_exception=WDL.Error.EvalError) + def test_sep(self): + outputs = self._test_task(R""" + version development + task SepTest { + input { + Array[String] inp = ["value1", "value2", "value3"] + } + command {} + output { + String out = sep(",", inp) + } + } + """) + self.assertEqual("value1,value2,value3", outputs["out"]) + + outputs = self._test_task(R""" + version development + task SepTest { + input { + Array[String] inp = ["value1", "value2", "value3"] + } + command <<< + echo ~{sep(",", inp)} + >>> + + output { + String out = read_string(stdout()) + } + } + """) + self.assertEqual("value1,value2,value3", outputs["out"]) + + self._test_task(R""" + version development + task SepTest { + input { + Array[String] inp = ["value1", "value2", "value3"] + } + command <<< + echo ~{sep="," inp} + >>> + } + """, expected_exception=WDL.Error.SyntaxError) + def test_suffix(self): outputs = self._test_task(R"""