Skip to content

Adopt buildPartialBlock. #204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ See [Declarative String Processing Overview][decl-string]

## Requirements

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

## Integration with Swift

Expand Down
20 changes: 10 additions & 10 deletions Sources/VariadicsGenerator/VariadicsGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,10 @@ struct VariadicsGenerator: ParsableCommand {
// Emit concatenation builder.
output("extension \(concatBuilderName) {\n")
output("""
public static func buildBlock<\(genericParams)>(
combining next: R1, into combined: R0
public static func buildPartialBlock<\(genericParams)>(
accumulated: R0, next: R1
) -> \(regexTypeName)<\(matchType)> \(whereClause) {
.init(node: combined.regex.root.appending(next.regex.root))
.init(node: accumulated.regex.root.appending(next.regex.root))
}
}

Expand All @@ -248,14 +248,14 @@ struct VariadicsGenerator: ParsableCommand {
// T + () = T
output("""
extension \(concatBuilderName) {
public static func buildBlock<W0
public static func buildPartialBlock<W0
""")
outputForEach(0..<leftArity) {
", C\($0)"
}
output("""
, R0: \(regexComponentProtocolName), R1: \(regexComponentProtocolName)>(
combining next: R1, into combined: R0
accumulated: R0, next: R1
) -> \(regexTypeName)<
""")
if leftArity == 0 {
Expand All @@ -279,7 +279,7 @@ struct VariadicsGenerator: ParsableCommand {
}
output("""
{
.init(node: combined.regex.root.appending(next.regex.root))
.init(node: accumulated.regex.root.appending(next.regex.root))
}
}

Expand Down Expand Up @@ -491,10 +491,10 @@ struct VariadicsGenerator: ParsableCommand {
}()
output("""
extension \(altBuilderName) {
public static func buildBlock<\(genericParams)>(
combining next: R1, into combined: R0
public static func buildPartialBlock<\(genericParams)>(
accumulated: R0, next: R1
) -> ChoiceOf<\(matchType)> \(whereClause) {
.init(node: combined.regex.root.appendingAlternationCase(next.regex.root))
.init(node: accumulated.regex.root.appendingAlternationCase(next.regex.root))
}
}

Expand All @@ -521,7 +521,7 @@ struct VariadicsGenerator: ParsableCommand {
let resultCaptures = (0..<arity).map { "C\($0)?" }.joined(separator: ", ")
output("""
extension \(altBuilderName) {
public static func buildBlock<\(genericParams)>(_ regex: R) -> ChoiceOf<(W, \(resultCaptures))> \(whereClause) {
public static func buildPartialBlock<\(genericParams)>(first regex: R) -> ChoiceOf<(W, \(resultCaptures))> \(whereClause) {
.init(node: .alternation([regex.regex.root]))
}
}
Expand Down
5 changes: 2 additions & 3 deletions Sources/_StringProcessing/RegexDSL/Builder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ public enum RegexComponentBuilder {
.init(node: .empty)
}

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

public static func buildExpression<R: RegexComponent>(_ regex: R) -> R {
Expand Down
4 changes: 3 additions & 1 deletion Sources/_StringProcessing/RegexDSL/DSL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ postfix operator .+
@resultBuilder
public struct AlternationBuilder {
@_disfavoredOverload
public static func buildBlock<R: RegexComponent>(_ component: R) -> ChoiceOf<R.Match> {
public static func buildPartialBlock<R: RegexComponent>(
first component: R
) -> ChoiceOf<R.Match> {
.init(component.regex)
}

Expand Down
Loading