Skip to content

Commit df76fad

Browse files
committed
Revert "Fix #186."
The fix is totally bogus. We obviously can't do anything meaningful with recording matches while computing cached states, since once a state is cached, we won't actually record the match. Stay tuned for greener pastures. This reverts commit 3fb34e2.
1 parent a1f63b6 commit df76fad

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

src/compile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ impl ByteClassSet {
998998
// N.B. If you're debugging the DFA, it's useful to simply return
999999
// `(0..256).collect()`, which effectively removes the byte classes
10001000
// and makes the transitions easier to read.
1001-
// return (0..256).map(|b| b as u8).collect();
1001+
// return (0..256).collect();
10021002
let mut byte_classes = vec![0; 256];
10031003
let mut class = 0u8;
10041004
for i in 0..256 {

src/dfa.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use std::fmt;
4646
use std::mem;
4747

4848
use exec::Search;
49-
use prog::Program;
49+
use prog::{Inst, Program};
5050
use sparse::SparseSet;
5151

5252
/// The cache limit specifies approximately how much space we're willing to
@@ -465,7 +465,6 @@ impl<'a, 'b, 'c, 'm> Dfa<'a, 'b, 'c, 'm> {
465465
}
466466
self.at += 1;
467467
}
468-
// println!("exiting loop at input {:?}", self.at);
469468
// Run the DFA once more on the special EOF senitnel value.
470469
si = match self.next_state(qcur, qnext, si, Byte::eof()) {
471470
None => return DfaResult::Quit,
@@ -482,6 +481,13 @@ impl<'a, 'b, 'c, 'm> Dfa<'a, 'b, 'c, 'm> {
482481
result = DfaResult::Match;
483482
self.search.set_end(Some(text.len()));
484483
}
484+
if result.is_match() && !self.search.find_one_match() {
485+
for &ip in &self.states[si as usize].insts {
486+
if let Inst::Match(slot) = self.prog[ip as usize] {
487+
self.search.set_match(slot);
488+
}
489+
}
490+
}
485491
result
486492
}
487493

@@ -622,16 +628,16 @@ impl<'a, 'b, 'c, 'm> Dfa<'a, 'b, 'c, 'm> {
622628
Char(_) | Ranges(_) => unreachable!(),
623629
// These states are handled when following epsilon transitions.
624630
Save(_) | Split(_) | EmptyLook(_) => {}
625-
Match(slot) => {
631+
Match(_) => {
626632
is_match = true;
627633
if !self.continue_past_first_match() {
628634
break;
629-
} else if !self.search.find_one_match()
630-
&& !self.search.has_match(slot)
631-
&& !qnext.contains_ip(ip as usize) {
635+
} else if !self.search.find_one_match() {
632636
// If we are continuing on to find other matches,
633637
// then keep a record of the match states we've seen.
634-
qnext.add(ip);
638+
if !qnext.contains_ip(ip as usize) {
639+
qnext.add(ip);
640+
}
635641
}
636642
}
637643
Bytes(ref inst) => {
@@ -870,9 +876,8 @@ impl<'a, 'b, 'c, 'm> Dfa<'a, 'b, 'c, 'm> {
870876
| NotWordBoundaryAscii => unreachable!(),
871877
}
872878
}
873-
Match(slot) => {
879+
Match(_) => {
874880
insts.push(ip);
875-
self.search.set_match(slot);
876881
if !self.continue_past_first_match() {
877882
break;
878883
}

src/exec.rs

-4
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ impl<'caps, 'matches> Search<'caps, 'matches> {
7676
self.matches.iter().all(|m| *m)
7777
}
7878

79-
pub fn has_match(&mut self, match_slot: usize) -> bool {
80-
self.matches.get(match_slot).map_or(false, |&b| b)
81-
}
82-
8379
pub fn set_match(&mut self, match_slot: usize) {
8480
self.matched_any = true;
8581
if let Some(old) = self.matches.get_mut(match_slot) {

0 commit comments

Comments
 (0)