Mercurial > lbo > hg > rex
changeset 70:06019f9a273c
rustfmt
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Sun, 01 Sep 2019 20:44:42 +0200 |
parents | 694d965661c7 |
children | 607b47aafad6 |
files | benches/profile.rs src/compile.rs src/matching.rs src/state.rs |
diffstat | 4 files changed, 29 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/benches/profile.rs Sun Sep 01 20:44:33 2019 +0200 +++ b/benches/profile.rs Sun Sep 01 20:44:42 2019 +0200 @@ -1,12 +1,16 @@ - fn bench_complicated() { let re_s = "^[hH][eE]l+o +[Ww]orld!?$"; let re = rex::compile(re_s).unwrap(); - let inputs = vec!["Hello World", "hEllo world!", "HEllllllo world", "Helllllllllo world!"]; + let inputs = vec![ + "Hello World", + "hEllo world!", + "HEllllllo world", + "Helllllllllo world!", + ]; let size = inputs.len(); println!("{}", rex::render_graph(re_s)); for i in 0..100_000 { - assert!(rex::match_re(&re, inputs[i%size]).0); + assert!(rex::match_re(&re, inputs[i % size]).0); } }
--- a/src/compile.rs Sun Sep 01 20:44:33 2019 +0200 +++ b/src/compile.rs Sun Sep 01 20:44:42 2019 +0200 @@ -1,6 +1,6 @@ use matcher::{self, wrap_matcher}; use repr::{AnchorLocation, Pattern, Repetition}; -use state::{State, Submatch, StateGraph, StateRef}; +use state::{State, StateGraph, StateRef, Submatch}; /// Types implementing Compile can be compiled into a state graph. pub trait Compile { @@ -158,7 +158,11 @@ } // alternate compiles a list of patterns into a graph that accepts any one of the patterns. -fn alternate(sg: &mut StateGraph, ps: &[Pattern], to_patch: &[StateRef]) -> (StateRef, Vec<StateRef>) { +fn alternate( + sg: &mut StateGraph, + ps: &[Pattern], + to_patch: &[StateRef], +) -> (StateRef, Vec<StateRef>) { if ps.len() == 1 { let (s, sp) = ps[0].to_state(sg); for e in to_patch {
--- a/src/matching.rs Sun Sep 01 20:44:33 2019 +0200 +++ b/src/matching.rs Sun Sep 01 20:44:42 2019 +0200 @@ -3,13 +3,13 @@ #![allow(dead_code)] -use std::ops::Deref; use std::cell::RefCell; use std::mem; +use std::ops::Deref; use std::rc::Rc; use matcher::Matchee; -use state::{Submatch, StateGraph, StateRef}; +use state::{StateGraph, StateRef, Submatch}; #[derive(Clone, Debug)] pub struct MatchState { @@ -69,9 +69,16 @@ } fn debug(&self, sg: &StateGraph) -> String { let m = self.matchee.string(); - let out = sg[self.node].out.map_or("".to_owned(), |ix| sg[ix].to_string()); - let out1 = sg[self.node].out1.map_or("".to_owned(), |ix| sg[ix].to_string()); - let full = format!("{} (<{}> next: 1. <{:?}> {} 2. <{:?}> {})\n", m, self.node, sg[self.node].out, out, sg[self.node].out1, out1); + let out = sg[self.node] + .out + .map_or("".to_owned(), |ix| sg[ix].to_string()); + let out1 = sg[self.node] + .out1 + .map_or("".to_owned(), |ix| sg[ix].to_string()); + let full = format!( + "{} (<{}> next: 1. <{:?}> {} 2. <{:?}> {})\n", + m, self.node, sg[self.node].out, out, sg[self.node].out1, out1 + ); full } } @@ -144,7 +151,10 @@ // Found match (intentionally down here, after finalizing submatch processing). Only // update match if this match is longer than the previous one. - if next1.is_none() && next2.is_none() && (matchst.matchee.pos() > longestmatch || longestmatch == 0) { + if next1.is_none() + && next2.is_none() + && (matchst.matchee.pos() > longestmatch || longestmatch == 0) + { ismatch = true; matches = matchst.submatches.borrow().clone(); longestmatch = matchst.matchee.pos();