@@ -211,19 +211,14 @@ struct VariadicsGenerator: ParsableCommand {
211
211
}
212
212
213
213
func emitConcatenation( leftArity: Int , rightArity: Int ) {
214
- func genericParameters ( withConstraints : Bool ) -> String {
214
+ let genericParams : String = {
215
215
var result = " W0, W1 "
216
216
result += ( 0 ..< leftArity+ rightArity) . map {
217
217
" , C \( $0) "
218
218
} . joined ( )
219
- result += " , "
220
- if withConstraints {
221
- result += " R0: \( regexProtocolName) , R1: \( regexProtocolName) "
222
- } else {
223
- result += " R0, R1 "
224
- }
219
+ result += " , R0: \( regexProtocolName) , R1: \( regexProtocolName) "
225
220
return result
226
- }
221
+ } ( )
227
222
228
223
// Emit concatenation type declaration.
229
224
@@ -260,13 +255,13 @@ struct VariadicsGenerator: ParsableCommand {
260
255
// Emit concatenation builder.
261
256
output ( " extension \( patternBuilderTypeName) { \n " )
262
257
output ( """
263
- @_disfavoredOverload
264
- public static func buildBlock< \( genericParameters ( withConstraints: true ) ) >(
265
- combining next: R1, into combined: R0
266
- ) -> \( regexTypeName) < \( matchType) > \( whereClause) {
267
- .init(node: combined.regex.root.appending(next.regex.root))
268
- }
258
+ @_disfavoredOverload
259
+ public static func buildBlock< \( genericParams) >(
260
+ combining next: R1, into combined: R0
261
+ ) -> \( regexTypeName) < \( matchType) > \( whereClause) {
262
+ .init(node: combined.regex.root.appending(next.regex.root))
269
263
}
264
+ }
270
265
271
266
""" )
272
267
}
@@ -338,19 +333,16 @@ struct VariadicsGenerator: ParsableCommand {
338
333
339
334
func emitQuantifier( kind: QuantifierKind , arity: Int ) {
340
335
assert ( arity >= 0 )
341
- func genericParameters ( withConstraints : Bool ) -> String {
336
+ let genericParams : String = {
342
337
var result = " "
343
338
if arity > 0 {
344
339
result += " W "
345
340
result += ( 0 ..< arity) . map { " , C \( $0) " } . joined ( )
346
341
result += " , "
347
342
}
348
- result += " Component "
349
- if withConstraints {
350
- result += " : \( regexProtocolName) "
351
- }
343
+ result += " Component: \( regexProtocolName) "
352
344
return result
353
- }
345
+ } ( )
354
346
let captures = ( 0 ..< arity) . map { " C \( $0) " } . joined ( separator: " , " )
355
347
let capturesTupled = arity == 1 ? captures : " ( \( captures) ) "
356
348
let whereClause : String = arity == 0 ? " " :
@@ -366,21 +358,23 @@ struct VariadicsGenerator: ParsableCommand {
366
358
let matchType = arity == 0 ? baseMatchTypeName : " ( \( baseMatchTypeName) , \( quantifiedCaptures) ) "
367
359
output ( """
368
360
\( arity == 0 ? " @_disfavoredOverload " : " " )
369
- public func \( kind. rawValue) < \( genericParameters ( withConstraints: true ) ) >(
370
- _ component: Component
361
+ public func \( kind. rawValue) < \( genericParams) >(
362
+ _ component: Component,
363
+ _ behavior: QuantificationBehavior = .eagerly
371
364
) -> \( regexTypeName) < \( matchType) > \( whereClause) {
372
- .init(node: .quantification(. \( kind. astQuantifierAmount) , .eager , component.regex.root))
365
+ .init(node: .quantification(. \( kind. astQuantifierAmount) , behavior.astKind , component.regex.root))
373
366
}
374
367
375
368
\( arity == 0 ? " @_disfavoredOverload " : " " )
376
- public func \( kind. rawValue) < \( genericParameters ( withConstraints: true ) ) >(
369
+ public func \( kind. rawValue) < \( genericParams) >(
370
+ _ behavior: QuantificationBehavior = .eagerly,
377
371
@RegexBuilder _ component: () -> Component
378
372
) -> \( regexTypeName) < \( matchType) > \( whereClause) {
379
- .init(node: .quantification(. \( kind. astQuantifierAmount) , .eager , component().regex.root))
373
+ .init(node: .quantification(. \( kind. astQuantifierAmount) , behavior.astKind , component().regex.root))
380
374
}
381
375
382
376
\( arity == 0 ? " @_disfavoredOverload " : " " )
383
- public postfix func \( kind. operatorName) < \( genericParameters ( withConstraints : true ) ) >(
377
+ public postfix func \( kind. operatorName) < \( genericParams ) >(
384
378
_ component: Component
385
379
) -> \( regexTypeName) < \( matchType) > \( whereClause) {
386
380
.init(node: .quantification(. \( kind. astQuantifierAmount) , .eager, component.regex.root))
@@ -389,7 +383,7 @@ struct VariadicsGenerator: ParsableCommand {
389
383
\( kind == . zeroOrOne ?
390
384
"""
391
385
extension RegexBuilder {
392
- public static func buildLimitedAvailability< \( genericParameters ( withConstraints : true ) ) >(
386
+ public static func buildLimitedAvailability< \( genericParams ) >(
393
387
_ component: Component
394
388
) -> \( regexTypeName) < \( matchType) > \( whereClause) {
395
389
.init(node: .quantification(. \( kind. astQuantifierAmount) , .eager, component.regex.root))
0 commit comments