Skip to content

Commit a9509fc

Browse files
committed
Adopt buildPartialBlock.
Transition from the old name `buildBlock(combining:into:)` to the [newly proposed](https://forums.swift.org/t/pitch-buildpartialblock-for-result-builders/55561) `buildPartialBlock(first:)` and `buildPartialBlock(accumulated:next:)`. Requires DEVELOPMENT-SNAPSHOT-2022-03-09 or later.
1 parent 85c7d90 commit a9509fc

File tree

5 files changed

+419
-418
lines changed

5 files changed

+419
-418
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ See [Declarative String Processing Overview][decl-string]
88

99
## Requirements
1010

11-
- [Swift Trunk Development Snapshot](https://www.swift.org/download/#snapshots) DEVELOPMENT-SNAPSHOT-2022-02-03 or later.
11+
- [Swift Trunk Development Snapshot](https://www.swift.org/download/#snapshots) DEVELOPMENT-SNAPSHOT-2022-03-09 or later.
1212

1313
## Integration with Swift
1414

Sources/VariadicsGenerator/VariadicsGenerator.swift

+10-10
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,10 @@ struct VariadicsGenerator: ParsableCommand {
234234
// Emit concatenation builder.
235235
output("extension \(concatBuilderName) {\n")
236236
output("""
237-
public static func buildBlock<\(genericParams)>(
238-
combining next: R1, into combined: R0
237+
public static func buildPartialBlock<\(genericParams)>(
238+
accumulated: R0, next: R1
239239
) -> \(regexTypeName)<\(matchType)> \(whereClause) {
240-
.init(node: combined.regex.root.appending(next.regex.root))
240+
.init(node: accumulated.regex.root.appending(next.regex.root))
241241
}
242242
}
243243
@@ -248,14 +248,14 @@ struct VariadicsGenerator: ParsableCommand {
248248
// T + () = T
249249
output("""
250250
extension \(concatBuilderName) {
251-
public static func buildBlock<W0
251+
public static func buildPartialBlock<W0
252252
""")
253253
outputForEach(0..<leftArity) {
254254
", C\($0)"
255255
}
256256
output("""
257257
, R0: \(regexComponentProtocolName), R1: \(regexComponentProtocolName)>(
258-
combining next: R1, into combined: R0
258+
accumulated: R0, next: R1
259259
) -> \(regexTypeName)<
260260
""")
261261
if leftArity == 0 {
@@ -279,7 +279,7 @@ struct VariadicsGenerator: ParsableCommand {
279279
}
280280
output("""
281281
{
282-
.init(node: combined.regex.root.appending(next.regex.root))
282+
.init(node: accumulated.regex.root.appending(next.regex.root))
283283
}
284284
}
285285
@@ -491,10 +491,10 @@ struct VariadicsGenerator: ParsableCommand {
491491
}()
492492
output("""
493493
extension \(altBuilderName) {
494-
public static func buildBlock<\(genericParams)>(
495-
combining next: R1, into combined: R0
494+
public static func buildPartialBlock<\(genericParams)>(
495+
accumulated: R0, next: R1
496496
) -> ChoiceOf<\(matchType)> \(whereClause) {
497-
.init(node: combined.regex.root.appendingAlternationCase(next.regex.root))
497+
.init(node: accumulated.regex.root.appendingAlternationCase(next.regex.root))
498498
}
499499
}
500500
@@ -521,7 +521,7 @@ struct VariadicsGenerator: ParsableCommand {
521521
let resultCaptures = (0..<arity).map { "C\($0)?" }.joined(separator: ", ")
522522
output("""
523523
extension \(altBuilderName) {
524-
public static func buildBlock<\(genericParams)>(_ regex: R) -> ChoiceOf<(W, \(resultCaptures))> \(whereClause) {
524+
public static func buildPartialBlock<\(genericParams)>(first regex: R) -> ChoiceOf<(W, \(resultCaptures))> \(whereClause) {
525525
.init(node: .alternation([regex.regex.root]))
526526
}
527527
}

Sources/_StringProcessing/RegexDSL/Builder.swift

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ public enum RegexComponentBuilder {
1515
.init(node: .empty)
1616
}
1717

18-
// TODO: Rename to `buildPartialBlock(first:)` when the feature lands.
19-
public static func buildBlock<R0: RegexComponent>(_ r0: R0) -> R0 {
20-
r0
18+
public static func buildPartialBlock<R: RegexComponent>(first: R ) -> R {
19+
first
2120
}
2221

2322
public static func buildExpression<R: RegexComponent>(_ regex: R) -> R {

Sources/_StringProcessing/RegexDSL/DSL.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@ postfix operator .+
192192
@resultBuilder
193193
public struct AlternationBuilder {
194194
@_disfavoredOverload
195-
public static func buildBlock<R: RegexComponent>(_ component: R) -> ChoiceOf<R.Match> {
195+
public static func buildPartialBlock<R: RegexComponent>(
196+
first component: R
197+
) -> ChoiceOf<R.Match> {
196198
.init(component.regex)
197199
}
198200

0 commit comments

Comments
 (0)