summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Turner <jturner.usa@gmail.com>2025-10-26 21:35:36 -0400
committerJohn Turner <jturner.usa@gmail.com>2025-10-26 21:35:36 -0400
commit191a3e2d48e153492e1480166a8511d0563c957c (patch)
tree659f3490dd2b2c83238d558405dad8b427f301a4
parent93933d808de27af1b45a120ce449b4cdfa2235c3 (diff)
downloadmon-191a3e2d48e153492e1480166a8511d0563c957c.tar.gz
take reference to regex struct in Regex parser
-rw-r--r--src/lib.rs16
-rw-r--r--tests/sexpr.rs4
2 files changed, 10 insertions, 10 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 41a914c..3454e96 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1006,15 +1006,15 @@ pub mod str {
use super::*;
- struct Regex(regex::Regex);
+ struct Regex<'a>(&'a regex::Regex);
- impl<'a> Parser<&'a str> for Regex {
- type Output = &'a str;
+ impl<'src, 'regex> Parser<&'src str> for Regex<'regex> {
+ type Output = &'src str;
- fn run<OM: Mode, EM: Mode, Tracer: Trace<&'a str>>(
+ fn run<OM: Mode, EM: Mode, Tracer: Trace<&'src str>>(
&self,
- it: InputIter<&'a str>,
- ) -> ParserResult<&'a str, Self::Output, OM, EM> {
+ it: InputIter<&'src str>,
+ ) -> ParserResult<&'src str, Self::Output, OM, EM> {
match self.0.find(it.rest()) {
Some(m) => {
let output = OM::bind(|| it.rest().slice(m.range()));
@@ -1026,7 +1026,7 @@ pub mod str {
}
}
- pub fn regex<'a>(regexp: regex::Regex) -> impl Parser<&'a str, Output = &'a str> {
+ pub fn regex<'a>(regexp: &'a regex::Regex) -> impl Parser<&'a str, Output = &'a str> {
Regex(regexp)
}
}
@@ -1050,7 +1050,7 @@ mod test {
fn test_regex_parser() {
let it = InputIter::new("abc 123");
- match crate::str::regex(regex::Regex::new("[a-z]+").unwrap()).parse(it) {
+ match crate::str::regex(&regex::Regex::new("[a-z]+").unwrap()).parse(it) {
Ok((rest, output)) => {
assert_eq!(output, "abc");
assert_eq!(rest.rest(), " 123");
diff --git a/tests/sexpr.rs b/tests/sexpr.rs
index 651d534..dd00b73 100644
--- a/tests/sexpr.rs
+++ b/tests/sexpr.rs
@@ -1,8 +1,8 @@
#![allow(dead_code)]
use mon::{
- alpha1, alphanumeric, alphanumeric1, input::InputIter, numeric1, tag, whitespace, Parser,
- ParserResult,
+ Parser, ParserResult, alpha1, alphanumeric, alphanumeric1, input::InputIter, numeric1, tag,
+ whitespace,
};
#[derive(Debug)]