Skip to content

Commit e34ed4f

Browse files
committed
Switch to variadic Local inits
Not totally sure why the `Capture0` trick from the quantification variadics isn't necessary here, so more source compatibility testing should be done before landing.
1 parent eb2628e commit e34ed4f

File tree

3 files changed

+30
-291
lines changed

3 files changed

+30
-291
lines changed

Sources/RegexBuilder/Variadics.swift

Lines changed: 6 additions & 291 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
// BEGIN AUTO-GENERATED CONTENT
13-
1412
@_spi(RegexBuilder) import _StringProcessing
1513

1614
@available(SwiftStdlib 5.7, *)
@@ -532,10 +530,7 @@ extension Local {
532530
let factory = makeFactory()
533531
self.init(factory.atomicNonCapturing(component))
534532
}
535-
}
536533

537-
@available(SwiftStdlib 5.7, *)
538-
extension Local {
539534
/// Creates an atomic group with the given regex component.
540535
///
541536
/// - Parameter componentBuilder: A builder closure that generates a
@@ -550,192 +545,7 @@ extension Local {
550545
self.init(factory.atomicNonCapturing(componentBuilder()))
551546
}
552547
}
553-
@available(SwiftStdlib 5.7, *)
554-
extension Local {
555-
/// Creates an atomic group with the given regex component.
556-
///
557-
/// - Parameter component: The regex component to wrap in an atomic
558-
/// group.
559-
@available(SwiftStdlib 5.7, *)
560-
@_alwaysEmitIntoClient
561-
public init<W, C1>(
562-
_ component: some RegexComponent<(W, C1)>
563-
) where RegexOutput == (Substring, C1) {
564-
let factory = makeFactory()
565-
self.init(factory.atomicNonCapturing(component))
566-
}
567-
}
568-
569-
@available(SwiftStdlib 5.7, *)
570-
extension Local {
571-
/// Creates an atomic group with the given regex component.
572-
///
573-
/// - Parameter componentBuilder: A builder closure that generates a
574-
/// regex component to wrap in an atomic group.
575-
@available(SwiftStdlib 5.7, *)
576-
@_alwaysEmitIntoClient
577-
public init<W, C1>(
578-
@RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1)>
579-
) where RegexOutput == (Substring, C1) {
580-
let factory = makeFactory()
581-
self.init(factory.atomicNonCapturing(componentBuilder()))
582-
}
583-
}
584-
@available(SwiftStdlib 5.7, *)
585-
extension Local {
586-
/// Creates an atomic group with the given regex component.
587-
///
588-
/// - Parameter component: The regex component to wrap in an atomic
589-
/// group.
590-
@available(SwiftStdlib 5.7, *)
591-
@_alwaysEmitIntoClient
592-
public init<W, C1, C2>(
593-
_ component: some RegexComponent<(W, C1, C2)>
594-
) where RegexOutput == (Substring, C1, C2) {
595-
let factory = makeFactory()
596-
self.init(factory.atomicNonCapturing(component))
597-
}
598-
}
599-
600-
@available(SwiftStdlib 5.7, *)
601-
extension Local {
602-
/// Creates an atomic group with the given regex component.
603-
///
604-
/// - Parameter componentBuilder: A builder closure that generates a
605-
/// regex component to wrap in an atomic group.
606-
@available(SwiftStdlib 5.7, *)
607-
@_alwaysEmitIntoClient
608-
public init<W, C1, C2>(
609-
@RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2)>
610-
) where RegexOutput == (Substring, C1, C2) {
611-
let factory = makeFactory()
612-
self.init(factory.atomicNonCapturing(componentBuilder()))
613-
}
614-
}
615-
@available(SwiftStdlib 5.7, *)
616-
extension Local {
617-
/// Creates an atomic group with the given regex component.
618-
///
619-
/// - Parameter component: The regex component to wrap in an atomic
620-
/// group.
621-
@available(SwiftStdlib 5.7, *)
622-
@_alwaysEmitIntoClient
623-
public init<W, C1, C2, C3>(
624-
_ component: some RegexComponent<(W, C1, C2, C3)>
625-
) where RegexOutput == (Substring, C1, C2, C3) {
626-
let factory = makeFactory()
627-
self.init(factory.atomicNonCapturing(component))
628-
}
629-
}
630-
631-
@available(SwiftStdlib 5.7, *)
632-
extension Local {
633-
/// Creates an atomic group with the given regex component.
634-
///
635-
/// - Parameter componentBuilder: A builder closure that generates a
636-
/// regex component to wrap in an atomic group.
637-
@available(SwiftStdlib 5.7, *)
638-
@_alwaysEmitIntoClient
639-
public init<W, C1, C2, C3>(
640-
@RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3)>
641-
) where RegexOutput == (Substring, C1, C2, C3) {
642-
let factory = makeFactory()
643-
self.init(factory.atomicNonCapturing(componentBuilder()))
644-
}
645-
}
646-
@available(SwiftStdlib 5.7, *)
647-
extension Local {
648-
/// Creates an atomic group with the given regex component.
649-
///
650-
/// - Parameter component: The regex component to wrap in an atomic
651-
/// group.
652-
@available(SwiftStdlib 5.7, *)
653-
@_alwaysEmitIntoClient
654-
public init<W, C1, C2, C3, C4>(
655-
_ component: some RegexComponent<(W, C1, C2, C3, C4)>
656-
) where RegexOutput == (Substring, C1, C2, C3, C4) {
657-
let factory = makeFactory()
658-
self.init(factory.atomicNonCapturing(component))
659-
}
660-
}
661-
662-
@available(SwiftStdlib 5.7, *)
663-
extension Local {
664-
/// Creates an atomic group with the given regex component.
665-
///
666-
/// - Parameter componentBuilder: A builder closure that generates a
667-
/// regex component to wrap in an atomic group.
668-
@available(SwiftStdlib 5.7, *)
669-
@_alwaysEmitIntoClient
670-
public init<W, C1, C2, C3, C4>(
671-
@RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4)>
672-
) where RegexOutput == (Substring, C1, C2, C3, C4) {
673-
let factory = makeFactory()
674-
self.init(factory.atomicNonCapturing(componentBuilder()))
675-
}
676-
}
677-
@available(SwiftStdlib 5.7, *)
678-
extension Local {
679-
/// Creates an atomic group with the given regex component.
680-
///
681-
/// - Parameter component: The regex component to wrap in an atomic
682-
/// group.
683-
@available(SwiftStdlib 5.7, *)
684-
@_alwaysEmitIntoClient
685-
public init<W, C1, C2, C3, C4, C5>(
686-
_ component: some RegexComponent<(W, C1, C2, C3, C4, C5)>
687-
) where RegexOutput == (Substring, C1, C2, C3, C4, C5) {
688-
let factory = makeFactory()
689-
self.init(factory.atomicNonCapturing(component))
690-
}
691-
}
692-
693-
@available(SwiftStdlib 5.7, *)
694-
extension Local {
695-
/// Creates an atomic group with the given regex component.
696-
///
697-
/// - Parameter componentBuilder: A builder closure that generates a
698-
/// regex component to wrap in an atomic group.
699-
@available(SwiftStdlib 5.7, *)
700-
@_alwaysEmitIntoClient
701-
public init<W, C1, C2, C3, C4, C5>(
702-
@RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5)>
703-
) where RegexOutput == (Substring, C1, C2, C3, C4, C5) {
704-
let factory = makeFactory()
705-
self.init(factory.atomicNonCapturing(componentBuilder()))
706-
}
707-
}
708-
@available(SwiftStdlib 5.7, *)
709-
extension Local {
710-
/// Creates an atomic group with the given regex component.
711-
///
712-
/// - Parameter component: The regex component to wrap in an atomic
713-
/// group.
714-
@available(SwiftStdlib 5.7, *)
715-
@_alwaysEmitIntoClient
716-
public init<W, C1, C2, C3, C4, C5, C6>(
717-
_ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6)>
718-
) where RegexOutput == (Substring, C1, C2, C3, C4, C5, C6) {
719-
let factory = makeFactory()
720-
self.init(factory.atomicNonCapturing(component))
721-
}
722-
}
723548

724-
@available(SwiftStdlib 5.7, *)
725-
extension Local {
726-
/// Creates an atomic group with the given regex component.
727-
///
728-
/// - Parameter componentBuilder: A builder closure that generates a
729-
/// regex component to wrap in an atomic group.
730-
@available(SwiftStdlib 5.7, *)
731-
@_alwaysEmitIntoClient
732-
public init<W, C1, C2, C3, C4, C5, C6>(
733-
@RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6)>
734-
) where RegexOutput == (Substring, C1, C2, C3, C4, C5, C6) {
735-
let factory = makeFactory()
736-
self.init(factory.atomicNonCapturing(componentBuilder()))
737-
}
738-
}
739549
@available(SwiftStdlib 5.7, *)
740550
extension Local {
741551
/// Creates an atomic group with the given regex component.
@@ -744,122 +554,27 @@ extension Local {
744554
/// group.
745555
@available(SwiftStdlib 5.7, *)
746556
@_alwaysEmitIntoClient
747-
public init<W, C1, C2, C3, C4, C5, C6, C7>(
748-
_ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7)>
749-
) where RegexOutput == (Substring, C1, C2, C3, C4, C5, C6, C7) {
557+
public init<W, each Capture>(
558+
_ component: some RegexComponent<(W, repeat each Capture)>
559+
) where RegexOutput == (Substring, repeat each Capture) {
750560
let factory = makeFactory()
751561
self.init(factory.atomicNonCapturing(component))
752562
}
753-
}
754563

755-
@available(SwiftStdlib 5.7, *)
756-
extension Local {
757564
/// Creates an atomic group with the given regex component.
758565
///
759566
/// - Parameter componentBuilder: A builder closure that generates a
760567
/// regex component to wrap in an atomic group.
761568
@available(SwiftStdlib 5.7, *)
762569
@_alwaysEmitIntoClient
763-
public init<W, C1, C2, C3, C4, C5, C6, C7>(
764-
@RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7)>
765-
) where RegexOutput == (Substring, C1, C2, C3, C4, C5, C6, C7) {
570+
public init<W, each Capture>(
571+
@RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, repeat each Capture)>
572+
) where RegexOutput == (Substring, repeat each Capture) {
766573
let factory = makeFactory()
767574
self.init(factory.atomicNonCapturing(componentBuilder()))
768575
}
769576
}
770-
@available(SwiftStdlib 5.7, *)
771-
extension Local {
772-
/// Creates an atomic group with the given regex component.
773-
///
774-
/// - Parameter component: The regex component to wrap in an atomic
775-
/// group.
776-
@available(SwiftStdlib 5.7, *)
777-
@_alwaysEmitIntoClient
778-
public init<W, C1, C2, C3, C4, C5, C6, C7, C8>(
779-
_ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8)>
780-
) where RegexOutput == (Substring, C1, C2, C3, C4, C5, C6, C7, C8) {
781-
let factory = makeFactory()
782-
self.init(factory.atomicNonCapturing(component))
783-
}
784-
}
785577

786-
@available(SwiftStdlib 5.7, *)
787-
extension Local {
788-
/// Creates an atomic group with the given regex component.
789-
///
790-
/// - Parameter componentBuilder: A builder closure that generates a
791-
/// regex component to wrap in an atomic group.
792-
@available(SwiftStdlib 5.7, *)
793-
@_alwaysEmitIntoClient
794-
public init<W, C1, C2, C3, C4, C5, C6, C7, C8>(
795-
@RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8)>
796-
) where RegexOutput == (Substring, C1, C2, C3, C4, C5, C6, C7, C8) {
797-
let factory = makeFactory()
798-
self.init(factory.atomicNonCapturing(componentBuilder()))
799-
}
800-
}
801-
@available(SwiftStdlib 5.7, *)
802-
extension Local {
803-
/// Creates an atomic group with the given regex component.
804-
///
805-
/// - Parameter component: The regex component to wrap in an atomic
806-
/// group.
807-
@available(SwiftStdlib 5.7, *)
808-
@_alwaysEmitIntoClient
809-
public init<W, C1, C2, C3, C4, C5, C6, C7, C8, C9>(
810-
_ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9)>
811-
) where RegexOutput == (Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9) {
812-
let factory = makeFactory()
813-
self.init(factory.atomicNonCapturing(component))
814-
}
815-
}
816-
817-
@available(SwiftStdlib 5.7, *)
818-
extension Local {
819-
/// Creates an atomic group with the given regex component.
820-
///
821-
/// - Parameter componentBuilder: A builder closure that generates a
822-
/// regex component to wrap in an atomic group.
823-
@available(SwiftStdlib 5.7, *)
824-
@_alwaysEmitIntoClient
825-
public init<W, C1, C2, C3, C4, C5, C6, C7, C8, C9>(
826-
@RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9)>
827-
) where RegexOutput == (Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9) {
828-
let factory = makeFactory()
829-
self.init(factory.atomicNonCapturing(componentBuilder()))
830-
}
831-
}
832-
@available(SwiftStdlib 5.7, *)
833-
extension Local {
834-
/// Creates an atomic group with the given regex component.
835-
///
836-
/// - Parameter component: The regex component to wrap in an atomic
837-
/// group.
838-
@available(SwiftStdlib 5.7, *)
839-
@_alwaysEmitIntoClient
840-
public init<W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10>(
841-
_ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)>
842-
) where RegexOutput == (Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10) {
843-
let factory = makeFactory()
844-
self.init(factory.atomicNonCapturing(component))
845-
}
846-
}
847-
848-
@available(SwiftStdlib 5.7, *)
849-
extension Local {
850-
/// Creates an atomic group with the given regex component.
851-
///
852-
/// - Parameter componentBuilder: A builder closure that generates a
853-
/// regex component to wrap in an atomic group.
854-
@available(SwiftStdlib 5.7, *)
855-
@_alwaysEmitIntoClient
856-
public init<W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10>(
857-
@RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)>
858-
) where RegexOutput == (Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10) {
859-
let factory = makeFactory()
860-
self.init(factory.atomicNonCapturing(componentBuilder()))
861-
}
862-
}
863578
// MARK: - Alternation builder (arity 0)
864579

865580
@available(SwiftStdlib 5.7, *)

Tests/RegexBuilderTests/RegexDSLTests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,21 @@ class RegexDSLTests: XCTestCase {
884884
}
885885
"a"
886886
}
887+
888+
// FIXME: Atomic groups lose their captures, will fix in:
889+
// https://github.com/apple/swift-experimental-string-processing/pull/723
890+
// try _testDSLCaptures(
891+
// ("aaa", ("aaa", "a")),
892+
// matchType: (Substring, Substring).self, ==)
893+
// {
894+
// Local {
895+
// "a"
896+
// Capture {
897+
// OneOrMore("a", .reluctant)
898+
// }
899+
// }
900+
// "a"
901+
// }
887902
}
888903

889904
func testAssertions() throws {

Tests/RegexTests/MatchTests.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,6 +1762,15 @@ extension RegexTests {
17621762
firstMatchTest(
17631763
#"(?:(?>a)|.b)c"#, input: "123abcacxyz", match: "abc")
17641764

1765+
firstMatchTest(
1766+
#"(?>a+)a"#, input: "aa", match: nil)
1767+
firstMatchTest(
1768+
#"(?>a+?)a"#, input: "aa", match: "aa")
1769+
firstMatchTest(
1770+
#"(?>(a+))a"#, input: "aa", match: nil)
1771+
firstMatchTest(
1772+
#"(?>(a+?))a"#, input: "aa", match: "aa")
1773+
17651774
// Quantifier behavior inside atomic groups
17661775

17671776
// (?:a+?) matches as few 'a's as possible, after matching the first

0 commit comments

Comments
 (0)