Skip to content

Commit 76d846f

Browse files
author
Peter Amstutz
committed
Update spec text discussing parameter references and inline expressions.
1 parent 526809a commit 76d846f

File tree

1 file changed

+88
-48
lines changed

1 file changed

+88
-48
lines changed

draft-3/cwl-avro.yml

Lines changed: 88 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,68 @@
323323
Process requirements are the primary mechanism for specifying extensions to
324324
the CWL core specification.
325325
326+
## Parameter references
327+
328+
Parameter references are denoted by the syntax `$(...)` and may be used in
329+
any field permitting the pseudo-type `Expression`, as specified by this
330+
document. Conforming implementations must support parameter
331+
references. Parameter references use the following subset of
332+
[Javascript/ECMAScript 5.1](http://www.ecma-international.org/ecma-262/5.1/) syntax:
333+
334+
symbol:: {Unicode alphanumeric}+
335+
singleq:: '[' ''' ( {character} - ''' | '\' ''' )* ''' ']'
336+
doubleq:: '[' '"' ( {character} - '"' | '\' '"' )* '"' ']'
337+
index:: '[' {decimal digit}+ ']'
338+
segment:: '.' {symbol} | {singleq} | {doubleq} | {index}
339+
parameter:: '$' '(' {symbol} {segment}* ')'
340+
341+
Use the following algorithm to resolve a parameter reference:
342+
343+
1. Match the leading symbol as key
344+
2. Look up the key in the parameter context (described below) to get the current value.
345+
It is an error if the key is not found in the parameter context.
346+
3. If there are no subsequent segments, terminate and return current value
347+
4. Else, match the next segment
348+
5. Extract the symbol, string, or index from the segment as key
349+
6. Look up the key in current value and assign as new current value. If
350+
the key is a symbol or string, the current value must be an object.
351+
If the key is an index, the current value must be an array or string.
352+
It is an error if the key does not match the required type, or the key is not found or out
353+
of range.
354+
7. Repeat steps 3-6
355+
356+
The root namspace is the parameter context. The following parameters must
357+
be provided:
358+
359+
* `inputs`: The input object to the current Process.
360+
* `self`: A context-specific value. The contextual values for 'self' are
361+
documented for specific fields elsewhere in this specification. If
362+
a contextual value of 'self' is not documented for a field, it
363+
must be 'null'.
364+
* `runtime`: An object containing configuration specific to the Process
365+
type. Values include `tmpdir`, `outdir`, and values associated with
366+
[ResourceRequirement](#resourcerequirement).
367+
Other fields under `runtime` are listed elsewhere in this document.
368+
369+
If the value of a field has no leading or trailing non-whitespace
370+
characters around a parameter reference, the effective value of the field
371+
becomes the value of the referenced parameter, preserving the return type.
372+
373+
If the value of a field has non-whitespace leading or trailing characters
374+
around an parameter reference, it is subject to string interpolation. The
375+
effective value of the field is a string containing the leading characters;
376+
followed by the string value of the parameter reference; followed by the
377+
trailing characters. The string value of the parameter reference is its
378+
textual JSON representation with the following rules:
379+
380+
* Leading and trailing quotes are stripped from strings
381+
* Objects entries are sorted by key
382+
383+
Multiple parameter references may appear in a single field. This case is
384+
must be treated as a string interpolation. After interpolating the first
385+
parameter reference, interpolation must be recursively applied to the
386+
trailing characters to yield the final string value.
387+
326388
## Expressions
327389
328390
An expression is a fragment of [Javascript/ECMAScript
@@ -334,62 +396,48 @@
334396
processes in that they are intended to modify the behavior of the workflow
335397
itself rather than perform the primary work of the workflow.
336398
337-
Expressions may be used in any field that allows expressions, as specified
338-
by this document.
399+
To declare the use of expressions, the document must include the process
400+
requirement `InlineJavascriptRequirement`. Expressions may be used in any
401+
field permitting the pseudo-type `Expression`, as specified by this
402+
document.
339403
340404
Expressions are denoted by the syntax `$(...)` or `${...}`. A code
341-
fragment wrapped in the `$(...)` syntax must be evaluated as a [ECMAScript
342-
expression](http://www.ecma-international.org/ecma-262/5.1/#sec-11). A
405+
fragment wrapped in the `$(...)` syntax must be evaluated as a
406+
[ECMAScript expression](http://www.ecma-international.org/ecma-262/5.1/#sec-11). A
343407
code fragment wrapped in the `${...}` syntax must be evaluated as a
344-
[EMACScript function
345-
body](http://www.ecma-international.org/ecma-262/5.1/#sec-13) for an
346-
anonymous, zero-argument function. Expressions must return a valid JSON
408+
[EMACScript function body](http://www.ecma-international.org/ecma-262/5.1/#sec-13)
409+
for an anonymous, zero-argument function. Expressions must return a valid JSON
347410
data type: one of null, string, number, boolean, array, object.
348411
Implementations must permit any syntatically valid Javascript and account
349-
for nesting of parenthesis or braces and the strings that may contain
412+
for nesting of parenthesis or braces and that strings that may contain
350413
parenthesis or braces when scanning for expressions.
351414
352-
If a field has no leading or trailing non-whitespace characters around an
353-
expression, the effective value of the field is the value returned by
354-
evaluating the expression, preserving the return type.
355-
356-
If a field has non-whitespace leading or trailing characters around an
357-
expression, it is subject to string interpolation. The effective value of
358-
the field is a string containing the leading characters followed by the
359-
value returned by evaluating the expression, followed by the trailing
360-
characters. The value returned by the expression is coerced to a string
361-
subject to the following rules:
362-
363-
* strings are included directly with no transformation
364-
* numbers are converted to decimal representation string
365-
* null is the string `(null)`
366-
* boolean "true" or "false" yield the strings "true" or "false"
367-
* arrays are serialized to JSON
368-
* objects are serialized to JSON
369-
370-
Multiple expressions may appear in a single field. This case is must be treated
371-
as a string interpolation.
372-
373-
Before executing the expression, the runtime must initialize the global
374-
object `inputs` containing a copy of the validated contents of the job
375-
object. The runtime must also initialize a global object `runtime`
376-
containing the values for `tmpdir`, `outdir`, and values associated with
377-
[ResourceRequirement](#resourcerequirement).
378-
379415
The runtime must include any code defined in the ["expressionLib" field of
380416
InlineJavascriptRequirement](#inlinejavascriptrequirement) prior to
381417
executing the actual expression.
382418
419+
Before executing the expression, the runtime must initialize as global
420+
variables the fields of the parameter context described above.
421+
422+
The effective value of the field after expression evaluation follows the
423+
same rules as parameter references discussed above. Multiple expressions
424+
may appear in a single field.
425+
383426
Expressions must be evaluated in an isolated context (a "sandbox") which
384427
permits no side effects to leak outside the context. Expressions also must
385-
be evaluated in [Javascript strict
386-
mode](http://www.ecma-international.org/ecma-262/5.1/#sec-4.2.2).
428+
be evaluated in [Javascript strict mode](http://www.ecma-international.org/ecma-262/5.1/#sec-4.2.2).
429+
430+
The order in which expressions are evaluated is undefined except where
431+
otherwise noted in this document.
387432
388-
The order in which expressions are evaluated is undefined.
433+
An implementation may choose to implement parameter references by
434+
evalutating as a Javascript expression. The results of evaluating
435+
parameter references must be identical whether implemented by Javascript
436+
evaluation or some other means.
389437
390438
Implementations may apply other limits, such as process isolation, timeouts,
391439
and operating system containers/jails to minimize the security risks associated
392-
with running untrusted code embedded in a tool description document.
440+
with running untrusted code embedded in a CWL document.
393441
394442
## Workflow graph
395443
@@ -719,15 +767,6 @@
719767
object.
720768
721769
722-
- name: StandardExpressionEngine
723-
type: enum
724-
doc: "Symbols for default CWL expression engines that may be used in the `engine` field."
725-
docParent: "#Expression"
726-
symbols:
727-
- "cwl:JsonPointer"
728-
- "cwl:JavascriptEngine"
729-
730-
731770
- type: enum
732771
name: Expression
733772
docAfter: "#ExpressionTool"
@@ -736,6 +775,7 @@
736775
symbols:
737776
- cwl:ExpressionPlaceholder
738777

778+
739779
- name: Binding
740780
type: record
741781
docParent: "#Parameter"

0 commit comments

Comments
 (0)