File tree Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -18,8 +18,10 @@ public enum RegexComponentBuilder {
1818 . init( node: . empty)
1919 }
2020
21- public static func buildPartialBlock< R: RegexComponent > ( first: R ) -> R {
22- first
21+ public static func buildPartialBlock< R: RegexComponent > (
22+ first component: R
23+ ) -> Regex < R . RegexOutput > {
24+ component. regex
2325 }
2426
2527 public static func buildExpression< R: RegexComponent > ( _ regex: R ) -> R {
Original file line number Diff line number Diff line change @@ -1015,7 +1015,7 @@ class RegexDSLTests: XCTestCase {
10151015 XCTAssertEqual ( str. wholeMatch ( of: parser) ? . 1 , version)
10161016 }
10171017 }
1018-
1018+
10191019 func testZeroWidthConsumer( ) throws {
10201020 struct Trace : CustomConsumingRegexComponent {
10211021 typealias RegexOutput = Void
@@ -1051,6 +1051,26 @@ class RegexDSLTests: XCTestCase {
10511051
10521052 """ )
10531053 }
1054+
1055+ func testRegexComponentBuilderResultType( ) {
1056+ // Test that the user can declare a closure or computed property marked with
1057+ // `@RegexComponentBuilder` with `Regex` as the result type.
1058+ @RegexComponentBuilder
1059+ var unaryWithSingleNonRegex : Regex < Substring > {
1060+ OneOrMore ( " a " )
1061+ }
1062+ @RegexComponentBuilder
1063+ var multiComponent : Regex < Substring > {
1064+ OneOrMore ( " a " )
1065+ " b "
1066+ }
1067+ struct MyCustomRegex : RegexComponent {
1068+ @RegexComponentBuilder
1069+ var regex : Regex < Substring > {
1070+ OneOrMore ( " a " )
1071+ }
1072+ }
1073+ }
10541074}
10551075
10561076extension Unicode . Scalar {
You can’t perform that action at this time.
0 commit comments