]> git.proxmox.com Git - rustc.git/blobdiff - vendor/regex-syntax/src/hir/literal/mod.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / vendor / regex-syntax / src / hir / literal / mod.rs
index 25ee88b065d820d1c6d56c11e0c1a9d777b5537e..1e66d2cc3d043c277a60d8dfa5e452f86bc5fff1 100644 (file)
@@ -735,18 +735,18 @@ fn repeat_zero_or_one_literals<F: FnMut(&Hir, &mut Literals)>(
     lits: &mut Literals,
     mut f: F,
 ) {
-    let (mut lits2, mut lits3) = (lits.clone(), lits.to_empty());
-    lits3.set_limit_size(lits.limit_size() / 2);
-    f(e, &mut lits3);
-
-    if lits3.is_empty() || !lits2.cross_product(&lits3) {
-        lits.cut();
-        return;
-    }
-    lits2.add(Literal::empty());
-    if !lits.union(lits2) {
-        lits.cut();
-    }
+    f(
+        &Hir::repetition(hir::Repetition {
+            kind: hir::RepetitionKind::ZeroOrMore,
+            // FIXME: Our literal extraction doesn't care about greediness.
+            // Which is partially why we're treating 'e?' as 'e*'. Namely,
+            // 'ab??' yields [Complete(ab), Complete(a)], but it should yield
+            // [Complete(a), Complete(ab)] because of the non-greediness.
+            greedy: true,
+            hir: Box::new(e.clone()),
+        }),
+        lits,
+    );
 }
 
 fn repeat_zero_or_more_literals<F: FnMut(&Hir, &mut Literals)>(
@@ -1141,6 +1141,11 @@ mod tests {
     test_lit!(pfx_group1, prefixes, "(a)", M("a"));
     test_lit!(pfx_rep_zero_or_one1, prefixes, "a?");
     test_lit!(pfx_rep_zero_or_one2, prefixes, "(?:abc)?");
+    test_lit!(pfx_rep_zero_or_one_cat1, prefixes, "ab?", C("ab"), M("a"));
+    // FIXME: This should return [M("a"), M("ab")] because of the non-greedy
+    // repetition. As a work-around, we rewrite ab?? as ab*?, and thus we get
+    // a cut literal.
+    test_lit!(pfx_rep_zero_or_one_cat2, prefixes, "ab??", C("ab"), M("a"));
     test_lit!(pfx_rep_zero_or_more1, prefixes, "a*");
     test_lit!(pfx_rep_zero_or_more2, prefixes, "(?:abc)*");
     test_lit!(pfx_rep_one_or_more1, prefixes, "a+", C("a"));
@@ -1249,8 +1254,8 @@ mod tests {
         pfx_crazy1,
         prefixes,
         r"M[ou]'?am+[ae]r .*([AEae]l[- ])?[GKQ]h?[aeu]+([dtz][dhz]?)+af[iy]",
-        C("Mo\\'am"),
-        C("Mu\\'am"),
+        C("Mo\\'"),
+        C("Mu\\'"),
         C("Moam"),
         C("Muam")
     );