@@ -90,10 +90,7 @@ var standardError = StandardErrorStream()
90
90
91
91
typealias Counter = Int64
92
92
let regexProtocolName = " RegexProtocol "
93
- let concatenationStructTypeBaseName = " Concatenate "
94
- let capturingGroupTypeBaseName = " CapturingGroup "
95
93
let matchAssociatedTypeName = " Match "
96
- let captureAssociatedTypeName = " Capture "
97
94
let patternBuilderTypeName = " RegexBuilder "
98
95
let patternProtocolRequirementName = " regex "
99
96
let regexTypeName = " Regex "
@@ -535,108 +532,169 @@ struct VariadicsGenerator: ParsableCommand {
535
532
: " ( \( baseMatchTypeName) , \( newCaptureType) , " + ( 0 ..< arity) . map { " C \( $0) " } . joined ( separator: " , " ) + " ) "
536
533
}
537
534
let whereClause = " where R. \( matchAssociatedTypeName) == \( matchType) "
535
+ let rawNewMatchType = newMatchType ( newCaptureType: " W " )
536
+ let transformedNewMatchType = newMatchType ( newCaptureType: " NewCapture " )
538
537
output ( """
539
538
// MARK: - Non-builder capture arity \( arity)
540
539
541
540
public func capture< \( genericParams) >(
542
- _ component: R, as reference: Reference? = nil
543
- ) -> \( regexTypeName) < \( newMatchType ( newCaptureType: " W " ) ) > \( whereClause) {
544
- .init(node: .group(.capture, component.regex.root, reference?.id))
541
+ _ component: R
542
+ ) -> \( regexTypeName) < \( rawNewMatchType) > \( whereClause) {
543
+ .init(node: .group(.capture, component.regex.root))
544
+ }
545
+
546
+ public func capture< \( genericParams) >(
547
+ _ component: R, as reference: Reference<W>
548
+ ) -> \( regexTypeName) < \( rawNewMatchType) > \( whereClause) {
549
+ .init(node: .group(.capture, component.regex.root, reference.id))
550
+ }
551
+
552
+ public func capture< \( genericParams) , NewCapture>(
553
+ _ component: R,
554
+ transform: @escaping (Substring) -> NewCapture
555
+ ) -> \( regexTypeName) < \( transformedNewMatchType) > \( whereClause) {
556
+ .init(node: .groupTransform(
557
+ .capture,
558
+ component.regex.root,
559
+ CaptureTransform(resultType: NewCapture.self) {
560
+ transform($0) as Any
561
+ }))
545
562
}
546
563
547
564
public func capture< \( genericParams) , NewCapture>(
548
565
_ component: R,
549
- as reference: Reference? = nil ,
566
+ as reference: Reference<NewCapture> ,
550
567
transform: @escaping (Substring) -> NewCapture
551
- ) -> \( regexTypeName) < \( newMatchType ( newCaptureType : " NewCapture " ) ) > \( whereClause) {
568
+ ) -> \( regexTypeName) < \( transformedNewMatchType ) > \( whereClause) {
552
569
.init(node: .groupTransform(
553
570
.capture,
554
571
component.regex.root,
555
572
CaptureTransform(resultType: NewCapture.self) {
556
573
transform($0) as Any
557
574
},
558
- reference? .id))
575
+ reference.id))
559
576
}
560
577
561
578
public func tryCapture< \( genericParams) , NewCapture>(
562
579
_ component: R,
563
- as reference: Reference? = nil,
564
580
transform: @escaping (Substring) throws -> NewCapture
565
- ) -> \( regexTypeName) < \( newMatchType ( newCaptureType: " NewCapture " ) ) > \( whereClause) {
581
+ ) -> \( regexTypeName) < \( transformedNewMatchType) > \( whereClause) {
582
+ .init(node: .groupTransform(
583
+ .capture,
584
+ component.regex.root,
585
+ CaptureTransform(resultType: NewCapture.self) {
586
+ try transform($0) as Any
587
+ }))
588
+ }
589
+
590
+ public func tryCapture< \( genericParams) , NewCapture>(
591
+ _ component: R,
592
+ as reference: Reference<NewCapture>,
593
+ transform: @escaping (Substring) throws -> NewCapture
594
+ ) -> \( regexTypeName) < \( transformedNewMatchType) > \( whereClause) {
566
595
.init(node: .groupTransform(
567
596
.capture,
568
597
component.regex.root,
569
598
CaptureTransform(resultType: NewCapture.self) {
570
599
try transform($0) as Any
571
600
},
572
- reference? .id))
601
+ reference.id))
573
602
}
574
603
575
604
public func tryCapture< \( genericParams) , NewCapture>(
576
605
_ component: R,
577
- as reference: Reference? = nil,
578
606
transform: @escaping (Substring) -> NewCapture?
579
- ) -> \( regexTypeName) < \( newMatchType ( newCaptureType: " NewCapture " ) ) > \( whereClause) {
607
+ ) -> \( regexTypeName) < \( transformedNewMatchType) > \( whereClause) {
608
+ .init(node: .groupTransform(
609
+ .capture,
610
+ component.regex.root,
611
+ CaptureTransform(resultType: NewCapture.self) {
612
+ transform($0) as Any?
613
+ }))
614
+ }
615
+
616
+ public func tryCapture< \( genericParams) , NewCapture>(
617
+ _ component: R,
618
+ as reference: Reference<NewCapture>,
619
+ transform: @escaping (Substring) -> NewCapture?
620
+ ) -> \( regexTypeName) < \( transformedNewMatchType) > \( whereClause) {
580
621
.init(node: .groupTransform(
581
622
.capture,
582
623
component.regex.root,
583
624
CaptureTransform(resultType: NewCapture.self) {
584
625
transform($0) as Any?
585
626
},
586
- reference? .id))
627
+ reference.id))
587
628
}
588
629
589
630
// MARK: - Builder capture arity \( arity)
590
631
591
632
public func capture< \( genericParams) >(
592
- as reference: Reference? = nil,
593
633
@RegexBuilder _ component: () -> R
594
- ) -> \( regexTypeName) < \( newMatchType ( newCaptureType: " W " ) ) > \( whereClause) {
595
- .init(node: .group(.capture, component().regex.root, reference?.id))
634
+ ) -> \( regexTypeName) < \( rawNewMatchType) > \( whereClause) {
635
+ .init(node: .group(.capture, component().regex.root))
636
+ }
637
+
638
+ public func capture< \( genericParams) >(
639
+ as reference: Reference<W>,
640
+ @RegexBuilder _ component: () -> R
641
+ ) -> \( regexTypeName) < \( rawNewMatchType) > \( whereClause) {
642
+ .init(node: .group(.capture, component().regex.root, reference.id))
596
643
}
597
644
598
645
public func capture< \( genericParams) , NewCapture>(
599
- as reference: Reference? = nil,
600
646
@RegexBuilder _ component: () -> R,
601
647
transform: @escaping (Substring) -> NewCapture
602
- ) -> \( regexTypeName) < \( newMatchType ( newCaptureType : " NewCapture " ) ) > \( whereClause) {
648
+ ) -> \( regexTypeName) < \( transformedNewMatchType ) > \( whereClause) {
603
649
.init(node: .groupTransform(
604
650
.capture,
605
651
component().regex.root,
606
652
CaptureTransform(resultType: NewCapture.self) {
607
653
transform($0) as Any
608
- },
609
- reference?.id))
654
+ }))
610
655
}
611
656
612
657
public func tryCapture< \( genericParams) , NewCapture>(
613
- as reference: Reference? = nil ,
658
+ as reference: Reference<NewCapture> ,
614
659
@RegexBuilder _ component: () -> R,
615
660
transform: @escaping (Substring) throws -> NewCapture
616
- ) -> \( regexTypeName) < \( newMatchType ( newCaptureType : " NewCapture " ) ) > \( whereClause) {
661
+ ) -> \( regexTypeName) < \( transformedNewMatchType ) > \( whereClause) {
617
662
.init(node: .groupTransform(
618
663
.capture,
619
664
component().regex.root,
620
665
CaptureTransform(resultType: NewCapture.self) {
621
666
try transform($0) as Any
622
667
},
623
- reference?.id))
668
+ reference.id))
669
+ }
670
+
671
+ public func tryCapture< \( genericParams) , NewCapture>(
672
+ @RegexBuilder _ component: () -> R,
673
+ transform: @escaping (Substring) -> NewCapture?
674
+ ) -> \( regexTypeName) < \( transformedNewMatchType) > \( whereClause) {
675
+ .init(node: .groupTransform(
676
+ .capture,
677
+ component().regex.root,
678
+ CaptureTransform(resultType: NewCapture.self) {
679
+ transform($0) as Any?
680
+ }))
624
681
}
625
682
626
683
public func tryCapture< \( genericParams) , NewCapture>(
627
- as reference: Reference? = nil ,
684
+ as reference: Reference<NewCapture> ,
628
685
@RegexBuilder _ component: () -> R,
629
686
transform: @escaping (Substring) -> NewCapture?
630
- ) -> \( regexTypeName) < \( newMatchType ( newCaptureType : " NewCapture " ) ) > \( whereClause) {
687
+ ) -> \( regexTypeName) < \( transformedNewMatchType ) > \( whereClause) {
631
688
.init(node: .groupTransform(
632
689
.capture,
633
690
component().regex.root,
634
691
CaptureTransform(resultType: NewCapture.self) {
635
692
transform($0) as Any?
636
693
},
637
- reference? .id))
694
+ reference.id))
638
695
}
639
696
697
+
640
698
""" )
641
699
}
642
700
}
0 commit comments