From 9643f8da316d7bbfcdb1f221d97171200ca08251 Mon Sep 17 00:00:00 2001 From: Nate Cook Date: Tue, 20 Jun 2023 14:43:27 -0500 Subject: [PATCH 01/11] Switch to variadic `buildPartialBlock` This uses parameter packs to replace the existing multitude of buildPartialBlock implementations in RegexBuilder. --- Sources/RegexBuilder/Variadics.swift | 765 +------------------- Tests/RegexBuilderTests/RegexDSLTests.swift | 9 +- 2 files changed, 34 insertions(+), 740 deletions(-) diff --git a/Sources/RegexBuilder/Variadics.swift b/Sources/RegexBuilder/Variadics.swift index 8f104eae0..8614ee056 100644 --- a/Sources/RegexBuilder/Variadics.swift +++ b/Sources/RegexBuilder/Variadics.swift @@ -13,756 +13,53 @@ @_spi(RegexBuilder) import _StringProcessing -// MARK: - Partial block (left arity 0) - -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent, - next: some RegexComponent<(W1, C1)> - ) -> Regex<(Substring, C1)> { - let factory = makeFactory() - return factory.accumulate(ignoringOutputTypeOf: accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent, - next: some RegexComponent<(W1, C1, C2)> - ) -> Regex<(Substring, C1, C2)> { - let factory = makeFactory() - return factory.accumulate(ignoringOutputTypeOf: accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent, - next: some RegexComponent<(W1, C1, C2, C3)> - ) -> Regex<(Substring, C1, C2, C3)> { - let factory = makeFactory() - return factory.accumulate(ignoringOutputTypeOf: accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent, - next: some RegexComponent<(W1, C1, C2, C3, C4)> - ) -> Regex<(Substring, C1, C2, C3, C4)> { - let factory = makeFactory() - return factory.accumulate(ignoringOutputTypeOf: accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent, - next: some RegexComponent<(W1, C1, C2, C3, C4, C5)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5)> { - let factory = makeFactory() - return factory.accumulate(ignoringOutputTypeOf: accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent, - next: some RegexComponent<(W1, C1, C2, C3, C4, C5, C6)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6)> { - let factory = makeFactory() - return factory.accumulate(ignoringOutputTypeOf: accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent, - next: some RegexComponent<(W1, C1, C2, C3, C4, C5, C6, C7)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7)> { - let factory = makeFactory() - return factory.accumulate(ignoringOutputTypeOf: accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent, - next: some RegexComponent<(W1, C1, C2, C3, C4, C5, C6, C7, C8)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7, C8)> { - let factory = makeFactory() - return factory.accumulate(ignoringOutputTypeOf: accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent, - next: some RegexComponent<(W1, C1, C2, C3, C4, C5, C6, C7, C8, C9)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9)> { - let factory = makeFactory() - return factory.accumulate(ignoringOutputTypeOf: accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent, - next: some RegexComponent<(W1, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)> { - let factory = makeFactory() - return factory.accumulate(ignoringOutputTypeOf: accumulated, next) - } -} -// MARK: - Partial block (left arity 1) - -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1)>, - next: some RegexComponent<(W1, C2)> - ) -> Regex<(Substring, C1, C2)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1)>, - next: some RegexComponent<(W1, C2, C3)> - ) -> Regex<(Substring, C1, C2, C3)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1)>, - next: some RegexComponent<(W1, C2, C3, C4)> - ) -> Regex<(Substring, C1, C2, C3, C4)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1)>, - next: some RegexComponent<(W1, C2, C3, C4, C5)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1)>, - next: some RegexComponent<(W1, C2, C3, C4, C5, C6)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1)>, - next: some RegexComponent<(W1, C2, C3, C4, C5, C6, C7)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1)>, - next: some RegexComponent<(W1, C2, C3, C4, C5, C6, C7, C8)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7, C8)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1)>, - next: some RegexComponent<(W1, C2, C3, C4, C5, C6, C7, C8, C9)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1)>, - next: some RegexComponent<(W1, C2, C3, C4, C5, C6, C7, C8, C9, C10)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -// MARK: - Partial block (left arity 2) - -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2)>, - next: some RegexComponent<(W1, C3)> - ) -> Regex<(Substring, C1, C2, C3)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2)>, - next: some RegexComponent<(W1, C3, C4)> - ) -> Regex<(Substring, C1, C2, C3, C4)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2)>, - next: some RegexComponent<(W1, C3, C4, C5)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2)>, - next: some RegexComponent<(W1, C3, C4, C5, C6)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2)>, - next: some RegexComponent<(W1, C3, C4, C5, C6, C7)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2)>, - next: some RegexComponent<(W1, C3, C4, C5, C6, C7, C8)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7, C8)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2)>, - next: some RegexComponent<(W1, C3, C4, C5, C6, C7, C8, C9)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2)>, - next: some RegexComponent<(W1, C3, C4, C5, C6, C7, C8, C9, C10)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -// MARK: - Partial block (left arity 3) - -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3)>, - next: some RegexComponent<(W1, C4)> - ) -> Regex<(Substring, C1, C2, C3, C4)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3)>, - next: some RegexComponent<(W1, C4, C5)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3)>, - next: some RegexComponent<(W1, C4, C5, C6)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3)>, - next: some RegexComponent<(W1, C4, C5, C6, C7)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3)>, - next: some RegexComponent<(W1, C4, C5, C6, C7, C8)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7, C8)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3)>, - next: some RegexComponent<(W1, C4, C5, C6, C7, C8, C9)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3)>, - next: some RegexComponent<(W1, C4, C5, C6, C7, C8, C9, C10)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -// MARK: - Partial block (left arity 4) - -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4)>, - next: some RegexComponent<(W1, C5)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4)>, - next: some RegexComponent<(W1, C5, C6)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4)>, - next: some RegexComponent<(W1, C5, C6, C7)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4)>, - next: some RegexComponent<(W1, C5, C6, C7, C8)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7, C8)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4)>, - next: some RegexComponent<(W1, C5, C6, C7, C8, C9)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4)>, - next: some RegexComponent<(W1, C5, C6, C7, C8, C9, C10)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -// MARK: - Partial block (left arity 5) - -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5)>, - next: some RegexComponent<(W1, C6)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5)>, - next: some RegexComponent<(W1, C6, C7)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5)>, - next: some RegexComponent<(W1, C6, C7, C8)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7, C8)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5)>, - next: some RegexComponent<(W1, C6, C7, C8, C9)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5)>, - next: some RegexComponent<(W1, C6, C7, C8, C9, C10)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -// MARK: - Partial block (left arity 6) - -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5, C6)>, - next: some RegexComponent<(W1, C7)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5, C6)>, - next: some RegexComponent<(W1, C7, C8)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7, C8)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5, C6)>, - next: some RegexComponent<(W1, C7, C8, C9)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5, C6)>, - next: some RegexComponent<(W1, C7, C8, C9, C10)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -// MARK: - Partial block (left arity 7) - -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5, C6, C7)>, - next: some RegexComponent<(W1, C8)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7, C8)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5, C6, C7)>, - next: some RegexComponent<(W1, C8, C9)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5, C6, C7)>, - next: some RegexComponent<(W1, C8, C9, C10)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -// MARK: - Partial block (left arity 8) - -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5, C6, C7, C8)>, - next: some RegexComponent<(W1, C9)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5, C6, C7, C8)>, - next: some RegexComponent<(W1, C9, C10)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)> { - let factory = makeFactory() - return factory.accumulate(accumulated, next) - } -} -// MARK: - Partial block (left arity 9) - @available(SwiftStdlib 5.7, *) extension RegexComponentBuilder { @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5, C6, C7, C8, C9)>, - next: some RegexComponent<(W1, C10)> - ) -> Regex<(Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)> { + public static func buildPartialBlock< + R0: RegexComponent, R1: RegexComponent, Whole0, Whole1, each Capture0, each Capture1 + >( + accumulated: R0, + next: R1 + ) -> Regex<(Substring, repeat each Capture0, repeat each Capture1)> + where R0.RegexOutput == (Whole0, repeat each Capture0), + R1.RegexOutput == (Whole1, repeat each Capture1) + { let factory = makeFactory() return factory.accumulate(accumulated, next) } -} -// MARK: - Partial block (empty) -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent, - next: some RegexComponent - ) -> Regex { - let factory = makeFactory() - return factory.accumulate(ignoringOutputTypeOf: accumulated, andAlso: next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C0)>, - next: some RegexComponent - ) -> Regex<(Substring, C0)> { - let factory = makeFactory() - return factory.accumulate(accumulated, ignoringOutputTypeOf: next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C0, C1)>, - next: some RegexComponent - ) -> Regex<(Substring, C0, C1)> { - let factory = makeFactory() - return factory.accumulate(accumulated, ignoringOutputTypeOf: next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C0, C1, C2)>, - next: some RegexComponent - ) -> Regex<(Substring, C0, C1, C2)> { - let factory = makeFactory() - return factory.accumulate(accumulated, ignoringOutputTypeOf: next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C0, C1, C2, C3)>, - next: some RegexComponent - ) -> Regex<(Substring, C0, C1, C2, C3)> { - let factory = makeFactory() - return factory.accumulate(accumulated, ignoringOutputTypeOf: next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C0, C1, C2, C3, C4)>, - next: some RegexComponent - ) -> Regex<(Substring, C0, C1, C2, C3, C4)> { - let factory = makeFactory() - return factory.accumulate(accumulated, ignoringOutputTypeOf: next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C0, C1, C2, C3, C4, C5)>, - next: some RegexComponent - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5)> { - let factory = makeFactory() - return factory.accumulate(accumulated, ignoringOutputTypeOf: next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C0, C1, C2, C3, C4, C5, C6)>, - next: some RegexComponent - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6)> { - let factory = makeFactory() - return factory.accumulate(accumulated, ignoringOutputTypeOf: next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C0, C1, C2, C3, C4, C5, C6, C7)>, - next: some RegexComponent - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7)> { - let factory = makeFactory() - return factory.accumulate(accumulated, ignoringOutputTypeOf: next) - } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C0, C1, C2, C3, C4, C5, C6, C7, C8)>, - next: some RegexComponent - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8)> { + @_disfavoredOverload + public static func buildPartialBlock< + R0: RegexComponent, R1: RegexComponent, Whole0, Whole1, each Capture1 + >( + accumulated: R0, + next: R1 + ) -> Regex<(Substring, repeat each Capture1)> + where R0.RegexOutput == Whole0, + R1.RegexOutput == (Whole1, repeat each Capture1) + { let factory = makeFactory() - return factory.accumulate(accumulated, ignoringOutputTypeOf: next) + return factory.accumulate(ignoringOutputTypeOf: accumulated, next) } -} -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { + @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9)>, - next: some RegexComponent - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9)> { + @_disfavoredOverload + public static func buildPartialBlock< + R0: RegexComponent, R1: RegexComponent, Whole0, Whole1, each Capture0 + >( + accumulated: R0, + next: R1 + ) -> Regex<(Substring, repeat each Capture0)> + where R0.RegexOutput == (Whole0, repeat each Capture0), + R1.RegexOutput == Whole1 + { let factory = makeFactory() return factory.accumulate(accumulated, ignoringOutputTypeOf: next) } } - // MARK: - Quantifiers (arity 0) @available(SwiftStdlib 5.7, *) diff --git a/Tests/RegexBuilderTests/RegexDSLTests.swift b/Tests/RegexBuilderTests/RegexDSLTests.swift index 7443cae55..9c85b05be 100644 --- a/Tests/RegexBuilderTests/RegexDSLTests.swift +++ b/Tests/RegexBuilderTests/RegexDSLTests.swift @@ -1831,7 +1831,6 @@ fileprivate let regexWithNonCapture = #/:(?:\d+):/# @available(SwiftStdlib 5.7, *) extension RegexDSLTests { func testLabeledCaptures_regularCapture() throws { - return // The output type of a regex with unlabeled captures is concatenated. let dslWithCapture = Regex { OneOrMore(.word) @@ -1846,7 +1845,6 @@ extension RegexDSLTests { } func testLabeledCaptures_labeledCapture() throws { - return guard #available(macOS 13, *) else { throw XCTSkip("Fix only exists on macOS 13") } @@ -1870,7 +1868,6 @@ extension RegexDSLTests { } func testLabeledCaptures_coalescingWithCapture() throws { - return let coalescingWithCapture = Regex { "e" as Character #/\u{301}(\d*)/# @@ -1887,7 +1884,6 @@ extension RegexDSLTests { } func testLabeledCaptures_bothCapture() throws { - return guard #available(macOS 13, *) else { throw XCTSkip("Fix only exists on macOS 13") } @@ -1914,7 +1910,6 @@ extension RegexDSLTests { } func testLabeledCaptures_tooManyCapture() throws { - return guard #available(macOS 13, *) else { throw XCTSkip("Fix only exists on macOS 13") } @@ -1930,13 +1925,15 @@ extension RegexDSLTests { TryCapture<(Substring, Int)>(OneOrMore(.word)) { Int($0) } #/:(\d+):/# } +// FIXME (Variadics): The output type is now `(Substring, Substring, Substring, Substring, Substring, Substring, Substring, Substring, Substring, Substring, Substring, Substring, Substring, Substring, Substring, Int, Substring)` XCTAssert(type(of: dslWithTooManyCaptures).self == Regex<(Substring, Substring, Int, Substring)>.self) let match = try XCTUnwrap(alpha.wholeMatch(of: dslWithTooManyCaptures)) XCTAssertEqual(match.output.0, alpha[...]) XCTAssertEqual(match.output.1, "AAA") - XCTAssertEqual(match.output.2, 123) +// FIXME (Variadics): match.output.2 is no longer an `Int` +// XCTAssertEqual(match.output.2, 123) XCTAssertEqual(match.output.3, "456") // All captures groups are available through `AnyRegexOutput`. From eb2628e0766eb196a3b31acdfb54d1aa3154034c Mon Sep 17 00:00:00 2001 From: Nate Cook Date: Thu, 29 Feb 2024 16:54:49 -0600 Subject: [PATCH 02/11] Switch to variadic quantifiers This converts the RegexBuilder quantifiers to use variadic generics instead of explicit overloads. This transition uses a particular generic pattern so that a variadic number of output parameters are captured correctly, without matching a "zero captures" component as having `()` as its output type. To accomplish this, the generic parameters for each quantification method are like: some RegexComponent<(W, Capture0, repeat each Capture)> The presence of `Capture0` requires that at least one sub-capture beyond the whole match is present. In addition to the variadic versions, unconstrained versions of each initializer are included, marked `@_disfavoredOverload`. These are only selected when the component's output type is a single type (e.g. `Regex`). --- Sources/RegexBuilder/Variadics.swift | 2176 +------------------------- 1 file changed, 40 insertions(+), 2136 deletions(-) diff --git a/Sources/RegexBuilder/Variadics.swift b/Sources/RegexBuilder/Variadics.swift index 8614ee056..b4ffa43cf 100644 --- a/Sources/RegexBuilder/Variadics.swift +++ b/Sources/RegexBuilder/Variadics.swift @@ -60,7 +60,7 @@ extension RegexComponentBuilder { } } -// MARK: - Quantifiers (arity 0) +// MARK: - Quantifiers (no output captures) @available(SwiftStdlib 5.7, *) extension Optionally { @@ -83,10 +83,7 @@ extension Optionally { let factory = makeFactory() self.init(factory.zeroOrOne(component, behavior)) } -} -@available(SwiftStdlib 5.7, *) -extension Optionally { /// Creates a regex component that matches the given component /// zero or one times. /// @@ -111,6 +108,7 @@ extension Optionally { @available(SwiftStdlib 5.7, *) extension RegexComponentBuilder { + @_disfavoredOverload @_alwaysEmitIntoClient public static func buildLimitedAvailability( _ component: some RegexComponent @@ -119,6 +117,7 @@ extension RegexComponentBuilder { return factory.zeroOrOne(component, nil) } } + @available(SwiftStdlib 5.7, *) extension ZeroOrMore { /// Creates a regex component that matches the given component @@ -140,10 +139,7 @@ extension ZeroOrMore { let factory = makeFactory() self.init(factory.zeroOrMore(component, behavior)) } -} -@available(SwiftStdlib 5.7, *) -extension ZeroOrMore { /// Creates a regex component that matches the given component /// zero or more times. /// @@ -166,7 +162,6 @@ extension ZeroOrMore { } } - @available(SwiftStdlib 5.7, *) extension OneOrMore { /// Creates a regex component that matches the given component @@ -188,10 +183,7 @@ extension OneOrMore { let factory = makeFactory() self.init(factory.oneOrMore(component, behavior)) } -} -@available(SwiftStdlib 5.7, *) -extension OneOrMore { /// Creates a regex component that matches the given component /// one or more times. /// @@ -214,7 +206,6 @@ extension OneOrMore { } } - @available(SwiftStdlib 5.7, *) extension Repeat { /// Creates a regex component that matches the given component repeated @@ -301,7 +292,8 @@ extension Repeat { self.init(factory.repeating(expression.relative(to: 0..( - _ component: some RegexComponent<(W, C1)>, + public init( + _ component: some RegexComponent<(W, Capture0, repeat each Capture)>, _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1?) { + ) where RegexOutput == (Substring, (Capture0, repeat each Capture)?) { let factory = makeFactory() self.init(factory.zeroOrOne(component, behavior)) } -} - -@available(SwiftStdlib 5.7, *) -extension Optionally { + /// Creates a regex component that matches the given component /// zero or one times. /// @@ -339,10 +328,10 @@ extension Optionally { /// - componentBuilder: A builder closure that generates a regex /// component. @_alwaysEmitIntoClient - public init( + public init( _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1)> - ) where RegexOutput == (Substring, C1?) { + @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, Capture0, repeat each Capture)> + ) where RegexOutput == (Substring, (Capture0, repeat each Capture)?) { let factory = makeFactory() self.init(factory.zeroOrOne(componentBuilder(), behavior)) } @@ -351,13 +340,14 @@ extension Optionally { @available(SwiftStdlib 5.7, *) extension RegexComponentBuilder { @_alwaysEmitIntoClient - public static func buildLimitedAvailability( - _ component: some RegexComponent<(W, C1)> - ) -> Regex<(Substring, C1?)> { + public static func buildLimitedAvailability( + _ component: some RegexComponent<(W, Capture0, repeat each Capture)> + ) -> Regex<(Substring, (Capture0, repeat each Capture)?)> { let factory = makeFactory() return factory.zeroOrOne(component, nil) } } + @available(SwiftStdlib 5.7, *) extension ZeroOrMore { /// Creates a regex component that matches the given component @@ -371,17 +361,14 @@ extension ZeroOrMore { /// `eager` by calling `repetitionBehavior(_:)` on the resulting /// `Regex`. @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1)>, + public init( + _ component: some RegexComponent<(W, Capture0, repeat each Capture)>, _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1?) { + ) where RegexOutput == (Substring, (Capture0, repeat each Capture)?) { let factory = makeFactory() self.init(factory.zeroOrMore(component, behavior)) } -} -@available(SwiftStdlib 5.7, *) -extension ZeroOrMore { /// Creates a regex component that matches the given component /// zero or more times. /// @@ -394,16 +381,15 @@ extension ZeroOrMore { /// - componentBuilder: A builder closure that generates a regex /// component. @_alwaysEmitIntoClient - public init( + public init( _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1)> - ) where RegexOutput == (Substring, C1?) { + @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, Capture0, repeat each Capture)> + ) where RegexOutput == (Substring, (Capture0, repeat each Capture)?) { let factory = makeFactory() self.init(factory.zeroOrMore(componentBuilder(), behavior)) } } - @available(SwiftStdlib 5.7, *) extension OneOrMore { /// Creates a regex component that matches the given component @@ -417,17 +403,14 @@ extension OneOrMore { /// `eager` by calling `repetitionBehavior(_:)` on the resulting /// `Regex`. @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1)>, + public init( + _ component: some RegexComponent<(W, Capture0, repeat each Capture)>, _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1) { + ) where RegexOutput == (Substring, Capture0, repeat each Capture) { let factory = makeFactory() self.init(factory.oneOrMore(component, behavior)) } -} -@available(SwiftStdlib 5.7, *) -extension OneOrMore { /// Creates a regex component that matches the given component /// one or more times. /// @@ -440,16 +423,15 @@ extension OneOrMore { /// - componentBuilder: A builder closure that generates a regex /// component. @_alwaysEmitIntoClient - public init( + public init( _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1)> - ) where RegexOutput == (Substring, C1) { + @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, Capture0, repeat each Capture)> + ) where RegexOutput == (Substring, Capture0, repeat each Capture) { let factory = makeFactory() self.init(factory.oneOrMore(componentBuilder(), behavior)) } } - @available(SwiftStdlib 5.7, *) extension Repeat { /// Creates a regex component that matches the given component repeated @@ -460,10 +442,10 @@ extension Repeat { /// - count: The number of times to repeat `component`. `count` must /// be greater than or equal to zero. @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1)>, + public init( + _ component: some RegexComponent<(W, Capture0, repeat each Capture)>, count: Int - ) where RegexOutput == (Substring, C1?) { + ) where RegexOutput == (Substring, (Capture0, repeat each Capture)?) { precondition(count >= 0, "Must specify a positive count") let factory = makeFactory() self.init(factory.exactly(count, component)) @@ -478,10 +460,10 @@ extension Repeat { /// - componentBuilder: A builder closure that creates the regex /// component to repeat. @_alwaysEmitIntoClient - public init( + public init( count: Int, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1)> - ) where RegexOutput == (Substring, C1?) { + @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, Capture0, repeat each Capture)> + ) where RegexOutput == (Substring, (Capture0, repeat each Capture)?) { precondition(count >= 0, "Must specify a positive count") let factory = makeFactory() self.init(factory.exactly(count, componentBuilder())) @@ -500,11 +482,11 @@ extension Repeat { /// `eager` by calling `repetitionBehavior(_:)` on the resulting /// `Regex`. @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1)>, + public init( + _ component: some RegexComponent<(W, Capture0, repeat each Capture)>, _ expression: some RangeExpression, _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1?) { + ) where RegexOutput == (Substring, (Capture0, repeat each Capture)?) { let factory = makeFactory() self.init(factory.repeating(expression.relative(to: 0..( + public init( _ expression: some RangeExpression, _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1)> - ) where RegexOutput == (Substring, C1?) { + @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, Capture0, repeat each Capture)> + ) where RegexOutput == (Substring, (Capture0, repeat each Capture)?) { let factory = makeFactory() self.init(factory.repeating(expression.relative(to: 0..( - _ component: some RegexComponent<(W, C1, C2)>, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1?, C2?) { - let factory = makeFactory() - self.init(factory.zeroOrOne(component, behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension Optionally { - /// Creates a regex component that matches the given component - /// zero or one times. - /// - /// - Parameters: - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - /// - componentBuilder: A builder closure that generates a regex - /// component. - @_alwaysEmitIntoClient - public init( - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2)> - ) where RegexOutput == (Substring, C1?, C2?) { - let factory = makeFactory() - self.init(factory.zeroOrOne(componentBuilder(), behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildLimitedAvailability( - _ component: some RegexComponent<(W, C1, C2)> - ) -> Regex<(Substring, C1?, C2?)> { - let factory = makeFactory() - return factory.zeroOrOne(component, nil) - } -} -@available(SwiftStdlib 5.7, *) -extension ZeroOrMore { - /// Creates a regex component that matches the given component - /// zero or more times. - /// - /// - Parameters: - /// - component: The regex component. - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2)>, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1?, C2?) { - let factory = makeFactory() - self.init(factory.zeroOrMore(component, behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension ZeroOrMore { - /// Creates a regex component that matches the given component - /// zero or more times. - /// - /// - Parameters: - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - /// - componentBuilder: A builder closure that generates a regex - /// component. - @_alwaysEmitIntoClient - public init( - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2)> - ) where RegexOutput == (Substring, C1?, C2?) { - let factory = makeFactory() - self.init(factory.zeroOrMore(componentBuilder(), behavior)) - } -} - - -@available(SwiftStdlib 5.7, *) -extension OneOrMore { - /// Creates a regex component that matches the given component - /// one or more times. - /// - /// - Parameters: - /// - component: The regex component. - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2)>, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1, C2) { - let factory = makeFactory() - self.init(factory.oneOrMore(component, behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension OneOrMore { - /// Creates a regex component that matches the given component - /// one or more times. - /// - /// - Parameters: - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - /// - componentBuilder: A builder closure that generates a regex - /// component. - @_alwaysEmitIntoClient - public init( - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2)> - ) where RegexOutput == (Substring, C1, C2) { - let factory = makeFactory() - self.init(factory.oneOrMore(componentBuilder(), behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension Repeat { - /// Creates a regex component that matches the given component repeated - /// the specified number of times. - /// - /// - Parameters: - /// - component: The regex component to repeat. - /// - count: The number of times to repeat `component`. `count` must - /// be greater than or equal to zero. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2)>, - count: Int - ) where RegexOutput == (Substring, C1?, C2?) { - precondition(count >= 0, "Must specify a positive count") - let factory = makeFactory() - self.init(factory.exactly(count, component)) - } - - /// Creates a regex component that matches the given component repeated - /// the specified number of times. - /// - /// - Parameters: - /// - count: The number of times to repeat `component`. `count` must - /// be greater than or equal to zero. - /// - componentBuilder: A builder closure that creates the regex - /// component to repeat. - @_alwaysEmitIntoClient - public init( - count: Int, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2)> - ) where RegexOutput == (Substring, C1?, C2?) { - precondition(count >= 0, "Must specify a positive count") - let factory = makeFactory() - self.init(factory.exactly(count, componentBuilder())) - } - - /// Creates a regex component that matches the given component repeated - /// a number of times specified by the given range expression. - /// - /// - Parameters: - /// - component: The regex component to repeat. - /// - expression: A range expression specifying the number of times - /// that `component` can repeat. - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2)>, - _ expression: some RangeExpression, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1?, C2?) { - let factory = makeFactory() - self.init(factory.repeating(expression.relative(to: 0..( - _ expression: some RangeExpression, - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2)> - ) where RegexOutput == (Substring, C1?, C2?) { - let factory = makeFactory() - self.init(factory.repeating(expression.relative(to: 0..( - _ component: some RegexComponent<(W, C1, C2, C3)>, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1?, C2?, C3?) { - let factory = makeFactory() - self.init(factory.zeroOrOne(component, behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension Optionally { - /// Creates a regex component that matches the given component - /// zero or one times. - /// - /// - Parameters: - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - /// - componentBuilder: A builder closure that generates a regex - /// component. - @_alwaysEmitIntoClient - public init( - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3)> - ) where RegexOutput == (Substring, C1?, C2?, C3?) { - let factory = makeFactory() - self.init(factory.zeroOrOne(componentBuilder(), behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildLimitedAvailability( - _ component: some RegexComponent<(W, C1, C2, C3)> - ) -> Regex<(Substring, C1?, C2?, C3?)> { - let factory = makeFactory() - return factory.zeroOrOne(component, nil) - } -} -@available(SwiftStdlib 5.7, *) -extension ZeroOrMore { - /// Creates a regex component that matches the given component - /// zero or more times. - /// - /// - Parameters: - /// - component: The regex component. - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3)>, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1?, C2?, C3?) { - let factory = makeFactory() - self.init(factory.zeroOrMore(component, behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension ZeroOrMore { - /// Creates a regex component that matches the given component - /// zero or more times. - /// - /// - Parameters: - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - /// - componentBuilder: A builder closure that generates a regex - /// component. - @_alwaysEmitIntoClient - public init( - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3)> - ) where RegexOutput == (Substring, C1?, C2?, C3?) { - let factory = makeFactory() - self.init(factory.zeroOrMore(componentBuilder(), behavior)) - } -} - - -@available(SwiftStdlib 5.7, *) -extension OneOrMore { - /// Creates a regex component that matches the given component - /// one or more times. - /// - /// - Parameters: - /// - component: The regex component. - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3)>, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1, C2, C3) { - let factory = makeFactory() - self.init(factory.oneOrMore(component, behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension OneOrMore { - /// Creates a regex component that matches the given component - /// one or more times. - /// - /// - Parameters: - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - /// - componentBuilder: A builder closure that generates a regex - /// component. - @_alwaysEmitIntoClient - public init( - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3)> - ) where RegexOutput == (Substring, C1, C2, C3) { - let factory = makeFactory() - self.init(factory.oneOrMore(componentBuilder(), behavior)) - } -} - - -@available(SwiftStdlib 5.7, *) -extension Repeat { - /// Creates a regex component that matches the given component repeated - /// the specified number of times. - /// - /// - Parameters: - /// - component: The regex component to repeat. - /// - count: The number of times to repeat `component`. `count` must - /// be greater than or equal to zero. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3)>, - count: Int - ) where RegexOutput == (Substring, C1?, C2?, C3?) { - precondition(count >= 0, "Must specify a positive count") - let factory = makeFactory() - self.init(factory.exactly(count, component)) - } - - /// Creates a regex component that matches the given component repeated - /// the specified number of times. - /// - /// - Parameters: - /// - count: The number of times to repeat `component`. `count` must - /// be greater than or equal to zero. - /// - componentBuilder: A builder closure that creates the regex - /// component to repeat. - @_alwaysEmitIntoClient - public init( - count: Int, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3)> - ) where RegexOutput == (Substring, C1?, C2?, C3?) { - precondition(count >= 0, "Must specify a positive count") - let factory = makeFactory() - self.init(factory.exactly(count, componentBuilder())) - } - - /// Creates a regex component that matches the given component repeated - /// a number of times specified by the given range expression. - /// - /// - Parameters: - /// - component: The regex component to repeat. - /// - expression: A range expression specifying the number of times - /// that `component` can repeat. - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3)>, - _ expression: some RangeExpression, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1?, C2?, C3?) { - let factory = makeFactory() - self.init(factory.repeating(expression.relative(to: 0..( - _ expression: some RangeExpression, - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3)> - ) where RegexOutput == (Substring, C1?, C2?, C3?) { - let factory = makeFactory() - self.init(factory.repeating(expression.relative(to: 0..( - _ component: some RegexComponent<(W, C1, C2, C3, C4)>, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?) { - let factory = makeFactory() - self.init(factory.zeroOrOne(component, behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension Optionally { - /// Creates a regex component that matches the given component - /// zero or one times. - /// - /// - Parameters: - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - /// - componentBuilder: A builder closure that generates a regex - /// component. - @_alwaysEmitIntoClient - public init( - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4)> - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?) { - let factory = makeFactory() - self.init(factory.zeroOrOne(componentBuilder(), behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildLimitedAvailability( - _ component: some RegexComponent<(W, C1, C2, C3, C4)> - ) -> Regex<(Substring, C1?, C2?, C3?, C4?)> { - let factory = makeFactory() - return factory.zeroOrOne(component, nil) - } -} -@available(SwiftStdlib 5.7, *) -extension ZeroOrMore { - /// Creates a regex component that matches the given component - /// zero or more times. - /// - /// - Parameters: - /// - component: The regex component. - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4)>, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?) { - let factory = makeFactory() - self.init(factory.zeroOrMore(component, behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension ZeroOrMore { - /// Creates a regex component that matches the given component - /// zero or more times. - /// - /// - Parameters: - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - /// - componentBuilder: A builder closure that generates a regex - /// component. - @_alwaysEmitIntoClient - public init( - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4)> - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?) { - let factory = makeFactory() - self.init(factory.zeroOrMore(componentBuilder(), behavior)) - } -} - - -@available(SwiftStdlib 5.7, *) -extension OneOrMore { - /// Creates a regex component that matches the given component - /// one or more times. - /// - /// - Parameters: - /// - component: The regex component. - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4)>, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1, C2, C3, C4) { - let factory = makeFactory() - self.init(factory.oneOrMore(component, behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension OneOrMore { - /// Creates a regex component that matches the given component - /// one or more times. - /// - /// - Parameters: - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - /// - componentBuilder: A builder closure that generates a regex - /// component. - @_alwaysEmitIntoClient - public init( - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4)> - ) where RegexOutput == (Substring, C1, C2, C3, C4) { - let factory = makeFactory() - self.init(factory.oneOrMore(componentBuilder(), behavior)) - } -} - - -@available(SwiftStdlib 5.7, *) -extension Repeat { - /// Creates a regex component that matches the given component repeated - /// the specified number of times. - /// - /// - Parameters: - /// - component: The regex component to repeat. - /// - count: The number of times to repeat `component`. `count` must - /// be greater than or equal to zero. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4)>, - count: Int - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?) { - precondition(count >= 0, "Must specify a positive count") - let factory = makeFactory() - self.init(factory.exactly(count, component)) - } - - /// Creates a regex component that matches the given component repeated - /// the specified number of times. - /// - /// - Parameters: - /// - count: The number of times to repeat `component`. `count` must - /// be greater than or equal to zero. - /// - componentBuilder: A builder closure that creates the regex - /// component to repeat. - @_alwaysEmitIntoClient - public init( - count: Int, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4)> - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?) { - precondition(count >= 0, "Must specify a positive count") - let factory = makeFactory() - self.init(factory.exactly(count, componentBuilder())) - } - - /// Creates a regex component that matches the given component repeated - /// a number of times specified by the given range expression. - /// - /// - Parameters: - /// - component: The regex component to repeat. - /// - expression: A range expression specifying the number of times - /// that `component` can repeat. - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4)>, - _ expression: some RangeExpression, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?) { - let factory = makeFactory() - self.init(factory.repeating(expression.relative(to: 0..( - _ expression: some RangeExpression, - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4)> - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?) { - let factory = makeFactory() - self.init(factory.repeating(expression.relative(to: 0..( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5)>, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?) { - let factory = makeFactory() - self.init(factory.zeroOrOne(component, behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension Optionally { - /// Creates a regex component that matches the given component - /// zero or one times. - /// - /// - Parameters: - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - /// - componentBuilder: A builder closure that generates a regex - /// component. - @_alwaysEmitIntoClient - public init( - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5)> - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?) { - let factory = makeFactory() - self.init(factory.zeroOrOne(componentBuilder(), behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildLimitedAvailability( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5)> - ) -> Regex<(Substring, C1?, C2?, C3?, C4?, C5?)> { - let factory = makeFactory() - return factory.zeroOrOne(component, nil) - } -} -@available(SwiftStdlib 5.7, *) -extension ZeroOrMore { - /// Creates a regex component that matches the given component - /// zero or more times. - /// - /// - Parameters: - /// - component: The regex component. - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5)>, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?) { - let factory = makeFactory() - self.init(factory.zeroOrMore(component, behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension ZeroOrMore { - /// Creates a regex component that matches the given component - /// zero or more times. - /// - /// - Parameters: - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - /// - componentBuilder: A builder closure that generates a regex - /// component. - @_alwaysEmitIntoClient - public init( - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5)> - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?) { - let factory = makeFactory() - self.init(factory.zeroOrMore(componentBuilder(), behavior)) - } -} - - -@available(SwiftStdlib 5.7, *) -extension OneOrMore { - /// Creates a regex component that matches the given component - /// one or more times. - /// - /// - Parameters: - /// - component: The regex component. - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5)>, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1, C2, C3, C4, C5) { - let factory = makeFactory() - self.init(factory.oneOrMore(component, behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension OneOrMore { - /// Creates a regex component that matches the given component - /// one or more times. - /// - /// - Parameters: - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - /// - componentBuilder: A builder closure that generates a regex - /// component. - @_alwaysEmitIntoClient - public init( - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5)> - ) where RegexOutput == (Substring, C1, C2, C3, C4, C5) { - let factory = makeFactory() - self.init(factory.oneOrMore(componentBuilder(), behavior)) - } -} - - -@available(SwiftStdlib 5.7, *) -extension Repeat { - /// Creates a regex component that matches the given component repeated - /// the specified number of times. - /// - /// - Parameters: - /// - component: The regex component to repeat. - /// - count: The number of times to repeat `component`. `count` must - /// be greater than or equal to zero. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5)>, - count: Int - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?) { - precondition(count >= 0, "Must specify a positive count") - let factory = makeFactory() - self.init(factory.exactly(count, component)) - } - - /// Creates a regex component that matches the given component repeated - /// the specified number of times. - /// - /// - Parameters: - /// - count: The number of times to repeat `component`. `count` must - /// be greater than or equal to zero. - /// - componentBuilder: A builder closure that creates the regex - /// component to repeat. - @_alwaysEmitIntoClient - public init( - count: Int, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5)> - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?) { - precondition(count >= 0, "Must specify a positive count") - let factory = makeFactory() - self.init(factory.exactly(count, componentBuilder())) - } - - /// Creates a regex component that matches the given component repeated - /// a number of times specified by the given range expression. - /// - /// - Parameters: - /// - component: The regex component to repeat. - /// - expression: A range expression specifying the number of times - /// that `component` can repeat. - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5)>, - _ expression: some RangeExpression, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?) { - let factory = makeFactory() - self.init(factory.repeating(expression.relative(to: 0..( - _ expression: some RangeExpression, - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5)> - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?) { - let factory = makeFactory() - self.init(factory.repeating(expression.relative(to: 0..( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6)>, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?) { - let factory = makeFactory() - self.init(factory.zeroOrOne(component, behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension Optionally { - /// Creates a regex component that matches the given component - /// zero or one times. - /// - /// - Parameters: - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - /// - componentBuilder: A builder closure that generates a regex - /// component. - @_alwaysEmitIntoClient - public init( - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6)> - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?) { - let factory = makeFactory() - self.init(factory.zeroOrOne(componentBuilder(), behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildLimitedAvailability( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6)> - ) -> Regex<(Substring, C1?, C2?, C3?, C4?, C5?, C6?)> { - let factory = makeFactory() - return factory.zeroOrOne(component, nil) - } -} -@available(SwiftStdlib 5.7, *) -extension ZeroOrMore { - /// Creates a regex component that matches the given component - /// zero or more times. - /// - /// - Parameters: - /// - component: The regex component. - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6)>, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?) { - let factory = makeFactory() - self.init(factory.zeroOrMore(component, behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension ZeroOrMore { - /// Creates a regex component that matches the given component - /// zero or more times. - /// - /// - Parameters: - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - /// - componentBuilder: A builder closure that generates a regex - /// component. - @_alwaysEmitIntoClient - public init( - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6)> - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?) { - let factory = makeFactory() - self.init(factory.zeroOrMore(componentBuilder(), behavior)) - } -} - - -@available(SwiftStdlib 5.7, *) -extension OneOrMore { - /// Creates a regex component that matches the given component - /// one or more times. - /// - /// - Parameters: - /// - component: The regex component. - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6)>, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1, C2, C3, C4, C5, C6) { - let factory = makeFactory() - self.init(factory.oneOrMore(component, behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension OneOrMore { - /// Creates a regex component that matches the given component - /// one or more times. - /// - /// - Parameters: - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - /// - componentBuilder: A builder closure that generates a regex - /// component. - @_alwaysEmitIntoClient - public init( - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6)> - ) where RegexOutput == (Substring, C1, C2, C3, C4, C5, C6) { - let factory = makeFactory() - self.init(factory.oneOrMore(componentBuilder(), behavior)) - } -} - - -@available(SwiftStdlib 5.7, *) -extension Repeat { - /// Creates a regex component that matches the given component repeated - /// the specified number of times. - /// - /// - Parameters: - /// - component: The regex component to repeat. - /// - count: The number of times to repeat `component`. `count` must - /// be greater than or equal to zero. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6)>, - count: Int - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?) { - precondition(count >= 0, "Must specify a positive count") - let factory = makeFactory() - self.init(factory.exactly(count, component)) - } - - /// Creates a regex component that matches the given component repeated - /// the specified number of times. - /// - /// - Parameters: - /// - count: The number of times to repeat `component`. `count` must - /// be greater than or equal to zero. - /// - componentBuilder: A builder closure that creates the regex - /// component to repeat. - @_alwaysEmitIntoClient - public init( - count: Int, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6)> - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?) { - precondition(count >= 0, "Must specify a positive count") - let factory = makeFactory() - self.init(factory.exactly(count, componentBuilder())) - } - - /// Creates a regex component that matches the given component repeated - /// a number of times specified by the given range expression. - /// - /// - Parameters: - /// - component: The regex component to repeat. - /// - expression: A range expression specifying the number of times - /// that `component` can repeat. - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6)>, - _ expression: some RangeExpression, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?) { - let factory = makeFactory() - self.init(factory.repeating(expression.relative(to: 0..( - _ expression: some RangeExpression, - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6)> - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?) { - let factory = makeFactory() - self.init(factory.repeating(expression.relative(to: 0..( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7)>, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?) { - let factory = makeFactory() - self.init(factory.zeroOrOne(component, behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension Optionally { - /// Creates a regex component that matches the given component - /// zero or one times. - /// - /// - Parameters: - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - /// - componentBuilder: A builder closure that generates a regex - /// component. - @_alwaysEmitIntoClient - public init( - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7)> - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?) { - let factory = makeFactory() - self.init(factory.zeroOrOne(componentBuilder(), behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildLimitedAvailability( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7)> - ) -> Regex<(Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?)> { - let factory = makeFactory() - return factory.zeroOrOne(component, nil) - } -} -@available(SwiftStdlib 5.7, *) -extension ZeroOrMore { - /// Creates a regex component that matches the given component - /// zero or more times. - /// - /// - Parameters: - /// - component: The regex component. - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7)>, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?) { - let factory = makeFactory() - self.init(factory.zeroOrMore(component, behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension ZeroOrMore { - /// Creates a regex component that matches the given component - /// zero or more times. - /// - /// - Parameters: - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - /// - componentBuilder: A builder closure that generates a regex - /// component. - @_alwaysEmitIntoClient - public init( - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7)> - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?) { - let factory = makeFactory() - self.init(factory.zeroOrMore(componentBuilder(), behavior)) - } -} - - -@available(SwiftStdlib 5.7, *) -extension OneOrMore { - /// Creates a regex component that matches the given component - /// one or more times. - /// - /// - Parameters: - /// - component: The regex component. - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7)>, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1, C2, C3, C4, C5, C6, C7) { - let factory = makeFactory() - self.init(factory.oneOrMore(component, behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension OneOrMore { - /// Creates a regex component that matches the given component - /// one or more times. - /// - /// - Parameters: - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - /// - componentBuilder: A builder closure that generates a regex - /// component. - @_alwaysEmitIntoClient - public init( - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7)> - ) where RegexOutput == (Substring, C1, C2, C3, C4, C5, C6, C7) { - let factory = makeFactory() - self.init(factory.oneOrMore(componentBuilder(), behavior)) - } -} - - -@available(SwiftStdlib 5.7, *) -extension Repeat { - /// Creates a regex component that matches the given component repeated - /// the specified number of times. - /// - /// - Parameters: - /// - component: The regex component to repeat. - /// - count: The number of times to repeat `component`. `count` must - /// be greater than or equal to zero. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7)>, - count: Int - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?) { - precondition(count >= 0, "Must specify a positive count") - let factory = makeFactory() - self.init(factory.exactly(count, component)) - } - - /// Creates a regex component that matches the given component repeated - /// the specified number of times. - /// - /// - Parameters: - /// - count: The number of times to repeat `component`. `count` must - /// be greater than or equal to zero. - /// - componentBuilder: A builder closure that creates the regex - /// component to repeat. - @_alwaysEmitIntoClient - public init( - count: Int, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7)> - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?) { - precondition(count >= 0, "Must specify a positive count") - let factory = makeFactory() - self.init(factory.exactly(count, componentBuilder())) - } - - /// Creates a regex component that matches the given component repeated - /// a number of times specified by the given range expression. - /// - /// - Parameters: - /// - component: The regex component to repeat. - /// - expression: A range expression specifying the number of times - /// that `component` can repeat. - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7)>, - _ expression: some RangeExpression, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?) { - let factory = makeFactory() - self.init(factory.repeating(expression.relative(to: 0..( - _ expression: some RangeExpression, - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7)> - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?) { - let factory = makeFactory() - self.init(factory.repeating(expression.relative(to: 0..( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8)>, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?) { - let factory = makeFactory() - self.init(factory.zeroOrOne(component, behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension Optionally { - /// Creates a regex component that matches the given component - /// zero or one times. - /// - /// - Parameters: - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - /// - componentBuilder: A builder closure that generates a regex - /// component. - @_alwaysEmitIntoClient - public init( - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8)> - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?) { - let factory = makeFactory() - self.init(factory.zeroOrOne(componentBuilder(), behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildLimitedAvailability( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8)> - ) -> Regex<(Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?)> { - let factory = makeFactory() - return factory.zeroOrOne(component, nil) - } -} -@available(SwiftStdlib 5.7, *) -extension ZeroOrMore { - /// Creates a regex component that matches the given component - /// zero or more times. - /// - /// - Parameters: - /// - component: The regex component. - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8)>, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?) { - let factory = makeFactory() - self.init(factory.zeroOrMore(component, behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension ZeroOrMore { - /// Creates a regex component that matches the given component - /// zero or more times. - /// - /// - Parameters: - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - /// - componentBuilder: A builder closure that generates a regex - /// component. - @_alwaysEmitIntoClient - public init( - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8)> - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?) { - let factory = makeFactory() - self.init(factory.zeroOrMore(componentBuilder(), behavior)) - } -} - - -@available(SwiftStdlib 5.7, *) -extension OneOrMore { - /// Creates a regex component that matches the given component - /// one or more times. - /// - /// - Parameters: - /// - component: The regex component. - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8)>, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1, C2, C3, C4, C5, C6, C7, C8) { - let factory = makeFactory() - self.init(factory.oneOrMore(component, behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension OneOrMore { - /// Creates a regex component that matches the given component - /// one or more times. - /// - /// - Parameters: - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - /// - componentBuilder: A builder closure that generates a regex - /// component. - @_alwaysEmitIntoClient - public init( - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8)> - ) where RegexOutput == (Substring, C1, C2, C3, C4, C5, C6, C7, C8) { - let factory = makeFactory() - self.init(factory.oneOrMore(componentBuilder(), behavior)) - } -} - - -@available(SwiftStdlib 5.7, *) -extension Repeat { - /// Creates a regex component that matches the given component repeated - /// the specified number of times. - /// - /// - Parameters: - /// - component: The regex component to repeat. - /// - count: The number of times to repeat `component`. `count` must - /// be greater than or equal to zero. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8)>, - count: Int - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?) { - precondition(count >= 0, "Must specify a positive count") - let factory = makeFactory() - self.init(factory.exactly(count, component)) - } - - /// Creates a regex component that matches the given component repeated - /// the specified number of times. - /// - /// - Parameters: - /// - count: The number of times to repeat `component`. `count` must - /// be greater than or equal to zero. - /// - componentBuilder: A builder closure that creates the regex - /// component to repeat. - @_alwaysEmitIntoClient - public init( - count: Int, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8)> - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?) { - precondition(count >= 0, "Must specify a positive count") - let factory = makeFactory() - self.init(factory.exactly(count, componentBuilder())) - } - - /// Creates a regex component that matches the given component repeated - /// a number of times specified by the given range expression. - /// - /// - Parameters: - /// - component: The regex component to repeat. - /// - expression: A range expression specifying the number of times - /// that `component` can repeat. - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8)>, - _ expression: some RangeExpression, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?) { - let factory = makeFactory() - self.init(factory.repeating(expression.relative(to: 0..( - _ expression: some RangeExpression, - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8)> - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?) { - let factory = makeFactory() - self.init(factory.repeating(expression.relative(to: 0..( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9)>, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?, C9?) { - let factory = makeFactory() - self.init(factory.zeroOrOne(component, behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension Optionally { - /// Creates a regex component that matches the given component - /// zero or one times. - /// - /// - Parameters: - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - /// - componentBuilder: A builder closure that generates a regex - /// component. - @_alwaysEmitIntoClient - public init( - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9)> - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?, C9?) { - let factory = makeFactory() - self.init(factory.zeroOrOne(componentBuilder(), behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildLimitedAvailability( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9)> - ) -> Regex<(Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?, C9?)> { - let factory = makeFactory() - return factory.zeroOrOne(component, nil) - } -} -@available(SwiftStdlib 5.7, *) -extension ZeroOrMore { - /// Creates a regex component that matches the given component - /// zero or more times. - /// - /// - Parameters: - /// - component: The regex component. - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9)>, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?, C9?) { - let factory = makeFactory() - self.init(factory.zeroOrMore(component, behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension ZeroOrMore { - /// Creates a regex component that matches the given component - /// zero or more times. - /// - /// - Parameters: - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - /// - componentBuilder: A builder closure that generates a regex - /// component. - @_alwaysEmitIntoClient - public init( - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9)> - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?, C9?) { - let factory = makeFactory() - self.init(factory.zeroOrMore(componentBuilder(), behavior)) - } -} - - -@available(SwiftStdlib 5.7, *) -extension OneOrMore { - /// Creates a regex component that matches the given component - /// one or more times. - /// - /// - Parameters: - /// - component: The regex component. - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9)>, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9) { - let factory = makeFactory() - self.init(factory.oneOrMore(component, behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension OneOrMore { - /// Creates a regex component that matches the given component - /// one or more times. - /// - /// - Parameters: - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - /// - componentBuilder: A builder closure that generates a regex - /// component. - @_alwaysEmitIntoClient - public init( - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9)> - ) where RegexOutput == (Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9) { - let factory = makeFactory() - self.init(factory.oneOrMore(componentBuilder(), behavior)) - } -} - - -@available(SwiftStdlib 5.7, *) -extension Repeat { - /// Creates a regex component that matches the given component repeated - /// the specified number of times. - /// - /// - Parameters: - /// - component: The regex component to repeat. - /// - count: The number of times to repeat `component`. `count` must - /// be greater than or equal to zero. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9)>, - count: Int - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?, C9?) { - precondition(count >= 0, "Must specify a positive count") - let factory = makeFactory() - self.init(factory.exactly(count, component)) - } - - /// Creates a regex component that matches the given component repeated - /// the specified number of times. - /// - /// - Parameters: - /// - count: The number of times to repeat `component`. `count` must - /// be greater than or equal to zero. - /// - componentBuilder: A builder closure that creates the regex - /// component to repeat. - @_alwaysEmitIntoClient - public init( - count: Int, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9)> - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?, C9?) { - precondition(count >= 0, "Must specify a positive count") - let factory = makeFactory() - self.init(factory.exactly(count, componentBuilder())) - } - - /// Creates a regex component that matches the given component repeated - /// a number of times specified by the given range expression. - /// - /// - Parameters: - /// - component: The regex component to repeat. - /// - expression: A range expression specifying the number of times - /// that `component` can repeat. - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9)>, - _ expression: some RangeExpression, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?, C9?) { - let factory = makeFactory() - self.init(factory.repeating(expression.relative(to: 0..( - _ expression: some RangeExpression, - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9)> - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?, C9?) { - let factory = makeFactory() - self.init(factory.repeating(expression.relative(to: 0..( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)>, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?, C9?, C10?) { - let factory = makeFactory() - self.init(factory.zeroOrOne(component, behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension Optionally { - /// Creates a regex component that matches the given component - /// zero or one times. - /// - /// - Parameters: - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - /// - componentBuilder: A builder closure that generates a regex - /// component. - @_alwaysEmitIntoClient - public init( - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)> - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?, C9?, C10?) { - let factory = makeFactory() - self.init(factory.zeroOrOne(componentBuilder(), behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildLimitedAvailability( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)> - ) -> Regex<(Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?, C9?, C10?)> { - let factory = makeFactory() - return factory.zeroOrOne(component, nil) - } -} -@available(SwiftStdlib 5.7, *) -extension ZeroOrMore { - /// Creates a regex component that matches the given component - /// zero or more times. - /// - /// - Parameters: - /// - component: The regex component. - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)>, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?, C9?, C10?) { - let factory = makeFactory() - self.init(factory.zeroOrMore(component, behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension ZeroOrMore { - /// Creates a regex component that matches the given component - /// zero or more times. - /// - /// - Parameters: - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - /// - componentBuilder: A builder closure that generates a regex - /// component. - @_alwaysEmitIntoClient - public init( - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)> - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?, C9?, C10?) { - let factory = makeFactory() - self.init(factory.zeroOrMore(componentBuilder(), behavior)) - } -} - - -@available(SwiftStdlib 5.7, *) -extension OneOrMore { - /// Creates a regex component that matches the given component - /// one or more times. - /// - /// - Parameters: - /// - component: The regex component. - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)>, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10) { - let factory = makeFactory() - self.init(factory.oneOrMore(component, behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension OneOrMore { - /// Creates a regex component that matches the given component - /// one or more times. - /// - /// - Parameters: - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - /// - componentBuilder: A builder closure that generates a regex - /// component. - @_alwaysEmitIntoClient - public init( - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)> - ) where RegexOutput == (Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10) { - let factory = makeFactory() - self.init(factory.oneOrMore(componentBuilder(), behavior)) - } -} - - -@available(SwiftStdlib 5.7, *) -extension Repeat { - /// Creates a regex component that matches the given component repeated - /// the specified number of times. - /// - /// - Parameters: - /// - component: The regex component to repeat. - /// - count: The number of times to repeat `component`. `count` must - /// be greater than or equal to zero. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)>, - count: Int - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?, C9?, C10?) { - precondition(count >= 0, "Must specify a positive count") - let factory = makeFactory() - self.init(factory.exactly(count, component)) - } - - /// Creates a regex component that matches the given component repeated - /// the specified number of times. - /// - /// - Parameters: - /// - count: The number of times to repeat `component`. `count` must - /// be greater than or equal to zero. - /// - componentBuilder: A builder closure that creates the regex - /// component to repeat. - @_alwaysEmitIntoClient - public init( - count: Int, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)> - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?, C9?, C10?) { - precondition(count >= 0, "Must specify a positive count") - let factory = makeFactory() - self.init(factory.exactly(count, componentBuilder())) - } - - /// Creates a regex component that matches the given component repeated - /// a number of times specified by the given range expression. - /// - /// - Parameters: - /// - component: The regex component to repeat. - /// - expression: A range expression specifying the number of times - /// that `component` can repeat. - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)>, - _ expression: some RangeExpression, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?, C9?, C10?) { - let factory = makeFactory() - self.init(factory.repeating(expression.relative(to: 0..( - _ expression: some RangeExpression, - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)> - ) where RegexOutput == (Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?, C9?, C10?) { - let factory = makeFactory() - self.init(factory.repeating(expression.relative(to: 0.. Date: Thu, 29 Feb 2024 17:32:16 -0600 Subject: [PATCH 03/11] 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. --- Sources/RegexBuilder/Variadics.swift | 297 +------------------- Tests/RegexBuilderTests/RegexDSLTests.swift | 15 + Tests/RegexTests/MatchTests.swift | 9 + 3 files changed, 30 insertions(+), 291 deletions(-) diff --git a/Sources/RegexBuilder/Variadics.swift b/Sources/RegexBuilder/Variadics.swift index b4ffa43cf..8855506f5 100644 --- a/Sources/RegexBuilder/Variadics.swift +++ b/Sources/RegexBuilder/Variadics.swift @@ -9,8 +9,6 @@ // //===----------------------------------------------------------------------===// -// BEGIN AUTO-GENERATED CONTENT - @_spi(RegexBuilder) import _StringProcessing @available(SwiftStdlib 5.7, *) @@ -532,10 +530,7 @@ extension Local { let factory = makeFactory() self.init(factory.atomicNonCapturing(component)) } -} -@available(SwiftStdlib 5.7, *) -extension Local { /// Creates an atomic group with the given regex component. /// /// - Parameter componentBuilder: A builder closure that generates a @@ -550,192 +545,7 @@ extension Local { self.init(factory.atomicNonCapturing(componentBuilder())) } } -@available(SwiftStdlib 5.7, *) -extension Local { - /// Creates an atomic group with the given regex component. - /// - /// - Parameter component: The regex component to wrap in an atomic - /// group. - @available(SwiftStdlib 5.7, *) - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1)> - ) where RegexOutput == (Substring, C1) { - let factory = makeFactory() - self.init(factory.atomicNonCapturing(component)) - } -} - -@available(SwiftStdlib 5.7, *) -extension Local { - /// Creates an atomic group with the given regex component. - /// - /// - Parameter componentBuilder: A builder closure that generates a - /// regex component to wrap in an atomic group. - @available(SwiftStdlib 5.7, *) - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1)> - ) where RegexOutput == (Substring, C1) { - let factory = makeFactory() - self.init(factory.atomicNonCapturing(componentBuilder())) - } -} -@available(SwiftStdlib 5.7, *) -extension Local { - /// Creates an atomic group with the given regex component. - /// - /// - Parameter component: The regex component to wrap in an atomic - /// group. - @available(SwiftStdlib 5.7, *) - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2)> - ) where RegexOutput == (Substring, C1, C2) { - let factory = makeFactory() - self.init(factory.atomicNonCapturing(component)) - } -} - -@available(SwiftStdlib 5.7, *) -extension Local { - /// Creates an atomic group with the given regex component. - /// - /// - Parameter componentBuilder: A builder closure that generates a - /// regex component to wrap in an atomic group. - @available(SwiftStdlib 5.7, *) - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2)> - ) where RegexOutput == (Substring, C1, C2) { - let factory = makeFactory() - self.init(factory.atomicNonCapturing(componentBuilder())) - } -} -@available(SwiftStdlib 5.7, *) -extension Local { - /// Creates an atomic group with the given regex component. - /// - /// - Parameter component: The regex component to wrap in an atomic - /// group. - @available(SwiftStdlib 5.7, *) - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3)> - ) where RegexOutput == (Substring, C1, C2, C3) { - let factory = makeFactory() - self.init(factory.atomicNonCapturing(component)) - } -} - -@available(SwiftStdlib 5.7, *) -extension Local { - /// Creates an atomic group with the given regex component. - /// - /// - Parameter componentBuilder: A builder closure that generates a - /// regex component to wrap in an atomic group. - @available(SwiftStdlib 5.7, *) - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3)> - ) where RegexOutput == (Substring, C1, C2, C3) { - let factory = makeFactory() - self.init(factory.atomicNonCapturing(componentBuilder())) - } -} -@available(SwiftStdlib 5.7, *) -extension Local { - /// Creates an atomic group with the given regex component. - /// - /// - Parameter component: The regex component to wrap in an atomic - /// group. - @available(SwiftStdlib 5.7, *) - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4)> - ) where RegexOutput == (Substring, C1, C2, C3, C4) { - let factory = makeFactory() - self.init(factory.atomicNonCapturing(component)) - } -} - -@available(SwiftStdlib 5.7, *) -extension Local { - /// Creates an atomic group with the given regex component. - /// - /// - Parameter componentBuilder: A builder closure that generates a - /// regex component to wrap in an atomic group. - @available(SwiftStdlib 5.7, *) - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4)> - ) where RegexOutput == (Substring, C1, C2, C3, C4) { - let factory = makeFactory() - self.init(factory.atomicNonCapturing(componentBuilder())) - } -} -@available(SwiftStdlib 5.7, *) -extension Local { - /// Creates an atomic group with the given regex component. - /// - /// - Parameter component: The regex component to wrap in an atomic - /// group. - @available(SwiftStdlib 5.7, *) - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5)> - ) where RegexOutput == (Substring, C1, C2, C3, C4, C5) { - let factory = makeFactory() - self.init(factory.atomicNonCapturing(component)) - } -} - -@available(SwiftStdlib 5.7, *) -extension Local { - /// Creates an atomic group with the given regex component. - /// - /// - Parameter componentBuilder: A builder closure that generates a - /// regex component to wrap in an atomic group. - @available(SwiftStdlib 5.7, *) - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5)> - ) where RegexOutput == (Substring, C1, C2, C3, C4, C5) { - let factory = makeFactory() - self.init(factory.atomicNonCapturing(componentBuilder())) - } -} -@available(SwiftStdlib 5.7, *) -extension Local { - /// Creates an atomic group with the given regex component. - /// - /// - Parameter component: The regex component to wrap in an atomic - /// group. - @available(SwiftStdlib 5.7, *) - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6)> - ) where RegexOutput == (Substring, C1, C2, C3, C4, C5, C6) { - let factory = makeFactory() - self.init(factory.atomicNonCapturing(component)) - } -} -@available(SwiftStdlib 5.7, *) -extension Local { - /// Creates an atomic group with the given regex component. - /// - /// - Parameter componentBuilder: A builder closure that generates a - /// regex component to wrap in an atomic group. - @available(SwiftStdlib 5.7, *) - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6)> - ) where RegexOutput == (Substring, C1, C2, C3, C4, C5, C6) { - let factory = makeFactory() - self.init(factory.atomicNonCapturing(componentBuilder())) - } -} @available(SwiftStdlib 5.7, *) extension Local { /// Creates an atomic group with the given regex component. @@ -744,122 +554,27 @@ extension Local { /// group. @available(SwiftStdlib 5.7, *) @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7)> - ) where RegexOutput == (Substring, C1, C2, C3, C4, C5, C6, C7) { + public init( + _ component: some RegexComponent<(W, repeat each Capture)> + ) where RegexOutput == (Substring, repeat each Capture) { let factory = makeFactory() self.init(factory.atomicNonCapturing(component)) } -} -@available(SwiftStdlib 5.7, *) -extension Local { /// Creates an atomic group with the given regex component. /// /// - Parameter componentBuilder: A builder closure that generates a /// regex component to wrap in an atomic group. @available(SwiftStdlib 5.7, *) @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7)> - ) where RegexOutput == (Substring, C1, C2, C3, C4, C5, C6, C7) { + public init( + @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, repeat each Capture)> + ) where RegexOutput == (Substring, repeat each Capture) { let factory = makeFactory() self.init(factory.atomicNonCapturing(componentBuilder())) } } -@available(SwiftStdlib 5.7, *) -extension Local { - /// Creates an atomic group with the given regex component. - /// - /// - Parameter component: The regex component to wrap in an atomic - /// group. - @available(SwiftStdlib 5.7, *) - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8)> - ) where RegexOutput == (Substring, C1, C2, C3, C4, C5, C6, C7, C8) { - let factory = makeFactory() - self.init(factory.atomicNonCapturing(component)) - } -} -@available(SwiftStdlib 5.7, *) -extension Local { - /// Creates an atomic group with the given regex component. - /// - /// - Parameter componentBuilder: A builder closure that generates a - /// regex component to wrap in an atomic group. - @available(SwiftStdlib 5.7, *) - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8)> - ) where RegexOutput == (Substring, C1, C2, C3, C4, C5, C6, C7, C8) { - let factory = makeFactory() - self.init(factory.atomicNonCapturing(componentBuilder())) - } -} -@available(SwiftStdlib 5.7, *) -extension Local { - /// Creates an atomic group with the given regex component. - /// - /// - Parameter component: The regex component to wrap in an atomic - /// group. - @available(SwiftStdlib 5.7, *) - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9)> - ) where RegexOutput == (Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9) { - let factory = makeFactory() - self.init(factory.atomicNonCapturing(component)) - } -} - -@available(SwiftStdlib 5.7, *) -extension Local { - /// Creates an atomic group with the given regex component. - /// - /// - Parameter componentBuilder: A builder closure that generates a - /// regex component to wrap in an atomic group. - @available(SwiftStdlib 5.7, *) - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9)> - ) where RegexOutput == (Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9) { - let factory = makeFactory() - self.init(factory.atomicNonCapturing(componentBuilder())) - } -} -@available(SwiftStdlib 5.7, *) -extension Local { - /// Creates an atomic group with the given regex component. - /// - /// - Parameter component: The regex component to wrap in an atomic - /// group. - @available(SwiftStdlib 5.7, *) - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)> - ) where RegexOutput == (Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10) { - let factory = makeFactory() - self.init(factory.atomicNonCapturing(component)) - } -} - -@available(SwiftStdlib 5.7, *) -extension Local { - /// Creates an atomic group with the given regex component. - /// - /// - Parameter componentBuilder: A builder closure that generates a - /// regex component to wrap in an atomic group. - @available(SwiftStdlib 5.7, *) - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)> - ) where RegexOutput == (Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10) { - let factory = makeFactory() - self.init(factory.atomicNonCapturing(componentBuilder())) - } -} // MARK: - Alternation builder (arity 0) @available(SwiftStdlib 5.7, *) diff --git a/Tests/RegexBuilderTests/RegexDSLTests.swift b/Tests/RegexBuilderTests/RegexDSLTests.swift index 9c85b05be..eb7b73033 100644 --- a/Tests/RegexBuilderTests/RegexDSLTests.swift +++ b/Tests/RegexBuilderTests/RegexDSLTests.swift @@ -884,6 +884,21 @@ class RegexDSLTests: XCTestCase { } "a" } + + // FIXME: Atomic groups lose their captures, will fix in: + // https://github.com/apple/swift-experimental-string-processing/pull/723 + // try _testDSLCaptures( + // ("aaa", ("aaa", "a")), + // matchType: (Substring, Substring).self, ==) + // { + // Local { + // "a" + // Capture { + // OneOrMore("a", .reluctant) + // } + // } + // "a" + // } } func testAssertions() throws { diff --git a/Tests/RegexTests/MatchTests.swift b/Tests/RegexTests/MatchTests.swift index 3d8cdf1ee..884be22b0 100644 --- a/Tests/RegexTests/MatchTests.swift +++ b/Tests/RegexTests/MatchTests.swift @@ -1762,6 +1762,15 @@ extension RegexTests { firstMatchTest( #"(?:(?>a)|.b)c"#, input: "123abcacxyz", match: "abc") + firstMatchTest( + #"(?>a+)a"#, input: "aa", match: nil) + firstMatchTest( + #"(?>a+?)a"#, input: "aa", match: "aa") + firstMatchTest( + #"(?>(a+))a"#, input: "aa", match: nil) + firstMatchTest( + #"(?>(a+?))a"#, input: "aa", match: "aa") + // Quantifier behavior inside atomic groups // (?:a+?) matches as few 'a's as possible, after matching the first From ec4e6a9309c35a97374ddc1112ef1056b2dc8eaf Mon Sep 17 00:00:00 2001 From: Nate Cook Date: Thu, 29 Feb 2024 18:03:33 -0600 Subject: [PATCH 04/11] Switch alternation builder to variadic Some trickiness involved in getting the optionality of captures to line up, but I think I got this right. Will need some more source- compatibility validation here, as well. --- Sources/RegexBuilder/Variadics.swift | 810 +-------------------------- 1 file changed, 13 insertions(+), 797 deletions(-) diff --git a/Sources/RegexBuilder/Variadics.swift b/Sources/RegexBuilder/Variadics.swift index 8855506f5..e70946218 100644 --- a/Sources/RegexBuilder/Variadics.swift +++ b/Sources/RegexBuilder/Variadics.swift @@ -575,823 +575,39 @@ extension Local { } } -// MARK: - Alternation builder (arity 0) +// MARK: - Alternation builder @available(SwiftStdlib 5.7, *) extension AlternationBuilder { @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent, - next: some RegexComponent - ) -> ChoiceOf { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent, + public static func buildPartialBlock( + accumulated: some RegexComponent<(W0, C0)>, next: some RegexComponent<(W1, C1)> - ) -> ChoiceOf<(Substring, C1?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent, - next: some RegexComponent<(W1, C1, C2)> - ) -> ChoiceOf<(Substring, C1?, C2?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent, - next: some RegexComponent<(W1, C1, C2, C3)> - ) -> ChoiceOf<(Substring, C1?, C2?, C3?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent, - next: some RegexComponent<(W1, C1, C2, C3, C4)> - ) -> ChoiceOf<(Substring, C1?, C2?, C3?, C4?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent, - next: some RegexComponent<(W1, C1, C2, C3, C4, C5)> - ) -> ChoiceOf<(Substring, C1?, C2?, C3?, C4?, C5?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent, - next: some RegexComponent<(W1, C1, C2, C3, C4, C5, C6)> - ) -> ChoiceOf<(Substring, C1?, C2?, C3?, C4?, C5?, C6?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent, - next: some RegexComponent<(W1, C1, C2, C3, C4, C5, C6, C7)> - ) -> ChoiceOf<(Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent, - next: some RegexComponent<(W1, C1, C2, C3, C4, C5, C6, C7, C8)> - ) -> ChoiceOf<(Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?)> { + ) -> ChoiceOf<(Substring, Optional, Optional)> { let factory = makeFactory() return .init(factory.accumulateAlternation(accumulated, next)) } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { + @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent, - next: some RegexComponent<(W1, C1, C2, C3, C4, C5, C6, C7, C8, C9)> - ) -> ChoiceOf<(Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?, C9?)> { + public static func buildPartialBlock( + accumulated: some RegexComponent<(W0, repeat each Capture0)>, + next: some RegexComponent<(W1, repeat each Capture1)> + ) -> ChoiceOf<(Substring, repeat each Capture0, repeat Optional)> { let factory = makeFactory() return .init(factory.accumulateAlternation(accumulated, next)) } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { + + @_disfavoredOverload @_alwaysEmitIntoClient - public static func buildPartialBlock( + public static func buildPartialBlock( accumulated: some RegexComponent, - next: some RegexComponent<(W1, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)> - ) -> ChoiceOf<(Substring, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?, C9?, C10?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -// MARK: - Alternation builder (arity 1) - -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1)>, - next: some RegexComponent - ) -> ChoiceOf<(Substring, C1)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1)>, - next: some RegexComponent<(W1, C2)> - ) -> ChoiceOf<(Substring, C1, C2?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1)>, - next: some RegexComponent<(W1, C2, C3)> - ) -> ChoiceOf<(Substring, C1, C2?, C3?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1)>, - next: some RegexComponent<(W1, C2, C3, C4)> - ) -> ChoiceOf<(Substring, C1, C2?, C3?, C4?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1)>, - next: some RegexComponent<(W1, C2, C3, C4, C5)> - ) -> ChoiceOf<(Substring, C1, C2?, C3?, C4?, C5?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1)>, - next: some RegexComponent<(W1, C2, C3, C4, C5, C6)> - ) -> ChoiceOf<(Substring, C1, C2?, C3?, C4?, C5?, C6?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1)>, - next: some RegexComponent<(W1, C2, C3, C4, C5, C6, C7)> - ) -> ChoiceOf<(Substring, C1, C2?, C3?, C4?, C5?, C6?, C7?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1)>, - next: some RegexComponent<(W1, C2, C3, C4, C5, C6, C7, C8)> - ) -> ChoiceOf<(Substring, C1, C2?, C3?, C4?, C5?, C6?, C7?, C8?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1)>, - next: some RegexComponent<(W1, C2, C3, C4, C5, C6, C7, C8, C9)> - ) -> ChoiceOf<(Substring, C1, C2?, C3?, C4?, C5?, C6?, C7?, C8?, C9?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1)>, - next: some RegexComponent<(W1, C2, C3, C4, C5, C6, C7, C8, C9, C10)> - ) -> ChoiceOf<(Substring, C1, C2?, C3?, C4?, C5?, C6?, C7?, C8?, C9?, C10?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -// MARK: - Alternation builder (arity 2) - -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2)>, next: some RegexComponent - ) -> ChoiceOf<(Substring, C1, C2)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2)>, - next: some RegexComponent<(W1, C3)> - ) -> ChoiceOf<(Substring, C1, C2, C3?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2)>, - next: some RegexComponent<(W1, C3, C4)> - ) -> ChoiceOf<(Substring, C1, C2, C3?, C4?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2)>, - next: some RegexComponent<(W1, C3, C4, C5)> - ) -> ChoiceOf<(Substring, C1, C2, C3?, C4?, C5?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2)>, - next: some RegexComponent<(W1, C3, C4, C5, C6)> - ) -> ChoiceOf<(Substring, C1, C2, C3?, C4?, C5?, C6?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2)>, - next: some RegexComponent<(W1, C3, C4, C5, C6, C7)> - ) -> ChoiceOf<(Substring, C1, C2, C3?, C4?, C5?, C6?, C7?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2)>, - next: some RegexComponent<(W1, C3, C4, C5, C6, C7, C8)> - ) -> ChoiceOf<(Substring, C1, C2, C3?, C4?, C5?, C6?, C7?, C8?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2)>, - next: some RegexComponent<(W1, C3, C4, C5, C6, C7, C8, C9)> - ) -> ChoiceOf<(Substring, C1, C2, C3?, C4?, C5?, C6?, C7?, C8?, C9?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2)>, - next: some RegexComponent<(W1, C3, C4, C5, C6, C7, C8, C9, C10)> - ) -> ChoiceOf<(Substring, C1, C2, C3?, C4?, C5?, C6?, C7?, C8?, C9?, C10?)> { + ) -> ChoiceOf { let factory = makeFactory() return .init(factory.accumulateAlternation(accumulated, next)) } } -// MARK: - Alternation builder (arity 3) -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3)>, - next: some RegexComponent - ) -> ChoiceOf<(Substring, C1, C2, C3)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3)>, - next: some RegexComponent<(W1, C4)> - ) -> ChoiceOf<(Substring, C1, C2, C3, C4?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3)>, - next: some RegexComponent<(W1, C4, C5)> - ) -> ChoiceOf<(Substring, C1, C2, C3, C4?, C5?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3)>, - next: some RegexComponent<(W1, C4, C5, C6)> - ) -> ChoiceOf<(Substring, C1, C2, C3, C4?, C5?, C6?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3)>, - next: some RegexComponent<(W1, C4, C5, C6, C7)> - ) -> ChoiceOf<(Substring, C1, C2, C3, C4?, C5?, C6?, C7?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3)>, - next: some RegexComponent<(W1, C4, C5, C6, C7, C8)> - ) -> ChoiceOf<(Substring, C1, C2, C3, C4?, C5?, C6?, C7?, C8?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3)>, - next: some RegexComponent<(W1, C4, C5, C6, C7, C8, C9)> - ) -> ChoiceOf<(Substring, C1, C2, C3, C4?, C5?, C6?, C7?, C8?, C9?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3)>, - next: some RegexComponent<(W1, C4, C5, C6, C7, C8, C9, C10)> - ) -> ChoiceOf<(Substring, C1, C2, C3, C4?, C5?, C6?, C7?, C8?, C9?, C10?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -// MARK: - Alternation builder (arity 4) - -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4)>, - next: some RegexComponent - ) -> ChoiceOf<(Substring, C1, C2, C3, C4)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4)>, - next: some RegexComponent<(W1, C5)> - ) -> ChoiceOf<(Substring, C1, C2, C3, C4, C5?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4)>, - next: some RegexComponent<(W1, C5, C6)> - ) -> ChoiceOf<(Substring, C1, C2, C3, C4, C5?, C6?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4)>, - next: some RegexComponent<(W1, C5, C6, C7)> - ) -> ChoiceOf<(Substring, C1, C2, C3, C4, C5?, C6?, C7?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4)>, - next: some RegexComponent<(W1, C5, C6, C7, C8)> - ) -> ChoiceOf<(Substring, C1, C2, C3, C4, C5?, C6?, C7?, C8?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4)>, - next: some RegexComponent<(W1, C5, C6, C7, C8, C9)> - ) -> ChoiceOf<(Substring, C1, C2, C3, C4, C5?, C6?, C7?, C8?, C9?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4)>, - next: some RegexComponent<(W1, C5, C6, C7, C8, C9, C10)> - ) -> ChoiceOf<(Substring, C1, C2, C3, C4, C5?, C6?, C7?, C8?, C9?, C10?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -// MARK: - Alternation builder (arity 5) - -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5)>, - next: some RegexComponent - ) -> ChoiceOf<(Substring, C1, C2, C3, C4, C5)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5)>, - next: some RegexComponent<(W1, C6)> - ) -> ChoiceOf<(Substring, C1, C2, C3, C4, C5, C6?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5)>, - next: some RegexComponent<(W1, C6, C7)> - ) -> ChoiceOf<(Substring, C1, C2, C3, C4, C5, C6?, C7?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5)>, - next: some RegexComponent<(W1, C6, C7, C8)> - ) -> ChoiceOf<(Substring, C1, C2, C3, C4, C5, C6?, C7?, C8?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5)>, - next: some RegexComponent<(W1, C6, C7, C8, C9)> - ) -> ChoiceOf<(Substring, C1, C2, C3, C4, C5, C6?, C7?, C8?, C9?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5)>, - next: some RegexComponent<(W1, C6, C7, C8, C9, C10)> - ) -> ChoiceOf<(Substring, C1, C2, C3, C4, C5, C6?, C7?, C8?, C9?, C10?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -// MARK: - Alternation builder (arity 6) - -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5, C6)>, - next: some RegexComponent - ) -> ChoiceOf<(Substring, C1, C2, C3, C4, C5, C6)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5, C6)>, - next: some RegexComponent<(W1, C7)> - ) -> ChoiceOf<(Substring, C1, C2, C3, C4, C5, C6, C7?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5, C6)>, - next: some RegexComponent<(W1, C7, C8)> - ) -> ChoiceOf<(Substring, C1, C2, C3, C4, C5, C6, C7?, C8?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5, C6)>, - next: some RegexComponent<(W1, C7, C8, C9)> - ) -> ChoiceOf<(Substring, C1, C2, C3, C4, C5, C6, C7?, C8?, C9?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5, C6)>, - next: some RegexComponent<(W1, C7, C8, C9, C10)> - ) -> ChoiceOf<(Substring, C1, C2, C3, C4, C5, C6, C7?, C8?, C9?, C10?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -// MARK: - Alternation builder (arity 7) - -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5, C6, C7)>, - next: some RegexComponent - ) -> ChoiceOf<(Substring, C1, C2, C3, C4, C5, C6, C7)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5, C6, C7)>, - next: some RegexComponent<(W1, C8)> - ) -> ChoiceOf<(Substring, C1, C2, C3, C4, C5, C6, C7, C8?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5, C6, C7)>, - next: some RegexComponent<(W1, C8, C9)> - ) -> ChoiceOf<(Substring, C1, C2, C3, C4, C5, C6, C7, C8?, C9?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5, C6, C7)>, - next: some RegexComponent<(W1, C8, C9, C10)> - ) -> ChoiceOf<(Substring, C1, C2, C3, C4, C5, C6, C7, C8?, C9?, C10?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -// MARK: - Alternation builder (arity 8) - -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5, C6, C7, C8)>, - next: some RegexComponent - ) -> ChoiceOf<(Substring, C1, C2, C3, C4, C5, C6, C7, C8)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5, C6, C7, C8)>, - next: some RegexComponent<(W1, C9)> - ) -> ChoiceOf<(Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5, C6, C7, C8)>, - next: some RegexComponent<(W1, C9, C10)> - ) -> ChoiceOf<(Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9?, C10?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -// MARK: - Alternation builder (arity 9) - -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5, C6, C7, C8, C9)>, - next: some RegexComponent - ) -> ChoiceOf<(Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock( - accumulated: some RegexComponent<(W0, C1, C2, C3, C4, C5, C6, C7, C8, C9)>, - next: some RegexComponent<(W1, C10)> - ) -> ChoiceOf<(Substring, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10?)> { - let factory = makeFactory() - return .init(factory.accumulateAlternation(accumulated, next)) - } -} -// MARK: - Alternation builder buildBlock - -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock(first regex: R) -> ChoiceOf<(W, C1?)> where R: RegexComponent, R.RegexOutput == (W, C1) { - let factory = makeFactory() - return .init(factory.orderedChoice(regex)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock(first regex: R) -> ChoiceOf<(W, C1?, C2?)> where R: RegexComponent, R.RegexOutput == (W, C1, C2) { - let factory = makeFactory() - return .init(factory.orderedChoice(regex)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock(first regex: R) -> ChoiceOf<(W, C1?, C2?, C3?)> where R: RegexComponent, R.RegexOutput == (W, C1, C2, C3) { - let factory = makeFactory() - return .init(factory.orderedChoice(regex)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock(first regex: R) -> ChoiceOf<(W, C1?, C2?, C3?, C4?)> where R: RegexComponent, R.RegexOutput == (W, C1, C2, C3, C4) { - let factory = makeFactory() - return .init(factory.orderedChoice(regex)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock(first regex: R) -> ChoiceOf<(W, C1?, C2?, C3?, C4?, C5?)> where R: RegexComponent, R.RegexOutput == (W, C1, C2, C3, C4, C5) { - let factory = makeFactory() - return .init(factory.orderedChoice(regex)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock(first regex: R) -> ChoiceOf<(W, C1?, C2?, C3?, C4?, C5?, C6?)> where R: RegexComponent, R.RegexOutput == (W, C1, C2, C3, C4, C5, C6) { - let factory = makeFactory() - return .init(factory.orderedChoice(regex)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock(first regex: R) -> ChoiceOf<(W, C1?, C2?, C3?, C4?, C5?, C6?, C7?)> where R: RegexComponent, R.RegexOutput == (W, C1, C2, C3, C4, C5, C6, C7) { - let factory = makeFactory() - return .init(factory.orderedChoice(regex)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock(first regex: R) -> ChoiceOf<(W, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?)> where R: RegexComponent, R.RegexOutput == (W, C1, C2, C3, C4, C5, C6, C7, C8) { - let factory = makeFactory() - return .init(factory.orderedChoice(regex)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock(first regex: R) -> ChoiceOf<(W, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?, C9?)> where R: RegexComponent, R.RegexOutput == (W, C1, C2, C3, C4, C5, C6, C7, C8, C9) { - let factory = makeFactory() - return .init(factory.orderedChoice(regex)) - } -} -@available(SwiftStdlib 5.7, *) -extension AlternationBuilder { - @_alwaysEmitIntoClient - public static func buildPartialBlock(first regex: R) -> ChoiceOf<(W, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?, C9?, C10?)> where R: RegexComponent, R.RegexOutput == (W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10) { - let factory = makeFactory() - return .init(factory.orderedChoice(regex)) - } -} // MARK: - Non-builder capture (arity 0) @available(SwiftStdlib 5.7, *) From 078106741b3f3a268f85bc4750b653f95fd36367 Mon Sep 17 00:00:00 2001 From: Nate Cook Date: Thu, 29 Feb 2024 18:04:48 -0600 Subject: [PATCH 05/11] Switch to variadic captures This one was a suspiciously simple transition, but all seems to be working. --- Sources/RegexBuilder/Variadics.swift | 2441 +------------------------- 1 file changed, 38 insertions(+), 2403 deletions(-) diff --git a/Sources/RegexBuilder/Variadics.swift b/Sources/RegexBuilder/Variadics.swift index e70946218..9ceaaea8e 100644 --- a/Sources/RegexBuilder/Variadics.swift +++ b/Sources/RegexBuilder/Variadics.swift @@ -608,2134 +608,7 @@ extension AlternationBuilder { } } -// MARK: - Non-builder capture (arity 0) - -@available(SwiftStdlib 5.7, *) -extension Capture { - /// Creates a capture for the given component. - /// - /// - Parameter component: The regex component to capture. - @_disfavoredOverload - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent - ) where RegexOutput == (Substring, W) { - let factory = makeFactory() - self.init(factory.capture(component)) - } - - /// Creates a capture for the given component using the specified - /// reference. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - reference: The reference to use for anything captured by - /// `component`. - @_disfavoredOverload - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent, - as reference: Reference - ) where RegexOutput == (Substring, W) { - let factory = makeFactory() - self.init(factory.capture(component, reference._raw)) - } - - /// Creates a capture for the given component, transforming with the - /// given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_disfavoredOverload - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture) { - let factory = makeFactory() - self.init(factory.capture(component, nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, transforming with the given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - reference: The reference to use for anything captured by - /// `component`. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_disfavoredOverload - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent, - as reference: Reference, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture) { - let factory = makeFactory() - self.init(factory.capture(component, reference._raw, transform)) - } -} - -@available(SwiftStdlib 5.7, *) -extension TryCapture { - /// Creates a capture for the given component, attempting to transform - /// with the given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_disfavoredOverload - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture) { - let factory = makeFactory() - self.init(factory.captureOptional(component, nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, attempting to transform with the given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - reference: The reference to use for anything captured by - /// `component`. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_disfavoredOverload - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent, - as reference: Reference, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture) { - let factory = makeFactory() - self.init(factory.captureOptional(component, reference._raw, transform)) - } -} -// MARK: - Builder capture (arity 0) - -@available(SwiftStdlib 5.7, *) -extension Capture { - /// Creates a capture for the given component. - /// - /// - Parameter componentBuilder: A builder closure that generates a - /// regex component to capture. - @_disfavoredOverload - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent - ) where RegexOutput == (Substring, W) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder())) - } - - /// Creates a capture for the given component using the specified - /// reference. - /// - /// - Parameters: - /// - reference: The reference to use for anything captured by - /// `component`. - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - @_disfavoredOverload - @_alwaysEmitIntoClient - public init( - as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent - ) where RegexOutput == (Substring, W) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder(), reference._raw)) - } - - /// Creates a capture for the given component, transforming with the - /// given closure. - /// - /// - Parameters: - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_disfavoredOverload - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder(), nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, transforming with the given closure. - /// - /// - Parameters: - /// - reference: The reference to use for anything captured by - /// `component`. - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_disfavoredOverload - @_alwaysEmitIntoClient - public init( - as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder(), reference._raw, transform)) - } -} - -@available(SwiftStdlib 5.7, *) -extension TryCapture { - /// Creates a capture for the given component, attempting to transform - /// with the given closure. - /// - /// - Parameters: - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_disfavoredOverload - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture) { - let factory = makeFactory() - self.init(factory.captureOptional(componentBuilder(), nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, attempting to transform with the given closure. - /// - /// - Parameters: - /// - reference: The reference to use for anything captured by - /// `component`. - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_disfavoredOverload - @_alwaysEmitIntoClient - public init( - as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture) { - let factory = makeFactory() - self.init(factory.captureOptional(componentBuilder(), reference._raw, transform)) - } -} - -// MARK: - Non-builder capture (arity 1) - -@available(SwiftStdlib 5.7, *) -extension Capture { - /// Creates a capture for the given component. - /// - /// - Parameter component: The regex component to capture. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1)> - ) where RegexOutput == (Substring, W, C1) { - let factory = makeFactory() - self.init(factory.capture(component)) - } - - /// Creates a capture for the given component using the specified - /// reference. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - reference: The reference to use for anything captured by - /// `component`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1)>, - as reference: Reference - ) where RegexOutput == (Substring, W, C1) { - let factory = makeFactory() - self.init(factory.capture(component, reference._raw)) - } - - /// Creates a capture for the given component, transforming with the - /// given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1)>, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1) { - let factory = makeFactory() - self.init(factory.capture(component, nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, transforming with the given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - reference: The reference to use for anything captured by - /// `component`. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1)>, - as reference: Reference, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1) { - let factory = makeFactory() - self.init(factory.capture(component, reference._raw, transform)) - } -} - -@available(SwiftStdlib 5.7, *) -extension TryCapture { - /// Creates a capture for the given component, attempting to transform - /// with the given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1)>, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1) { - let factory = makeFactory() - self.init(factory.captureOptional(component, nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, attempting to transform with the given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - reference: The reference to use for anything captured by - /// `component`. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1)>, - as reference: Reference, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1) { - let factory = makeFactory() - self.init(factory.captureOptional(component, reference._raw, transform)) - } -} -// MARK: - Builder capture (arity 1) - -@available(SwiftStdlib 5.7, *) -extension Capture { - /// Creates a capture for the given component. - /// - /// - Parameter componentBuilder: A builder closure that generates a - /// regex component to capture. - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1)> - ) where RegexOutput == (Substring, W, C1) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder())) - } - - /// Creates a capture for the given component using the specified - /// reference. - /// - /// - Parameters: - /// - reference: The reference to use for anything captured by - /// `component`. - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - @_alwaysEmitIntoClient - public init( - as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1)> - ) where RegexOutput == (Substring, W, C1) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder(), reference._raw)) - } - - /// Creates a capture for the given component, transforming with the - /// given closure. - /// - /// - Parameters: - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1)>, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder(), nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, transforming with the given closure. - /// - /// - Parameters: - /// - reference: The reference to use for anything captured by - /// `component`. - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1)>, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder(), reference._raw, transform)) - } -} - -@available(SwiftStdlib 5.7, *) -extension TryCapture { - /// Creates a capture for the given component, attempting to transform - /// with the given closure. - /// - /// - Parameters: - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1)>, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1) { - let factory = makeFactory() - self.init(factory.captureOptional(componentBuilder(), nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, attempting to transform with the given closure. - /// - /// - Parameters: - /// - reference: The reference to use for anything captured by - /// `component`. - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1)>, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1) { - let factory = makeFactory() - self.init(factory.captureOptional(componentBuilder(), reference._raw, transform)) - } -} - -// MARK: - Non-builder capture (arity 2) - -@available(SwiftStdlib 5.7, *) -extension Capture { - /// Creates a capture for the given component. - /// - /// - Parameter component: The regex component to capture. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2)> - ) where RegexOutput == (Substring, W, C1, C2) { - let factory = makeFactory() - self.init(factory.capture(component)) - } - - /// Creates a capture for the given component using the specified - /// reference. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - reference: The reference to use for anything captured by - /// `component`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2)>, - as reference: Reference - ) where RegexOutput == (Substring, W, C1, C2) { - let factory = makeFactory() - self.init(factory.capture(component, reference._raw)) - } - - /// Creates a capture for the given component, transforming with the - /// given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2)>, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2) { - let factory = makeFactory() - self.init(factory.capture(component, nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, transforming with the given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - reference: The reference to use for anything captured by - /// `component`. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2)>, - as reference: Reference, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2) { - let factory = makeFactory() - self.init(factory.capture(component, reference._raw, transform)) - } -} - -@available(SwiftStdlib 5.7, *) -extension TryCapture { - /// Creates a capture for the given component, attempting to transform - /// with the given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2)>, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2) { - let factory = makeFactory() - self.init(factory.captureOptional(component, nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, attempting to transform with the given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - reference: The reference to use for anything captured by - /// `component`. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2)>, - as reference: Reference, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2) { - let factory = makeFactory() - self.init(factory.captureOptional(component, reference._raw, transform)) - } -} -// MARK: - Builder capture (arity 2) - -@available(SwiftStdlib 5.7, *) -extension Capture { - /// Creates a capture for the given component. - /// - /// - Parameter componentBuilder: A builder closure that generates a - /// regex component to capture. - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2)> - ) where RegexOutput == (Substring, W, C1, C2) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder())) - } - - /// Creates a capture for the given component using the specified - /// reference. - /// - /// - Parameters: - /// - reference: The reference to use for anything captured by - /// `component`. - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - @_alwaysEmitIntoClient - public init( - as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2)> - ) where RegexOutput == (Substring, W, C1, C2) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder(), reference._raw)) - } - - /// Creates a capture for the given component, transforming with the - /// given closure. - /// - /// - Parameters: - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2)>, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder(), nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, transforming with the given closure. - /// - /// - Parameters: - /// - reference: The reference to use for anything captured by - /// `component`. - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2)>, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder(), reference._raw, transform)) - } -} - -@available(SwiftStdlib 5.7, *) -extension TryCapture { - /// Creates a capture for the given component, attempting to transform - /// with the given closure. - /// - /// - Parameters: - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2)>, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2) { - let factory = makeFactory() - self.init(factory.captureOptional(componentBuilder(), nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, attempting to transform with the given closure. - /// - /// - Parameters: - /// - reference: The reference to use for anything captured by - /// `component`. - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2)>, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2) { - let factory = makeFactory() - self.init(factory.captureOptional(componentBuilder(), reference._raw, transform)) - } -} - -// MARK: - Non-builder capture (arity 3) - -@available(SwiftStdlib 5.7, *) -extension Capture { - /// Creates a capture for the given component. - /// - /// - Parameter component: The regex component to capture. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3)> - ) where RegexOutput == (Substring, W, C1, C2, C3) { - let factory = makeFactory() - self.init(factory.capture(component)) - } - - /// Creates a capture for the given component using the specified - /// reference. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - reference: The reference to use for anything captured by - /// `component`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3)>, - as reference: Reference - ) where RegexOutput == (Substring, W, C1, C2, C3) { - let factory = makeFactory() - self.init(factory.capture(component, reference._raw)) - } - - /// Creates a capture for the given component, transforming with the - /// given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3)>, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3) { - let factory = makeFactory() - self.init(factory.capture(component, nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, transforming with the given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - reference: The reference to use for anything captured by - /// `component`. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3)>, - as reference: Reference, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3) { - let factory = makeFactory() - self.init(factory.capture(component, reference._raw, transform)) - } -} - -@available(SwiftStdlib 5.7, *) -extension TryCapture { - /// Creates a capture for the given component, attempting to transform - /// with the given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3)>, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3) { - let factory = makeFactory() - self.init(factory.captureOptional(component, nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, attempting to transform with the given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - reference: The reference to use for anything captured by - /// `component`. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3)>, - as reference: Reference, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3) { - let factory = makeFactory() - self.init(factory.captureOptional(component, reference._raw, transform)) - } -} -// MARK: - Builder capture (arity 3) - -@available(SwiftStdlib 5.7, *) -extension Capture { - /// Creates a capture for the given component. - /// - /// - Parameter componentBuilder: A builder closure that generates a - /// regex component to capture. - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3)> - ) where RegexOutput == (Substring, W, C1, C2, C3) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder())) - } - - /// Creates a capture for the given component using the specified - /// reference. - /// - /// - Parameters: - /// - reference: The reference to use for anything captured by - /// `component`. - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - @_alwaysEmitIntoClient - public init( - as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3)> - ) where RegexOutput == (Substring, W, C1, C2, C3) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder(), reference._raw)) - } - - /// Creates a capture for the given component, transforming with the - /// given closure. - /// - /// - Parameters: - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3)>, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder(), nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, transforming with the given closure. - /// - /// - Parameters: - /// - reference: The reference to use for anything captured by - /// `component`. - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3)>, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder(), reference._raw, transform)) - } -} - -@available(SwiftStdlib 5.7, *) -extension TryCapture { - /// Creates a capture for the given component, attempting to transform - /// with the given closure. - /// - /// - Parameters: - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3)>, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3) { - let factory = makeFactory() - self.init(factory.captureOptional(componentBuilder(), nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, attempting to transform with the given closure. - /// - /// - Parameters: - /// - reference: The reference to use for anything captured by - /// `component`. - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3)>, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3) { - let factory = makeFactory() - self.init(factory.captureOptional(componentBuilder(), reference._raw, transform)) - } -} - -// MARK: - Non-builder capture (arity 4) - -@available(SwiftStdlib 5.7, *) -extension Capture { - /// Creates a capture for the given component. - /// - /// - Parameter component: The regex component to capture. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4)> - ) where RegexOutput == (Substring, W, C1, C2, C3, C4) { - let factory = makeFactory() - self.init(factory.capture(component)) - } - - /// Creates a capture for the given component using the specified - /// reference. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - reference: The reference to use for anything captured by - /// `component`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4)>, - as reference: Reference - ) where RegexOutput == (Substring, W, C1, C2, C3, C4) { - let factory = makeFactory() - self.init(factory.capture(component, reference._raw)) - } - - /// Creates a capture for the given component, transforming with the - /// given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4)>, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4) { - let factory = makeFactory() - self.init(factory.capture(component, nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, transforming with the given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - reference: The reference to use for anything captured by - /// `component`. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4)>, - as reference: Reference, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4) { - let factory = makeFactory() - self.init(factory.capture(component, reference._raw, transform)) - } -} - -@available(SwiftStdlib 5.7, *) -extension TryCapture { - /// Creates a capture for the given component, attempting to transform - /// with the given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4)>, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4) { - let factory = makeFactory() - self.init(factory.captureOptional(component, nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, attempting to transform with the given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - reference: The reference to use for anything captured by - /// `component`. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4)>, - as reference: Reference, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4) { - let factory = makeFactory() - self.init(factory.captureOptional(component, reference._raw, transform)) - } -} -// MARK: - Builder capture (arity 4) - -@available(SwiftStdlib 5.7, *) -extension Capture { - /// Creates a capture for the given component. - /// - /// - Parameter componentBuilder: A builder closure that generates a - /// regex component to capture. - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4)> - ) where RegexOutput == (Substring, W, C1, C2, C3, C4) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder())) - } - - /// Creates a capture for the given component using the specified - /// reference. - /// - /// - Parameters: - /// - reference: The reference to use for anything captured by - /// `component`. - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - @_alwaysEmitIntoClient - public init( - as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4)> - ) where RegexOutput == (Substring, W, C1, C2, C3, C4) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder(), reference._raw)) - } - - /// Creates a capture for the given component, transforming with the - /// given closure. - /// - /// - Parameters: - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4)>, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder(), nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, transforming with the given closure. - /// - /// - Parameters: - /// - reference: The reference to use for anything captured by - /// `component`. - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4)>, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder(), reference._raw, transform)) - } -} - -@available(SwiftStdlib 5.7, *) -extension TryCapture { - /// Creates a capture for the given component, attempting to transform - /// with the given closure. - /// - /// - Parameters: - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4)>, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4) { - let factory = makeFactory() - self.init(factory.captureOptional(componentBuilder(), nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, attempting to transform with the given closure. - /// - /// - Parameters: - /// - reference: The reference to use for anything captured by - /// `component`. - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4)>, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4) { - let factory = makeFactory() - self.init(factory.captureOptional(componentBuilder(), reference._raw, transform)) - } -} - -// MARK: - Non-builder capture (arity 5) - -@available(SwiftStdlib 5.7, *) -extension Capture { - /// Creates a capture for the given component. - /// - /// - Parameter component: The regex component to capture. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5)> - ) where RegexOutput == (Substring, W, C1, C2, C3, C4, C5) { - let factory = makeFactory() - self.init(factory.capture(component)) - } - - /// Creates a capture for the given component using the specified - /// reference. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - reference: The reference to use for anything captured by - /// `component`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5)>, - as reference: Reference - ) where RegexOutput == (Substring, W, C1, C2, C3, C4, C5) { - let factory = makeFactory() - self.init(factory.capture(component, reference._raw)) - } - - /// Creates a capture for the given component, transforming with the - /// given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5)>, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5) { - let factory = makeFactory() - self.init(factory.capture(component, nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, transforming with the given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - reference: The reference to use for anything captured by - /// `component`. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5)>, - as reference: Reference, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5) { - let factory = makeFactory() - self.init(factory.capture(component, reference._raw, transform)) - } -} - -@available(SwiftStdlib 5.7, *) -extension TryCapture { - /// Creates a capture for the given component, attempting to transform - /// with the given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5)>, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5) { - let factory = makeFactory() - self.init(factory.captureOptional(component, nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, attempting to transform with the given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - reference: The reference to use for anything captured by - /// `component`. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5)>, - as reference: Reference, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5) { - let factory = makeFactory() - self.init(factory.captureOptional(component, reference._raw, transform)) - } -} -// MARK: - Builder capture (arity 5) - -@available(SwiftStdlib 5.7, *) -extension Capture { - /// Creates a capture for the given component. - /// - /// - Parameter componentBuilder: A builder closure that generates a - /// regex component to capture. - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5)> - ) where RegexOutput == (Substring, W, C1, C2, C3, C4, C5) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder())) - } - - /// Creates a capture for the given component using the specified - /// reference. - /// - /// - Parameters: - /// - reference: The reference to use for anything captured by - /// `component`. - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - @_alwaysEmitIntoClient - public init( - as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5)> - ) where RegexOutput == (Substring, W, C1, C2, C3, C4, C5) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder(), reference._raw)) - } - - /// Creates a capture for the given component, transforming with the - /// given closure. - /// - /// - Parameters: - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5)>, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder(), nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, transforming with the given closure. - /// - /// - Parameters: - /// - reference: The reference to use for anything captured by - /// `component`. - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5)>, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder(), reference._raw, transform)) - } -} - -@available(SwiftStdlib 5.7, *) -extension TryCapture { - /// Creates a capture for the given component, attempting to transform - /// with the given closure. - /// - /// - Parameters: - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5)>, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5) { - let factory = makeFactory() - self.init(factory.captureOptional(componentBuilder(), nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, attempting to transform with the given closure. - /// - /// - Parameters: - /// - reference: The reference to use for anything captured by - /// `component`. - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5)>, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5) { - let factory = makeFactory() - self.init(factory.captureOptional(componentBuilder(), reference._raw, transform)) - } -} - -// MARK: - Non-builder capture (arity 6) - -@available(SwiftStdlib 5.7, *) -extension Capture { - /// Creates a capture for the given component. - /// - /// - Parameter component: The regex component to capture. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6)> - ) where RegexOutput == (Substring, W, C1, C2, C3, C4, C5, C6) { - let factory = makeFactory() - self.init(factory.capture(component)) - } - - /// Creates a capture for the given component using the specified - /// reference. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - reference: The reference to use for anything captured by - /// `component`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6)>, - as reference: Reference - ) where RegexOutput == (Substring, W, C1, C2, C3, C4, C5, C6) { - let factory = makeFactory() - self.init(factory.capture(component, reference._raw)) - } - - /// Creates a capture for the given component, transforming with the - /// given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6)>, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6) { - let factory = makeFactory() - self.init(factory.capture(component, nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, transforming with the given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - reference: The reference to use for anything captured by - /// `component`. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6)>, - as reference: Reference, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6) { - let factory = makeFactory() - self.init(factory.capture(component, reference._raw, transform)) - } -} - -@available(SwiftStdlib 5.7, *) -extension TryCapture { - /// Creates a capture for the given component, attempting to transform - /// with the given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6)>, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6) { - let factory = makeFactory() - self.init(factory.captureOptional(component, nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, attempting to transform with the given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - reference: The reference to use for anything captured by - /// `component`. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6)>, - as reference: Reference, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6) { - let factory = makeFactory() - self.init(factory.captureOptional(component, reference._raw, transform)) - } -} -// MARK: - Builder capture (arity 6) - -@available(SwiftStdlib 5.7, *) -extension Capture { - /// Creates a capture for the given component. - /// - /// - Parameter componentBuilder: A builder closure that generates a - /// regex component to capture. - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6)> - ) where RegexOutput == (Substring, W, C1, C2, C3, C4, C5, C6) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder())) - } - - /// Creates a capture for the given component using the specified - /// reference. - /// - /// - Parameters: - /// - reference: The reference to use for anything captured by - /// `component`. - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - @_alwaysEmitIntoClient - public init( - as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6)> - ) where RegexOutput == (Substring, W, C1, C2, C3, C4, C5, C6) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder(), reference._raw)) - } - - /// Creates a capture for the given component, transforming with the - /// given closure. - /// - /// - Parameters: - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6)>, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder(), nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, transforming with the given closure. - /// - /// - Parameters: - /// - reference: The reference to use for anything captured by - /// `component`. - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6)>, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder(), reference._raw, transform)) - } -} - -@available(SwiftStdlib 5.7, *) -extension TryCapture { - /// Creates a capture for the given component, attempting to transform - /// with the given closure. - /// - /// - Parameters: - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6)>, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6) { - let factory = makeFactory() - self.init(factory.captureOptional(componentBuilder(), nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, attempting to transform with the given closure. - /// - /// - Parameters: - /// - reference: The reference to use for anything captured by - /// `component`. - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6)>, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6) { - let factory = makeFactory() - self.init(factory.captureOptional(componentBuilder(), reference._raw, transform)) - } -} - -// MARK: - Non-builder capture (arity 7) - -@available(SwiftStdlib 5.7, *) -extension Capture { - /// Creates a capture for the given component. - /// - /// - Parameter component: The regex component to capture. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7)> - ) where RegexOutput == (Substring, W, C1, C2, C3, C4, C5, C6, C7) { - let factory = makeFactory() - self.init(factory.capture(component)) - } - - /// Creates a capture for the given component using the specified - /// reference. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - reference: The reference to use for anything captured by - /// `component`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7)>, - as reference: Reference - ) where RegexOutput == (Substring, W, C1, C2, C3, C4, C5, C6, C7) { - let factory = makeFactory() - self.init(factory.capture(component, reference._raw)) - } - - /// Creates a capture for the given component, transforming with the - /// given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7)>, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7) { - let factory = makeFactory() - self.init(factory.capture(component, nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, transforming with the given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - reference: The reference to use for anything captured by - /// `component`. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7)>, - as reference: Reference, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7) { - let factory = makeFactory() - self.init(factory.capture(component, reference._raw, transform)) - } -} - -@available(SwiftStdlib 5.7, *) -extension TryCapture { - /// Creates a capture for the given component, attempting to transform - /// with the given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7)>, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7) { - let factory = makeFactory() - self.init(factory.captureOptional(component, nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, attempting to transform with the given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - reference: The reference to use for anything captured by - /// `component`. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7)>, - as reference: Reference, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7) { - let factory = makeFactory() - self.init(factory.captureOptional(component, reference._raw, transform)) - } -} -// MARK: - Builder capture (arity 7) - -@available(SwiftStdlib 5.7, *) -extension Capture { - /// Creates a capture for the given component. - /// - /// - Parameter componentBuilder: A builder closure that generates a - /// regex component to capture. - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7)> - ) where RegexOutput == (Substring, W, C1, C2, C3, C4, C5, C6, C7) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder())) - } - - /// Creates a capture for the given component using the specified - /// reference. - /// - /// - Parameters: - /// - reference: The reference to use for anything captured by - /// `component`. - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - @_alwaysEmitIntoClient - public init( - as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7)> - ) where RegexOutput == (Substring, W, C1, C2, C3, C4, C5, C6, C7) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder(), reference._raw)) - } - - /// Creates a capture for the given component, transforming with the - /// given closure. - /// - /// - Parameters: - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7)>, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder(), nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, transforming with the given closure. - /// - /// - Parameters: - /// - reference: The reference to use for anything captured by - /// `component`. - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7)>, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder(), reference._raw, transform)) - } -} - -@available(SwiftStdlib 5.7, *) -extension TryCapture { - /// Creates a capture for the given component, attempting to transform - /// with the given closure. - /// - /// - Parameters: - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7)>, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7) { - let factory = makeFactory() - self.init(factory.captureOptional(componentBuilder(), nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, attempting to transform with the given closure. - /// - /// - Parameters: - /// - reference: The reference to use for anything captured by - /// `component`. - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7)>, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7) { - let factory = makeFactory() - self.init(factory.captureOptional(componentBuilder(), reference._raw, transform)) - } -} - -// MARK: - Non-builder capture (arity 8) - -@available(SwiftStdlib 5.7, *) -extension Capture { - /// Creates a capture for the given component. - /// - /// - Parameter component: The regex component to capture. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8)> - ) where RegexOutput == (Substring, W, C1, C2, C3, C4, C5, C6, C7, C8) { - let factory = makeFactory() - self.init(factory.capture(component)) - } - - /// Creates a capture for the given component using the specified - /// reference. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - reference: The reference to use for anything captured by - /// `component`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8)>, - as reference: Reference - ) where RegexOutput == (Substring, W, C1, C2, C3, C4, C5, C6, C7, C8) { - let factory = makeFactory() - self.init(factory.capture(component, reference._raw)) - } - - /// Creates a capture for the given component, transforming with the - /// given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8)>, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7, C8) { - let factory = makeFactory() - self.init(factory.capture(component, nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, transforming with the given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - reference: The reference to use for anything captured by - /// `component`. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8)>, - as reference: Reference, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7, C8) { - let factory = makeFactory() - self.init(factory.capture(component, reference._raw, transform)) - } -} - -@available(SwiftStdlib 5.7, *) -extension TryCapture { - /// Creates a capture for the given component, attempting to transform - /// with the given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8)>, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7, C8) { - let factory = makeFactory() - self.init(factory.captureOptional(component, nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, attempting to transform with the given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - reference: The reference to use for anything captured by - /// `component`. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8)>, - as reference: Reference, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7, C8) { - let factory = makeFactory() - self.init(factory.captureOptional(component, reference._raw, transform)) - } -} -// MARK: - Builder capture (arity 8) - -@available(SwiftStdlib 5.7, *) -extension Capture { - /// Creates a capture for the given component. - /// - /// - Parameter componentBuilder: A builder closure that generates a - /// regex component to capture. - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8)> - ) where RegexOutput == (Substring, W, C1, C2, C3, C4, C5, C6, C7, C8) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder())) - } - - /// Creates a capture for the given component using the specified - /// reference. - /// - /// - Parameters: - /// - reference: The reference to use for anything captured by - /// `component`. - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - @_alwaysEmitIntoClient - public init( - as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8)> - ) where RegexOutput == (Substring, W, C1, C2, C3, C4, C5, C6, C7, C8) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder(), reference._raw)) - } - - /// Creates a capture for the given component, transforming with the - /// given closure. - /// - /// - Parameters: - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8)>, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7, C8) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder(), nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, transforming with the given closure. - /// - /// - Parameters: - /// - reference: The reference to use for anything captured by - /// `component`. - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8)>, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7, C8) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder(), reference._raw, transform)) - } -} - -@available(SwiftStdlib 5.7, *) -extension TryCapture { - /// Creates a capture for the given component, attempting to transform - /// with the given closure. - /// - /// - Parameters: - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8)>, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7, C8) { - let factory = makeFactory() - self.init(factory.captureOptional(componentBuilder(), nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, attempting to transform with the given closure. - /// - /// - Parameters: - /// - reference: The reference to use for anything captured by - /// `component`. - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8)>, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7, C8) { - let factory = makeFactory() - self.init(factory.captureOptional(componentBuilder(), reference._raw, transform)) - } -} - -// MARK: - Non-builder capture (arity 9) +// MARK: - Non-builder captures @available(SwiftStdlib 5.7, *) extension Capture { @@ -2743,9 +616,9 @@ extension Capture { /// /// - Parameter component: The regex component to capture. @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9)> - ) where RegexOutput == (Substring, W, C1, C2, C3, C4, C5, C6, C7, C8, C9) { + public init( + _ component: some RegexComponent<(W, repeat each Capture)> + ) where RegexOutput == (Substring, W, repeat each Capture) { let factory = makeFactory() self.init(factory.capture(component)) } @@ -2758,10 +631,10 @@ extension Capture { /// - reference: The reference to use for anything captured by /// `component`. @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9)>, + public init( + _ component: some RegexComponent<(W, repeat each Capture)>, as reference: Reference - ) where RegexOutput == (Substring, W, C1, C2, C3, C4, C5, C6, C7, C8, C9) { + ) where RegexOutput == (Substring, W, repeat each Capture) { let factory = makeFactory() self.init(factory.capture(component, reference._raw)) } @@ -2776,10 +649,10 @@ extension Capture { /// throws an error, matching is abandoned and the error is returned /// to the caller. @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9)>, + public init( + _ component: some RegexComponent<(W, repeat each Capture)>, transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7, C8, C9) { + ) where RegexOutput == (Substring, NewCapture, repeat each Capture) { let factory = makeFactory() self.init(factory.capture(component, nil, transform)) } @@ -2796,11 +669,11 @@ extension Capture { /// throws an error, matching is abandoned and the error is returned /// to the caller. @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9)>, + public init( + _ component: some RegexComponent<(W, repeat each Capture)>, as reference: Reference, transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7, C8, C9) { + ) where RegexOutput == (Substring, NewCapture, repeat each Capture) { let factory = makeFactory() self.init(factory.capture(component, reference._raw, transform)) } @@ -2819,10 +692,10 @@ extension TryCapture { /// throws an error, matching is abandoned and the error is returned /// to the caller. @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9)>, + public init( + _ component: some RegexComponent<(W, repeat each Capture)>, transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7, C8, C9) { + ) where RegexOutput == (Substring, NewCapture, repeat each Capture) { let factory = makeFactory() self.init(factory.captureOptional(component, nil, transform)) } @@ -2840,251 +713,17 @@ extension TryCapture { /// throws an error, matching is abandoned and the error is returned /// to the caller. @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9)>, + public init( + _ component: some RegexComponent<(W, repeat each Capture)>, as reference: Reference, transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7, C8, C9) { + ) where RegexOutput == (Substring, NewCapture, repeat each Capture) { let factory = makeFactory() self.init(factory.captureOptional(component, reference._raw, transform)) } } -// MARK: - Builder capture (arity 9) - -@available(SwiftStdlib 5.7, *) -extension Capture { - /// Creates a capture for the given component. - /// - /// - Parameter componentBuilder: A builder closure that generates a - /// regex component to capture. - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9)> - ) where RegexOutput == (Substring, W, C1, C2, C3, C4, C5, C6, C7, C8, C9) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder())) - } - - /// Creates a capture for the given component using the specified - /// reference. - /// - /// - Parameters: - /// - reference: The reference to use for anything captured by - /// `component`. - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - @_alwaysEmitIntoClient - public init( - as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9)> - ) where RegexOutput == (Substring, W, C1, C2, C3, C4, C5, C6, C7, C8, C9) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder(), reference._raw)) - } - - /// Creates a capture for the given component, transforming with the - /// given closure. - /// - /// - Parameters: - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9)>, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7, C8, C9) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder(), nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, transforming with the given closure. - /// - /// - Parameters: - /// - reference: The reference to use for anything captured by - /// `component`. - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9)>, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7, C8, C9) { - let factory = makeFactory() - self.init(factory.capture(componentBuilder(), reference._raw, transform)) - } -} - -@available(SwiftStdlib 5.7, *) -extension TryCapture { - /// Creates a capture for the given component, attempting to transform - /// with the given closure. - /// - /// - Parameters: - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9)>, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7, C8, C9) { - let factory = makeFactory() - self.init(factory.captureOptional(componentBuilder(), nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, attempting to transform with the given closure. - /// - /// - Parameters: - /// - reference: The reference to use for anything captured by - /// `component`. - /// - componentBuilder: A builder closure that generates a regex - /// component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9)>, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7, C8, C9) { - let factory = makeFactory() - self.init(factory.captureOptional(componentBuilder(), reference._raw, transform)) - } -} - -// MARK: - Non-builder capture (arity 10) - -@available(SwiftStdlib 5.7, *) -extension Capture { - /// Creates a capture for the given component. - /// - /// - Parameter component: The regex component to capture. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)> - ) where RegexOutput == (Substring, W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10) { - let factory = makeFactory() - self.init(factory.capture(component)) - } - - /// Creates a capture for the given component using the specified - /// reference. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - reference: The reference to use for anything captured by - /// `component`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)>, - as reference: Reference - ) where RegexOutput == (Substring, W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10) { - let factory = makeFactory() - self.init(factory.capture(component, reference._raw)) - } - - /// Creates a capture for the given component, transforming with the - /// given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)>, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10) { - let factory = makeFactory() - self.init(factory.capture(component, nil, transform)) - } - - /// Creates a capture for the given component using the specified - /// reference, transforming with the given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - reference: The reference to use for anything captured by - /// `component`. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)>, - as reference: Reference, - transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10) { - let factory = makeFactory() - self.init(factory.capture(component, reference._raw, transform)) - } -} - -@available(SwiftStdlib 5.7, *) -extension TryCapture { - /// Creates a capture for the given component, attempting to transform - /// with the given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)>, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10) { - let factory = makeFactory() - self.init(factory.captureOptional(component, nil, transform)) - } - /// Creates a capture for the given component using the specified - /// reference, attempting to transform with the given closure. - /// - /// - Parameters: - /// - component: The regex component to capture. - /// - reference: The reference to use for anything captured by - /// `component`. - /// - transform: A closure that takes the substring matched by - /// `component` and returns a new value to capture, or `nil` if - /// matching should proceed, backtracking if allowed. If `transform` - /// throws an error, matching is abandoned and the error is returned - /// to the caller. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)>, - as reference: Reference, - transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10) { - let factory = makeFactory() - self.init(factory.captureOptional(component, reference._raw, transform)) - } -} -// MARK: - Builder capture (arity 10) +// MARK: - Builder captures @available(SwiftStdlib 5.7, *) extension Capture { @@ -3093,9 +732,9 @@ extension Capture { /// - Parameter componentBuilder: A builder closure that generates a /// regex component to capture. @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)> - ) where RegexOutput == (Substring, W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10) { + public init( + @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, repeat each Capture)> + ) where RegexOutput == (Substring, W, repeat each Capture) { let factory = makeFactory() self.init(factory.capture(componentBuilder())) } @@ -3109,10 +748,10 @@ extension Capture { /// - componentBuilder: A builder closure that generates a regex /// component to capture. @_alwaysEmitIntoClient - public init( + public init( as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)> - ) where RegexOutput == (Substring, W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10) { + @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, repeat each Capture)> + ) where RegexOutput == (Substring, W, repeat each Capture) { let factory = makeFactory() self.init(factory.capture(componentBuilder(), reference._raw)) } @@ -3128,10 +767,10 @@ extension Capture { /// throws an error, matching is abandoned and the error is returned /// to the caller. @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)>, + public init( + @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, repeat each Capture)>, transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10) { + ) where RegexOutput == (Substring, NewCapture, repeat each Capture) { let factory = makeFactory() self.init(factory.capture(componentBuilder(), nil, transform)) } @@ -3149,11 +788,11 @@ extension Capture { /// throws an error, matching is abandoned and the error is returned /// to the caller. @_alwaysEmitIntoClient - public init( + public init( as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)>, + @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, repeat each Capture)>, transform: @escaping (W) throws -> NewCapture - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10) { + ) where RegexOutput == (Substring, NewCapture, repeat each Capture) { let factory = makeFactory() self.init(factory.capture(componentBuilder(), reference._raw, transform)) } @@ -3173,10 +812,10 @@ extension TryCapture { /// throws an error, matching is abandoned and the error is returned /// to the caller. @_alwaysEmitIntoClient - public init( - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)>, + public init( + @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, repeat each Capture)>, transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10) { + ) where RegexOutput == (Substring, NewCapture, repeat each Capture) { let factory = makeFactory() self.init(factory.captureOptional(componentBuilder(), nil, transform)) } @@ -3195,16 +834,12 @@ extension TryCapture { /// throws an error, matching is abandoned and the error is returned /// to the caller. @_alwaysEmitIntoClient - public init( + public init( as reference: Reference, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)>, + @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, repeat each Capture)>, transform: @escaping (W) throws -> NewCapture? - ) where RegexOutput == (Substring, NewCapture, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10) { + ) where RegexOutput == (Substring, NewCapture, repeat each Capture) { let factory = makeFactory() self.init(factory.captureOptional(componentBuilder(), reference._raw, transform)) } } - - - -// END AUTO-GENERATED CONTENT From e1ed179c7710c586290d171a96b96e2212af2d56 Mon Sep 17 00:00:00 2001 From: Nate Cook Date: Fri, 8 Mar 2024 16:00:06 -0600 Subject: [PATCH 06/11] Add test for deeply/strangly nested builder regexes --- Tests/RegexBuilderTests/RegexDSLTests.swift | 66 +++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/Tests/RegexBuilderTests/RegexDSLTests.swift b/Tests/RegexBuilderTests/RegexDSLTests.swift index eb7b73033..e37855367 100644 --- a/Tests/RegexBuilderTests/RegexDSLTests.swift +++ b/Tests/RegexBuilderTests/RegexDSLTests.swift @@ -1963,6 +1963,72 @@ extension RegexDSLTests { XCTAssertEqual(anyOutput[15].value as? Int, 123) XCTAssertEqual(anyOutput[16].substring, "456") } + + func testDeeplyNestedCapture() throws { + // Broken up: 'unable to type-check this expression in reasonable time' + let r0 = Optionally { + Capture { + OneOrMore(CharacterClass.digit) + } + } + let r1 = ZeroOrMore { + Capture { + r0 + } + } + let regex = Regex { + Capture { + OneOrMore { + Capture { + r1 + } + } + } + } + XCTAssert(type(of: regex).self + == Regex<(Substring, Substring, Substring, Substring?, Substring??)>.self) + let match = try XCTUnwrap("123".wholeMatch(of: regex)) + XCTAssertEqual(match.output.0, "123") + XCTAssertEqual(match.output.1, "123") + XCTAssertEqual(match.output.4, "123") + // Because capture groups only retain the last capture, these two groups + // are the empty string. After matching/capturing "123", the outer + // `OneOrMore` loops again, and since the innermost quanitifier is optional, + // the second loop matches the empty substring at the end of the input. + // That empty substring is then captured by capture groups 2 and 3. + XCTAssertEqual(match.output.2, "") + XCTAssertEqual(match.output.3, "") + } + + func testVariedNesting() throws { + let regex = Regex { + "a" + OneOrMore { + Capture { + Optionally { + Capture { + "b" + } + } + "c" + } + "d" + } + "e" + ZeroOrMore { + Capture { + "f" + } + } + } + XCTAssert(type(of: regex).self + == Regex<(Substring, Substring, Substring?, Substring?)>.self) + let match = try XCTUnwrap("acdbcdcde".wholeMatch(of: regex)) + XCTAssertEqual(match.output.0, "acdbcdcde") + XCTAssertEqual(match.output.1, "c") + XCTAssertEqual(match.output.2, "b") + XCTAssertNil(match.output.3) + } } extension Unicode.Scalar { From 9430a76c9b8b62fd0c850947dcaee2af9ee07834 Mon Sep 17 00:00:00 2001 From: Nate Cook Date: Sat, 9 Mar 2024 16:02:33 -0600 Subject: [PATCH 07/11] Consolidate variadic quantifier implementations --- Sources/RegexBuilder/Variadics.swift | 365 +++++++++++++-------------- 1 file changed, 174 insertions(+), 191 deletions(-) diff --git a/Sources/RegexBuilder/Variadics.swift b/Sources/RegexBuilder/Variadics.swift index 9ceaaea8e..2a2d8b9e7 100644 --- a/Sources/RegexBuilder/Variadics.swift +++ b/Sources/RegexBuilder/Variadics.swift @@ -58,7 +58,7 @@ extension RegexComponentBuilder { } } -// MARK: - Quantifiers (no output captures) +// MARK: - Quantifiers @available(SwiftStdlib 5.7, *) extension Optionally { @@ -82,6 +82,25 @@ extension Optionally { self.init(factory.zeroOrOne(component, behavior)) } + /// Creates a regex component that matches the given component + /// zero or one times. + /// + /// - Parameters: + /// - component: The regex component. + /// - behavior: The repetition behavior to use when repeating + /// `component` in the match. If `behavior` is `nil`, the default + /// repetition behavior is used, which can be changed from + /// `eager` by calling `repetitionBehavior(_:)` on the resulting + /// `Regex`. + @_alwaysEmitIntoClient + public init( + _ component: some RegexComponent<(C0, C1, repeat each Capture)>, + _ behavior: RegexRepetitionBehavior? = nil + ) where RegexOutput == (Substring, C1, repeat (each Capture)?) { + let factory = makeFactory() + self.init(factory.zeroOrOne(component, behavior)) + } + /// Creates a regex component that matches the given component /// zero or one times. /// @@ -102,6 +121,26 @@ extension Optionally { let factory = makeFactory() self.init(factory.zeroOrOne(componentBuilder(), behavior)) } + + /// Creates a regex component that matches the given component + /// zero or one times. + /// + /// - Parameters: + /// - behavior: The repetition behavior to use when repeating + /// `component` in the match. If `behavior` is `nil`, the default + /// repetition behavior is used, which can be changed from + /// `eager` by calling `repetitionBehavior(_:)` on the resulting + /// `Regex`. + /// - componentBuilder: A builder closure that generates a regex + /// component. + @_alwaysEmitIntoClient + public init( + _ behavior: RegexRepetitionBehavior? = nil, + @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(C0, C1, repeat each Capture)> + ) where RegexOutput == (Substring, C1?, repeat (each Capture)?) { + let factory = makeFactory() + self.init(factory.zeroOrOne(componentBuilder(), behavior)) + } } @available(SwiftStdlib 5.7, *) @@ -114,6 +153,14 @@ extension RegexComponentBuilder { let factory = makeFactory() return factory.zeroOrOne(component, nil) } + + @_alwaysEmitIntoClient + public static func buildLimitedAvailability( + _ component: some RegexComponent<(C0, C1, repeat each Capture)> + ) -> Regex<(Substring, C1?, repeat (each Capture)?)> { + let factory = makeFactory() + return factory.zeroOrOne(component, nil) + } } @available(SwiftStdlib 5.7, *) @@ -142,48 +189,44 @@ extension ZeroOrMore { /// zero or more times. /// /// - Parameters: + /// - component: The regex component. /// - behavior: The repetition behavior to use when repeating /// `component` in the match. If `behavior` is `nil`, the default /// repetition behavior is used, which can be changed from /// `eager` by calling `repetitionBehavior(_:)` on the resulting /// `Regex`. - /// - componentBuilder: A builder closure that generates a regex - /// component. - @_disfavoredOverload @_alwaysEmitIntoClient - public init( - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent - ) where RegexOutput == Substring { + public init( + _ component: some RegexComponent<(C0, C1, repeat each Capture)>, + _ behavior: RegexRepetitionBehavior? = nil + ) where RegexOutput == (Substring, C1?, repeat (each Capture)?) { let factory = makeFactory() - self.init(factory.zeroOrMore(componentBuilder(), behavior)) + self.init(factory.zeroOrMore(component, behavior)) } -} -@available(SwiftStdlib 5.7, *) -extension OneOrMore { /// Creates a regex component that matches the given component - /// one or more times. + /// zero or more times. /// /// - Parameters: - /// - component: The regex component. /// - behavior: The repetition behavior to use when repeating /// `component` in the match. If `behavior` is `nil`, the default /// repetition behavior is used, which can be changed from /// `eager` by calling `repetitionBehavior(_:)` on the resulting /// `Regex`. + /// - componentBuilder: A builder closure that generates a regex + /// component. @_disfavoredOverload @_alwaysEmitIntoClient public init( - _ component: some RegexComponent, - _ behavior: RegexRepetitionBehavior? = nil + _ behavior: RegexRepetitionBehavior? = nil, + @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent ) where RegexOutput == Substring { let factory = makeFactory() - self.init(factory.oneOrMore(component, behavior)) + self.init(factory.zeroOrMore(componentBuilder(), behavior)) } /// Creates a regex component that matches the given component - /// one or more times. + /// zero or more times. /// /// - Parameters: /// - behavior: The repetition behavior to use when repeating @@ -193,63 +236,23 @@ extension OneOrMore { /// `Regex`. /// - componentBuilder: A builder closure that generates a regex /// component. - @_disfavoredOverload @_alwaysEmitIntoClient - public init( + public init( _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent - ) where RegexOutput == Substring { + @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(C0, C1, repeat each Capture)> + ) where RegexOutput == (Substring, C1?, repeat (each Capture)?) { let factory = makeFactory() - self.init(factory.oneOrMore(componentBuilder(), behavior)) + self.init(factory.zeroOrMore(componentBuilder(), behavior)) } } @available(SwiftStdlib 5.7, *) -extension Repeat { - /// Creates a regex component that matches the given component repeated - /// the specified number of times. - /// - /// - Parameters: - /// - component: The regex component to repeat. - /// - count: The number of times to repeat `component`. `count` must - /// be greater than or equal to zero. - @_disfavoredOverload - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent, - count: Int - ) where RegexOutput == Substring { - precondition(count >= 0, "Must specify a positive count") - let factory = makeFactory() - self.init(factory.exactly(count, component)) - } - - /// Creates a regex component that matches the given component repeated - /// the specified number of times. - /// - /// - Parameters: - /// - count: The number of times to repeat `component`. `count` must - /// be greater than or equal to zero. - /// - componentBuilder: A builder closure that creates the regex - /// component to repeat. - @_disfavoredOverload - @_alwaysEmitIntoClient - public init( - count: Int, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent - ) where RegexOutput == Substring { - precondition(count >= 0, "Must specify a positive count") - let factory = makeFactory() - self.init(factory.exactly(count, componentBuilder())) - } - - /// Creates a regex component that matches the given component repeated - /// a number of times specified by the given range expression. +extension OneOrMore { + /// Creates a regex component that matches the given component + /// one or more times. /// /// - Parameters: - /// - component: The regex component to repeat. - /// - expression: A range expression specifying the number of times - /// that `component` can repeat. + /// - component: The regex component. /// - behavior: The repetition behavior to use when repeating /// `component` in the match. If `behavior` is `nil`, the default /// repetition behavior is used, which can be changed from @@ -259,44 +262,14 @@ extension Repeat { @_alwaysEmitIntoClient public init( _ component: some RegexComponent, - _ expression: some RangeExpression, _ behavior: RegexRepetitionBehavior? = nil ) where RegexOutput == Substring { let factory = makeFactory() - self.init(factory.repeating(expression.relative(to: 0.., - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent - ) where RegexOutput == Substring { - let factory = makeFactory() - self.init(factory.repeating(expression.relative(to: 0..( - _ component: some RegexComponent<(W, Capture0, repeat each Capture)>, + public init( + _ component: some RegexComponent<(C0, C1, repeat each Capture)>, _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, (Capture0, repeat each Capture)?) { + ) where RegexOutput == (Substring, C1, repeat each Capture) { let factory = makeFactory() - self.init(factory.zeroOrOne(component, behavior)) + self.init(factory.oneOrMore(component, behavior)) } - + /// Creates a regex component that matches the given component - /// zero or one times. + /// one or more times. /// /// - Parameters: /// - behavior: The repetition behavior to use when repeating @@ -325,50 +298,18 @@ extension Optionally { /// `Regex`. /// - componentBuilder: A builder closure that generates a regex /// component. + @_disfavoredOverload @_alwaysEmitIntoClient - public init( + public init( _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, Capture0, repeat each Capture)> - ) where RegexOutput == (Substring, (Capture0, repeat each Capture)?) { - let factory = makeFactory() - self.init(factory.zeroOrOne(componentBuilder(), behavior)) - } -} - -@available(SwiftStdlib 5.7, *) -extension RegexComponentBuilder { - @_alwaysEmitIntoClient - public static func buildLimitedAvailability( - _ component: some RegexComponent<(W, Capture0, repeat each Capture)> - ) -> Regex<(Substring, (Capture0, repeat each Capture)?)> { - let factory = makeFactory() - return factory.zeroOrOne(component, nil) - } -} - -@available(SwiftStdlib 5.7, *) -extension ZeroOrMore { - /// Creates a regex component that matches the given component - /// zero or more times. - /// - /// - Parameters: - /// - component: The regex component. - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, Capture0, repeat each Capture)>, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, (Capture0, repeat each Capture)?) { + @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent + ) where RegexOutput == Substring { let factory = makeFactory() - self.init(factory.zeroOrMore(component, behavior)) + self.init(factory.oneOrMore(componentBuilder(), behavior)) } /// Creates a regex component that matches the given component - /// zero or more times. + /// one or more times. /// /// - Parameters: /// - behavior: The repetition behavior to use when repeating @@ -379,59 +320,54 @@ extension ZeroOrMore { /// - componentBuilder: A builder closure that generates a regex /// component. @_alwaysEmitIntoClient - public init( + public init( _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, Capture0, repeat each Capture)> - ) where RegexOutput == (Substring, (Capture0, repeat each Capture)?) { + @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(C0, C1, repeat each Capture)> + ) where RegexOutput == (Substring, C1, repeat each Capture) { let factory = makeFactory() - self.init(factory.zeroOrMore(componentBuilder(), behavior)) + self.init(factory.oneOrMore(componentBuilder(), behavior)) } } @available(SwiftStdlib 5.7, *) -extension OneOrMore { - /// Creates a regex component that matches the given component - /// one or more times. +extension Repeat { + /// Creates a regex component that matches the given component repeated + /// the specified number of times. /// /// - Parameters: - /// - component: The regex component. - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. + /// - component: The regex component to repeat. + /// - count: The number of times to repeat `component`. `count` must + /// be greater than or equal to zero. + @_disfavoredOverload @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, Capture0, repeat each Capture)>, - _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, Capture0, repeat each Capture) { + public init( + _ component: some RegexComponent, + count: Int + ) where RegexOutput == Substring { + precondition(count >= 0, "Must specify a positive count") let factory = makeFactory() - self.init(factory.oneOrMore(component, behavior)) + self.init(factory.exactly(count, component)) } - /// Creates a regex component that matches the given component - /// one or more times. + /// Creates a regex component that matches the given component repeated + /// the specified number of times. /// /// - Parameters: - /// - behavior: The repetition behavior to use when repeating - /// `component` in the match. If `behavior` is `nil`, the default - /// repetition behavior is used, which can be changed from - /// `eager` by calling `repetitionBehavior(_:)` on the resulting - /// `Regex`. - /// - componentBuilder: A builder closure that generates a regex - /// component. + /// - count: The number of times to repeat `component`. `count` must + /// be greater than or equal to zero. + /// - componentBuilder: A builder closure that creates the regex + /// component to repeat. + @_disfavoredOverload @_alwaysEmitIntoClient - public init( - _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, Capture0, repeat each Capture)> - ) where RegexOutput == (Substring, Capture0, repeat each Capture) { + public init( + count: Int, + @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent + ) where RegexOutput == Substring { + precondition(count >= 0, "Must specify a positive count") let factory = makeFactory() - self.init(factory.oneOrMore(componentBuilder(), behavior)) + self.init(factory.exactly(count, componentBuilder())) } -} -@available(SwiftStdlib 5.7, *) -extension Repeat { /// Creates a regex component that matches the given component repeated /// the specified number of times. /// @@ -440,10 +376,10 @@ extension Repeat { /// - count: The number of times to repeat `component`. `count` must /// be greater than or equal to zero. @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, Capture0, repeat each Capture)>, + public init( + _ component: some RegexComponent<(C0, C1, repeat each Capture)>, count: Int - ) where RegexOutput == (Substring, (Capture0, repeat each Capture)?) { + ) where RegexOutput == (Substring, C1?, repeat (each Capture)?) { precondition(count >= 0, "Must specify a positive count") let factory = makeFactory() self.init(factory.exactly(count, component)) @@ -458,10 +394,10 @@ extension Repeat { /// - componentBuilder: A builder closure that creates the regex /// component to repeat. @_alwaysEmitIntoClient - public init( + public init( count: Int, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, Capture0, repeat each Capture)> - ) where RegexOutput == (Substring, (Capture0, repeat each Capture)?) { + @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(C0, C1, repeat each Capture)> + ) where RegexOutput == (Substring, C1?, repeat (each Capture)?) { precondition(count >= 0, "Must specify a positive count") let factory = makeFactory() self.init(factory.exactly(count, componentBuilder())) @@ -479,15 +415,62 @@ extension Repeat { /// repetition behavior is used, which can be changed from /// `eager` by calling `repetitionBehavior(_:)` on the resulting /// `Regex`. + @_disfavoredOverload @_alwaysEmitIntoClient - public init( - _ component: some RegexComponent<(W, Capture0, repeat each Capture)>, + public init( + _ component: some RegexComponent, _ expression: some RangeExpression, _ behavior: RegexRepetitionBehavior? = nil - ) where RegexOutput == (Substring, (Capture0, repeat each Capture)?) { + ) where RegexOutput == Substring { let factory = makeFactory() self.init(factory.repeating(expression.relative(to: 0..( + _ component: some RegexComponent<(C0, C1, repeat each Capture)>, + _ expression: some RangeExpression, + _ behavior: RegexRepetitionBehavior? = nil + ) where RegexOutput == (Substring, C1?, repeat (each Capture)?) { + let factory = makeFactory() + self.init(factory.repeating(expression.relative(to: 0.., + _ behavior: RegexRepetitionBehavior? = nil, + @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent + ) where RegexOutput == Substring { + let factory = makeFactory() + self.init(factory.repeating(expression.relative(to: 0..( + public init( _ expression: some RangeExpression, _ behavior: RegexRepetitionBehavior? = nil, - @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(W, Capture0, repeat each Capture)> - ) where RegexOutput == (Substring, (Capture0, repeat each Capture)?) { + @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent<(C0, C1, repeat each Capture)> + ) where RegexOutput == (Substring, C1?, repeat (each Capture)?) { let factory = makeFactory() self.init(factory.repeating(expression.relative(to: 0..( accumulated: some RegexComponent<(W0, C0)>, next: some RegexComponent<(W1, C1)> - ) -> ChoiceOf<(Substring, Optional, Optional)> { + ) -> ChoiceOf<(Substring, C0?, C1?)> { let factory = makeFactory() return .init(factory.accumulateAlternation(accumulated, next)) } @@ -592,7 +575,7 @@ extension AlternationBuilder { public static func buildPartialBlock( accumulated: some RegexComponent<(W0, repeat each Capture0)>, next: some RegexComponent<(W1, repeat each Capture1)> - ) -> ChoiceOf<(Substring, repeat each Capture0, repeat Optional)> { + ) -> ChoiceOf<(Substring, repeat each Capture0, repeat (each Capture1)?)> { let factory = makeFactory() return .init(factory.accumulateAlternation(accumulated, next)) } From a82307b8c6cc31f058b28b2393aa30451b514f22 Mon Sep 17 00:00:00 2001 From: Nate Cook Date: Sat, 9 Mar 2024 16:03:04 -0600 Subject: [PATCH 08/11] Expand variadic compilation tests --- Tests/RegexBuilderTests/RegexDSLTests.swift | 90 +++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/Tests/RegexBuilderTests/RegexDSLTests.swift b/Tests/RegexBuilderTests/RegexDSLTests.swift index e37855367..e0c52a47c 100644 --- a/Tests/RegexBuilderTests/RegexDSLTests.swift +++ b/Tests/RegexBuilderTests/RegexDSLTests.swift @@ -1842,6 +1842,8 @@ fileprivate let regexWithCapture = #/:(\d+):/# fileprivate let regexWithLabeledCapture = #/:(?\d+):/# @available(SwiftStdlib 5.7, *) fileprivate let regexWithNonCapture = #/:(?:\d+):/# +@available(SwiftStdlib 5.7, *) +fileprivate let regexWithMultipleCaptures = #/:(\d+):(.+):(\d+):/# @available(SwiftStdlib 5.7, *) extension RegexDSLTests { @@ -1949,6 +1951,7 @@ extension RegexDSLTests { XCTAssertEqual(match.output.1, "AAA") // FIXME (Variadics): match.output.2 is no longer an `Int` // XCTAssertEqual(match.output.2, 123) +// FIXME (Variadics): match.output.3 is now the second letter of `regexWithTooManyCaptures`, i.e. "b" XCTAssertEqual(match.output.3, "456") // All captures groups are available through `AnyRegexOutput`. @@ -2029,6 +2032,93 @@ extension RegexDSLTests { XCTAssertEqual(match.output.2, "b") XCTAssertNil(match.output.3) } + + func testVariadicNesting_Compilation() { + let regex_OC = Regex { // sOCsco + "a" + Optionally { + Capture { "b" } + } + } + let _: Regex<(Substring, Substring?)> = regex_OC + + let regex_OCC = Regex { + "a" + Optionally { + Capture { "b" } + Capture { "c" } + } + } + let _: Regex<(Substring, Substring?, Substring?)> = regex_OCC + + let regex_O_OC = Regex { + Optionally { + regex_OC + } + } + let _: Regex<(Substring, Substring??)> = regex_O_OC + + let regex_O_OCC = Regex { + Optionally { + regex_OCC + } + } + let _: Regex<(Substring, Substring??, Substring??)> = regex_O_OCC + + let regex_O_OC_OC = Regex { + Optionally { + regex_OC + regex_OC + } + } + let _: Regex<(Substring, Substring??, Substring??)> = regex_O_OC_OC + + let regex_O_OCC_OC = Regex { + Optionally { + regex_OCC + regex_OC + } + } + let _: Regex<(Substring, Substring??, Substring??, Substring??)> = regex_O_OCC_OC + + let regex_O_OCC_OCC = Regex { + Optionally { + regex_OCC + regex_OCC + } + } + let _: Regex<(Substring, Substring??, Substring??, Substring??, Substring??)> = regex_O_OCC_OCC + + let regexChoices_CCOC = Regex { + ChoiceOf { + Capture { "A" } + "b" + "c" + Capture { "D" } + Optionally { + Capture { + "E" + } + } + } + } + let _: Regex<(Substring, Substring?, Substring?, Substring??)> = regexChoices_CCOC + + let regex_Zr3Mr3MOr3 = Regex { + ZeroOrMore { + regexWithMultipleCaptures + } + OneOrMore { + regexWithMultipleCaptures + } + OneOrMore { + Optionally { + regexWithMultipleCaptures + } + } + } + let _: Regex<(Substring, Substring?, Substring?, Substring?, Substring, Substring, Substring, Substring?, Substring?, Substring?)> = regex_Zr3Mr3MOr3 + } } extension Unicode.Scalar { From faa66e1cb0f89da44971a9ea610e00e4ab748c14 Mon Sep 17 00:00:00 2001 From: Nate Cook Date: Tue, 23 Apr 2024 16:43:52 -0500 Subject: [PATCH 09/11] More variadic DSL test improvements --- Tests/RegexBuilderTests/RegexDSLTests.swift | 62 ++++++++++++++------- 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/Tests/RegexBuilderTests/RegexDSLTests.swift b/Tests/RegexBuilderTests/RegexDSLTests.swift index e0c52a47c..666ce4b7e 100644 --- a/Tests/RegexBuilderTests/RegexDSLTests.swift +++ b/Tests/RegexBuilderTests/RegexDSLTests.swift @@ -885,20 +885,18 @@ class RegexDSLTests: XCTestCase { "a" } - // FIXME: Atomic groups lose their captures, will fix in: - // https://github.com/apple/swift-experimental-string-processing/pull/723 - // try _testDSLCaptures( - // ("aaa", ("aaa", "a")), - // matchType: (Substring, Substring).self, ==) - // { - // Local { - // "a" - // Capture { - // OneOrMore("a", .reluctant) - // } - // } - // "a" - // } + try _testDSLCaptures( + ("aaa", ("aaa", "a")), + matchType: (Substring, Substring).self, ==) + { + Local { + "a" + Capture { + OneOrMore("a", .reluctant) + } + } + "a" + } } func testAssertions() throws { @@ -2079,7 +2077,8 @@ extension RegexDSLTests { regex_OC } } - let _: Regex<(Substring, Substring??, Substring??, Substring??)> = regex_O_OCC_OC + let _: Regex<(Substring, Substring??, Substring??, Substring??)> + = regex_O_OCC_OC let regex_O_OCC_OCC = Regex { Optionally { @@ -2087,7 +2086,8 @@ extension RegexDSLTests { regex_OCC } } - let _: Regex<(Substring, Substring??, Substring??, Substring??, Substring??)> = regex_O_OCC_OCC + let _: Regex<(Substring, Substring??, Substring??, Substring??, Substring??)> + = regex_O_OCC_OCC let regexChoices_CCOC = Regex { ChoiceOf { @@ -2102,9 +2102,10 @@ extension RegexDSLTests { } } } - let _: Regex<(Substring, Substring?, Substring?, Substring??)> = regexChoices_CCOC + let _: Regex<(Substring, Substring?, Substring?, Substring??)> + = regexChoices_CCOC - let regex_Zr3Mr3MOr3 = Regex { + let regex_NineCaptures = Regex { ZeroOrMore { regexWithMultipleCaptures } @@ -2117,7 +2118,30 @@ extension RegexDSLTests { } } } - let _: Regex<(Substring, Substring?, Substring?, Substring?, Substring, Substring, Substring, Substring?, Substring?, Substring?)> = regex_Zr3Mr3MOr3 + let _: Regex<( + Substring, Substring?, Substring?, Substring?, Substring, Substring, + Substring, Substring?, Substring?, Substring?)> + = regex_NineCaptures + + let regex_ElevenCaptures = Regex { + regex_NineCaptures + regex_OCC + } + let _: Regex<( + Substring, Substring?, Substring?, Substring?, Substring, Substring, + Substring, Substring?, Substring?, Substring?, Substring?, Substring?)> + = regex_ElevenCaptures + + let regex_TwentyCaptures = Regex { + regex_ElevenCaptures + regex_NineCaptures + } + let _: Regex<( + Substring, Substring?, Substring?, Substring?, Substring, Substring, + Substring, Substring?, Substring?, Substring?, Substring?, Substring?, + Substring?, Substring?, Substring?, Substring, Substring, Substring, + Substring?, Substring?, Substring?)> + = regex_TwentyCaptures } } From 9a1ab4d2430430d0044502b6a2a403cb8893a455 Mon Sep 17 00:00:00 2001 From: Nate Cook Date: Tue, 23 Apr 2024 16:50:01 -0500 Subject: [PATCH 10/11] Fix source changes in tests --- Tests/RegexBuilderTests/RegexDSLTests.swift | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Tests/RegexBuilderTests/RegexDSLTests.swift b/Tests/RegexBuilderTests/RegexDSLTests.swift index 666ce4b7e..455ddc29f 100644 --- a/Tests/RegexBuilderTests/RegexDSLTests.swift +++ b/Tests/RegexBuilderTests/RegexDSLTests.swift @@ -1940,18 +1940,17 @@ extension RegexDSLTests { TryCapture<(Substring, Int)>(OneOrMore(.word)) { Int($0) } #/:(\d+):/# } -// FIXME (Variadics): The output type is now `(Substring, Substring, Substring, Substring, Substring, Substring, Substring, Substring, Substring, Substring, Substring, Substring, Substring, Substring, Substring, Int, Substring)` XCTAssert(type(of: dslWithTooManyCaptures).self - == Regex<(Substring, Substring, Int, Substring)>.self) + == Regex<(Substring, Substring, Substring, Substring, Substring, Substring, Substring, Substring, Substring, Substring, Substring, Substring, Substring, Substring, Substring, Int, Substring)>.self) let match = try XCTUnwrap(alpha.wholeMatch(of: dslWithTooManyCaptures)) XCTAssertEqual(match.output.0, alpha[...]) XCTAssertEqual(match.output.1, "AAA") -// FIXME (Variadics): match.output.2 is no longer an `Int` -// XCTAssertEqual(match.output.2, 123) -// FIXME (Variadics): match.output.3 is now the second letter of `regexWithTooManyCaptures`, i.e. "b" - XCTAssertEqual(match.output.3, "456") - + XCTAssertEqual(match.output.2, "a") + XCTAssertEqual(match.output.3, "b") + XCTAssertEqual(match.output.15, 123) + XCTAssertEqual(match.output.16, "456") + // All captures groups are available through `AnyRegexOutput`. let anyOutput = AnyRegexOutput(match) XCTAssertEqual(anyOutput.count, 17) From a164ddc9ec84690137b41c98cdab88304016e96c Mon Sep 17 00:00:00 2001 From: Nate Cook Date: Wed, 24 Apr 2024 09:28:48 -0500 Subject: [PATCH 11/11] Include static type checks for variadic regexes --- Tests/RegexBuilderTests/RegexDSLTests.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tests/RegexBuilderTests/RegexDSLTests.swift b/Tests/RegexBuilderTests/RegexDSLTests.swift index 455ddc29f..bf179ac86 100644 --- a/Tests/RegexBuilderTests/RegexDSLTests.swift +++ b/Tests/RegexBuilderTests/RegexDSLTests.swift @@ -1870,6 +1870,7 @@ extension RegexDSLTests { OneOrMore(.word) } XCTAssert(type(of: dslWithLabeledCapture).self == Regex.self) + let _: Regex = dslWithLabeledCapture let match = try XCTUnwrap(oneNumericField.wholeMatch(of: dslWithLabeledCapture)) XCTAssertEqual(match.output, oneNumericField[...]) @@ -1912,6 +1913,7 @@ extension RegexDSLTests { OneOrMore(.word) } XCTAssert(type(of: dslWithBothCaptures).self == Regex<(Substring, Substring)>.self) + let _: Regex<(Substring, Substring)> = dslWithBothCaptures let match = try XCTUnwrap(twoNumericFields.wholeMatch(of: dslWithBothCaptures)) XCTAssertEqual(match.output.0, twoNumericFields[...])