3 ms·
Indeed. I've been responding to questions like this for a long time. :-) https://old.reddit.com/r/rust/comments/4a8pbv/the_regex_crate_now_supports_matching_on_
by burntsushi 3y ago
Indeed. I've been responding to questions like this for a long time. :-) https://old.reddit.com/r/rust/comments/4a8pbv/the_regex_crate_now_supports_matching_on_u8/d0z0oom/ https://old.reddit.com/r/rust/comments/4a8pbv/the_regex_crat...
Someone should go out and built it. It won't be me though, that's for sure. Believe it or not, such a library wouldn't leverage much of my experience. The vast majority of the complexity inside the regex crate is about optimizing for sequences of bytes.
- IshKebab 3y agoYeah I am slowly working on it. I think even custom alphabets wouldn't work for me. I'm trying to build something so this works: let is_even = |x: &i32| *x % 2 == 0; let is_odd = |x: &i32| *x % 2 == 0; let pattern = sequence(&[ is_even, is_odd, repeat(or(is_even, is_odd), 2, 4), ]); let mut matcher = Matcher::compile(pattern); let elements = [4, 1, 23, 5, 6]; for element in elements { matcher.step(element); } assert!(matcher.matches()); I'll get there one day. Amazing work on the Regex crate by the way!
- ynik 3y agoIt's not that hard to build a backtracking matching engine, at least if performance is not important. I did that in the past for the C# syntax tree used in a decompiler. Basically the syntax tree has a bunch of additional (non-syntax) pattern nodes, that support flexible regex-style matching of a pattern-tree against a concrete syntax tree. Example pattern: https://github.com/icsharpcode/ILSpy/blob/1100d64e4bbd878164e3cbf17d8b741ad11bdb44/ICSharpCode.Decompiler/CSharp/Transforms/CombineQueryExpressions.cs#L92 https://github.com/icsharpcode/ILSpy/blob/1100d64e4bbd878164... Implementation: https://github.com/icsharpcode/ILSpy/tree/1100d64e4bbd878164e3cbf17d8b741ad11bdb44/ICSharpCode.Decompiler/CSharp/Syntax/PatternMatching https://github.com/icsharpcode/ILSpy/tree/1100d64e4bbd878164...