diff options
author | Andrew Gallant <jamslam@gmail.com> | 2018-09-24 20:58:17 -0400 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2018-09-25 16:56:04 -0400 |
commit | db256c87ebd52ccab144db5e1bb35f2c1be8f6d5 (patch) | |
tree | 22315ebfc7baa98888b33c16fd8a8d9b70b85655 /src | |
parent | ba533f390edbad39a334c3fb8b56f839642292ee (diff) |
ripgrep: suggest -U/--multiline
When a "\n literal is not allowed" error is reported, ripgrep will now
suggest the use of the -U/--multiline flag, which enables matching
newlines.
Fixes #1055
Diffstat (limited to 'src')
-rw-r--r-- | src/args.rs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/args.rs b/src/args.rs index 7aed9144..623a230c 100644 --- a/src/args.rs +++ b/src/args.rs @@ -615,7 +615,10 @@ impl ArgMatches { if let Some(limit) = self.dfa_size_limit()? { builder.dfa_size_limit(limit); } - Ok(builder.build(&patterns.join("|"))?) + match builder.build(&patterns.join("|")) { + Ok(m) => Ok(m), + Err(err) => Err(From::from(suggest_multiline(err.to_string()))), + } } /// Build a matcher using PCRE2. @@ -1546,6 +1549,17 @@ and look-around.", msg) } } +fn suggest_multiline(msg: String) -> String { + if msg.contains("the literal") && msg.contains("not allowed") { + format!("{} + +Consider enabling multiline mode with the --multiline flag (or -U for short). +When multiline mode is enabled, new line characters can be matched.", msg) + } else { + msg + } +} + /// Convert the result of parsing a human readable file size to a `usize`, /// failing if the type does not fit. fn u64_to_usize( |