Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fixes invalid string parsing
Browse files Browse the repository at this point in the history
claymcleod committed Nov 22, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent e7dc1f1 commit 05726cc
Showing 12 changed files with 457 additions and 265 deletions.
36 changes: 10 additions & 26 deletions Gauntlet.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
version = "v1"

[[repositories]]
organization = "biowdl"
name = "tasks"

[[repositories]]
organization = "chanzuckerberg"
name = "czid-workflows"

[[repositories]]
organization = "stjudecloud"
name = "workflows"
@@ -16,33 +8,25 @@ name = "workflows"
organization = "PacificBiosciences"
name = "HiFi-human-WGS-WDL"

[[repositories]]
organization = "chanzuckerberg"
name = "czid-workflows"

[[repositories]]
organization = "biowdl"
name = "tasks"

[[ignored_errors]]
document = "biowdl/tasks:bcftools.wdl"
error = '''validation error: [v1::001] invalid escape character '\_' in string at line 114:75'''

[[ignored_errors]]
document = "biowdl/tasks:bedtools.wdl"
error = """
parse error:
--> 29:67
|
29 | String memory = \"~{512 + ceil(size([inputBed, faidx], \"MiB\"))}MiB\"
| ^---
|
= expected WHITESPACE or OPTION"""
error = '''validation error: [v1::001] invalid escape character '\.' in string at line 27:48'''

[[ignored_errors]]
document = "biowdl/tasks:bowtie.wdl"
error = """
parse error:
--> 40:58
|
40 | String memory = \"~{5 + ceil(size(indexFiles, \"GiB\"))}GiB\"
| ^---
|
= expected WHITESPACE or OPTION"""
error = '''validation error: [v1::001] invalid escape character '\.' in string at line 63:32'''

[[ignored_errors]]
document = "biowdl/tasks:centrifuge.wdl"
6 changes: 3 additions & 3 deletions wdl-grammar/src/commands/gauntlet.rs
Original file line number Diff line number Diff line change
@@ -89,7 +89,7 @@ pub struct Args {
quiet: bool,

/// Overwrites the configuration file.
#[arg(short, long, global = true)]
#[arg(long, global = true)]
save_config: bool,

/// Silences printing detailed error information.
@@ -101,7 +101,7 @@ pub struct Args {
skip_remote: bool,

/// Displays warnings as part of the report output.
#[arg(short, long, global = true)]
#[arg(long, global = true)]
show_warnings: bool,

/// The Workflow Description Language (WDL) specification version to use.
@@ -307,7 +307,7 @@ pub async fn gauntlet(args: Args) -> Result<()> {
println!(
"\n{}\n",
"Undetected expected errors: you should remove these from your \
Config.toml or run this command with the `-s` option!"
Config.toml or run this command with the `--save-config` option!"
.red()
.bold()
);
11 changes: 11 additions & 0 deletions wdl-grammar/src/main.rs
Original file line number Diff line number Diff line change
@@ -106,3 +106,14 @@ async fn main() {
Err(err) => eprintln!("error: {}", err),
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn verify_arguments() {
use clap::CommandFactory;
Args::command().debug_assert()
}
}
42 changes: 41 additions & 1 deletion wdl-grammar/src/v1/lint/whitespace.rs
Original file line number Diff line number Diff line change
@@ -46,6 +46,21 @@ impl Whitespace {
.try_build()
.unwrap()
}

/// Creates an error corresponding to a line with a trailing tab.
fn trailing_tab(&self, line_no: NonZeroUsize) -> lint::Warning
where
Self: Rule<v1::Rule>,
{
// SAFETY: this error is written so that it will always unwrap.
lint::warning::Builder::default()
.code(self.code())
.level(lint::Level::Low)
.group(lint::Group::Style)
.message(format!("trailing tab at the end of line {}", line_no))
.try_build()
.unwrap()
}
}

impl Rule<v1::Rule> for Whitespace {
@@ -73,6 +88,8 @@ impl Rule<v1::Rule> for Whitespace {
results.push(self.empty_line(line_no));
} else if line.ends_with(' ') {
results.push(self.trailing_space(line_no));
} else if line.ends_with('\t') {
results.push(self.trailing_tab(line_no));
}
}

@@ -122,14 +139,37 @@ mod tests {
}

#[test]
fn it_unwraps_a_trailing_whitespace_error() {
fn it_catches_a_trailing_tab() -> Result<(), Box<dyn std::error::Error>> {
let tree = Parser::parse(Rule::document, "version 1.1\t")?;
let warning = Whitespace.check(tree)?.unwrap();

assert_eq!(warning.len(), 1);
assert_eq!(
warning.first().unwrap().to_string(),
"[v1::001::Style/Low] trailing tab at the end of line 1"
);

Ok(())
}

#[test]
fn it_unwraps_a_trailing_space_error() {
let warning = Whitespace.trailing_space(NonZeroUsize::try_from(1).unwrap());
assert_eq!(
warning.to_string(),
"[v1::001::Style/Low] trailing space at the end of line 1"
)
}

#[test]
fn it_unwraps_a_trailing_tab_error() {
let warning = Whitespace.trailing_tab(NonZeroUsize::try_from(1).unwrap());
assert_eq!(
warning.to_string(),
"[v1::001::Style/Low] trailing tab at the end of line 1"
)
}

#[test]
fn it_unwraps_an_empty_line_error() {
let warning = Whitespace.empty_line(NonZeroUsize::try_from(1).unwrap());
78 changes: 41 additions & 37 deletions wdl-grammar/src/v1/tests/expression/core.rs
Original file line number Diff line number Diff line change
@@ -18,45 +18,49 @@ fn it_successfully_parses_an_array_literal_with_spaces_inside() {
parser: WdlParser,
input: "[if a then b else c, \"Hello, world!\"]",
rule: Rule::core,
tokens: [array_literal(0, 37, [
expression(1, 19, [
r#if(1, 19, [
WHITESPACE(3, 4, [
SPACE(3, 4),
]),
expression(4, 5, [
identifier(4, 5),
]),
WHITESPACE(5, 6, [
SPACE(5, 6),
]),
WHITESPACE(10, 11, [
SPACE(10, 11),
]),
expression(11, 12, [
identifier(11, 12),
]),
WHITESPACE(12, 13, [
SPACE(12, 13),
]),
WHITESPACE(17, 18, [
SPACE(17, 18),
tokens: [
// `[if a then b else c, "Hello, world!"]`
array_literal(0, 37, [
// `if a then b else c`
expression(1, 19, [
// `if a then b else c`
r#if(1, 19, [
WHITESPACE(3, 4, [SPACE(3, 4)]),
// `a`
expression(4, 5, [
// `a`
identifier(4, 5),
]),
WHITESPACE(5, 6, [SPACE(5, 6)]),
WHITESPACE(10, 11, [SPACE(10, 11)]),
// `b`
expression(11, 12, [
// `b`
identifier(11, 12),
]),
WHITESPACE(12, 13, [SPACE(12, 13)]),
WHITESPACE(17, 18, [SPACE(17, 18)]),
// `c`
expression(18, 19, [
// `c`
identifier(18, 19),
]),
]),
]),
expression(18, 19, [
identifier(18, 19),
// `,`
COMMA(19, 20),
WHITESPACE(20, 21, [SPACE(20, 21)]),
// `"Hello, world!"`
expression(21, 36, [
// `"Hello, world!"`
string(21, 36, [
// `"`
double_quote(21, 22),
// `Hello, world!`
string_literal_contents(22, 35),
]),
]),
]),
]),
COMMA(19, 20),
WHITESPACE(20, 21, [
SPACE(20, 21),
]),
expression(21, 36, [
string(21, 36, [
double_quoted_string(21, 36),
]),
]),
])
])
]
}
}
Loading

0 comments on commit 05726cc

Please sign in to comment.