miniwdl icon indicating copy to clipboard operation
miniwdl copied to clipboard

Helper function to generate WDL string literal safely

Open mr-c opened this issue 2 years ago • 1 comments

Hello!

Many thanks for miniwdl, we've recently re-implemented https://github.com/common-workflow-lab/wdl-cwl-translator to use it instead of another parser and we have gained a lot of functionality from that move.

As we are translating WDL expressions to CWL expressions (which are Javascript based) we have to put strings in quotes and escape any conflicting quotation marks therein.

Most everywhere we've been able to save time by using the original quoting by calling str(expr.literal) on WDL.Expr.String when possible, but for the options fields of a WDL.Expr.Placeholder is a dictionary of with plain string values, so we don't have that information any more.

Currently we add quotes back in and escape quotation marks as needed, but if this information is easy to keep then exposing it in miniwdl would be appreciated for consistency!

Cheers,

mr-c avatar Feb 16 '22 16:02 mr-c

Thanks @mr-c! The project mission has always been first and foremost a developer toolkit (secondly a runtime), so we're very happy and supportive about your work.

I think as a compromise we could add some kind of WDL-safe-quoting function (along the lines of your nice_quote()) to the toolkit, then you could use that directly or WDL.parse_expr() to get a WDL.Expr.String from it. This would have more general use, as the deprecation of the placeholder options in WDL 1.1 makes it difficult to prioritize work aimed specifically at that.

mlin avatar Feb 17 '22 08:02 mlin