Skip to content

Commit 43ba6b8

Browse files
authored
syntax: improve literal extraction from certain repetitions
When repetitions didn't have an explicit max value, like in `(ab){2,}` the literal extractor was producing sub-optimal literals, like `"ab"` instead of `"abab"`. Close rust-lang#1032
1 parent 28e16fa commit 43ba6b8

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

regex-syntax/src/hir/literal.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ impl Extractor {
477477
}
478478
seq
479479
}
480-
hir::Repetition { min, max: Some(max), .. } if min < max => {
480+
hir::Repetition { min, .. } => {
481481
assert!(min > 0); // handled above
482482
let limit =
483483
u32::try_from(self.limit_repeat).unwrap_or(u32::MAX);
@@ -491,10 +491,6 @@ impl Extractor {
491491
seq.make_inexact();
492492
seq
493493
}
494-
hir::Repetition { .. } => {
495-
subseq.make_inexact();
496-
subseq
497-
}
498494
}
499495
}
500496

@@ -2655,6 +2651,12 @@ mod tests {
26552651
]),
26562652
e(r"(ab|cd)(ef|gh)(ij|kl)")
26572653
);
2654+
2655+
assert_eq!(inexact([E("abab")], [E("abab")]), e(r"(ab){2}"));
2656+
2657+
assert_eq!(inexact([I("abab")], [I("abab")]), e(r"(ab){2,3}"));
2658+
2659+
assert_eq!(inexact([I("abab")], [I("abab")]), e(r"(ab){2,}"));
26582660
}
26592661

26602662
#[test]

0 commit comments

Comments
 (0)