mirror of
				https://github.com/BurntSushi/ripgrep.git
				synced 2025-10-30 23:17:47 +02:00 
			
		
		
		
	pcre2: small polishing
This commit is contained in:
		| @@ -15,5 +15,5 @@ edition = "2018" | ||||
|  | ||||
| [dependencies] | ||||
| grep-matcher = { version = "0.1.6", path = "../matcher" } | ||||
| log = "0.4.19" | ||||
| log = "0.4.20" | ||||
| pcre2 = "0.2.4" | ||||
|   | ||||
| @@ -1,6 +1,3 @@ | ||||
| use std::error; | ||||
| use std::fmt; | ||||
|  | ||||
| /// An error that can occur in this crate. | ||||
| /// | ||||
| /// Generally, this error corresponds to problems building a regular | ||||
| @@ -12,7 +9,7 @@ pub struct Error { | ||||
| } | ||||
|  | ||||
| impl Error { | ||||
|     pub(crate) fn regex<E: error::Error>(err: E) -> Error { | ||||
|     pub(crate) fn regex<E: std::error::Error>(err: E) -> Error { | ||||
|         Error { kind: ErrorKind::Regex(err.to_string()) } | ||||
|     } | ||||
|  | ||||
| @@ -24,6 +21,7 @@ impl Error { | ||||
|  | ||||
| /// The kind of an error that can occur. | ||||
| #[derive(Clone, Debug)] | ||||
| #[non_exhaustive] | ||||
| pub enum ErrorKind { | ||||
|     /// An error that occurred as a result of parsing a regular expression. | ||||
|     /// This can be a syntax error or an error that results from attempting to | ||||
| @@ -31,29 +29,20 @@ pub enum ErrorKind { | ||||
|     /// | ||||
|     /// The string here is the underlying error converted to a string. | ||||
|     Regex(String), | ||||
|     /// Hints that destructuring should not be exhaustive. | ||||
|     /// | ||||
|     /// This enum may grow additional variants, so this makes sure clients | ||||
|     /// don't count on exhaustive matching. (Otherwise, adding a new variant | ||||
|     /// could break existing code.) | ||||
|     #[doc(hidden)] | ||||
|     __Nonexhaustive, | ||||
| } | ||||
|  | ||||
| impl error::Error for Error { | ||||
| impl std::error::Error for Error { | ||||
|     fn description(&self) -> &str { | ||||
|         match self.kind { | ||||
|             ErrorKind::Regex(_) => "regex error", | ||||
|             ErrorKind::__Nonexhaustive => unreachable!(), | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl fmt::Display for Error { | ||||
|     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||||
| impl std::fmt::Display for Error { | ||||
|     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||||
|         match self.kind { | ||||
|             ErrorKind::Regex(ref s) => write!(f, "{}", s), | ||||
|             ErrorKind::__Nonexhaustive => unreachable!(), | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -5,9 +5,12 @@ An implementation of `grep-matcher`'s `Matcher` trait for | ||||
|  | ||||
| #![deny(missing_docs)] | ||||
|  | ||||
| pub use crate::error::{Error, ErrorKind}; | ||||
| pub use crate::matcher::{RegexCaptures, RegexMatcher, RegexMatcherBuilder}; | ||||
| pub use pcre2::{is_jit_available, version}; | ||||
|  | ||||
| pub use crate::{ | ||||
|     error::{Error, ErrorKind}, | ||||
|     matcher::{RegexCaptures, RegexMatcher, RegexMatcherBuilder}, | ||||
| }; | ||||
|  | ||||
| mod error; | ||||
| mod matcher; | ||||
|   | ||||
| @@ -1,7 +1,9 @@ | ||||
| use std::collections::HashMap; | ||||
|  | ||||
| use grep_matcher::{Captures, Match, Matcher}; | ||||
| use pcre2::bytes::{CaptureLocations, Regex, RegexBuilder}; | ||||
| use { | ||||
|     grep_matcher::{Captures, Match, Matcher}, | ||||
|     pcre2::bytes::{CaptureLocations, Regex, RegexBuilder}, | ||||
| }; | ||||
|  | ||||
| use crate::error::Error; | ||||
|  | ||||
| @@ -426,9 +428,10 @@ fn has_uppercase_literal(pattern: &str) -> bool { | ||||
|  | ||||
| #[cfg(test)] | ||||
| mod tests { | ||||
|     use super::*; | ||||
|     use grep_matcher::{LineMatchKind, Matcher}; | ||||
|  | ||||
|     use super::*; | ||||
|  | ||||
|     // Test that enabling word matches does the right thing and demonstrate | ||||
|     // the difference between it and surrounding the regex in `\b`. | ||||
|     #[test] | ||||
|   | ||||
		Reference in New Issue
	
	Block a user