Skip to content

Commit

Permalink
parse Array types with both nonempty & optional quantifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
mlin committed Dec 3, 2018
1 parent d5365f1 commit 62e0b42
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
8 changes: 4 additions & 4 deletions WDL/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
_MAP.2: "Map"
_PAIR.2: "Pair"
QUANT: "?"
ARRAY_QUANT: "?" | "+"
ARRAY_QUANT: "+?" | "+" | "?"
unbound_decl: type CNAME -> decl
bound_decl: type CNAME "=" expr -> decl
Expand Down Expand Up @@ -399,10 +399,10 @@ def array_type(self, items, meta):
assert isinstance(items[0], T.Base)
optional = False
nonempty = False
if len(items) > 1:
if items[1].value == "?":
for c in "".join(items[1:]):
if c == "?":
optional = True
if items[1].value == "+":
if c == "+":
nonempty = True
return T.Array(items[0], optional, nonempty)

Expand Down
15 changes: 15 additions & 0 deletions tests/test_2calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,19 @@ def test_forward_reference(self):
doc = WDL.parse_document(txt)
doc.typecheck()

txt = tsk + r"""
workflow contrived {
Array[Int]+? s = sum.z
if (2 == 2) {
scatter (z in [1,2,3]) {
call sum { input: x = s2.z }
}
}
call sum as s2
}
"""
doc = WDL.parse_document(txt)
doc.typecheck()
assert(doc.workflow.elements[0].type.nonempty and doc.workflow.elements[0].type.optional)

# TODO: test cycle detection

0 comments on commit 62e0b42

Please sign in to comment.