@@ -89,12 +89,13 @@ struct StandardErrorStream: TextOutputStream {
89
89
var standardError = StandardErrorStream ( )
90
90
91
91
typealias Counter = Int64
92
- let regexProtocolName = " RegexProtocol "
92
+ let regexComponentProtocolName = " RegexComponent "
93
93
let matchAssociatedTypeName = " Match "
94
- let patternBuilderTypeName = " RegexBuilder "
95
94
let patternProtocolRequirementName = " regex "
96
95
let regexTypeName = " Regex "
97
96
let baseMatchTypeName = " Substring "
97
+ let concatBuilderName = " RegexComponentBuilder "
98
+ let altBuilderName = " AlternationBuilder "
98
99
99
100
@main
100
101
struct VariadicsGenerator : ParsableCommand {
@@ -194,7 +195,7 @@ struct VariadicsGenerator: ParsableCommand {
194
195
result += ( 0 ..< leftArity+ rightArity) . map {
195
196
" , C \( $0) "
196
197
} . joined ( )
197
- result += " , R0: \( regexProtocolName ) , R1: \( regexProtocolName ) "
198
+ result += " , R0: \( regexComponentProtocolName ) , R1: \( regexComponentProtocolName ) "
198
199
return result
199
200
} ( )
200
201
@@ -231,7 +232,7 @@ struct VariadicsGenerator: ParsableCommand {
231
232
} ( )
232
233
233
234
// Emit concatenation builder.
234
- output ( " extension \( patternBuilderTypeName ) { \n " )
235
+ output ( " extension \( concatBuilderName ) { \n " )
235
236
output ( """
236
237
public static func buildBlock< \( genericParams) >(
237
238
combining next: R1, into combined: R0
@@ -246,14 +247,14 @@ struct VariadicsGenerator: ParsableCommand {
246
247
func emitConcatenationWithEmpty( leftArity: Int ) {
247
248
// T + () = T
248
249
output ( """
249
- extension RegexBuilder {
250
+ extension \( concatBuilderName ) {
250
251
public static func buildBlock<W0
251
252
""" )
252
253
outputForEach ( 0 ..< leftArity) {
253
254
" , C \( $0) "
254
255
}
255
256
output ( """
256
- , R0: \( regexProtocolName ) , R1: \( regexProtocolName ) >(
257
+ , R0: \( regexComponentProtocolName ) , R1: \( regexComponentProtocolName ) >(
257
258
combining next: R1, into combined: R0
258
259
) -> \( regexTypeName) <
259
260
""" )
@@ -329,7 +330,7 @@ struct VariadicsGenerator: ParsableCommand {
329
330
result += ( 0 ..< arity) . map { " , C \( $0) " } . joined ( )
330
331
result += " , "
331
332
}
332
- result += " Component: \( regexProtocolName ) "
333
+ result += " Component: \( regexComponentProtocolName ) "
333
334
return result
334
335
} ( )
335
336
@@ -366,7 +367,7 @@ struct VariadicsGenerator: ParsableCommand {
366
367
\( params. disfavored) \
367
368
public func \( kind. rawValue) < \( params. genericParams) >(
368
369
_ behavior: QuantificationBehavior = .eagerly,
369
- @RegexBuilder _ component: () -> Component
370
+ @ \( concatBuilderName ) _ component: () -> Component
370
371
) -> \( regexTypeName) < \( params. matchType) > \( params. whereClause) {
371
372
.init(node: .quantification(. \( kind. astQuantifierAmount) , behavior.astKind, component().regex.root))
372
373
}
@@ -380,7 +381,7 @@ struct VariadicsGenerator: ParsableCommand {
380
381
381
382
\( kind == . zeroOrOne ?
382
383
"""
383
- extension RegexBuilder {
384
+ extension \( concatBuilderName ) {
384
385
public static func buildLimitedAvailability< \( params. genericParams) >(
385
386
_ component: Component
386
387
) -> \( regexTypeName) < \( params. matchType) > \( params. whereClause) {
@@ -413,7 +414,7 @@ struct VariadicsGenerator: ParsableCommand {
413
414
\( params. disfavored) \
414
415
public func repeating< \( params. genericParams) >(
415
416
count: Int,
416
- @RegexBuilder _ component: () -> Component
417
+ @ \( concatBuilderName ) _ component: () -> Component
417
418
) -> \( regexTypeName) < \( params. matchType) > \( params. whereClause) {
418
419
assert(count > 0, " Must specify a positive count " )
419
420
// TODO: Emit a warning about `repeatMatch(count: 0)` or `repeatMatch(count: 1)`
@@ -433,7 +434,7 @@ struct VariadicsGenerator: ParsableCommand {
433
434
public func repeating< \( params. genericParams) , R: RangeExpression>(
434
435
_ expression: R,
435
436
_ behavior: QuantificationBehavior = .eagerly,
436
- @RegexBuilder _ component: () -> Component
437
+ @ \( concatBuilderName ) _ component: () -> Component
437
438
) -> \( regexTypeName) < \( params. matchType) > \( params. repeatingWhereClause) {
438
439
.init(node: .repeating(expression.relative(to: 0..<Int.max), behavior, component().regex.root))
439
440
}
@@ -456,7 +457,7 @@ struct VariadicsGenerator: ParsableCommand {
456
457
} ( )
457
458
let genericParams = leftGenParams + " , " + rightGenParams
458
459
let whereClause : String = {
459
- var result = " where R0: \( regexProtocolName ) , R1: \( regexProtocolName ) "
460
+ var result = " where R0: \( regexComponentProtocolName ) , R1: \( regexComponentProtocolName ) "
460
461
if leftArity > 0 {
461
462
result += " , R0. \( matchAssociatedTypeName) == (W0, \( ( 0 ..< leftArity) . map { " C \( $0) " } . joined ( separator: " , " ) ) ) "
462
463
}
@@ -480,7 +481,7 @@ struct VariadicsGenerator: ParsableCommand {
480
481
return " ( \( baseMatchTypeName) , \( resultCaptures) ) "
481
482
} ( )
482
483
output ( """
483
- extension AlternationBuilder {
484
+ extension \( altBuilderName ) {
484
485
public static func buildBlock< \( genericParams) >(
485
486
combining next: R1, into combined: R0
486
487
) -> \( regexTypeName) < \( matchType) > \( whereClause) {
@@ -505,12 +506,12 @@ struct VariadicsGenerator: ParsableCommand {
505
506
return " R, W, " + captures
506
507
} ( )
507
508
let whereClause : String = """
508
- where R: \( regexProtocolName ) , \
509
+ where R: \( regexComponentProtocolName ) , \
509
510
R. \( matchAssociatedTypeName) == (W, \( captures) )
510
511
"""
511
512
let resultCaptures = ( 0 ..< arity) . map { " C \( $0) ? " } . joined ( separator: " , " )
512
513
output ( """
513
- extension AlternationBuilder {
514
+ extension \( altBuilderName ) {
514
515
public static func buildBlock< \( genericParams) >(_ regex: R) -> \( regexTypeName) <(W, \( resultCaptures) )> \( whereClause) {
515
516
.init(node: .alternation([regex.regex.root]))
516
517
}
@@ -521,8 +522,8 @@ struct VariadicsGenerator: ParsableCommand {
521
522
522
523
func emitCapture( arity: Int ) {
523
524
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: " , " )
526
527
let matchType = arity == 0
527
528
? " W "
528
529
: " (W, " + ( 0 ..< arity) . map { " C \( $0) " } . joined ( separator: " , " ) + " ) "
@@ -630,20 +631,20 @@ struct VariadicsGenerator: ParsableCommand {
630
631
// MARK: - Builder capture arity \( arity)
631
632
632
633
public func capture< \( genericParams) >(
633
- @RegexBuilder _ component: () -> R
634
+ @ \( concatBuilderName ) _ component: () -> R
634
635
) -> \( regexTypeName) < \( rawNewMatchType) > \( whereClause) {
635
636
.init(node: .group(.capture, component().regex.root))
636
637
}
637
638
638
639
public func capture< \( genericParams) >(
639
640
as reference: Reference<W>,
640
- @RegexBuilder _ component: () -> R
641
+ @ \( concatBuilderName ) _ component: () -> R
641
642
) -> \( regexTypeName) < \( rawNewMatchType) > \( whereClause) {
642
643
.init(node: .group(.capture, component().regex.root, reference.id))
643
644
}
644
645
645
646
public func capture< \( genericParams) , NewCapture>(
646
- @RegexBuilder _ component: () -> R,
647
+ @ \( concatBuilderName ) _ component: () -> R,
647
648
transform: @escaping (Substring) -> NewCapture
648
649
) -> \( regexTypeName) < \( transformedNewMatchType) > \( whereClause) {
649
650
.init(node: .groupTransform(
@@ -656,7 +657,7 @@ struct VariadicsGenerator: ParsableCommand {
656
657
657
658
public func tryCapture< \( genericParams) , NewCapture>(
658
659
as reference: Reference<NewCapture>,
659
- @RegexBuilder _ component: () -> R,
660
+ @ \( concatBuilderName ) _ component: () -> R,
660
661
transform: @escaping (Substring) throws -> NewCapture
661
662
) -> \( regexTypeName) < \( transformedNewMatchType) > \( whereClause) {
662
663
.init(node: .groupTransform(
@@ -669,7 +670,7 @@ struct VariadicsGenerator: ParsableCommand {
669
670
}
670
671
671
672
public func tryCapture< \( genericParams) , NewCapture>(
672
- @RegexBuilder _ component: () -> R,
673
+ @ \( concatBuilderName ) _ component: () -> R,
673
674
transform: @escaping (Substring) -> NewCapture?
674
675
) -> \( regexTypeName) < \( transformedNewMatchType) > \( whereClause) {
675
676
.init(node: .groupTransform(
@@ -682,7 +683,7 @@ struct VariadicsGenerator: ParsableCommand {
682
683
683
684
public func tryCapture< \( genericParams) , NewCapture>(
684
685
as reference: Reference<NewCapture>,
685
- @RegexBuilder _ component: () -> R,
686
+ @ \( concatBuilderName ) _ component: () -> R,
686
687
transform: @escaping (Substring) -> NewCapture?
687
688
) -> \( regexTypeName) < \( transformedNewMatchType) > \( whereClause) {
688
689
.init(node: .groupTransform(
0 commit comments