Skip to content

Commit

Permalink
Change repr of meta/parameter_meta values from string to string_liter…
Browse files Browse the repository at this point in the history
…al (#122)

Fixes string_literal lexer for escaped single quote marks
Fixes and adds regression test for #120
  • Loading branch information
mlin authored Apr 23, 2019
1 parent 7cadfd4 commit 71fb6f4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions WDL/Error.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def __lt__(self, rhs: TVSourceNode) -> bool:
return False

def __eq__(self, rhs: TVSourceNode) -> bool:
assert isinstance(rhs, SourceNode)
return self.pos == rhs.pos

@property
Expand Down
5 changes: 3 additions & 2 deletions WDL/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
?string: string1 | string2
STRING_INNER1: ("\\\'"|/[^']/)
STRING_INNER1: ("\\'"|/[^']/)
ESCAPED_STRING1: "'" STRING_INNER1* "'"
string_literal: ESCAPED_STRING | ESCAPED_STRING1
Expand Down Expand Up @@ -48,7 +48,7 @@
// task meta/parameter_meta sections (effectively JSON)
meta_object: "{" [meta_kv (","? meta_kv)*] "}"
meta_kv: CNAME ":" meta_value
?meta_value: literal | string
?meta_value: literal | string_literal
| meta_object
| "[" [meta_value ("," meta_value)*] "]" -> meta_array
META_KIND.2: "meta" | "parameter_meta" | "runtime" // .2 ensures higher priority than CNAME
Expand Down Expand Up @@ -528,6 +528,7 @@ def meta_array(self, items, meta):

def meta_section(self, items, meta):
kind = items[0].value
assert kind in ["meta", "parameter_meta"]
d = dict()
d[kind] = items[1]
return d
Expand Down
16 changes: 16 additions & 0 deletions test_corpi/contrived/issue120.wdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# UnusedDeclaration warning for run_archive should be suppressed due to
# presence of meta fields indicating this is a dxWDL native applet stub.
task bcl2fastq220 {
input {
Array[File] run_archive
}
command {
}
output {
Array[File]+ stats = [""]
}
meta {
type: "native"
id: "applet-xxxx"
}
}
8 changes: 4 additions & 4 deletions tests/test_1doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ def test_meta(self):
}
""")[0]
task.typecheck()
self.assertIsInstance(task.parameter_meta['b']['help'], WDL.Expr.String)
self.assertEqual(task.parameter_meta['b']['help'].parts, ['"', "it's a boolean", '"'])
self.assertIsInstance(task.parameter_meta['b']['help'], str)
self.assertEqual(task.parameter_meta['b']['help'], "it's a boolean")
self.assertIsInstance(task.runtime['cpu'], WDL.Expr.Int)
self.assertEqual(task.runtime['cpu'].value, 42)
self.assertTrue(task.inputs[0].type.optional)
Expand Down Expand Up @@ -288,8 +288,8 @@ def test_meta(self):
}
""")[0]
task.typecheck()
self.assertIsInstance(task.meta['description'], WDL.Expr.String)
self.assertEqual(task.meta['description'].parts, ["'", "it\\'s a task", "'"])
self.assertIsInstance(task.meta['description'], str)
self.assertEqual(task.meta['description'], "it's a task")

def test_compare_md5sums(self):
txt = """
Expand Down

0 comments on commit 71fb6f4

Please sign in to comment.