aboutsummaryrefslogtreecommitdiffstats
path: root/src/parse/regex/enfa.rs
diff options
context:
space:
mode:
authorJonas Maier <jonas@x77.dev>2026-06-02 23:52:23 +0200
committerJonas Maier <jonas@x77.dev>2026-06-02 23:52:23 +0200
commit5ce263b586c5047d16ee93cc53bc3bce6f7ff12c (patch)
tree5b009e8404723f1f91b22085fc06cf8324555be7 /src/parse/regex/enfa.rs
parentec7d2f2b16a0cd2b5a1185284cafa8725c26a160 (diff)
downloadpish-5ce263b586c5047d16ee93cc53bc3bce6f7ff12c.tar.gz
fix lookahead
Diffstat (limited to 'src/parse/regex/enfa.rs')
-rw-r--r--src/parse/regex/enfa.rs28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/parse/regex/enfa.rs b/src/parse/regex/enfa.rs
index a407e9e..272c709 100644
--- a/src/parse/regex/enfa.rs
+++ b/src/parse/regex/enfa.rs
@@ -116,7 +116,7 @@ mod product_tests {
}
}
-#[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
+#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
struct Thread {
state: StateId,
positives: Vec<Thread>,
@@ -200,19 +200,28 @@ impl Thread {
let Self {
state,
- mut positives,
- mut negatives,
+ positives,
+ negatives,
} = self;
+ let mut p = Vec::new();
+ let mut n = Vec::new();
for assertion in new_assertions {
- let mut threads = Self::new_simple(assertion.to).step_epsilon(enfa);
+ let threads = Self::new_simple(assertion.to).step_epsilon(enfa);
let vec = match assertion.polarity {
- LookPolarity::Positive => &mut positives,
- LookPolarity::Negative => &mut negatives,
+ LookPolarity::Positive => &mut p,
+ LookPolarity::Negative => &mut n,
};
- vec.append(&mut threads);
+ vec.push(threads);
}
- if let Some(thread) = Self::new(enfa, state, positives, negatives) {
- ret(thread);
+ let p = cartesian_product(p);
+ for mut p in p {
+ let mut positives = positives.clone();
+ let mut negatives = negatives.clone();
+ positives.append(&mut p);
+ negatives.append(&mut n.iter().cloned().flatten().collect());
+ if let Some(thread) = Self::new(enfa, state, positives, negatives) {
+ ret(thread);
+ }
}
}
@@ -230,6 +239,7 @@ impl Thread {
fn step0(self, enfa: &ENFA, input: ByteRange, ret: &mut impl FnMut(Thread)) {
let positives = self
.positives
+ .clone()
.into_iter()
.map(|t| t.step(enfa, input))
.collect();