Skip to content

Commit

Permalink
Add special case for Rd syntax patterns, closes #164
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkdp committed May 26, 2018
1 parent d216da6 commit 3841101
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/parsing/yaml_load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,10 @@ fn rewrite_regex(regex: String) -> String {
return regex;
}

// A special fix to rewrite a pattern from the `Rd` syntax that the RegexRewriter can not
// handle properly.
let regex = regex.replace("(?:\\n)?", "(?:$|)");

let rewriter = RegexRewriter {
bytes: regex.as_bytes(),
index: 0,
Expand Down Expand Up @@ -870,7 +874,7 @@ mod tests {
// In order to properly understand nesting, we'd have to have a full parser, so ignore it.
assert_eq!(&rewrite(r"[[a]&&[\n]]"), r"[[a]&&[\n]]");

assert_eq!(&rewrite(r"ab(?:\n)?"), r"ab(?:$)?");
assert_eq!(&rewrite(r"ab(?:\n)?"), r"ab(?:$|)");
assert_eq!(&rewrite(r"(?<!\n)ab"), r"(?<!$)ab");
assert_eq!(&rewrite(r"(?<=\n)ab"), r"(?<=$)ab");
}
Expand Down

0 comments on commit 3841101

Please sign in to comment.