diff --git a/Sources/RegexBuilder/Variadics.swift b/Sources/RegexBuilder/Variadics.swift index 989e5d463..2f4a6240a 100644 --- a/Sources/RegexBuilder/Variadics.swift +++ b/Sources/RegexBuilder/Variadics.swift @@ -2255,35 +2255,6 @@ extension Capture { self.init(node: .capture(reference: reference.id, component.regex.root)) } - @_disfavoredOverload - public init( - _ component: R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture), R.Output == W { - self.init(node: .capture(.transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component.regex.root))) - } - - @_disfavoredOverload - public init( - _ component: R, - as reference: Reference, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture), R.Output == W { - self.init(node: .capture( - reference: reference.id, - .transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component.regex.root))) - } -} - -extension TryCapture { @_disfavoredOverload public init( _ component: R, @@ -2310,15 +2281,17 @@ extension TryCapture { }, component.regex.root))) } +} +extension TryCapture { @_disfavoredOverload public init( _ component: R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture), R.Output == W { self.init(node: .capture(.transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component.regex.root))) } @@ -2327,13 +2300,13 @@ extension TryCapture { public init( _ component: R, as reference: Reference, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture), R.Output == W { self.init(node: .capture( reference: reference.id, .transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component.regex.root))) } @@ -2359,35 +2332,6 @@ extension Capture { component().regex.root)) } - @_disfavoredOverload - public init( - @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture), R.Output == W { - self.init(node: .capture(.transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component().regex.root))) - } - - @_disfavoredOverload - public init( - as reference: Reference, - @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture), R.Output == W { - self.init(node: .capture( - reference: reference.id, - .transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component().regex.root))) - } -} - -extension TryCapture { @_disfavoredOverload public init( @RegexComponentBuilder _ component: () -> R, @@ -2414,15 +2358,17 @@ extension TryCapture { }, component().regex.root))) } +} +extension TryCapture { @_disfavoredOverload public init( @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture), R.Output == W { self.init(node: .capture(.transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component().regex.root))) } @@ -2431,13 +2377,13 @@ extension TryCapture { public init( as reference: Reference, @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture), R.Output == W { self.init(node: .capture( reference: reference.id, .transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component().regex.root))) } @@ -2458,33 +2404,6 @@ extension Capture { self.init(node: .capture(reference: reference.id, component.regex.root)) } - public init( - _ component: R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0), R.Output == (W, C0) { - self.init(node: .capture(.transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component.regex.root))) - } - - public init( - _ component: R, - as reference: Reference, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0), R.Output == (W, C0) { - self.init(node: .capture( - reference: reference.id, - .transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component.regex.root))) - } -} - -extension TryCapture { public init( _ component: R, transform: @escaping (Substring) throws -> NewCapture @@ -2509,14 +2428,16 @@ extension TryCapture { }, component.regex.root))) } +} +extension TryCapture { public init( _ component: R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0), R.Output == (W, C0) { self.init(node: .capture(.transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component.regex.root))) } @@ -2524,13 +2445,13 @@ extension TryCapture { public init( _ component: R, as reference: Reference, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0), R.Output == (W, C0) { self.init(node: .capture( reference: reference.id, .transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component.regex.root))) } @@ -2554,33 +2475,6 @@ extension Capture { component().regex.root)) } - public init( - @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0), R.Output == (W, C0) { - self.init(node: .capture(.transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component().regex.root))) - } - - public init( - as reference: Reference, - @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0), R.Output == (W, C0) { - self.init(node: .capture( - reference: reference.id, - .transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component().regex.root))) - } -} - -extension TryCapture { public init( @RegexComponentBuilder _ component: () -> R, transform: @escaping (Substring) throws -> NewCapture @@ -2605,14 +2499,16 @@ extension TryCapture { }, component().regex.root))) } +} +extension TryCapture { public init( @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0), R.Output == (W, C0) { self.init(node: .capture(.transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component().regex.root))) } @@ -2620,13 +2516,13 @@ extension TryCapture { public init( as reference: Reference, @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0), R.Output == (W, C0) { self.init(node: .capture( reference: reference.id, .transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component().regex.root))) } @@ -2647,33 +2543,6 @@ extension Capture { self.init(node: .capture(reference: reference.id, component.regex.root)) } - public init( - _ component: R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1), R.Output == (W, C0, C1) { - self.init(node: .capture(.transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component.regex.root))) - } - - public init( - _ component: R, - as reference: Reference, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1), R.Output == (W, C0, C1) { - self.init(node: .capture( - reference: reference.id, - .transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component.regex.root))) - } -} - -extension TryCapture { public init( _ component: R, transform: @escaping (Substring) throws -> NewCapture @@ -2698,14 +2567,16 @@ extension TryCapture { }, component.regex.root))) } +} +extension TryCapture { public init( _ component: R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1), R.Output == (W, C0, C1) { self.init(node: .capture(.transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component.regex.root))) } @@ -2713,13 +2584,13 @@ extension TryCapture { public init( _ component: R, as reference: Reference, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1), R.Output == (W, C0, C1) { self.init(node: .capture( reference: reference.id, .transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component.regex.root))) } @@ -2743,33 +2614,6 @@ extension Capture { component().regex.root)) } - public init( - @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1), R.Output == (W, C0, C1) { - self.init(node: .capture(.transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component().regex.root))) - } - - public init( - as reference: Reference, - @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1), R.Output == (W, C0, C1) { - self.init(node: .capture( - reference: reference.id, - .transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component().regex.root))) - } -} - -extension TryCapture { public init( @RegexComponentBuilder _ component: () -> R, transform: @escaping (Substring) throws -> NewCapture @@ -2794,14 +2638,16 @@ extension TryCapture { }, component().regex.root))) } +} +extension TryCapture { public init( @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1), R.Output == (W, C0, C1) { self.init(node: .capture(.transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component().regex.root))) } @@ -2809,13 +2655,13 @@ extension TryCapture { public init( as reference: Reference, @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1), R.Output == (W, C0, C1) { self.init(node: .capture( reference: reference.id, .transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component().regex.root))) } @@ -2836,33 +2682,6 @@ extension Capture { self.init(node: .capture(reference: reference.id, component.regex.root)) } - public init( - _ component: R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2), R.Output == (W, C0, C1, C2) { - self.init(node: .capture(.transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component.regex.root))) - } - - public init( - _ component: R, - as reference: Reference, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2), R.Output == (W, C0, C1, C2) { - self.init(node: .capture( - reference: reference.id, - .transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component.regex.root))) - } -} - -extension TryCapture { public init( _ component: R, transform: @escaping (Substring) throws -> NewCapture @@ -2887,14 +2706,16 @@ extension TryCapture { }, component.regex.root))) } +} +extension TryCapture { public init( _ component: R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2), R.Output == (W, C0, C1, C2) { self.init(node: .capture(.transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component.regex.root))) } @@ -2902,13 +2723,13 @@ extension TryCapture { public init( _ component: R, as reference: Reference, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2), R.Output == (W, C0, C1, C2) { self.init(node: .capture( reference: reference.id, .transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component.regex.root))) } @@ -2932,33 +2753,6 @@ extension Capture { component().regex.root)) } - public init( - @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2), R.Output == (W, C0, C1, C2) { - self.init(node: .capture(.transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component().regex.root))) - } - - public init( - as reference: Reference, - @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2), R.Output == (W, C0, C1, C2) { - self.init(node: .capture( - reference: reference.id, - .transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component().regex.root))) - } -} - -extension TryCapture { public init( @RegexComponentBuilder _ component: () -> R, transform: @escaping (Substring) throws -> NewCapture @@ -2983,14 +2777,16 @@ extension TryCapture { }, component().regex.root))) } +} +extension TryCapture { public init( @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2), R.Output == (W, C0, C1, C2) { self.init(node: .capture(.transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component().regex.root))) } @@ -2998,13 +2794,13 @@ extension TryCapture { public init( as reference: Reference, @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2), R.Output == (W, C0, C1, C2) { self.init(node: .capture( reference: reference.id, .transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component().regex.root))) } @@ -3025,33 +2821,6 @@ extension Capture { self.init(node: .capture(reference: reference.id, component.regex.root)) } - public init( - _ component: R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2, C3), R.Output == (W, C0, C1, C2, C3) { - self.init(node: .capture(.transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component.regex.root))) - } - - public init( - _ component: R, - as reference: Reference, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2, C3), R.Output == (W, C0, C1, C2, C3) { - self.init(node: .capture( - reference: reference.id, - .transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component.regex.root))) - } -} - -extension TryCapture { public init( _ component: R, transform: @escaping (Substring) throws -> NewCapture @@ -3076,14 +2845,16 @@ extension TryCapture { }, component.regex.root))) } +} +extension TryCapture { public init( _ component: R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2, C3), R.Output == (W, C0, C1, C2, C3) { self.init(node: .capture(.transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component.regex.root))) } @@ -3091,13 +2862,13 @@ extension TryCapture { public init( _ component: R, as reference: Reference, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2, C3), R.Output == (W, C0, C1, C2, C3) { self.init(node: .capture( reference: reference.id, .transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component.regex.root))) } @@ -3121,33 +2892,6 @@ extension Capture { component().regex.root)) } - public init( - @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2, C3), R.Output == (W, C0, C1, C2, C3) { - self.init(node: .capture(.transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component().regex.root))) - } - - public init( - as reference: Reference, - @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2, C3), R.Output == (W, C0, C1, C2, C3) { - self.init(node: .capture( - reference: reference.id, - .transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component().regex.root))) - } -} - -extension TryCapture { public init( @RegexComponentBuilder _ component: () -> R, transform: @escaping (Substring) throws -> NewCapture @@ -3172,14 +2916,16 @@ extension TryCapture { }, component().regex.root))) } +} +extension TryCapture { public init( @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2, C3), R.Output == (W, C0, C1, C2, C3) { self.init(node: .capture(.transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component().regex.root))) } @@ -3187,13 +2933,13 @@ extension TryCapture { public init( as reference: Reference, @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2, C3), R.Output == (W, C0, C1, C2, C3) { self.init(node: .capture( reference: reference.id, .transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component().regex.root))) } @@ -3214,33 +2960,6 @@ extension Capture { self.init(node: .capture(reference: reference.id, component.regex.root)) } - public init( - _ component: R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4), R.Output == (W, C0, C1, C2, C3, C4) { - self.init(node: .capture(.transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component.regex.root))) - } - - public init( - _ component: R, - as reference: Reference, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4), R.Output == (W, C0, C1, C2, C3, C4) { - self.init(node: .capture( - reference: reference.id, - .transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component.regex.root))) - } -} - -extension TryCapture { public init( _ component: R, transform: @escaping (Substring) throws -> NewCapture @@ -3265,14 +2984,16 @@ extension TryCapture { }, component.regex.root))) } +} +extension TryCapture { public init( _ component: R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4), R.Output == (W, C0, C1, C2, C3, C4) { self.init(node: .capture(.transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component.regex.root))) } @@ -3280,13 +3001,13 @@ extension TryCapture { public init( _ component: R, as reference: Reference, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4), R.Output == (W, C0, C1, C2, C3, C4) { self.init(node: .capture( reference: reference.id, .transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component.regex.root))) } @@ -3306,37 +3027,10 @@ extension Capture { @RegexComponentBuilder _ component: () -> R ) where Output == (Substring, W, C0, C1, C2, C3, C4), R.Output == (W, C0, C1, C2, C3, C4) { self.init(node: .capture( - reference: reference.id, - component().regex.root)) - } - - public init( - @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4), R.Output == (W, C0, C1, C2, C3, C4) { - self.init(node: .capture(.transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component().regex.root))) - } - - public init( - as reference: Reference, - @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4), R.Output == (W, C0, C1, C2, C3, C4) { - self.init(node: .capture( - reference: reference.id, - .transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component().regex.root))) + reference: reference.id, + component().regex.root)) } -} -extension TryCapture { public init( @RegexComponentBuilder _ component: () -> R, transform: @escaping (Substring) throws -> NewCapture @@ -3361,14 +3055,16 @@ extension TryCapture { }, component().regex.root))) } +} +extension TryCapture { public init( @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4), R.Output == (W, C0, C1, C2, C3, C4) { self.init(node: .capture(.transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component().regex.root))) } @@ -3376,13 +3072,13 @@ extension TryCapture { public init( as reference: Reference, @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4), R.Output == (W, C0, C1, C2, C3, C4) { self.init(node: .capture( reference: reference.id, .transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component().regex.root))) } @@ -3403,33 +3099,6 @@ extension Capture { self.init(node: .capture(reference: reference.id, component.regex.root)) } - public init( - _ component: R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5), R.Output == (W, C0, C1, C2, C3, C4, C5) { - self.init(node: .capture(.transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component.regex.root))) - } - - public init( - _ component: R, - as reference: Reference, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5), R.Output == (W, C0, C1, C2, C3, C4, C5) { - self.init(node: .capture( - reference: reference.id, - .transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component.regex.root))) - } -} - -extension TryCapture { public init( _ component: R, transform: @escaping (Substring) throws -> NewCapture @@ -3454,14 +3123,16 @@ extension TryCapture { }, component.regex.root))) } +} +extension TryCapture { public init( _ component: R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5), R.Output == (W, C0, C1, C2, C3, C4, C5) { self.init(node: .capture(.transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component.regex.root))) } @@ -3469,13 +3140,13 @@ extension TryCapture { public init( _ component: R, as reference: Reference, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5), R.Output == (W, C0, C1, C2, C3, C4, C5) { self.init(node: .capture( reference: reference.id, .transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component.regex.root))) } @@ -3499,33 +3170,6 @@ extension Capture { component().regex.root)) } - public init( - @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5), R.Output == (W, C0, C1, C2, C3, C4, C5) { - self.init(node: .capture(.transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component().regex.root))) - } - - public init( - as reference: Reference, - @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5), R.Output == (W, C0, C1, C2, C3, C4, C5) { - self.init(node: .capture( - reference: reference.id, - .transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component().regex.root))) - } -} - -extension TryCapture { public init( @RegexComponentBuilder _ component: () -> R, transform: @escaping (Substring) throws -> NewCapture @@ -3550,14 +3194,16 @@ extension TryCapture { }, component().regex.root))) } +} +extension TryCapture { public init( @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5), R.Output == (W, C0, C1, C2, C3, C4, C5) { self.init(node: .capture(.transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component().regex.root))) } @@ -3565,13 +3211,13 @@ extension TryCapture { public init( as reference: Reference, @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5), R.Output == (W, C0, C1, C2, C3, C4, C5) { self.init(node: .capture( reference: reference.id, .transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component().regex.root))) } @@ -3592,33 +3238,6 @@ extension Capture { self.init(node: .capture(reference: reference.id, component.regex.root)) } - public init( - _ component: R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6), R.Output == (W, C0, C1, C2, C3, C4, C5, C6) { - self.init(node: .capture(.transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component.regex.root))) - } - - public init( - _ component: R, - as reference: Reference, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6), R.Output == (W, C0, C1, C2, C3, C4, C5, C6) { - self.init(node: .capture( - reference: reference.id, - .transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component.regex.root))) - } -} - -extension TryCapture { public init( _ component: R, transform: @escaping (Substring) throws -> NewCapture @@ -3643,14 +3262,16 @@ extension TryCapture { }, component.regex.root))) } +} +extension TryCapture { public init( _ component: R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6), R.Output == (W, C0, C1, C2, C3, C4, C5, C6) { self.init(node: .capture(.transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component.regex.root))) } @@ -3658,13 +3279,13 @@ extension TryCapture { public init( _ component: R, as reference: Reference, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6), R.Output == (W, C0, C1, C2, C3, C4, C5, C6) { self.init(node: .capture( reference: reference.id, .transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component.regex.root))) } @@ -3688,33 +3309,6 @@ extension Capture { component().regex.root)) } - public init( - @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6), R.Output == (W, C0, C1, C2, C3, C4, C5, C6) { - self.init(node: .capture(.transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component().regex.root))) - } - - public init( - as reference: Reference, - @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6), R.Output == (W, C0, C1, C2, C3, C4, C5, C6) { - self.init(node: .capture( - reference: reference.id, - .transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component().regex.root))) - } -} - -extension TryCapture { public init( @RegexComponentBuilder _ component: () -> R, transform: @escaping (Substring) throws -> NewCapture @@ -3739,14 +3333,16 @@ extension TryCapture { }, component().regex.root))) } +} +extension TryCapture { public init( @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6), R.Output == (W, C0, C1, C2, C3, C4, C5, C6) { self.init(node: .capture(.transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component().regex.root))) } @@ -3754,13 +3350,13 @@ extension TryCapture { public init( as reference: Reference, @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6), R.Output == (W, C0, C1, C2, C3, C4, C5, C6) { self.init(node: .capture( reference: reference.id, .transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component().regex.root))) } @@ -3781,33 +3377,6 @@ extension Capture { self.init(node: .capture(reference: reference.id, component.regex.root)) } - public init( - _ component: R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7), R.Output == (W, C0, C1, C2, C3, C4, C5, C6, C7) { - self.init(node: .capture(.transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component.regex.root))) - } - - public init( - _ component: R, - as reference: Reference, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7), R.Output == (W, C0, C1, C2, C3, C4, C5, C6, C7) { - self.init(node: .capture( - reference: reference.id, - .transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component.regex.root))) - } -} - -extension TryCapture { public init( _ component: R, transform: @escaping (Substring) throws -> NewCapture @@ -3832,14 +3401,16 @@ extension TryCapture { }, component.regex.root))) } +} +extension TryCapture { public init( _ component: R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7), R.Output == (W, C0, C1, C2, C3, C4, C5, C6, C7) { self.init(node: .capture(.transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component.regex.root))) } @@ -3847,13 +3418,13 @@ extension TryCapture { public init( _ component: R, as reference: Reference, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7), R.Output == (W, C0, C1, C2, C3, C4, C5, C6, C7) { self.init(node: .capture( reference: reference.id, .transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component.regex.root))) } @@ -3877,33 +3448,6 @@ extension Capture { component().regex.root)) } - public init( - @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7), R.Output == (W, C0, C1, C2, C3, C4, C5, C6, C7) { - self.init(node: .capture(.transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component().regex.root))) - } - - public init( - as reference: Reference, - @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7), R.Output == (W, C0, C1, C2, C3, C4, C5, C6, C7) { - self.init(node: .capture( - reference: reference.id, - .transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component().regex.root))) - } -} - -extension TryCapture { public init( @RegexComponentBuilder _ component: () -> R, transform: @escaping (Substring) throws -> NewCapture @@ -3928,14 +3472,16 @@ extension TryCapture { }, component().regex.root))) } +} +extension TryCapture { public init( @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7), R.Output == (W, C0, C1, C2, C3, C4, C5, C6, C7) { self.init(node: .capture(.transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component().regex.root))) } @@ -3943,13 +3489,13 @@ extension TryCapture { public init( as reference: Reference, @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7), R.Output == (W, C0, C1, C2, C3, C4, C5, C6, C7) { self.init(node: .capture( reference: reference.id, .transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component().regex.root))) } @@ -3970,33 +3516,6 @@ extension Capture { self.init(node: .capture(reference: reference.id, component.regex.root)) } - public init( - _ component: R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7, C8), R.Output == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { - self.init(node: .capture(.transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component.regex.root))) - } - - public init( - _ component: R, - as reference: Reference, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7, C8), R.Output == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { - self.init(node: .capture( - reference: reference.id, - .transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component.regex.root))) - } -} - -extension TryCapture { public init( _ component: R, transform: @escaping (Substring) throws -> NewCapture @@ -4021,14 +3540,16 @@ extension TryCapture { }, component.regex.root))) } +} +extension TryCapture { public init( _ component: R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7, C8), R.Output == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { self.init(node: .capture(.transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component.regex.root))) } @@ -4036,13 +3557,13 @@ extension TryCapture { public init( _ component: R, as reference: Reference, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7, C8), R.Output == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { self.init(node: .capture( reference: reference.id, .transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component.regex.root))) } @@ -4066,33 +3587,6 @@ extension Capture { component().regex.root)) } - public init( - @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7, C8), R.Output == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { - self.init(node: .capture(.transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component().regex.root))) - } - - public init( - as reference: Reference, - @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7, C8), R.Output == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { - self.init(node: .capture( - reference: reference.id, - .transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component().regex.root))) - } -} - -extension TryCapture { public init( @RegexComponentBuilder _ component: () -> R, transform: @escaping (Substring) throws -> NewCapture @@ -4117,14 +3611,16 @@ extension TryCapture { }, component().regex.root))) } +} +extension TryCapture { public init( @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7, C8), R.Output == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { self.init(node: .capture(.transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component().regex.root))) } @@ -4132,13 +3628,13 @@ extension TryCapture { public init( as reference: Reference, @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7, C8), R.Output == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { self.init(node: .capture( reference: reference.id, .transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component().regex.root))) } @@ -4159,33 +3655,6 @@ extension Capture { self.init(node: .capture(reference: reference.id, component.regex.root)) } - public init( - _ component: R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9), R.Output == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9) { - self.init(node: .capture(.transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component.regex.root))) - } - - public init( - _ component: R, - as reference: Reference, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9), R.Output == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9) { - self.init(node: .capture( - reference: reference.id, - .transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component.regex.root))) - } -} - -extension TryCapture { public init( _ component: R, transform: @escaping (Substring) throws -> NewCapture @@ -4210,14 +3679,16 @@ extension TryCapture { }, component.regex.root))) } +} +extension TryCapture { public init( _ component: R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9), R.Output == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9) { self.init(node: .capture(.transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component.regex.root))) } @@ -4225,13 +3696,13 @@ extension TryCapture { public init( _ component: R, as reference: Reference, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9), R.Output == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9) { self.init(node: .capture( reference: reference.id, .transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component.regex.root))) } @@ -4255,33 +3726,6 @@ extension Capture { component().regex.root)) } - public init( - @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9), R.Output == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9) { - self.init(node: .capture(.transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component().regex.root))) - } - - public init( - as reference: Reference, - @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture - ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9), R.Output == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9) { - self.init(node: .capture( - reference: reference.id, - .transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component().regex.root))) - } -} - -extension TryCapture { public init( @RegexComponentBuilder _ component: () -> R, transform: @escaping (Substring) throws -> NewCapture @@ -4306,14 +3750,16 @@ extension TryCapture { }, component().regex.root))) } +} +extension TryCapture { public init( @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9), R.Output == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9) { self.init(node: .capture(.transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component().regex.root))) } @@ -4321,13 +3767,13 @@ extension TryCapture { public init( as reference: Reference, @RegexComponentBuilder _ component: () -> R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) where Output == (Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9), R.Output == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9) { self.init(node: .capture( reference: reference.id, .transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component().regex.root))) } diff --git a/Sources/VariadicsGenerator/VariadicsGenerator.swift b/Sources/VariadicsGenerator/VariadicsGenerator.swift index dbeff818c..5fbd2bf2d 100644 --- a/Sources/VariadicsGenerator/VariadicsGenerator.swift +++ b/Sources/VariadicsGenerator/VariadicsGenerator.swift @@ -615,35 +615,6 @@ struct VariadicsGenerator: ParsableCommand { self.init(node: .capture(reference: reference.id, component.regex.root)) } - \(disfavored)\ - public init<\(genericParams), NewCapture>( - _ component: R, - transform: @escaping (Substring) -> NewCapture - ) \(whereClauseTransformed) { - self.init(node: .capture(.transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component.regex.root))) - } - - \(disfavored)\ - public init<\(genericParams), NewCapture>( - _ component: R, - as reference: Reference, - transform: @escaping (Substring) -> NewCapture - ) \(whereClauseTransformed) { - self.init(node: .capture( - reference: reference.id, - .transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component.regex.root))) - } - } - - extension TryCapture { \(disfavored)\ public init<\(genericParams), NewCapture>( _ component: R, @@ -670,15 +641,17 @@ struct VariadicsGenerator: ParsableCommand { }, component.regex.root))) } + } + extension TryCapture { \(disfavored)\ public init<\(genericParams), NewCapture>( _ component: R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) \(whereClauseTransformed) { self.init(node: .capture(.transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component.regex.root))) } @@ -687,13 +660,13 @@ struct VariadicsGenerator: ParsableCommand { public init<\(genericParams), NewCapture>( _ component: R, as reference: Reference, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) \(whereClauseTransformed) { self.init(node: .capture( reference: reference.id, .transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component.regex.root))) } @@ -719,35 +692,6 @@ struct VariadicsGenerator: ParsableCommand { component().regex.root)) } - \(disfavored)\ - public init<\(genericParams), NewCapture>( - @\(concatBuilderName) _ component: () -> R, - transform: @escaping (Substring) -> NewCapture - ) \(whereClauseTransformed) { - self.init(node: .capture(.transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component().regex.root))) - } - - \(disfavored)\ - public init<\(genericParams), NewCapture>( - as reference: Reference, - @\(concatBuilderName) _ component: () -> R, - transform: @escaping (Substring) -> NewCapture - ) \(whereClauseTransformed) { - self.init(node: .capture( - reference: reference.id, - .transform( - CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - component().regex.root))) - } - } - - extension TryCapture { \(disfavored)\ public init<\(genericParams), NewCapture>( @\(concatBuilderName) _ component: () -> R, @@ -774,15 +718,17 @@ struct VariadicsGenerator: ParsableCommand { }, component().regex.root))) } + } + extension TryCapture { \(disfavored)\ public init<\(genericParams), NewCapture>( @\(concatBuilderName) _ component: () -> R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) \(whereClauseTransformed) { self.init(node: .capture(.transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component().regex.root))) } @@ -791,13 +737,13 @@ struct VariadicsGenerator: ParsableCommand { public init<\(genericParams), NewCapture>( as reference: Reference, @\(concatBuilderName) _ component: () -> R, - transform: @escaping (Substring) -> NewCapture? + transform: @escaping (Substring) throws -> NewCapture? ) \(whereClauseTransformed) { self.init(node: .capture( reference: reference.id, .transform( CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any? + try transform($0) as Any? }, component().regex.root))) } diff --git a/Sources/_RegexParser/Regex/AST/AST.swift b/Sources/_RegexParser/Regex/AST/AST.swift index ba37b6d62..409d5a7ee 100644 --- a/Sources/_RegexParser/Regex/AST/AST.swift +++ b/Sources/_RegexParser/Regex/AST/AST.swift @@ -304,78 +304,3 @@ extension AST { } } } - -// FIXME: Get this out of here -public struct CaptureTransform: Equatable, Hashable, CustomStringConvertible { - public enum Closure { - case nonfailable((Substring) -> Any) - case failable((Substring) -> Any?) - case throwing((Substring) throws -> Any) - } - public let resultType: Any.Type - public let closure: Closure - - public init(resultType: Any.Type, closure: Closure) { - self.resultType = resultType - self.closure = closure - } - - public init( - resultType: Any.Type, - _ closure: @escaping (Substring) -> Any - ) { - self.init(resultType: resultType, closure: .nonfailable(closure)) - } - - public init( - resultType: Any.Type, - _ closure: @escaping (Substring) -> Any? - ) { - self.init(resultType: resultType, closure: .failable(closure)) - } - - public init( - resultType: Any.Type, - _ closure: @escaping (Substring) throws -> Any - ) { - self.init(resultType: resultType, closure: .throwing(closure)) - } - - public func callAsFunction(_ input: Substring) -> Any? { - switch closure { - case .nonfailable(let closure): - let result = closure(input) - assert(type(of: result) == resultType) - return result - case .failable(let closure): - guard let result = closure(input) else { - return nil - } - assert(type(of: result) == resultType) - return result - case .throwing(let closure): - do { - let result = try closure(input) - assert(type(of: result) == resultType) - return result - } catch { - return nil - } - } - } - - public static func == (lhs: CaptureTransform, rhs: CaptureTransform) -> Bool { - unsafeBitCast(lhs.closure, to: (Int, Int).self) == - unsafeBitCast(rhs.closure, to: (Int, Int).self) - } - - public func hash(into hasher: inout Hasher) { - let (fn, ctx) = unsafeBitCast(closure, to: (Int, Int).self) - hasher.combine(fn) - hasher.combine(ctx) - } - - public var description: String { - "" - } -} diff --git a/Sources/_StringProcessing/ByteCodeGen.swift b/Sources/_StringProcessing/ByteCodeGen.swift index ed84fadbd..70233cf4f 100644 --- a/Sources/_StringProcessing/ByteCodeGen.swift +++ b/Sources/_StringProcessing/ByteCodeGen.swift @@ -317,7 +317,7 @@ extension Compiler.ByteCodeGen { ) throws { let transform = builder.makeTransformFunction { input, range in - t(input[range]) + try t(input[range]) } builder.buildBeginCapture(cap) try emitNode(child) diff --git a/Sources/_StringProcessing/Engine/Consume.swift b/Sources/_StringProcessing/Engine/Consume.swift index 4e00a34b4..bc60ba260 100644 --- a/Sources/_StringProcessing/Engine/Consume.swift +++ b/Sources/_StringProcessing/Engine/Consume.swift @@ -25,6 +25,7 @@ extension Engine { } extension Processor where Input == String { + // TODO: Should we throw here? mutating func consume() -> Input.Index? { while true { switch self.state { diff --git a/Sources/_StringProcessing/Engine/MEProgram.swift b/Sources/_StringProcessing/Engine/MEProgram.swift index a31134cc9..ecd67d4ba 100644 --- a/Sources/_StringProcessing/Engine/MEProgram.swift +++ b/Sources/_StringProcessing/Engine/MEProgram.swift @@ -14,11 +14,11 @@ import _RegexParser struct MEProgram where Input.Element: Equatable { typealias ConsumeFunction = (Input, Range) -> Input.Index? typealias AssertionFunction = - (Input, Input.Index, Range) -> Bool + (Input, Input.Index, Range) throws -> Bool typealias TransformFunction = - (Input, Range) -> Any? + (Input, Range) throws -> Any? typealias MatcherFunction = - (Input, Input.Index, Range) -> (Input.Index, Any)? + (Input, Input.Index, Range) throws -> (Input.Index, Any)? var instructions: InstructionList diff --git a/Sources/_StringProcessing/Engine/Processor.swift b/Sources/_StringProcessing/Engine/Processor.swift index 343b02c92..8f777ad33 100644 --- a/Sources/_StringProcessing/Engine/Processor.swift +++ b/Sources/_StringProcessing/Engine/Processor.swift @@ -51,6 +51,8 @@ struct Processor< var state: State = .inProgress + var failureReason: Error? = nil + var isTracingEnabled: Bool var storedCaptures: Array<_StoredCapture> @@ -181,6 +183,13 @@ extension Processor { registers.ints = intRegisters } + mutating func abort(_ e: Error? = nil) { + if let e = e { + self.failureReason = e + } + self.state = .fail + } + mutating func tryAccept() { switch (currentPosition, matchMode) { // When reaching the end of the match bounds or when we are only doing a @@ -355,8 +364,13 @@ extension Processor { case .assertBy: let reg = payload.assertion let assertion = registers[reg] - guard assertion(input, currentPosition, bounds) else { - signalFailure() + do { + guard try assertion(input, currentPosition, bounds) else { + signalFailure() + return + } + } catch { + abort(error) return } controller.step() @@ -364,15 +378,20 @@ extension Processor { case .matchBy: let (matcherReg, valReg) = payload.pairedMatcherValue let matcher = registers[matcherReg] - guard let (nextIdx, val) = matcher( - input, currentPosition, bounds - ) else { - signalFailure() + do { + guard let (nextIdx, val) = try matcher( + input, currentPosition, bounds + ) else { + signalFailure() + return + } + registers[valReg] = val + advance(to: nextIdx) + controller.step() + } catch { + abort(error) return } - registers[valReg] = val - advance(to: nextIdx) - controller.step() case .print: // TODO: Debug stream @@ -431,14 +450,18 @@ extension Processor { fatalError( "Unreachable: transforming without a capture") } - // FIXME: Pass input or the slice? - guard let value = transform(input, range) else { - signalFailure() + do { + // FIXME: Pass input or the slice? + guard let value = try transform(input, range) else { + signalFailure() + return + } + storedCaptures[capNum].registerValue(value) + controller.step() + } catch { + abort(error) return } - storedCaptures[capNum].registerValue(value) - - controller.step() case .captureValue: let (val, cap) = payload.pairedValueCapture diff --git a/Sources/_StringProcessing/Executor.swift b/Sources/_StringProcessing/Executor.swift index 148ddf468..563e90970 100644 --- a/Sources/_StringProcessing/Executor.swift +++ b/Sources/_StringProcessing/Executor.swift @@ -28,6 +28,9 @@ struct Executor { input: input, bounds: inputRange, matchMode: mode) guard let endIdx = cpu.consume() else { + if let e = cpu.failureReason { + throw e + } return nil } diff --git a/Sources/_StringProcessing/Regex/DSLTree.swift b/Sources/_StringProcessing/Regex/DSLTree.swift index 59ebd38af..f37505cb4 100644 --- a/Sources/_StringProcessing/Regex/DSLTree.swift +++ b/Sources/_StringProcessing/Regex/DSLTree.swift @@ -164,14 +164,14 @@ extension DSLTree { @_spi(RegexBuilder) public typealias _ConsumerInterface = ( String, Range -) -> String.Index? +) throws -> String.Index? // Type producing consume // TODO: better name @_spi(RegexBuilder) public typealias _MatcherInterface = ( String, String.Index, Range -) -> (String.Index, Any)? +) throws -> (String.Index, Any)? // Character-set (post grapheme segmentation) @_spi(RegexBuilder) @@ -384,3 +384,62 @@ public struct ReferenceID: Hashable, Equatable { Self.counter += 1 } } + +@_spi(RegexBuilder) +public struct CaptureTransform: Hashable, CustomStringConvertible { + public enum Closure { + case failable((Substring) throws -> Any?) + case nonfailable((Substring) throws -> Any) + } + public let resultType: Any.Type + public let closure: Closure + + public init(resultType: Any.Type, closure: Closure) { + self.resultType = resultType + self.closure = closure + } + + public init( + resultType: Any.Type, + _ closure: @escaping (Substring) throws -> Any + ) { + self.init(resultType: resultType, closure: .nonfailable(closure)) + } + + public init( + resultType: Any.Type, + _ closure: @escaping (Substring) throws -> Any? + ) { + self.init(resultType: resultType, closure: .failable(closure)) + } + + public func callAsFunction(_ input: Substring) throws -> Any? { + switch closure { + case .nonfailable(let closure): + let result = try closure(input) + assert(type(of: result) == resultType) + return result + case .failable(let closure): + guard let result = try closure(input) else { + return nil + } + assert(type(of: result) == resultType) + return result + } + } + + public static func == (lhs: CaptureTransform, rhs: CaptureTransform) -> Bool { + unsafeBitCast(lhs.closure, to: (Int, Int).self) == + unsafeBitCast(rhs.closure, to: (Int, Int).self) + } + + public func hash(into hasher: inout Hasher) { + let (fn, ctx) = unsafeBitCast(closure, to: (Int, Int).self) + hasher.combine(fn) + hasher.combine(ctx) + } + + public var description: String { + "" + } +} diff --git a/Sources/_StringProcessing/Regex/Match.swift b/Sources/_StringProcessing/Regex/Match.swift index 45d33f03e..5c846c0fd 100644 --- a/Sources/_StringProcessing/Regex/Match.swift +++ b/Sources/_StringProcessing/Regex/Match.swift @@ -130,7 +130,7 @@ extension RegexComponent { mode: MatchMode = .wholeString ) throws -> Regex.Match? { let executor = Executor(program: regex.program.loweredProgram) - return try executor.match(input, in: inputRange, mode) + return try executor.match(input, in: inputRange, mode) } func _firstMatch( diff --git a/Tests/RegexBuilderTests/CustomTests.swift b/Tests/RegexBuilderTests/CustomTests.swift index 19c4a3896..79ebc2693 100644 --- a/Tests/RegexBuilderTests/CustomTests.swift +++ b/Tests/RegexBuilderTests/CustomTests.swift @@ -138,4 +138,89 @@ class CustomRegexComponentTests: XCTestCase { XCTAssertEqual(res4.output.0, "123") XCTAssertEqual(res4.output.1, 3) } + + func testRegexAbort() { + + enum Radix: Hashable { + case dot + case comma + } + struct Abort: Error, Hashable {} + + let hexRegex = Regex { + Capture { OneOrMore(.hexDigit) } + TryCapture { CharacterClass.any } transform: { c -> Radix? in + switch c { + case ".": return Radix.dot + case ",": return Radix.comma + case "❗️": + // Malicious! Toxic levels of emphasis detected. + throw Abort() + default: + // Not a radix + return nil + } + } + Capture { OneOrMore(.hexDigit) } + } + // hexRegex: Regex<(Substring, Substring, Radix?, Substring)> + // TODO: Why is Radix optional? + + do { + guard let m = try hexRegex.matchWhole("123aef.345") else { + XCTFail() + return + } + XCTAssertEqual(m.0, "123aef.345") + XCTAssertEqual(m.1, "123aef") + XCTAssertEqual(m.2, .dot) + XCTAssertEqual(m.3, "345") + } catch { + XCTFail() + } + + do { + _ = try hexRegex.matchWhole("123aef❗️345") + XCTFail() + } catch let e as Abort { + XCTAssertEqual(e, Abort()) + } catch { + XCTFail() + } + + struct Poison: Error, Hashable {} + + let addressRegex = Regex { + "0x" + Capture(Repeat(.hexDigit, count: 8)) { hex -> Int in + let i = Int(hex, radix: 16)! + if i == 0xdeadbeef { + throw Poison() + } + return i + } + } + + do { + guard let m = try addressRegex.matchWhole("0x1234567f") else { + XCTFail() + return + } + XCTAssertEqual(m.0, "0x1234567f") + XCTAssertEqual(m.1, 0x1234567f) + } catch { + XCTFail() + } + + do { + _ = try addressRegex.matchWhole("0xdeadbeef") + XCTFail() + } catch let e as Poison { + XCTAssertEqual(e, Poison()) + } catch { + XCTFail() + } + + + } }