diff --git a/Sources/VariadicsGenerator/VariadicsGenerator.swift b/Sources/VariadicsGenerator/VariadicsGenerator.swift index 7aaf70697..312ea9a97 100644 --- a/Sources/VariadicsGenerator/VariadicsGenerator.swift +++ b/Sources/VariadicsGenerator/VariadicsGenerator.swift @@ -90,10 +90,7 @@ var standardError = StandardErrorStream() typealias Counter = Int64 let regexProtocolName = "RegexProtocol" -let concatenationStructTypeBaseName = "Concatenate" -let capturingGroupTypeBaseName = "CapturingGroup" let matchAssociatedTypeName = "Match" -let captureAssociatedTypeName = "Capture" let patternBuilderTypeName = "RegexBuilder" let patternProtocolRequirementName = "regex" let regexTypeName = "Regex" @@ -535,108 +532,169 @@ struct VariadicsGenerator: ParsableCommand { : "(\(baseMatchTypeName), \(newCaptureType), " + (0..( - _ component: R, as reference: Reference? = nil - ) -> \(regexTypeName)<\(newMatchType(newCaptureType: "W"))> \(whereClause) { - .init(node: .group(.capture, component.regex.root, reference?.id)) + _ component: R + ) -> \(regexTypeName)<\(rawNewMatchType)> \(whereClause) { + .init(node: .group(.capture, component.regex.root)) + } + + public func capture<\(genericParams)>( + _ component: R, as reference: Reference + ) -> \(regexTypeName)<\(rawNewMatchType)> \(whereClause) { + .init(node: .group(.capture, component.regex.root, reference.id)) + } + + public func capture<\(genericParams), NewCapture>( + _ component: R, + transform: @escaping (Substring) -> NewCapture + ) -> \(regexTypeName)<\(transformedNewMatchType)> \(whereClause) { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any + })) } public func capture<\(genericParams), NewCapture>( _ component: R, - as reference: Reference? = nil, + as reference: Reference, transform: @escaping (Substring) -> NewCapture - ) -> \(regexTypeName)<\(newMatchType(newCaptureType: "NewCapture"))> \(whereClause) { + ) -> \(regexTypeName)<\(transformedNewMatchType)> \(whereClause) { .init(node: .groupTransform( .capture, component.regex.root, CaptureTransform(resultType: NewCapture.self) { transform($0) as Any }, - reference?.id)) + reference.id)) } public func tryCapture<\(genericParams), NewCapture>( _ component: R, - as reference: Reference? = nil, transform: @escaping (Substring) throws -> NewCapture - ) -> \(regexTypeName)<\(newMatchType(newCaptureType: "NewCapture"))> \(whereClause) { + ) -> \(regexTypeName)<\(transformedNewMatchType)> \(whereClause) { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + try transform($0) as Any + })) + } + + public func tryCapture<\(genericParams), NewCapture>( + _ component: R, + as reference: Reference, + transform: @escaping (Substring) throws -> NewCapture + ) -> \(regexTypeName)<\(transformedNewMatchType)> \(whereClause) { .init(node: .groupTransform( .capture, component.regex.root, CaptureTransform(resultType: NewCapture.self) { try transform($0) as Any }, - reference?.id)) + reference.id)) } public func tryCapture<\(genericParams), NewCapture>( _ component: R, - as reference: Reference? = nil, transform: @escaping (Substring) -> NewCapture? - ) -> \(regexTypeName)<\(newMatchType(newCaptureType: "NewCapture"))> \(whereClause) { + ) -> \(regexTypeName)<\(transformedNewMatchType)> \(whereClause) { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any? + })) + } + + public func tryCapture<\(genericParams), NewCapture>( + _ component: R, + as reference: Reference, + transform: @escaping (Substring) -> NewCapture? + ) -> \(regexTypeName)<\(transformedNewMatchType)> \(whereClause) { .init(node: .groupTransform( .capture, component.regex.root, CaptureTransform(resultType: NewCapture.self) { transform($0) as Any? }, - reference?.id)) + reference.id)) } // MARK: - Builder capture arity \(arity) public func capture<\(genericParams)>( - as reference: Reference? = nil, @RegexBuilder _ component: () -> R - ) -> \(regexTypeName)<\(newMatchType(newCaptureType: "W"))> \(whereClause) { - .init(node: .group(.capture, component().regex.root, reference?.id)) + ) -> \(regexTypeName)<\(rawNewMatchType)> \(whereClause) { + .init(node: .group(.capture, component().regex.root)) + } + + public func capture<\(genericParams)>( + as reference: Reference, + @RegexBuilder _ component: () -> R + ) -> \(regexTypeName)<\(rawNewMatchType)> \(whereClause) { + .init(node: .group(.capture, component().regex.root, reference.id)) } public func capture<\(genericParams), NewCapture>( - as reference: Reference? = nil, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) -> NewCapture - ) -> \(regexTypeName)<\(newMatchType(newCaptureType: "NewCapture"))> \(whereClause) { + ) -> \(regexTypeName)<\(transformedNewMatchType)> \(whereClause) { .init(node: .groupTransform( .capture, component().regex.root, CaptureTransform(resultType: NewCapture.self) { transform($0) as Any - }, - reference?.id)) + })) } public func tryCapture<\(genericParams), NewCapture>( - as reference: Reference? = nil, + as reference: Reference, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) throws -> NewCapture - ) -> \(regexTypeName)<\(newMatchType(newCaptureType: "NewCapture"))> \(whereClause) { + ) -> \(regexTypeName)<\(transformedNewMatchType)> \(whereClause) { .init(node: .groupTransform( .capture, component().regex.root, CaptureTransform(resultType: NewCapture.self) { try transform($0) as Any }, - reference?.id)) + reference.id)) + } + + public func tryCapture<\(genericParams), NewCapture>( + @RegexBuilder _ component: () -> R, + transform: @escaping (Substring) -> NewCapture? + ) -> \(regexTypeName)<\(transformedNewMatchType)> \(whereClause) { + .init(node: .groupTransform( + .capture, + component().regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any? + })) } public func tryCapture<\(genericParams), NewCapture>( - as reference: Reference? = nil, + as reference: Reference, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) -> NewCapture? - ) -> \(regexTypeName)<\(newMatchType(newCaptureType: "NewCapture"))> \(whereClause) { + ) -> \(regexTypeName)<\(transformedNewMatchType)> \(whereClause) { .init(node: .groupTransform( .capture, component().regex.root, CaptureTransform(resultType: NewCapture.self) { transform($0) as Any? }, - reference?.id)) + reference.id)) } + """) } } diff --git a/Sources/_StringProcessing/ByteCodeGen.swift b/Sources/_StringProcessing/ByteCodeGen.swift index 5b73f10ea..93dca17a8 100644 --- a/Sources/_StringProcessing/ByteCodeGen.swift +++ b/Sources/_StringProcessing/ByteCodeGen.swift @@ -298,7 +298,7 @@ extension Compiler.ByteCodeGen { mutating func emitGroup( _ kind: AST.Group.Kind, _ child: DSLTree.Node, - _ referenceID: Reference.ID? + _ referenceID: ReferenceID? ) throws -> CaptureRegister? { guard kind.isCapturing || referenceID == nil else { throw Unreachable("Reference ID shouldn't exist for non-capturing groups") diff --git a/Sources/_StringProcessing/Capture.swift b/Sources/_StringProcessing/Capture.swift index 7706cc49f..915c4c5d7 100644 --- a/Sources/_StringProcessing/Capture.swift +++ b/Sources/_StringProcessing/Capture.swift @@ -52,9 +52,11 @@ func constructExistentialMatchComponent( underlying = Optional(nil) as Any someCount = optionalCount - 1 } - for _ in 0..(_ x: T) { + underlying = Optional(x) as Any + } + _openExistential(underlying, do: wrap) } return underlying } diff --git a/Sources/_StringProcessing/Engine/Consume.swift b/Sources/_StringProcessing/Engine/Consume.swift index 327d5de8e..52f752539 100644 --- a/Sources/_StringProcessing/Engine/Consume.swift +++ b/Sources/_StringProcessing/Engine/Consume.swift @@ -63,7 +63,8 @@ extension Engine where Input == String { guard let result = result else { return nil } let capList = cpu.storedCaptures - return (result, CaptureList(caps: capList)) + return (result, CaptureList( + values: capList, referencedCaptureOffsets: program.referencedCaptureOffsets)) } } diff --git a/Sources/_StringProcessing/Engine/MEBuilder.swift b/Sources/_StringProcessing/Engine/MEBuilder.swift index 1a7d10170..d81c583a8 100644 --- a/Sources/_StringProcessing/Engine/MEBuilder.swift +++ b/Sources/_StringProcessing/Engine/MEBuilder.swift @@ -43,8 +43,8 @@ extension MEProgram where Input.Element: Hashable { var captureStructure: CaptureStructure = .empty // Symbolic reference resolution - var unresolvedReferences: [Reference.ID: [InstructionAddress]] = [:] - var captureOffsets: [Reference.ID: Int] = [:] + var unresolvedReferences: [ReferenceID: [InstructionAddress]] = [:] + var referencedCaptureOffsets: [ReferenceID: Int] = [:] var captureCount: Int { // We currently deduce the capture count from the capture register number. nextCaptureRegister.rawValue @@ -274,7 +274,7 @@ extension MEProgram.Builder { .init(.backreference, .init(capture: cap))) } - public mutating func buildUnresolvedReference(id: Reference.ID) { + public mutating func buildUnresolvedReference(id: ReferenceID) { buildBackreference(.init(0)) unresolvedReferences[id, default: []].append(lastInstructionAddress) } @@ -352,7 +352,8 @@ extension MEProgram.Builder { staticTransformFunctions: transformFunctions, staticMatcherFunctions: matcherFunctions, registerInfo: regInfo, - captureStructure: captureStructure) + captureStructure: captureStructure, + referencedCaptureOffsets: referencedCaptureOffsets) } public mutating func reset() { self = Self() } @@ -424,7 +425,7 @@ extension MEProgram.Builder { fileprivate extension MEProgram.Builder { mutating func resolveReferences() throws { for (id, uses) in unresolvedReferences { - guard let offset = captureOffsets[id] else { + guard let offset = referencedCaptureOffsets[id] else { throw RegexCompilationError.uncapturedReference } for use in uses { @@ -437,11 +438,11 @@ fileprivate extension MEProgram.Builder { // Register helpers extension MEProgram.Builder { - public mutating func makeCapture(id: Reference.ID?) -> CaptureRegister { + public mutating func makeCapture(id: ReferenceID?) -> CaptureRegister { defer { nextCaptureRegister.rawValue += 1 } // Register the capture for later lookup via symbolic references. if let id = id { - let preexistingValue = captureOffsets.updateValue( + let preexistingValue = referencedCaptureOffsets.updateValue( captureCount, forKey: id) assert(preexistingValue == nil) } diff --git a/Sources/_StringProcessing/Engine/MECapture.swift b/Sources/_StringProcessing/Engine/MECapture.swift index e20eae34e..88f912ecb 100644 --- a/Sources/_StringProcessing/Engine/MECapture.swift +++ b/Sources/_StringProcessing/Engine/MECapture.swift @@ -143,14 +143,15 @@ extension Processor._StoredCapture: CustomStringConvertible { } public struct CaptureList { - var caps: Array._StoredCapture> + var values: Array._StoredCapture> + var referencedCaptureOffsets: [ReferenceID: Int] // func extract(from s: String) -> Array> { // caps.map { $0.map { s[$0] } } // } // func latestUntyped(from s: String) -> Array { - caps.map { + values.map { guard let last = $0.latest else { return nil } diff --git a/Sources/_StringProcessing/Engine/MEProgram.swift b/Sources/_StringProcessing/Engine/MEProgram.swift index 416649a14..d616657e8 100644 --- a/Sources/_StringProcessing/Engine/MEProgram.swift +++ b/Sources/_StringProcessing/Engine/MEProgram.swift @@ -35,6 +35,7 @@ public struct MEProgram where Input.Element: Equatable { var enableTracing: Bool = false let captureStructure: CaptureStructure + let referencedCaptureOffsets: [ReferenceID: Int] } extension MEProgram: CustomStringConvertible { diff --git a/Sources/_StringProcessing/Engine/Processor.swift b/Sources/_StringProcessing/Engine/Processor.swift index 91c126e42..10c3eb781 100644 --- a/Sources/_StringProcessing/Engine/Processor.swift +++ b/Sources/_StringProcessing/Engine/Processor.swift @@ -14,6 +14,8 @@ public enum MatchMode { case partialFromFront } +typealias Program = MEProgram + /// A concrete CU. Somehow will run the concrete logic and /// feed stuff back to generic code struct Controller { diff --git a/Sources/_StringProcessing/Engine/StringProcessor.swift b/Sources/_StringProcessing/Engine/StringProcessor.swift deleted file mode 100644 index 14fe02681..000000000 --- a/Sources/_StringProcessing/Engine/StringProcessor.swift +++ /dev/null @@ -1,33 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2021-2022 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -//===----------------------------------------------------------------------===// - -import _MatchingEngine -typealias Program = MEProgram - -public struct MatchResult { - public var range: Range - var captures: [StructuredCapture] - - var destructure: ( - matched: Range, - captures: [StructuredCapture] - ) { - (range, captures) - } - - init( - _ matched: Range, - _ captures: [StructuredCapture] - ) { - self.range = matched - self.captures = captures - } -} diff --git a/Sources/_StringProcessing/Engine/Structuralize.swift b/Sources/_StringProcessing/Engine/Structuralize.swift index 39fb25213..30e7b9efe 100644 --- a/Sources/_StringProcessing/Engine/Structuralize.swift +++ b/Sources/_StringProcessing/Engine/Structuralize.swift @@ -62,17 +62,17 @@ extension CaptureStructure { } switch self { - case let .tuple(caps): - assert(list.caps.count == caps.count) + case let .tuple(values): + assert(list.values.count == values.count) var result = Array() - for (cap, storedCap) in zip(caps, list.caps) { + for (cap, storedCap) in zip(values, list.values) { result.append(mapCap(cap, storedCap)) } return result default: - assert(list.caps.count == 1) - return [mapCap(self, list.caps.first!)] + assert(list.values.count == 1) + return [mapCap(self, list.values.first!)] } } } diff --git a/Sources/_StringProcessing/Executor.swift b/Sources/_StringProcessing/Executor.swift index 9bff0fa78..e066a4369 100644 --- a/Sources/_StringProcessing/Executor.swift +++ b/Sources/_StringProcessing/Executor.swift @@ -11,6 +11,7 @@ import _MatchingEngine + // FIXME: Public for prototype public struct Executor { // TODO: consider let, for now lets us toggle tracing var engine: Engine @@ -19,11 +20,35 @@ public struct Executor { self.engine = Engine(program, enableTracing: enablesTracing) } + // FIXME: Public for prototype + public struct Result { + public var range: Range + var captures: [StructuredCapture] + var referencedCaptureOffsets: [ReferenceID: Int] + + var destructure: ( + matched: Range, + captures: [StructuredCapture], + referencedCaptureOffsets: [ReferenceID: Int] + ) { + (range, captures, referencedCaptureOffsets) + } + + init( + _ matched: Range, _ captures: [StructuredCapture], + _ referencedCaptureOffsets: [ReferenceID: Int] + ) { + self.range = matched + self.captures = captures + self.referencedCaptureOffsets = referencedCaptureOffsets + } + } + public func execute( input: String, in range: Range, mode: MatchMode = .wholeString - ) -> MatchResult? { + ) -> Result? { guard let (endIdx, capList) = engine.consume( input, in: range, matchMode: mode ) else { @@ -35,7 +60,7 @@ public struct Executor { let caps = try capStruct.structuralize( capList, input) - return MatchResult(range, caps) + return Result(range, caps, capList.referencedCaptureOffsets) } catch { fatalError(String(describing: error)) } @@ -43,7 +68,7 @@ public struct Executor { public func execute( input: Substring, mode: MatchMode = .wholeString - ) -> MatchResult? { + ) -> Result? { self.execute( input: input.base, in: input.startIndex..( // MARK: - Backreference -public struct Reference: RegexProtocol { - // FIXME: Public for prototypes. - public struct ID: Hashable, Equatable { - private static var counter: Int = 0 - var base: Int - init() { - base = ID.counter - ID.counter += 1 - } + +// FIXME: Public for prototypes. +public struct ReferenceID: Hashable, Equatable { + private static var counter: Int = 0 + var base: Int + + init() { + base = Self.counter + Self.counter += 1 } +} - let id = ID() +public struct Reference: RegexProtocol { + let id = ReferenceID() - public init() {} + public init(_ captureType: Capture.Type = Capture.self) {} - public var regex: Regex { + public var regex: Regex { .init(node: .atom(.symbolicReference(id))) } } diff --git a/Sources/_StringProcessing/RegexDSL/DSLTree.swift b/Sources/_StringProcessing/RegexDSL/DSLTree.swift index 53d9ec338..a44220925 100644 --- a/Sources/_StringProcessing/RegexDSL/DSLTree.swift +++ b/Sources/_StringProcessing/RegexDSL/DSLTree.swift @@ -30,7 +30,7 @@ extension DSLTree { case concatenation([Node]) /// (...) - case group(AST.Group.Kind, Node, Reference.ID? = nil) + case group(AST.Group.Kind, Node, ReferenceID? = nil) /// (?(cond) true-branch | false-branch) /// @@ -82,7 +82,7 @@ extension DSLTree { AST.Group.Kind, Node, CaptureTransform, - Reference.ID? = nil) + ReferenceID? = nil) case consumer(_ConsumerInterface) @@ -120,7 +120,7 @@ extension DSLTree { case assertion(AST.Atom.AssertionKind) case backreference(AST.Reference) - case symbolicReference(Reference.ID) + case symbolicReference(ReferenceID) case unconverted(AST.Atom) } diff --git a/Sources/_StringProcessing/RegexDSL/Match.swift b/Sources/_StringProcessing/RegexDSL/Match.swift index 0b25d7a09..bec0860c6 100644 --- a/Sources/_StringProcessing/RegexDSL/Match.swift +++ b/Sources/_StringProcessing/RegexDSL/Match.swift @@ -11,10 +11,23 @@ @dynamicMemberLookup public struct RegexMatch { + let input: String public let range: Range + let rawCaptures: [StructuredCapture] + let referencedCaptureOffsets: [ReferenceID: Int] - // FIXME: Computed instead of stored - public let match: Match + public var match: Match { + if Match.self == (Substring, DynamicCaptures).self { + let dynCaps = rawCaptures.map { StoredDynamicCapture($0, in: input) } + return (input[range], dynCaps) as! Match + } else if Match.self == Substring.self { + // FIXME: Plumb whole match (`.0`) through the matching engine. + return input[range] as! Match + } else { + let typeErasedMatch = rawCaptures.existentialMatch(from: input[range]) + return typeErasedMatch as! Match + } + } public subscript(dynamicMember keyPath: KeyPath) -> T { match[keyPath: keyPath] @@ -27,6 +40,15 @@ public struct RegexMatch { ) -> Match { match } + + public subscript(_ reference: Reference) -> Capture { + guard let offset = referencedCaptureOffsets[reference.id] else { + preconditionFailure( + "Reference did not capture any match in the regex") + } + return rawCaptures[offset].existentialMatchComponent(from: input[...]) + as! Capture + } } extension RegexProtocol { @@ -45,28 +67,16 @@ extension RegexProtocol { mode: MatchMode = .wholeString ) -> RegexMatch? { let executor = Executor(program: regex.program.loweredProgram) - guard let (range, captures) = executor.execute( + guard let (range, captures, captureOffsets) = executor.execute( input: input, in: inputRange, mode: mode )?.destructure else { return nil } - let convertedMatch: Match - if Match.self == (Substring, DynamicCaptures).self { - let dynCaps = DynamicCaptures(captures.map { - StoredDynamicCapture($0, in: input) - }) - convertedMatch = (input[range], dynCaps) as! Match - } else - if Match.self == Substring.self { - convertedMatch = input[range] as! Match - } else { - // FIXME: Defer construction until accessed - let typeErasedMatch = captures.existentialMatch( - from: input[range] - ) - convertedMatch = typeErasedMatch as! Match - } - return RegexMatch(range: range, match: convertedMatch) + return RegexMatch( + input: input, + range: range, + rawCaptures: captures, + referencedCaptureOffsets: captureOffsets) } } diff --git a/Sources/_StringProcessing/RegexDSL/Variadics.swift b/Sources/_StringProcessing/RegexDSL/Variadics.swift index 61b1c1618..3ca1261f1 100644 --- a/Sources/_StringProcessing/RegexDSL/Variadics.swift +++ b/Sources/_StringProcessing/RegexDSL/Variadics.swift @@ -2266,14 +2266,32 @@ extension AlternationBuilder { // MARK: - Non-builder capture arity 0 public func capture( - _ component: R, as reference: Reference? = nil + _ component: R ) -> Regex<(Substring, W)> where R.Match == W { - .init(node: .group(.capture, component.regex.root, reference?.id)) + .init(node: .group(.capture, component.regex.root)) +} + +public func capture( + _ component: R, as reference: Reference +) -> Regex<(Substring, W)> where R.Match == W { + .init(node: .group(.capture, component.regex.root, reference.id)) } public func capture( _ component: R, - as reference: Reference? = nil, + transform: @escaping (Substring) -> NewCapture +) -> Regex<(Substring, NewCapture)> where R.Match == W { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any + })) +} + +public func capture( + _ component: R, + as reference: Reference, transform: @escaping (Substring) -> NewCapture ) -> Regex<(Substring, NewCapture)> where R.Match == W { .init(node: .groupTransform( @@ -2282,12 +2300,24 @@ public func capture( CaptureTransform(resultType: NewCapture.self) { transform($0) as Any }, - reference?.id)) + reference.id)) +} + +public func tryCapture( + _ component: R, + transform: @escaping (Substring) throws -> NewCapture +) -> Regex<(Substring, NewCapture)> where R.Match == W { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + try transform($0) as Any + })) } public func tryCapture( _ component: R, - as reference: Reference? = nil, + as reference: Reference, transform: @escaping (Substring) throws -> NewCapture ) -> Regex<(Substring, NewCapture)> where R.Match == W { .init(node: .groupTransform( @@ -2296,12 +2326,24 @@ public func tryCapture( CaptureTransform(resultType: NewCapture.self) { try transform($0) as Any }, - reference?.id)) + reference.id)) } public func tryCapture( _ component: R, - as reference: Reference? = nil, + transform: @escaping (Substring) -> NewCapture? +) -> Regex<(Substring, NewCapture)> where R.Match == W { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any? + })) +} + +public func tryCapture( + _ component: R, + as reference: Reference, transform: @escaping (Substring) -> NewCapture? ) -> Regex<(Substring, NewCapture)> where R.Match == W { .init(node: .groupTransform( @@ -2310,20 +2352,25 @@ public func tryCapture( CaptureTransform(resultType: NewCapture.self) { transform($0) as Any? }, - reference?.id)) + reference.id)) } // MARK: - Builder capture arity 0 public func capture( - as reference: Reference? = nil, @RegexBuilder _ component: () -> R ) -> Regex<(Substring, W)> where R.Match == W { - .init(node: .group(.capture, component().regex.root, reference?.id)) + .init(node: .group(.capture, component().regex.root)) +} + +public func capture( + as reference: Reference, + @RegexBuilder _ component: () -> R +) -> Regex<(Substring, W)> where R.Match == W { + .init(node: .group(.capture, component().regex.root, reference.id)) } public func capture( - as reference: Reference? = nil, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) -> NewCapture ) -> Regex<(Substring, NewCapture)> where R.Match == W { @@ -2332,12 +2379,11 @@ public func capture( component().regex.root, CaptureTransform(resultType: NewCapture.self) { transform($0) as Any - }, - reference?.id)) + })) } public func tryCapture( - as reference: Reference? = nil, + as reference: Reference, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) throws -> NewCapture ) -> Regex<(Substring, NewCapture)> where R.Match == W { @@ -2347,11 +2393,23 @@ public func tryCapture( CaptureTransform(resultType: NewCapture.self) { try transform($0) as Any }, - reference?.id)) + reference.id)) } public func tryCapture( - as reference: Reference? = nil, + @RegexBuilder _ component: () -> R, + transform: @escaping (Substring) -> NewCapture? +) -> Regex<(Substring, NewCapture)> where R.Match == W { + .init(node: .groupTransform( + .capture, + component().regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any? + })) +} + +public func tryCapture( + as reference: Reference, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) -> NewCapture? ) -> Regex<(Substring, NewCapture)> where R.Match == W { @@ -2361,19 +2419,38 @@ public func tryCapture( CaptureTransform(resultType: NewCapture.self) { transform($0) as Any? }, - reference?.id)) + reference.id)) } + // MARK: - Non-builder capture arity 1 public func capture( - _ component: R, as reference: Reference? = nil + _ component: R +) -> Regex<(Substring, W, C0)> where R.Match == (W, C0) { + .init(node: .group(.capture, component.regex.root)) +} + +public func capture( + _ component: R, as reference: Reference ) -> Regex<(Substring, W, C0)> where R.Match == (W, C0) { - .init(node: .group(.capture, component.regex.root, reference?.id)) + .init(node: .group(.capture, component.regex.root, reference.id)) } public func capture( _ component: R, - as reference: Reference? = nil, + transform: @escaping (Substring) -> NewCapture +) -> Regex<(Substring, NewCapture, C0)> where R.Match == (W, C0) { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any + })) +} + +public func capture( + _ component: R, + as reference: Reference, transform: @escaping (Substring) -> NewCapture ) -> Regex<(Substring, NewCapture, C0)> where R.Match == (W, C0) { .init(node: .groupTransform( @@ -2382,12 +2459,24 @@ public func capture( CaptureTransform(resultType: NewCapture.self) { transform($0) as Any }, - reference?.id)) + reference.id)) } public func tryCapture( _ component: R, - as reference: Reference? = nil, + transform: @escaping (Substring) throws -> NewCapture +) -> Regex<(Substring, NewCapture, C0)> where R.Match == (W, C0) { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + try transform($0) as Any + })) +} + +public func tryCapture( + _ component: R, + as reference: Reference, transform: @escaping (Substring) throws -> NewCapture ) -> Regex<(Substring, NewCapture, C0)> where R.Match == (W, C0) { .init(node: .groupTransform( @@ -2396,12 +2485,24 @@ public func tryCapture( CaptureTransform(resultType: NewCapture.self) { try transform($0) as Any }, - reference?.id)) + reference.id)) } public func tryCapture( _ component: R, - as reference: Reference? = nil, + transform: @escaping (Substring) -> NewCapture? +) -> Regex<(Substring, NewCapture, C0)> where R.Match == (W, C0) { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any? + })) +} + +public func tryCapture( + _ component: R, + as reference: Reference, transform: @escaping (Substring) -> NewCapture? ) -> Regex<(Substring, NewCapture, C0)> where R.Match == (W, C0) { .init(node: .groupTransform( @@ -2410,20 +2511,25 @@ public func tryCapture( CaptureTransform(resultType: NewCapture.self) { transform($0) as Any? }, - reference?.id)) + reference.id)) } // MARK: - Builder capture arity 1 public func capture( - as reference: Reference? = nil, @RegexBuilder _ component: () -> R ) -> Regex<(Substring, W, C0)> where R.Match == (W, C0) { - .init(node: .group(.capture, component().regex.root, reference?.id)) + .init(node: .group(.capture, component().regex.root)) +} + +public func capture( + as reference: Reference, + @RegexBuilder _ component: () -> R +) -> Regex<(Substring, W, C0)> where R.Match == (W, C0) { + .init(node: .group(.capture, component().regex.root, reference.id)) } public func capture( - as reference: Reference? = nil, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) -> NewCapture ) -> Regex<(Substring, NewCapture, C0)> where R.Match == (W, C0) { @@ -2432,12 +2538,11 @@ public func capture( component().regex.root, CaptureTransform(resultType: NewCapture.self) { transform($0) as Any - }, - reference?.id)) + })) } public func tryCapture( - as reference: Reference? = nil, + as reference: Reference, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) throws -> NewCapture ) -> Regex<(Substring, NewCapture, C0)> where R.Match == (W, C0) { @@ -2447,11 +2552,23 @@ public func tryCapture( CaptureTransform(resultType: NewCapture.self) { try transform($0) as Any }, - reference?.id)) + reference.id)) } public func tryCapture( - as reference: Reference? = nil, + @RegexBuilder _ component: () -> R, + transform: @escaping (Substring) -> NewCapture? +) -> Regex<(Substring, NewCapture, C0)> where R.Match == (W, C0) { + .init(node: .groupTransform( + .capture, + component().regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any? + })) +} + +public func tryCapture( + as reference: Reference, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) -> NewCapture? ) -> Regex<(Substring, NewCapture, C0)> where R.Match == (W, C0) { @@ -2461,19 +2578,38 @@ public func tryCapture( CaptureTransform(resultType: NewCapture.self) { transform($0) as Any? }, - reference?.id)) + reference.id)) } + // MARK: - Non-builder capture arity 2 public func capture( - _ component: R, as reference: Reference? = nil + _ component: R +) -> Regex<(Substring, W, C0, C1)> where R.Match == (W, C0, C1) { + .init(node: .group(.capture, component.regex.root)) +} + +public func capture( + _ component: R, as reference: Reference ) -> Regex<(Substring, W, C0, C1)> where R.Match == (W, C0, C1) { - .init(node: .group(.capture, component.regex.root, reference?.id)) + .init(node: .group(.capture, component.regex.root, reference.id)) } public func capture( _ component: R, - as reference: Reference? = nil, + transform: @escaping (Substring) -> NewCapture +) -> Regex<(Substring, NewCapture, C0, C1)> where R.Match == (W, C0, C1) { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any + })) +} + +public func capture( + _ component: R, + as reference: Reference, transform: @escaping (Substring) -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1)> where R.Match == (W, C0, C1) { .init(node: .groupTransform( @@ -2482,12 +2618,24 @@ public func capture( CaptureTransform(resultType: NewCapture.self) { transform($0) as Any }, - reference?.id)) + reference.id)) } public func tryCapture( _ component: R, - as reference: Reference? = nil, + transform: @escaping (Substring) throws -> NewCapture +) -> Regex<(Substring, NewCapture, C0, C1)> where R.Match == (W, C0, C1) { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + try transform($0) as Any + })) +} + +public func tryCapture( + _ component: R, + as reference: Reference, transform: @escaping (Substring) throws -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1)> where R.Match == (W, C0, C1) { .init(node: .groupTransform( @@ -2496,12 +2644,24 @@ public func tryCapture( CaptureTransform(resultType: NewCapture.self) { try transform($0) as Any }, - reference?.id)) + reference.id)) +} + +public func tryCapture( + _ component: R, + transform: @escaping (Substring) -> NewCapture? +) -> Regex<(Substring, NewCapture, C0, C1)> where R.Match == (W, C0, C1) { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any? + })) } public func tryCapture( _ component: R, - as reference: Reference? = nil, + as reference: Reference, transform: @escaping (Substring) -> NewCapture? ) -> Regex<(Substring, NewCapture, C0, C1)> where R.Match == (W, C0, C1) { .init(node: .groupTransform( @@ -2510,20 +2670,25 @@ public func tryCapture( CaptureTransform(resultType: NewCapture.self) { transform($0) as Any? }, - reference?.id)) + reference.id)) } // MARK: - Builder capture arity 2 public func capture( - as reference: Reference? = nil, @RegexBuilder _ component: () -> R ) -> Regex<(Substring, W, C0, C1)> where R.Match == (W, C0, C1) { - .init(node: .group(.capture, component().regex.root, reference?.id)) + .init(node: .group(.capture, component().regex.root)) +} + +public func capture( + as reference: Reference, + @RegexBuilder _ component: () -> R +) -> Regex<(Substring, W, C0, C1)> where R.Match == (W, C0, C1) { + .init(node: .group(.capture, component().regex.root, reference.id)) } public func capture( - as reference: Reference? = nil, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1)> where R.Match == (W, C0, C1) { @@ -2532,12 +2697,11 @@ public func capture( component().regex.root, CaptureTransform(resultType: NewCapture.self) { transform($0) as Any - }, - reference?.id)) + })) } public func tryCapture( - as reference: Reference? = nil, + as reference: Reference, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) throws -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1)> where R.Match == (W, C0, C1) { @@ -2547,11 +2711,23 @@ public func tryCapture( CaptureTransform(resultType: NewCapture.self) { try transform($0) as Any }, - reference?.id)) + reference.id)) } public func tryCapture( - as reference: Reference? = nil, + @RegexBuilder _ component: () -> R, + transform: @escaping (Substring) -> NewCapture? +) -> Regex<(Substring, NewCapture, C0, C1)> where R.Match == (W, C0, C1) { + .init(node: .groupTransform( + .capture, + component().regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any? + })) +} + +public func tryCapture( + as reference: Reference, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) -> NewCapture? ) -> Regex<(Substring, NewCapture, C0, C1)> where R.Match == (W, C0, C1) { @@ -2561,19 +2737,38 @@ public func tryCapture( CaptureTransform(resultType: NewCapture.self) { transform($0) as Any? }, - reference?.id)) + reference.id)) } + // MARK: - Non-builder capture arity 3 public func capture( - _ component: R, as reference: Reference? = nil + _ component: R ) -> Regex<(Substring, W, C0, C1, C2)> where R.Match == (W, C0, C1, C2) { - .init(node: .group(.capture, component.regex.root, reference?.id)) + .init(node: .group(.capture, component.regex.root)) +} + +public func capture( + _ component: R, as reference: Reference +) -> Regex<(Substring, W, C0, C1, C2)> where R.Match == (W, C0, C1, C2) { + .init(node: .group(.capture, component.regex.root, reference.id)) +} + +public func capture( + _ component: R, + transform: @escaping (Substring) -> NewCapture +) -> Regex<(Substring, NewCapture, C0, C1, C2)> where R.Match == (W, C0, C1, C2) { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any + })) } public func capture( _ component: R, - as reference: Reference? = nil, + as reference: Reference, transform: @escaping (Substring) -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1, C2)> where R.Match == (W, C0, C1, C2) { .init(node: .groupTransform( @@ -2582,12 +2777,24 @@ public func capture( CaptureTransform(resultType: NewCapture.self) { transform($0) as Any }, - reference?.id)) + reference.id)) +} + +public func tryCapture( + _ component: R, + transform: @escaping (Substring) throws -> NewCapture +) -> Regex<(Substring, NewCapture, C0, C1, C2)> where R.Match == (W, C0, C1, C2) { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + try transform($0) as Any + })) } public func tryCapture( _ component: R, - as reference: Reference? = nil, + as reference: Reference, transform: @escaping (Substring) throws -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1, C2)> where R.Match == (W, C0, C1, C2) { .init(node: .groupTransform( @@ -2596,12 +2803,24 @@ public func tryCapture( CaptureTransform(resultType: NewCapture.self) { try transform($0) as Any }, - reference?.id)) + reference.id)) } public func tryCapture( _ component: R, - as reference: Reference? = nil, + transform: @escaping (Substring) -> NewCapture? +) -> Regex<(Substring, NewCapture, C0, C1, C2)> where R.Match == (W, C0, C1, C2) { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any? + })) +} + +public func tryCapture( + _ component: R, + as reference: Reference, transform: @escaping (Substring) -> NewCapture? ) -> Regex<(Substring, NewCapture, C0, C1, C2)> where R.Match == (W, C0, C1, C2) { .init(node: .groupTransform( @@ -2610,20 +2829,25 @@ public func tryCapture( CaptureTransform(resultType: NewCapture.self) { transform($0) as Any? }, - reference?.id)) + reference.id)) } // MARK: - Builder capture arity 3 public func capture( - as reference: Reference? = nil, @RegexBuilder _ component: () -> R ) -> Regex<(Substring, W, C0, C1, C2)> where R.Match == (W, C0, C1, C2) { - .init(node: .group(.capture, component().regex.root, reference?.id)) + .init(node: .group(.capture, component().regex.root)) +} + +public func capture( + as reference: Reference, + @RegexBuilder _ component: () -> R +) -> Regex<(Substring, W, C0, C1, C2)> where R.Match == (W, C0, C1, C2) { + .init(node: .group(.capture, component().regex.root, reference.id)) } public func capture( - as reference: Reference? = nil, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1, C2)> where R.Match == (W, C0, C1, C2) { @@ -2632,12 +2856,11 @@ public func capture( component().regex.root, CaptureTransform(resultType: NewCapture.self) { transform($0) as Any - }, - reference?.id)) + })) } public func tryCapture( - as reference: Reference? = nil, + as reference: Reference, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) throws -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1, C2)> where R.Match == (W, C0, C1, C2) { @@ -2647,11 +2870,23 @@ public func tryCapture( CaptureTransform(resultType: NewCapture.self) { try transform($0) as Any }, - reference?.id)) + reference.id)) } public func tryCapture( - as reference: Reference? = nil, + @RegexBuilder _ component: () -> R, + transform: @escaping (Substring) -> NewCapture? +) -> Regex<(Substring, NewCapture, C0, C1, C2)> where R.Match == (W, C0, C1, C2) { + .init(node: .groupTransform( + .capture, + component().regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any? + })) +} + +public func tryCapture( + as reference: Reference, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) -> NewCapture? ) -> Regex<(Substring, NewCapture, C0, C1, C2)> where R.Match == (W, C0, C1, C2) { @@ -2661,19 +2896,38 @@ public func tryCapture( CaptureTransform(resultType: NewCapture.self) { transform($0) as Any? }, - reference?.id)) + reference.id)) } + // MARK: - Non-builder capture arity 4 public func capture( - _ component: R, as reference: Reference? = nil + _ component: R ) -> Regex<(Substring, W, C0, C1, C2, C3)> where R.Match == (W, C0, C1, C2, C3) { - .init(node: .group(.capture, component.regex.root, reference?.id)) + .init(node: .group(.capture, component.regex.root)) +} + +public func capture( + _ component: R, as reference: Reference +) -> Regex<(Substring, W, C0, C1, C2, C3)> where R.Match == (W, C0, C1, C2, C3) { + .init(node: .group(.capture, component.regex.root, reference.id)) } public func capture( _ component: R, - as reference: Reference? = nil, + transform: @escaping (Substring) -> NewCapture +) -> Regex<(Substring, NewCapture, C0, C1, C2, C3)> where R.Match == (W, C0, C1, C2, C3) { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any + })) +} + +public func capture( + _ component: R, + as reference: Reference, transform: @escaping (Substring) -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3)> where R.Match == (W, C0, C1, C2, C3) { .init(node: .groupTransform( @@ -2682,12 +2936,24 @@ public func capture( CaptureTransform(resultType: NewCapture.self) { transform($0) as Any }, - reference?.id)) + reference.id)) +} + +public func tryCapture( + _ component: R, + transform: @escaping (Substring) throws -> NewCapture +) -> Regex<(Substring, NewCapture, C0, C1, C2, C3)> where R.Match == (W, C0, C1, C2, C3) { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + try transform($0) as Any + })) } public func tryCapture( _ component: R, - as reference: Reference? = nil, + as reference: Reference, transform: @escaping (Substring) throws -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3)> where R.Match == (W, C0, C1, C2, C3) { .init(node: .groupTransform( @@ -2696,12 +2962,24 @@ public func tryCapture( CaptureTransform(resultType: NewCapture.self) { try transform($0) as Any }, - reference?.id)) + reference.id)) } public func tryCapture( _ component: R, - as reference: Reference? = nil, + transform: @escaping (Substring) -> NewCapture? +) -> Regex<(Substring, NewCapture, C0, C1, C2, C3)> where R.Match == (W, C0, C1, C2, C3) { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any? + })) +} + +public func tryCapture( + _ component: R, + as reference: Reference, transform: @escaping (Substring) -> NewCapture? ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3)> where R.Match == (W, C0, C1, C2, C3) { .init(node: .groupTransform( @@ -2710,20 +2988,25 @@ public func tryCapture( CaptureTransform(resultType: NewCapture.self) { transform($0) as Any? }, - reference?.id)) + reference.id)) } // MARK: - Builder capture arity 4 public func capture( - as reference: Reference? = nil, @RegexBuilder _ component: () -> R ) -> Regex<(Substring, W, C0, C1, C2, C3)> where R.Match == (W, C0, C1, C2, C3) { - .init(node: .group(.capture, component().regex.root, reference?.id)) + .init(node: .group(.capture, component().regex.root)) +} + +public func capture( + as reference: Reference, + @RegexBuilder _ component: () -> R +) -> Regex<(Substring, W, C0, C1, C2, C3)> where R.Match == (W, C0, C1, C2, C3) { + .init(node: .group(.capture, component().regex.root, reference.id)) } public func capture( - as reference: Reference? = nil, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3)> where R.Match == (W, C0, C1, C2, C3) { @@ -2732,12 +3015,11 @@ public func capture( component().regex.root, CaptureTransform(resultType: NewCapture.self) { transform($0) as Any - }, - reference?.id)) + })) } public func tryCapture( - as reference: Reference? = nil, + as reference: Reference, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) throws -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3)> where R.Match == (W, C0, C1, C2, C3) { @@ -2747,11 +3029,23 @@ public func tryCapture( CaptureTransform(resultType: NewCapture.self) { try transform($0) as Any }, - reference?.id)) + reference.id)) } public func tryCapture( - as reference: Reference? = nil, + @RegexBuilder _ component: () -> R, + transform: @escaping (Substring) -> NewCapture? +) -> Regex<(Substring, NewCapture, C0, C1, C2, C3)> where R.Match == (W, C0, C1, C2, C3) { + .init(node: .groupTransform( + .capture, + component().regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any? + })) +} + +public func tryCapture( + as reference: Reference, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) -> NewCapture? ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3)> where R.Match == (W, C0, C1, C2, C3) { @@ -2761,33 +3055,64 @@ public func tryCapture( CaptureTransform(resultType: NewCapture.self) { transform($0) as Any? }, - reference?.id)) + reference.id)) } + // MARK: - Non-builder capture arity 5 public func capture( - _ component: R, as reference: Reference? = nil + _ component: R ) -> Regex<(Substring, W, C0, C1, C2, C3, C4)> where R.Match == (W, C0, C1, C2, C3, C4) { - .init(node: .group(.capture, component.regex.root, reference?.id)) + .init(node: .group(.capture, component.regex.root)) +} + +public func capture( + _ component: R, as reference: Reference +) -> Regex<(Substring, W, C0, C1, C2, C3, C4)> where R.Match == (W, C0, C1, C2, C3, C4) { + .init(node: .group(.capture, component.regex.root, reference.id)) +} + +public func capture( + _ component: R, + transform: @escaping (Substring) -> NewCapture +) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4)> where R.Match == (W, C0, C1, C2, C3, C4) { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any + })) +} + +public func capture( + _ component: R, + as reference: Reference, + transform: @escaping (Substring) -> NewCapture +) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4)> where R.Match == (W, C0, C1, C2, C3, C4) { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any + }, + reference.id)) } -public func capture( +public func tryCapture( _ component: R, - as reference: Reference? = nil, - transform: @escaping (Substring) -> NewCapture + transform: @escaping (Substring) throws -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4)> where R.Match == (W, C0, C1, C2, C3, C4) { .init(node: .groupTransform( .capture, component.regex.root, CaptureTransform(resultType: NewCapture.self) { - transform($0) as Any - }, - reference?.id)) + try transform($0) as Any + })) } public func tryCapture( _ component: R, - as reference: Reference? = nil, + as reference: Reference, transform: @escaping (Substring) throws -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4)> where R.Match == (W, C0, C1, C2, C3, C4) { .init(node: .groupTransform( @@ -2796,12 +3121,24 @@ public func tryCapture( CaptureTransform(resultType: NewCapture.self) { try transform($0) as Any }, - reference?.id)) + reference.id)) +} + +public func tryCapture( + _ component: R, + transform: @escaping (Substring) -> NewCapture? +) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4)> where R.Match == (W, C0, C1, C2, C3, C4) { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any? + })) } public func tryCapture( _ component: R, - as reference: Reference? = nil, + as reference: Reference, transform: @escaping (Substring) -> NewCapture? ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4)> where R.Match == (W, C0, C1, C2, C3, C4) { .init(node: .groupTransform( @@ -2810,20 +3147,25 @@ public func tryCapture( CaptureTransform(resultType: NewCapture.self) { transform($0) as Any? }, - reference?.id)) + reference.id)) } // MARK: - Builder capture arity 5 public func capture( - as reference: Reference? = nil, @RegexBuilder _ component: () -> R ) -> Regex<(Substring, W, C0, C1, C2, C3, C4)> where R.Match == (W, C0, C1, C2, C3, C4) { - .init(node: .group(.capture, component().regex.root, reference?.id)) + .init(node: .group(.capture, component().regex.root)) +} + +public func capture( + as reference: Reference, + @RegexBuilder _ component: () -> R +) -> Regex<(Substring, W, C0, C1, C2, C3, C4)> where R.Match == (W, C0, C1, C2, C3, C4) { + .init(node: .group(.capture, component().regex.root, reference.id)) } public func capture( - as reference: Reference? = nil, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4)> where R.Match == (W, C0, C1, C2, C3, C4) { @@ -2832,12 +3174,11 @@ public func capture( component().regex.root, CaptureTransform(resultType: NewCapture.self) { transform($0) as Any - }, - reference?.id)) + })) } public func tryCapture( - as reference: Reference? = nil, + as reference: Reference, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) throws -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4)> where R.Match == (W, C0, C1, C2, C3, C4) { @@ -2847,11 +3188,23 @@ public func tryCapture( CaptureTransform(resultType: NewCapture.self) { try transform($0) as Any }, - reference?.id)) + reference.id)) +} + +public func tryCapture( + @RegexBuilder _ component: () -> R, + transform: @escaping (Substring) -> NewCapture? +) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4)> where R.Match == (W, C0, C1, C2, C3, C4) { + .init(node: .groupTransform( + .capture, + component().regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any? + })) } public func tryCapture( - as reference: Reference? = nil, + as reference: Reference, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) -> NewCapture? ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4)> where R.Match == (W, C0, C1, C2, C3, C4) { @@ -2861,19 +3214,38 @@ public func tryCapture( CaptureTransform(resultType: NewCapture.self) { transform($0) as Any? }, - reference?.id)) + reference.id)) } + // MARK: - Non-builder capture arity 6 public func capture( - _ component: R, as reference: Reference? = nil + _ component: R +) -> Regex<(Substring, W, C0, C1, C2, C3, C4, C5)> where R.Match == (W, C0, C1, C2, C3, C4, C5) { + .init(node: .group(.capture, component.regex.root)) +} + +public func capture( + _ component: R, as reference: Reference ) -> Regex<(Substring, W, C0, C1, C2, C3, C4, C5)> where R.Match == (W, C0, C1, C2, C3, C4, C5) { - .init(node: .group(.capture, component.regex.root, reference?.id)) + .init(node: .group(.capture, component.regex.root, reference.id)) +} + +public func capture( + _ component: R, + transform: @escaping (Substring) -> NewCapture +) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5)> where R.Match == (W, C0, C1, C2, C3, C4, C5) { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any + })) } public func capture( _ component: R, - as reference: Reference? = nil, + as reference: Reference, transform: @escaping (Substring) -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5)> where R.Match == (W, C0, C1, C2, C3, C4, C5) { .init(node: .groupTransform( @@ -2882,12 +3254,24 @@ public func capture( CaptureTransform(resultType: NewCapture.self) { transform($0) as Any }, - reference?.id)) + reference.id)) +} + +public func tryCapture( + _ component: R, + transform: @escaping (Substring) throws -> NewCapture +) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5)> where R.Match == (W, C0, C1, C2, C3, C4, C5) { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + try transform($0) as Any + })) } public func tryCapture( _ component: R, - as reference: Reference? = nil, + as reference: Reference, transform: @escaping (Substring) throws -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5)> where R.Match == (W, C0, C1, C2, C3, C4, C5) { .init(node: .groupTransform( @@ -2896,12 +3280,24 @@ public func tryCapture( CaptureTransform(resultType: NewCapture.self) { try transform($0) as Any }, - reference?.id)) + reference.id)) +} + +public func tryCapture( + _ component: R, + transform: @escaping (Substring) -> NewCapture? +) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5)> where R.Match == (W, C0, C1, C2, C3, C4, C5) { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any? + })) } public func tryCapture( _ component: R, - as reference: Reference? = nil, + as reference: Reference, transform: @escaping (Substring) -> NewCapture? ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5)> where R.Match == (W, C0, C1, C2, C3, C4, C5) { .init(node: .groupTransform( @@ -2910,20 +3306,25 @@ public func tryCapture( CaptureTransform(resultType: NewCapture.self) { transform($0) as Any? }, - reference?.id)) + reference.id)) } // MARK: - Builder capture arity 6 public func capture( - as reference: Reference? = nil, @RegexBuilder _ component: () -> R ) -> Regex<(Substring, W, C0, C1, C2, C3, C4, C5)> where R.Match == (W, C0, C1, C2, C3, C4, C5) { - .init(node: .group(.capture, component().regex.root, reference?.id)) + .init(node: .group(.capture, component().regex.root)) +} + +public func capture( + as reference: Reference, + @RegexBuilder _ component: () -> R +) -> Regex<(Substring, W, C0, C1, C2, C3, C4, C5)> where R.Match == (W, C0, C1, C2, C3, C4, C5) { + .init(node: .group(.capture, component().regex.root, reference.id)) } public func capture( - as reference: Reference? = nil, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5)> where R.Match == (W, C0, C1, C2, C3, C4, C5) { @@ -2932,12 +3333,11 @@ public func capture( component().regex.root, CaptureTransform(resultType: NewCapture.self) { transform($0) as Any - }, - reference?.id)) + })) } public func tryCapture( - as reference: Reference? = nil, + as reference: Reference, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) throws -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5)> where R.Match == (W, C0, C1, C2, C3, C4, C5) { @@ -2947,11 +3347,23 @@ public func tryCapture( CaptureTransform(resultType: NewCapture.self) { try transform($0) as Any }, - reference?.id)) + reference.id)) +} + +public func tryCapture( + @RegexBuilder _ component: () -> R, + transform: @escaping (Substring) -> NewCapture? +) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5)> where R.Match == (W, C0, C1, C2, C3, C4, C5) { + .init(node: .groupTransform( + .capture, + component().regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any? + })) } public func tryCapture( - as reference: Reference? = nil, + as reference: Reference, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) -> NewCapture? ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5)> where R.Match == (W, C0, C1, C2, C3, C4, C5) { @@ -2961,19 +3373,38 @@ public func tryCapture( CaptureTransform(resultType: NewCapture.self) { transform($0) as Any? }, - reference?.id)) + reference.id)) } + // MARK: - Non-builder capture arity 7 public func capture( - _ component: R, as reference: Reference? = nil + _ component: R +) -> Regex<(Substring, W, C0, C1, C2, C3, C4, C5, C6)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6) { + .init(node: .group(.capture, component.regex.root)) +} + +public func capture( + _ component: R, as reference: Reference ) -> Regex<(Substring, W, C0, C1, C2, C3, C4, C5, C6)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6) { - .init(node: .group(.capture, component.regex.root, reference?.id)) + .init(node: .group(.capture, component.regex.root, reference.id)) +} + +public func capture( + _ component: R, + transform: @escaping (Substring) -> NewCapture +) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6) { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any + })) } public func capture( _ component: R, - as reference: Reference? = nil, + as reference: Reference, transform: @escaping (Substring) -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6) { .init(node: .groupTransform( @@ -2982,12 +3413,24 @@ public func capture CaptureTransform(resultType: NewCapture.self) { transform($0) as Any }, - reference?.id)) + reference.id)) +} + +public func tryCapture( + _ component: R, + transform: @escaping (Substring) throws -> NewCapture +) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6) { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + try transform($0) as Any + })) } public func tryCapture( _ component: R, - as reference: Reference? = nil, + as reference: Reference, transform: @escaping (Substring) throws -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6) { .init(node: .groupTransform( @@ -2996,12 +3439,24 @@ public func tryCapture( + _ component: R, + transform: @escaping (Substring) -> NewCapture? +) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6) { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any? + })) } public func tryCapture( _ component: R, - as reference: Reference? = nil, + as reference: Reference, transform: @escaping (Substring) -> NewCapture? ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6) { .init(node: .groupTransform( @@ -3010,20 +3465,25 @@ public func tryCapture( - as reference: Reference? = nil, @RegexBuilder _ component: () -> R ) -> Regex<(Substring, W, C0, C1, C2, C3, C4, C5, C6)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6) { - .init(node: .group(.capture, component().regex.root, reference?.id)) + .init(node: .group(.capture, component().regex.root)) +} + +public func capture( + as reference: Reference, + @RegexBuilder _ component: () -> R +) -> Regex<(Substring, W, C0, C1, C2, C3, C4, C5, C6)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6) { + .init(node: .group(.capture, component().regex.root, reference.id)) } public func capture( - as reference: Reference? = nil, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6) { @@ -3032,12 +3492,11 @@ public func capture component().regex.root, CaptureTransform(resultType: NewCapture.self) { transform($0) as Any - }, - reference?.id)) + })) } public func tryCapture( - as reference: Reference? = nil, + as reference: Reference, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) throws -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6) { @@ -3047,11 +3506,23 @@ public func tryCapture( + @RegexBuilder _ component: () -> R, + transform: @escaping (Substring) -> NewCapture? +) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6) { + .init(node: .groupTransform( + .capture, + component().regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any? + })) } public func tryCapture( - as reference: Reference? = nil, + as reference: Reference, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) -> NewCapture? ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6) { @@ -3061,19 +3532,38 @@ public func tryCapture( - _ component: R, as reference: Reference? = nil + _ component: R +) -> Regex<(Substring, W, C0, C1, C2, C3, C4, C5, C6, C7)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { + .init(node: .group(.capture, component.regex.root)) +} + +public func capture( + _ component: R, as reference: Reference ) -> Regex<(Substring, W, C0, C1, C2, C3, C4, C5, C6, C7)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { - .init(node: .group(.capture, component.regex.root, reference?.id)) + .init(node: .group(.capture, component.regex.root, reference.id)) +} + +public func capture( + _ component: R, + transform: @escaping (Substring) -> NewCapture +) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any + })) } public func capture( _ component: R, - as reference: Reference? = nil, + as reference: Reference, transform: @escaping (Substring) -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { .init(node: .groupTransform( @@ -3082,12 +3572,24 @@ public func capture( + _ component: R, + transform: @escaping (Substring) throws -> NewCapture +) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + try transform($0) as Any + })) } public func tryCapture( _ component: R, - as reference: Reference? = nil, + as reference: Reference, transform: @escaping (Substring) throws -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { .init(node: .groupTransform( @@ -3096,12 +3598,24 @@ public func tryCapture( + _ component: R, + transform: @escaping (Substring) -> NewCapture? +) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any? + })) } public func tryCapture( _ component: R, - as reference: Reference? = nil, + as reference: Reference, transform: @escaping (Substring) -> NewCapture? ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { .init(node: .groupTransform( @@ -3110,20 +3624,25 @@ public func tryCapture( - as reference: Reference? = nil, @RegexBuilder _ component: () -> R ) -> Regex<(Substring, W, C0, C1, C2, C3, C4, C5, C6, C7)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { - .init(node: .group(.capture, component().regex.root, reference?.id)) + .init(node: .group(.capture, component().regex.root)) +} + +public func capture( + as reference: Reference, + @RegexBuilder _ component: () -> R +) -> Regex<(Substring, W, C0, C1, C2, C3, C4, C5, C6, C7)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { + .init(node: .group(.capture, component().regex.root, reference.id)) } public func capture( - as reference: Reference? = nil, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { @@ -3132,12 +3651,11 @@ public func capture( - as reference: Reference? = nil, + as reference: Reference, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) throws -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { @@ -3147,11 +3665,23 @@ public func tryCapture( + @RegexBuilder _ component: () -> R, + transform: @escaping (Substring) -> NewCapture? +) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { + .init(node: .groupTransform( + .capture, + component().regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any? + })) } public func tryCapture( - as reference: Reference? = nil, + as reference: Reference, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) -> NewCapture? ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { @@ -3161,19 +3691,38 @@ public func tryCapture( - _ component: R, as reference: Reference? = nil + _ component: R +) -> Regex<(Substring, W, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { + .init(node: .group(.capture, component.regex.root)) +} + +public func capture( + _ component: R, as reference: Reference ) -> Regex<(Substring, W, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { - .init(node: .group(.capture, component.regex.root, reference?.id)) + .init(node: .group(.capture, component.regex.root, reference.id)) +} + +public func capture( + _ component: R, + transform: @escaping (Substring) -> NewCapture +) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any + })) } public func capture( _ component: R, - as reference: Reference? = nil, + as reference: Reference, transform: @escaping (Substring) -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { .init(node: .groupTransform( @@ -3182,12 +3731,24 @@ public func capture( + _ component: R, + transform: @escaping (Substring) throws -> NewCapture +) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + try transform($0) as Any + })) } public func tryCapture( _ component: R, - as reference: Reference? = nil, + as reference: Reference, transform: @escaping (Substring) throws -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { .init(node: .groupTransform( @@ -3196,12 +3757,24 @@ public func tryCapture( + _ component: R, + transform: @escaping (Substring) -> NewCapture? +) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { + .init(node: .groupTransform( + .capture, + component.regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any? + })) } public func tryCapture( _ component: R, - as reference: Reference? = nil, + as reference: Reference, transform: @escaping (Substring) -> NewCapture? ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { .init(node: .groupTransform( @@ -3210,20 +3783,25 @@ public func tryCapture( - as reference: Reference? = nil, @RegexBuilder _ component: () -> R ) -> Regex<(Substring, W, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { - .init(node: .group(.capture, component().regex.root, reference?.id)) + .init(node: .group(.capture, component().regex.root)) +} + +public func capture( + as reference: Reference, + @RegexBuilder _ component: () -> R +) -> Regex<(Substring, W, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { + .init(node: .group(.capture, component().regex.root, reference.id)) } public func capture( - as reference: Reference? = nil, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { @@ -3232,12 +3810,11 @@ public func capture( - as reference: Reference? = nil, + as reference: Reference, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) throws -> NewCapture ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { @@ -3247,11 +3824,23 @@ public func tryCapture( + @RegexBuilder _ component: () -> R, + transform: @escaping (Substring) -> NewCapture? +) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { + .init(node: .groupTransform( + .capture, + component().regex.root, + CaptureTransform(resultType: NewCapture.self) { + transform($0) as Any? + })) } public func tryCapture( - as reference: Reference? = nil, + as reference: Reference, @RegexBuilder _ component: () -> R, transform: @escaping (Substring) -> NewCapture? ) -> Regex<(Substring, NewCapture, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { @@ -3261,8 +3850,9 @@ public func tryCapture