File tree 2 files changed +25
-3
lines changed
2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -18,8 +18,10 @@ public enum RegexComponentBuilder {
18
18
. init( node: . empty)
19
19
}
20
20
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
23
25
}
24
26
25
27
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 {
1015
1015
XCTAssertEqual ( str. wholeMatch ( of: parser) ? . 1 , version)
1016
1016
}
1017
1017
}
1018
-
1018
+
1019
1019
func testZeroWidthConsumer( ) throws {
1020
1020
struct Trace : CustomConsumingRegexComponent {
1021
1021
typealias RegexOutput = Void
@@ -1051,6 +1051,26 @@ class RegexDSLTests: XCTestCase {
1051
1051
1052
1052
""" )
1053
1053
}
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
+ }
1054
1074
}
1055
1075
1056
1076
extension Unicode . Scalar {
You can’t perform that action at this time.
0 commit comments