Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit34c7bb3

Browse files
authored
Merge pull request#169 from jalil-salame/push-szutvmxzkkku
fix(#168): remove dependency on derivative
2 parents39bee77 +4d8c945 commit34c7bb3

File tree

5 files changed

+44
-28
lines changed

5 files changed

+44
-28
lines changed

‎Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ default-features = false
3333
version ="0.8"
3434
default-features =false
3535

36-
[dependencies.derivative]
37-
version ="2.2.0"
38-
default-features =false
39-
features = ["use_core"]
40-
4136
[dev-dependencies]
4237
criterion ="0.5"
4338
matches ="0.1.10"

‎examples/toy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ mod tests {
168168
"a+bc?",
169169
"\
170170
digraph G {
171-
0 [label=\"0: Delegate { pattern:\\\"(?s:.)*?(a+bc?)\\\", start_group: 0, end_group: 1 }\"];
171+
0 [label=\"0: Delegate(Delegate { pattern:\\\"(?s:.)*?(a+bc?)\\\", start_group: 0, end_group: 1 })\"];
172172
0 -> 1;
173173
1 [label=\"1: End\"];
174174
}

‎src/compile.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use regex_automata::meta::{Builder as RaBuilder, Config as RaConfig};
2929
use std::{collections::BTreeMap, sync::RwLock};
3030

3131
usecrate::analyze::Info;
32-
usecrate::vm::{Insn,Prog};
32+
usecrate::vm::{Delegate,Insn,Prog};
3333
usecrate::LookAround::*;
3434
usecrate::{CompileError,Error,Expr,LookAround,RegexOptions,Result};
3535

@@ -581,12 +581,12 @@ impl DelegateBuilder {
581581

582582
let compiled =compile_inner(&self.re, options)?;
583583

584-
Ok(Insn::Delegate{
584+
Ok(Insn::Delegate(Delegate{
585585
inner: compiled,
586586
pattern:self.re.clone(),
587587
start_group,
588588
end_group,
589-
})
589+
}))
590590
}
591591
}
592592

@@ -723,8 +723,10 @@ mod tests {
723723

724724
#[cfg(feature ="std")]
725725
fnassert_delegate(insn:&Insn,re:&str){
726+
usecrate::vm::Delegate;
727+
726728
match insn{
727-
Insn::Delegate{ inner, ..} =>{
729+
Insn::Delegate(Delegate{ inner, ..}) =>{
728730
assert_eq!(
729731
PATTERN_MAPPING
730732
.read()

‎src/parse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl<'a> Parser<'a> {
102102
backrefs:Default::default(),
103103
named_groups:Default::default(),
104104
numeric_backrefs:false,
105-
flags: flags,
105+
flags,
106106
curr_group:0,
107107
contains_subroutines:false,
108108
has_unresolved_subroutines:false,

‎src/vm.rs

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ use alloc::string::String;
7474
use alloc::vec;
7575
use alloc::vec::Vec;
7676
use core::usize;
77-
use derivative::Derivative;
7877
use regex_automata::meta::Regex;
7978
use regex_automata::util::look::LookMatcher;
8079
use regex_automata::util::primitives::NonMaxUsize;
@@ -102,9 +101,39 @@ pub(crate) const OPTION_SKIPPED_EMPTY_MATCH: u32 = 1 << 1;
102101
// TODO: make configurable
103102
constMAX_STACK:usize =1_000_000;
104103

104+
#[derive(Clone)]
105+
/// Delegate matching to the regex crate
106+
pubstructDelegate{
107+
/// The regex
108+
pubinner:Regex,
109+
/// The regex pattern as a string
110+
pubpattern:String,
111+
/// The first group number that this regex captures (if it contains groups)
112+
pubstart_group:usize,
113+
/// The last group number
114+
pubend_group:usize,
115+
}
116+
117+
impl core::fmt::DebugforDelegate{
118+
fnfmt(&self,f:&mutFormatter<'_>) -> core::fmt::Result{
119+
// Ensures it fails to compile if the struct changes
120+
letSelf{
121+
inner: _,
122+
pattern,
123+
start_group,
124+
end_group,
125+
} =self;
126+
127+
f.debug_struct("Delegate")
128+
.field("pattern", pattern)
129+
.field("start_group", start_group)
130+
.field("end_group", end_group)
131+
.finish()
132+
}
133+
}
134+
105135
/// Instruction of the VM.
106-
#[derive(Clone,Derivative)]
107-
#[derivative(Debug)]
136+
#[derive(Clone,Debug)]
108137
pubenumInsn{
109138
/// Successful end of program
110139
End,
@@ -187,17 +216,7 @@ pub enum Insn {
187216
/// End of atomic group
188217
EndAtomic,
189218
/// Delegate matching to the regex crate
190-
Delegate{
191-
/// The regex
192-
#[derivative(Debug ="ignore")]
193-
inner:Regex,
194-
/// The regex pattern as a string
195-
pattern:String,
196-
/// The first group number that this regex captures (if it contains groups)
197-
start_group:usize,
198-
/// The last group number
199-
end_group:usize,
200-
},
219+
Delegate(Delegate),
201220
/// Anchor to match at the position where the previous match ended
202221
ContinueFromPreviousMatchEnd,
203222
/// Continue only if the specified capture group has already been populated as part of the match
@@ -444,7 +463,7 @@ fn matches_literal_casei(s: &str, ix: usize, end: usize, literal: &str) -> bool
444463
Ast::literal(Literal{
445464
span,
446465
kind:LiteralKind::Verbatim,
447-
c: c,
466+
c,
448467
})
449468
})
450469
.collect();
@@ -718,12 +737,12 @@ pub(crate) fn run(
718737
let count = state.stack_pop();
719738
state.backtrack_cut(count);
720739
}
721-
Insn::Delegate{
740+
Insn::Delegate(Delegate{
722741
ref inner,
723742
pattern: _,
724743
start_group,
725744
end_group,
726-
} =>{
745+
}) =>{
727746
let input =Input::new(s).span(ix..s.len()).anchored(Anchored::Yes);
728747
if start_group == end_group{
729748
// No groups, so we can use faster methods

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp