@@ -89,12 +89,13 @@ struct StandardErrorStream: TextOutputStream {
8989var standardError = StandardErrorStream ( )
9090
9191typealias Counter = Int64
92- let regexProtocolName = " RegexProtocol "
92+ let regexComponentProtocolName = " RegexComponent "
9393let matchAssociatedTypeName = " Match "
94- let patternBuilderTypeName = " RegexBuilder "
9594let patternProtocolRequirementName = " regex "
9695let regexTypeName = " Regex "
9796let baseMatchTypeName = " Substring "
97+ let concatBuilderName = " RegexComponentBuilder "
98+ let altBuilderName = " AlternationBuilder "
9899
99100@main
100101struct VariadicsGenerator : ParsableCommand {
@@ -194,7 +195,7 @@ struct VariadicsGenerator: ParsableCommand {
194195 result += ( 0 ..< leftArity+ rightArity) . map {
195196 " , C \( $0) "
196197 } . joined ( )
197- result += " , R0: \( regexProtocolName ) , R1: \( regexProtocolName ) "
198+ result += " , R0: \( regexComponentProtocolName ) , R1: \( regexComponentProtocolName ) "
198199 return result
199200 } ( )
200201
@@ -231,7 +232,7 @@ struct VariadicsGenerator: ParsableCommand {
231232 } ( )
232233
233234 // Emit concatenation builder.
234- output ( " extension \( patternBuilderTypeName ) { \n " )
235+ output ( " extension \( concatBuilderName ) { \n " )
235236 output ( """
236237 public static func buildBlock< \( genericParams) >(
237238 combining next: R1, into combined: R0
@@ -246,14 +247,14 @@ struct VariadicsGenerator: ParsableCommand {
246247 func emitConcatenationWithEmpty( leftArity: Int ) {
247248 // T + () = T
248249 output ( """
249- extension RegexBuilder {
250+ extension \( concatBuilderName ) {
250251 public static func buildBlock<W0
251252 """ )
252253 outputForEach ( 0 ..< leftArity) {
253254 " , C \( $0) "
254255 }
255256 output ( """
256- , R0: \( regexProtocolName ) , R1: \( regexProtocolName ) >(
257+ , R0: \( regexComponentProtocolName ) , R1: \( regexComponentProtocolName ) >(
257258 combining next: R1, into combined: R0
258259 ) -> \( regexTypeName) <
259260 """ )
@@ -329,7 +330,7 @@ struct VariadicsGenerator: ParsableCommand {
329330 result += ( 0 ..< arity) . map { " , C \( $0) " } . joined ( )
330331 result += " , "
331332 }
332- result += " Component: \( regexProtocolName ) "
333+ result += " Component: \( regexComponentProtocolName ) "
333334 return result
334335 } ( )
335336
@@ -366,7 +367,7 @@ struct VariadicsGenerator: ParsableCommand {
366367 \( params. disfavored) \
367368 public func \( kind. rawValue) < \( params. genericParams) >(
368369 _ behavior: QuantificationBehavior = .eagerly,
369- @RegexBuilder _ component: () -> Component
370+ @ \( concatBuilderName ) _ component: () -> Component
370371 ) -> \( regexTypeName) < \( params. matchType) > \( params. whereClause) {
371372 .init(node: .quantification(. \( kind. astQuantifierAmount) , behavior.astKind, component().regex.root))
372373 }
@@ -380,7 +381,7 @@ struct VariadicsGenerator: ParsableCommand {
380381
381382 \( kind == . zeroOrOne ?
382383 """
383- extension RegexBuilder {
384+ extension \( concatBuilderName ) {
384385 public static func buildLimitedAvailability< \( params. genericParams) >(
385386 _ component: Component
386387 ) -> \( regexTypeName) < \( params. matchType) > \( params. whereClause) {
@@ -413,7 +414,7 @@ struct VariadicsGenerator: ParsableCommand {
413414 \( params. disfavored) \
414415 public func repeating< \( params. genericParams) >(
415416 count: Int,
416- @RegexBuilder _ component: () -> Component
417+ @ \( concatBuilderName ) _ component: () -> Component
417418 ) -> \( regexTypeName) < \( params. matchType) > \( params. whereClause) {
418419 assert(count > 0, " Must specify a positive count " )
419420 // TODO: Emit a warning about `repeatMatch(count: 0)` or `repeatMatch(count: 1)`
@@ -433,7 +434,7 @@ struct VariadicsGenerator: ParsableCommand {
433434 public func repeating< \( params. genericParams) , R: RangeExpression>(
434435 _ expression: R,
435436 _ behavior: QuantificationBehavior = .eagerly,
436- @RegexBuilder _ component: () -> Component
437+ @ \( concatBuilderName ) _ component: () -> Component
437438 ) -> \( regexTypeName) < \( params. matchType) > \( params. repeatingWhereClause) {
438439 .init(node: .repeating(expression.relative(to: 0..<Int.max), behavior, component().regex.root))
439440 }
@@ -456,7 +457,7 @@ struct VariadicsGenerator: ParsableCommand {
456457 } ( )
457458 let genericParams = leftGenParams + " , " + rightGenParams
458459 let whereClause : String = {
459- var result = " where R0: \( regexProtocolName ) , R1: \( regexProtocolName ) "
460+ var result = " where R0: \( regexComponentProtocolName ) , R1: \( regexComponentProtocolName ) "
460461 if leftArity > 0 {
461462 result += " , R0. \( matchAssociatedTypeName) == (W0, \( ( 0 ..< leftArity) . map { " C \( $0) " } . joined ( separator: " , " ) ) ) "
462463 }
@@ -480,7 +481,7 @@ struct VariadicsGenerator: ParsableCommand {
480481 return " ( \( baseMatchTypeName) , \( resultCaptures) ) "
481482 } ( )
482483 output ( """
483- extension AlternationBuilder {
484+ extension \( altBuilderName ) {
484485 public static func buildBlock< \( genericParams) >(
485486 combining next: R1, into combined: R0
486487 ) -> \( regexTypeName) < \( matchType) > \( whereClause) {
@@ -505,12 +506,12 @@ struct VariadicsGenerator: ParsableCommand {
505506 return " R, W, " + captures
506507 } ( )
507508 let whereClause : String = """
508- where R: \( regexProtocolName ) , \
509+ where R: \( regexComponentProtocolName ) , \
509510 R. \( matchAssociatedTypeName) == (W, \( captures) )
510511 """
511512 let resultCaptures = ( 0 ..< arity) . map { " C \( $0) ? " } . joined ( separator: " , " )
512513 output ( """
513- extension AlternationBuilder {
514+ extension \( altBuilderName ) {
514515 public static func buildBlock< \( genericParams) >(_ regex: R) -> \( regexTypeName) <(W, \( resultCaptures) )> \( whereClause) {
515516 .init(node: .alternation([regex.regex.root]))
516517 }
@@ -521,8 +522,8 @@ struct VariadicsGenerator: ParsableCommand {
521522
522523 func emitCapture( arity: Int ) {
523524 let genericParams = arity == 0
524- ? " R: \( regexProtocolName ) , W "
525- : " R: \( regexProtocolName ) , W, " + ( 0 ..< arity) . map { " C \( $0) " } . joined ( separator: " , " )
525+ ? " R: \( regexComponentProtocolName ) , W "
526+ : " R: \( regexComponentProtocolName ) , W, " + ( 0 ..< arity) . map { " C \( $0) " } . joined ( separator: " , " )
526527 let matchType = arity == 0
527528 ? " W "
528529 : " (W, " + ( 0 ..< arity) . map { " C \( $0) " } . joined ( separator: " , " ) + " ) "
@@ -630,20 +631,20 @@ struct VariadicsGenerator: ParsableCommand {
630631 // MARK: - Builder capture arity \( arity)
631632
632633 public func capture< \( genericParams) >(
633- @RegexBuilder _ component: () -> R
634+ @ \( concatBuilderName ) _ component: () -> R
634635 ) -> \( regexTypeName) < \( rawNewMatchType) > \( whereClause) {
635636 .init(node: .group(.capture, component().regex.root))
636637 }
637638
638639 public func capture< \( genericParams) >(
639640 as reference: Reference<W>,
640- @RegexBuilder _ component: () -> R
641+ @ \( concatBuilderName ) _ component: () -> R
641642 ) -> \( regexTypeName) < \( rawNewMatchType) > \( whereClause) {
642643 .init(node: .group(.capture, component().regex.root, reference.id))
643644 }
644645
645646 public func capture< \( genericParams) , NewCapture>(
646- @RegexBuilder _ component: () -> R,
647+ @ \( concatBuilderName ) _ component: () -> R,
647648 transform: @escaping (Substring) -> NewCapture
648649 ) -> \( regexTypeName) < \( transformedNewMatchType) > \( whereClause) {
649650 .init(node: .groupTransform(
@@ -656,7 +657,7 @@ struct VariadicsGenerator: ParsableCommand {
656657
657658 public func tryCapture< \( genericParams) , NewCapture>(
658659 as reference: Reference<NewCapture>,
659- @RegexBuilder _ component: () -> R,
660+ @ \( concatBuilderName ) _ component: () -> R,
660661 transform: @escaping (Substring) throws -> NewCapture
661662 ) -> \( regexTypeName) < \( transformedNewMatchType) > \( whereClause) {
662663 .init(node: .groupTransform(
@@ -669,7 +670,7 @@ struct VariadicsGenerator: ParsableCommand {
669670 }
670671
671672 public func tryCapture< \( genericParams) , NewCapture>(
672- @RegexBuilder _ component: () -> R,
673+ @ \( concatBuilderName ) _ component: () -> R,
673674 transform: @escaping (Substring) -> NewCapture?
674675 ) -> \( regexTypeName) < \( transformedNewMatchType) > \( whereClause) {
675676 .init(node: .groupTransform(
@@ -682,7 +683,7 @@ struct VariadicsGenerator: ParsableCommand {
682683
683684 public func tryCapture< \( genericParams) , NewCapture>(
684685 as reference: Reference<NewCapture>,
685- @RegexBuilder _ component: () -> R,
686+ @ \( concatBuilderName ) _ component: () -> R,
686687 transform: @escaping (Substring) -> NewCapture?
687688 ) -> \( regexTypeName) < \( transformedNewMatchType) > \( whereClause) {
688689 .init(node: .groupTransform(
0 commit comments