From b1675a0b9cde3bb48fdc4c1f4a7949704df6991d Mon Sep 17 00:00:00 2001 From: Nate Cook Date: Tue, 8 Feb 2022 22:59:29 -0600 Subject: [PATCH 1/7] Consolidate RegexDSLTests testing logic --- Tests/RegexTests/RegexDSLTests.swift | 107 ++++++++++++++------------- 1 file changed, 57 insertions(+), 50 deletions(-) diff --git a/Tests/RegexTests/RegexDSLTests.swift b/Tests/RegexTests/RegexDSLTests.swift index 4fa8f7030..695153c1b 100644 --- a/Tests/RegexTests/RegexDSLTests.swift +++ b/Tests/RegexTests/RegexDSLTests.swift @@ -13,6 +13,30 @@ import XCTest @testable import _StringProcessing class RegexDSLTests: XCTestCase { + func _testDSLCaptures( + _ tests: (input: String, expectedCaptures: CaptureType?)..., + captureType: CaptureType.Type, + _ equivalence: (CaptureType, CaptureType) -> Bool, + file: StaticString = #file, + line: UInt = #line, + @RegexBuilder _ content: () -> Content + ) throws { + let regex = Regex(content()) + for (input, maybeExpectedCaptures) in tests { + let maybeMatch = input.match(regex) + if let expectedCaptures = maybeExpectedCaptures { + let match = try XCTUnwrap(maybeMatch, file: file, line: line) + let captures = try XCTUnwrap(match.match as? CaptureType, file: file, line: line) + XCTAssertTrue( + equivalence(captures, expectedCaptures), + "'\(captures)' is not equal to the expected '\(expectedCaptures)'.", + file: file, line: line) + } else { + XCTAssertNil(maybeMatch, file: file, line: line) + } + } + } + func testSimpleStrings() throws { let regex = Regex { "a" @@ -31,16 +55,14 @@ class RegexDSLTests: XCTestCase { } func testCharacterClasses() throws { - let regex = Regex { + try _testDSLCaptures( + ("a c", ("a c", " ", "c")), + captureType: (Substring, Substring, Substring).self, ==) + { CharacterClass.any - CharacterClass.whitespace.capture() // Character + CharacterClass.whitespace.capture() // Substring "c".capture() // Substring } - // Assert the inferred capture type. - let _: (Substring, Substring, Substring).Type = type(of: regex).Match.self - let maybeMatch = "a c".match(regex) - let match = try XCTUnwrap(maybeMatch) - XCTAssertTrue(match.match == ("a c", " ", "c")) } func testAlternation() throws { @@ -109,7 +131,10 @@ class RegexDSLTests: XCTestCase { } func testCombinators() throws { - let regex = Regex { + try _testDSLCaptures( + ("aaaabccccdddkj", ("aaaabccccdddkj", "b", "cccc", ["d", "d", "d"], "k", nil, "j")), + captureType: (Substring, Substring, Substring, [Substring], Substring, Substring?, Substring?).self, ==) + { "a".+ oneOrMore(Character("b")).capture() // Substring many("c").capture() // Substring @@ -118,22 +143,13 @@ class RegexDSLTests: XCTestCase { ("t" | "k").capture() // Substring oneOf { "k".capture(); "j".capture() } // (Substring?, Substring?) } - // Assert the inferred capture type. - let _: (Substring, Substring, Substring, [Substring], Substring, Substring?, Substring?).Type - = type(of: regex).Match.self - let maybeMatch = "aaaabccccdddkj".match(regex) - let match = try XCTUnwrap(maybeMatch).match - XCTAssertEqual(match.0, "aaaabccccdddkj") - XCTAssertEqual(match.1, "b") - XCTAssertEqual(match.2, "cccc") - XCTAssertEqual(match.3, ["d", "d", "d"]) - XCTAssertEqual(match.4, "k") - XCTAssertEqual(match.5, .none) - XCTAssertEqual(match.6, .some("j")) } func testNestedGroups() throws { - let regex = Regex { + try _testDSLCaptures( + ("aaaabccccddd", ("aaaabccccddd", [("b", "cccc", ["d", "d", "d"])])), + captureType: (Substring, [(Substring, Substring, [Substring])]).self, ==) + { "a".+ oneOrMore { oneOrMore("b").capture() @@ -142,16 +158,6 @@ class RegexDSLTests: XCTestCase { "e".? } } - // Assert the inferred capture type. - let _: (Substring, [(Substring, Substring, [Substring])]).Type - = type(of: regex).Match.self - let maybeMatch = "aaaabccccddd".match(regex) - let match = try XCTUnwrap(maybeMatch) - XCTAssertEqual(match.match.1.count, 1) - XCTAssertEqual(match.match.0, "aaaabccccddd") - XCTAssertTrue( - match.match.1[0] - == ("b", "cccc", ["d", "d", "d"])) } func testCapturelessQuantification() throws { @@ -184,7 +190,11 @@ class RegexDSLTests: XCTestCase { } } } - let regex = Regex { + try _testDSLCaptures( + ("aaa 123 apple orange apple", ("aaa 123 apple orange apple", 123, [.apple, .orange, .apple])), + ("aaa ", ("aaa ", nil, [])), + captureType: (Substring, Int?, [Word]).self, ==) + { "a".+ oneOrMore(.whitespace) optionally { @@ -195,24 +205,6 @@ class RegexDSLTests: XCTestCase { oneOrMore(.word).capture { Word($0)! } } } - // Assert the inferred capture type. - let _: (Substring, Int?, [Word]).Type = type(of: regex).Match.self - do { - let input = "aaa 123 apple orange apple" - let match = input.match(regex)?.match - let (whole, number, words) = try XCTUnwrap(match) - XCTAssertTrue(whole == input) - XCTAssertEqual(number, 123) - XCTAssertEqual(words, [.apple, .orange, .apple]) - } - do { - let input = "aaa " - let match = input.match(regex)?.match - let (whole, number, words) = try XCTUnwrap(match) - XCTAssertTrue(whole == input) - XCTAssertEqual(number, nil) - XCTAssertTrue(words.isEmpty) - } } func testNestedCaptureTypes() throws { @@ -408,3 +400,18 @@ extension Unicode.Scalar { self = scalar } } + +// MARK: Extra == functions + +// (Substring, [(Substring, Substring, [Substring])]) +typealias S_AS = (Substring, [(Substring, Substring, [Substring])]) + +func ==(lhs: S_AS, rhs: S_AS) -> Bool { + lhs.0 == rhs.0 && lhs.1.elementsEqual(rhs.1, by: ==) +} + +func == ( + l: (T0, T1, T2, T3, T4, T5, T6), r: (T0, T1, T2, T3, T4, T5, T6) +) -> Bool { + l.0 == r.0 && (l.1, l.2, l.3, l.4, l.5, l.6) == (r.1, r.2, r.3, r.4, r.5, r.6) +} From 5875fb36874629b928991464becb7c4aae76f1d3 Mon Sep 17 00:00:00 2001 From: Nate Cook Date: Tue, 8 Feb 2022 23:15:13 -0600 Subject: [PATCH 2/7] Remove unused parameter --- .../VariadicsGenerator.swift | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/Sources/VariadicsGenerator/VariadicsGenerator.swift b/Sources/VariadicsGenerator/VariadicsGenerator.swift index b0907101e..00c0c4f6a 100644 --- a/Sources/VariadicsGenerator/VariadicsGenerator.swift +++ b/Sources/VariadicsGenerator/VariadicsGenerator.swift @@ -205,19 +205,14 @@ struct VariadicsGenerator: ParsableCommand { } func emitConcatenation(leftArity: Int, rightArity: Int) { - func genericParameters(withConstraints: Bool) -> String { + let genericParams: String = { var result = "W0, W1" result += (0..= 0) - func genericParameters(withConstraints: Bool) -> String { + let genericParams: String = { var result = "" if arity > 0 { result += "W" result += (0..( + public func \(kind.rawValue)<\(genericParams)>( _ component: Component ) -> \(regexTypeName)<\(matchType)> \(whereClause) { .init(node: .quantification(.\(kind.astQuantifierAmount), .eager, component.regex.root)) } \(arity == 0 ? "@_disfavoredOverload" : "") - public func \(kind.rawValue)<\(genericParameters(withConstraints: true))>( + public func \(kind.rawValue)<\(genericParams)>( @RegexBuilder _ component: () -> Component ) -> \(regexTypeName)<\(matchType)> \(whereClause) { .init(node: .quantification(.\(kind.astQuantifierAmount), .eager, component().regex.root)) } \(arity == 0 ? "@_disfavoredOverload" : "") - public postfix func \(kind.operatorName)<\(genericParameters(withConstraints: true))>( + public postfix func \(kind.operatorName)<\(genericParams)>( _ component: Component ) -> \(regexTypeName)<\(matchType)> \(whereClause) { .init(node: .quantification(.\(kind.astQuantifierAmount), .eager, component.regex.root)) @@ -383,7 +375,7 @@ struct VariadicsGenerator: ParsableCommand { \(kind == .zeroOrOne ? """ extension RegexBuilder { - public static func buildLimitedAvailability<\(genericParameters(withConstraints: true))>( + public static func buildLimitedAvailability<\(genericParams)>( _ component: Component ) -> \(regexTypeName)<\(matchType)> \(whereClause) { .init(node: .quantification(.\(kind.astQuantifierAmount), .eager, component.regex.root)) From 453505b6001cf6f0f73a43f0f8c66e06119aef59 Mon Sep 17 00:00:00 2001 From: Nate Cook Date: Tue, 8 Feb 2022 23:15:43 -0600 Subject: [PATCH 3/7] Fix indentation in variadic generator --- .../VariadicsGenerator.swift | 12 +- .../RegexDSL/Variadics.swift | 880 +++++++++--------- 2 files changed, 446 insertions(+), 446 deletions(-) diff --git a/Sources/VariadicsGenerator/VariadicsGenerator.swift b/Sources/VariadicsGenerator/VariadicsGenerator.swift index 00c0c4f6a..7b0aa75b3 100644 --- a/Sources/VariadicsGenerator/VariadicsGenerator.swift +++ b/Sources/VariadicsGenerator/VariadicsGenerator.swift @@ -249,13 +249,13 @@ struct VariadicsGenerator: ParsableCommand { // Emit concatenation builder. output("extension \(patternBuilderTypeName) {\n") output(""" - @_disfavoredOverload - public static func buildBlock<\(genericParameters(withConstraints: true))>( - combining next: R1, into combined: R0 - ) -> \(regexTypeName)<\(matchType)> \(whereClause) { - .init(node: combined.regex.root.appending(next.regex.root)) - } + @_disfavoredOverload + public static func buildBlock<\(genericParams)>( + combining next: R1, into combined: R0 + ) -> \(regexTypeName)<\(matchType)> \(whereClause) { + .init(node: combined.regex.root.appending(next.regex.root)) } + } """) } diff --git a/Sources/_StringProcessing/RegexDSL/Variadics.swift b/Sources/_StringProcessing/RegexDSL/Variadics.swift index 6289bb6f8..4513bba96 100644 --- a/Sources/_StringProcessing/RegexDSL/Variadics.swift +++ b/Sources/_StringProcessing/RegexDSL/Variadics.swift @@ -77,446 +77,446 @@ extension RegexBuilder { } } extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0)> where R0.Match == W0, R1.Match == (W1, C0) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1)> where R0.Match == W0, R1.Match == (W1, C0, C1) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2)> where R0.Match == W0, R1.Match == (W1, C0, C1, C2) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3)> where R0.Match == W0, R1.Match == (W1, C0, C1, C2, C3) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4)> where R0.Match == W0, R1.Match == (W1, C0, C1, C2, C3, C4) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5)> where R0.Match == W0, R1.Match == (W1, C0, C1, C2, C3, C4, C5) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6)> where R0.Match == W0, R1.Match == (W1, C0, C1, C2, C3, C4, C5, C6) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7)> where R0.Match == W0, R1.Match == (W1, C0, C1, C2, C3, C4, C5, C6, C7) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R0.Match == W0, R1.Match == (W1, C0, C1, C2, C3, C4, C5, C6, C7, C8) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9)> where R0.Match == W0, R1.Match == (W1, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1)> where R0.Match == (W0, C0), R1.Match == (W1, C1) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2)> where R0.Match == (W0, C0), R1.Match == (W1, C1, C2) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3)> where R0.Match == (W0, C0), R1.Match == (W1, C1, C2, C3) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4)> where R0.Match == (W0, C0), R1.Match == (W1, C1, C2, C3, C4) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5)> where R0.Match == (W0, C0), R1.Match == (W1, C1, C2, C3, C4, C5) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6)> where R0.Match == (W0, C0), R1.Match == (W1, C1, C2, C3, C4, C5, C6) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7)> where R0.Match == (W0, C0), R1.Match == (W1, C1, C2, C3, C4, C5, C6, C7) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R0.Match == (W0, C0), R1.Match == (W1, C1, C2, C3, C4, C5, C6, C7, C8) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9)> where R0.Match == (W0, C0), R1.Match == (W1, C1, C2, C3, C4, C5, C6, C7, C8, C9) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2)> where R0.Match == (W0, C0, C1), R1.Match == (W1, C2) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3)> where R0.Match == (W0, C0, C1), R1.Match == (W1, C2, C3) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4)> where R0.Match == (W0, C0, C1), R1.Match == (W1, C2, C3, C4) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5)> where R0.Match == (W0, C0, C1), R1.Match == (W1, C2, C3, C4, C5) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6)> where R0.Match == (W0, C0, C1), R1.Match == (W1, C2, C3, C4, C5, C6) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7)> where R0.Match == (W0, C0, C1), R1.Match == (W1, C2, C3, C4, C5, C6, C7) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R0.Match == (W0, C0, C1), R1.Match == (W1, C2, C3, C4, C5, C6, C7, C8) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9)> where R0.Match == (W0, C0, C1), R1.Match == (W1, C2, C3, C4, C5, C6, C7, C8, C9) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3)> where R0.Match == (W0, C0, C1, C2), R1.Match == (W1, C3) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4)> where R0.Match == (W0, C0, C1, C2), R1.Match == (W1, C3, C4) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5)> where R0.Match == (W0, C0, C1, C2), R1.Match == (W1, C3, C4, C5) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6)> where R0.Match == (W0, C0, C1, C2), R1.Match == (W1, C3, C4, C5, C6) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7)> where R0.Match == (W0, C0, C1, C2), R1.Match == (W1, C3, C4, C5, C6, C7) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R0.Match == (W0, C0, C1, C2), R1.Match == (W1, C3, C4, C5, C6, C7, C8) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9)> where R0.Match == (W0, C0, C1, C2), R1.Match == (W1, C3, C4, C5, C6, C7, C8, C9) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4)> where R0.Match == (W0, C0, C1, C2, C3), R1.Match == (W1, C4) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5)> where R0.Match == (W0, C0, C1, C2, C3), R1.Match == (W1, C4, C5) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6)> where R0.Match == (W0, C0, C1, C2, C3), R1.Match == (W1, C4, C5, C6) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7)> where R0.Match == (W0, C0, C1, C2, C3), R1.Match == (W1, C4, C5, C6, C7) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R0.Match == (W0, C0, C1, C2, C3), R1.Match == (W1, C4, C5, C6, C7, C8) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9)> where R0.Match == (W0, C0, C1, C2, C3), R1.Match == (W1, C4, C5, C6, C7, C8, C9) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5)> where R0.Match == (W0, C0, C1, C2, C3, C4), R1.Match == (W1, C5) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6)> where R0.Match == (W0, C0, C1, C2, C3, C4), R1.Match == (W1, C5, C6) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7)> where R0.Match == (W0, C0, C1, C2, C3, C4), R1.Match == (W1, C5, C6, C7) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R0.Match == (W0, C0, C1, C2, C3, C4), R1.Match == (W1, C5, C6, C7, C8) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9)> where R0.Match == (W0, C0, C1, C2, C3, C4), R1.Match == (W1, C5, C6, C7, C8, C9) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6)> where R0.Match == (W0, C0, C1, C2, C3, C4, C5), R1.Match == (W1, C6) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7)> where R0.Match == (W0, C0, C1, C2, C3, C4, C5), R1.Match == (W1, C6, C7) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R0.Match == (W0, C0, C1, C2, C3, C4, C5), R1.Match == (W1, C6, C7, C8) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9)> where R0.Match == (W0, C0, C1, C2, C3, C4, C5), R1.Match == (W1, C6, C7, C8, C9) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7)> where R0.Match == (W0, C0, C1, C2, C3, C4, C5, C6), R1.Match == (W1, C7) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R0.Match == (W0, C0, C1, C2, C3, C4, C5, C6), R1.Match == (W1, C7, C8) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9)> where R0.Match == (W0, C0, C1, C2, C3, C4, C5, C6), R1.Match == (W1, C7, C8, C9) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R0.Match == (W0, C0, C1, C2, C3, C4, C5, C6, C7), R1.Match == (W1, C8) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9)> where R0.Match == (W0, C0, C1, C2, C3, C4, C5, C6, C7), R1.Match == (W1, C8, C9) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { - @_disfavoredOverload - public static func buildBlock( - combining next: R1, into combined: R0 - ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9)> where R0.Match == (W0, C0, C1, C2, C3, C4, C5, C6, C7, C8), R1.Match == (W1, C9) { - .init(node: combined.regex.root.appending(next.regex.root)) - } - } - extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0)> where R0.Match == W0, R1.Match == (W1, C0) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1)> where R0.Match == W0, R1.Match == (W1, C0, C1) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2)> where R0.Match == W0, R1.Match == (W1, C0, C1, C2) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3)> where R0.Match == W0, R1.Match == (W1, C0, C1, C2, C3) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4)> where R0.Match == W0, R1.Match == (W1, C0, C1, C2, C3, C4) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5)> where R0.Match == W0, R1.Match == (W1, C0, C1, C2, C3, C4, C5) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6)> where R0.Match == W0, R1.Match == (W1, C0, C1, C2, C3, C4, C5, C6) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7)> where R0.Match == W0, R1.Match == (W1, C0, C1, C2, C3, C4, C5, C6, C7) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R0.Match == W0, R1.Match == (W1, C0, C1, C2, C3, C4, C5, C6, C7, C8) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9)> where R0.Match == W0, R1.Match == (W1, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1)> where R0.Match == (W0, C0), R1.Match == (W1, C1) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2)> where R0.Match == (W0, C0), R1.Match == (W1, C1, C2) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3)> where R0.Match == (W0, C0), R1.Match == (W1, C1, C2, C3) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4)> where R0.Match == (W0, C0), R1.Match == (W1, C1, C2, C3, C4) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5)> where R0.Match == (W0, C0), R1.Match == (W1, C1, C2, C3, C4, C5) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6)> where R0.Match == (W0, C0), R1.Match == (W1, C1, C2, C3, C4, C5, C6) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7)> where R0.Match == (W0, C0), R1.Match == (W1, C1, C2, C3, C4, C5, C6, C7) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R0.Match == (W0, C0), R1.Match == (W1, C1, C2, C3, C4, C5, C6, C7, C8) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9)> where R0.Match == (W0, C0), R1.Match == (W1, C1, C2, C3, C4, C5, C6, C7, C8, C9) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2)> where R0.Match == (W0, C0, C1), R1.Match == (W1, C2) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3)> where R0.Match == (W0, C0, C1), R1.Match == (W1, C2, C3) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4)> where R0.Match == (W0, C0, C1), R1.Match == (W1, C2, C3, C4) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5)> where R0.Match == (W0, C0, C1), R1.Match == (W1, C2, C3, C4, C5) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6)> where R0.Match == (W0, C0, C1), R1.Match == (W1, C2, C3, C4, C5, C6) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7)> where R0.Match == (W0, C0, C1), R1.Match == (W1, C2, C3, C4, C5, C6, C7) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R0.Match == (W0, C0, C1), R1.Match == (W1, C2, C3, C4, C5, C6, C7, C8) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9)> where R0.Match == (W0, C0, C1), R1.Match == (W1, C2, C3, C4, C5, C6, C7, C8, C9) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3)> where R0.Match == (W0, C0, C1, C2), R1.Match == (W1, C3) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4)> where R0.Match == (W0, C0, C1, C2), R1.Match == (W1, C3, C4) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5)> where R0.Match == (W0, C0, C1, C2), R1.Match == (W1, C3, C4, C5) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6)> where R0.Match == (W0, C0, C1, C2), R1.Match == (W1, C3, C4, C5, C6) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7)> where R0.Match == (W0, C0, C1, C2), R1.Match == (W1, C3, C4, C5, C6, C7) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R0.Match == (W0, C0, C1, C2), R1.Match == (W1, C3, C4, C5, C6, C7, C8) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9)> where R0.Match == (W0, C0, C1, C2), R1.Match == (W1, C3, C4, C5, C6, C7, C8, C9) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4)> where R0.Match == (W0, C0, C1, C2, C3), R1.Match == (W1, C4) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5)> where R0.Match == (W0, C0, C1, C2, C3), R1.Match == (W1, C4, C5) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6)> where R0.Match == (W0, C0, C1, C2, C3), R1.Match == (W1, C4, C5, C6) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7)> where R0.Match == (W0, C0, C1, C2, C3), R1.Match == (W1, C4, C5, C6, C7) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R0.Match == (W0, C0, C1, C2, C3), R1.Match == (W1, C4, C5, C6, C7, C8) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9)> where R0.Match == (W0, C0, C1, C2, C3), R1.Match == (W1, C4, C5, C6, C7, C8, C9) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5)> where R0.Match == (W0, C0, C1, C2, C3, C4), R1.Match == (W1, C5) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6)> where R0.Match == (W0, C0, C1, C2, C3, C4), R1.Match == (W1, C5, C6) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7)> where R0.Match == (W0, C0, C1, C2, C3, C4), R1.Match == (W1, C5, C6, C7) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R0.Match == (W0, C0, C1, C2, C3, C4), R1.Match == (W1, C5, C6, C7, C8) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9)> where R0.Match == (W0, C0, C1, C2, C3, C4), R1.Match == (W1, C5, C6, C7, C8, C9) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6)> where R0.Match == (W0, C0, C1, C2, C3, C4, C5), R1.Match == (W1, C6) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7)> where R0.Match == (W0, C0, C1, C2, C3, C4, C5), R1.Match == (W1, C6, C7) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R0.Match == (W0, C0, C1, C2, C3, C4, C5), R1.Match == (W1, C6, C7, C8) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9)> where R0.Match == (W0, C0, C1, C2, C3, C4, C5), R1.Match == (W1, C6, C7, C8, C9) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7)> where R0.Match == (W0, C0, C1, C2, C3, C4, C5, C6), R1.Match == (W1, C7) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R0.Match == (W0, C0, C1, C2, C3, C4, C5, C6), R1.Match == (W1, C7, C8) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9)> where R0.Match == (W0, C0, C1, C2, C3, C4, C5, C6), R1.Match == (W1, C7, C8, C9) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8)> where R0.Match == (W0, C0, C1, C2, C3, C4, C5, C6, C7), R1.Match == (W1, C8) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9)> where R0.Match == (W0, C0, C1, C2, C3, C4, C5, C6, C7), R1.Match == (W1, C8, C9) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { + @_disfavoredOverload + public static func buildBlock( + combining next: R1, into combined: R0 + ) -> Regex<(Substring, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9)> where R0.Match == (W0, C0, C1, C2, C3, C4, C5, C6, C7, C8), R1.Match == (W1, C9) { + .init(node: combined.regex.root.appending(next.regex.root)) + } +} +extension RegexBuilder { @_disfavoredOverload public static func buildBlock( combining next: R1, into combined: R0 From c66b434fd248bd550b8b46a3c78926a304460519 Mon Sep 17 00:00:00 2001 From: Nate Cook Date: Tue, 8 Feb 2022 23:45:38 -0600 Subject: [PATCH 4/7] Add support for quantification kinds This adds support for specifying eager / reluctant / possessive quantification from within the DSL, like the literal quantification operators with an appended `?`. --- ```swift let regex = Regex { oneOrMore(.word, .reluctant) CharacterClass.digit.capture() } "aaa1bbb2".match(regex).match // ("aaa1", "1") ``` --- .../VariadicsGenerator.swift | 8 +- Sources/_StringProcessing/RegexDSL/DSL.swift | 59 ++++- .../RegexDSL/Variadics.swift | 240 +++++++++++------- Tests/RegexTests/RegexDSLTests.swift | 34 +++ 4 files changed, 242 insertions(+), 99 deletions(-) diff --git a/Sources/VariadicsGenerator/VariadicsGenerator.swift b/Sources/VariadicsGenerator/VariadicsGenerator.swift index 7b0aa75b3..204406579 100644 --- a/Sources/VariadicsGenerator/VariadicsGenerator.swift +++ b/Sources/VariadicsGenerator/VariadicsGenerator.swift @@ -353,16 +353,18 @@ struct VariadicsGenerator: ParsableCommand { output(""" \(arity == 0 ? "@_disfavoredOverload" : "") public func \(kind.rawValue)<\(genericParams)>( - _ component: Component + _ component: Component, + _ kind: QuantificationKind = .eager ) -> \(regexTypeName)<\(matchType)> \(whereClause) { - .init(node: .quantification(.\(kind.astQuantifierAmount), .eager, component.regex.root)) + .init(node: .quantification(.\(kind.astQuantifierAmount), kind.astKind, component.regex.root)) } \(arity == 0 ? "@_disfavoredOverload" : "") public func \(kind.rawValue)<\(genericParams)>( + _ kind: QuantificationKind = .eager, @RegexBuilder _ component: () -> Component ) -> \(regexTypeName)<\(matchType)> \(whereClause) { - .init(node: .quantification(.\(kind.astQuantifierAmount), .eager, component().regex.root)) + .init(node: .quantification(.\(kind.astQuantifierAmount), kind.astKind, component().regex.root)) } \(arity == 0 ? "@_disfavoredOverload" : "") diff --git a/Sources/_StringProcessing/RegexDSL/DSL.swift b/Sources/_StringProcessing/RegexDSL/DSL.swift index f6eb91fdb..823cd2a27 100644 --- a/Sources/_StringProcessing/RegexDSL/DSL.swift +++ b/Sources/_StringProcessing/RegexDSL/DSL.swift @@ -62,6 +62,44 @@ extension CharacterClass: RegexProtocol { // Note: Quantifiers are currently gyb'd. +/// Specifies how much to attempt to match when using a quantifier. +public struct QuantificationKind { + internal enum Kind { + case eager + case reluctant + case possessive + } + + var kind: Kind + + internal var astKind: AST.Quantification.Kind { + switch kind { + case .eager: return .eager + case .reluctant: return .reluctant + case .possessive: return .possessive + } + } +} + +extension QuantificationKind { + /// Match as much of the input string as possible, backtracking when + /// necessary. + public static var eager: QuantificationKind { + .init(kind: .eager) + } + + /// Match as little of the input string as possible, expanding the matched + /// region as necessary to complete a match. + public static var reluctant: QuantificationKind { + .init(kind: .reluctant) + } + + /// Match as much of the input string as possible, performing no backtracking. + public static var possessive: QuantificationKind { + .init(kind: .possessive) + } +} + // TODO: Variadic generics // struct _OneOrMore // where R.Match == (W, C...) @@ -99,16 +137,25 @@ postfix operator .* postfix operator .+ // Overloads for quantifying over a character class. -public func zeroOrOne(_ cc: CharacterClass) -> Regex { - .init(node: .quantification(.zeroOrOne, .eager, cc.regex.root)) +public func zeroOrOne( + _ cc: CharacterClass, + _ kind: QuantificationKind = .eager +) -> Regex { + .init(node: .quantification(.zeroOrOne, kind.astKind, cc.regex.root)) } -public func many(_ cc: CharacterClass) -> Regex { - .init(node: .quantification(.zeroOrMore, .eager, cc.regex.root)) +public func many( + _ cc: CharacterClass, + _ kind: QuantificationKind = .eager +) -> Regex { + .init(node: .quantification(.zeroOrMore, kind.astKind, cc.regex.root)) } -public func oneOrMore(_ cc: CharacterClass) -> Regex { - .init(node: .quantification(.oneOrMore, .eager, cc.regex.root)) +public func oneOrMore( + _ cc: CharacterClass, + _ kind: QuantificationKind = .eager +) -> Regex { + .init(node: .quantification(.oneOrMore, kind.astKind, cc.regex.root)) } // MARK: Alternation diff --git a/Sources/_StringProcessing/RegexDSL/Variadics.swift b/Sources/_StringProcessing/RegexDSL/Variadics.swift index 4513bba96..698c858c3 100644 --- a/Sources/_StringProcessing/RegexDSL/Variadics.swift +++ b/Sources/_StringProcessing/RegexDSL/Variadics.swift @@ -600,16 +600,18 @@ extension RegexBuilder { @_disfavoredOverload public func optionally( - _ component: Component + _ component: Component, + _ kind: QuantificationKind = .eager ) -> Regex { - .init(node: .quantification(.zeroOrOne, .eager, component.regex.root)) + .init(node: .quantification(.zeroOrOne, kind.astKind, component.regex.root)) } @_disfavoredOverload public func optionally( + _ kind: QuantificationKind = .eager, @RegexBuilder _ component: () -> Component ) -> Regex { - .init(node: .quantification(.zeroOrOne, .eager, component().regex.root)) + .init(node: .quantification(.zeroOrOne, kind.astKind, component().regex.root)) } @_disfavoredOverload @@ -628,16 +630,18 @@ extension RegexBuilder { } @_disfavoredOverload public func many( - _ component: Component + _ component: Component, + _ kind: QuantificationKind = .eager ) -> Regex { - .init(node: .quantification(.zeroOrMore, .eager, component.regex.root)) + .init(node: .quantification(.zeroOrMore, kind.astKind, component.regex.root)) } @_disfavoredOverload public func many( + _ kind: QuantificationKind = .eager, @RegexBuilder _ component: () -> Component ) -> Regex { - .init(node: .quantification(.zeroOrMore, .eager, component().regex.root)) + .init(node: .quantification(.zeroOrMore, kind.astKind, component().regex.root)) } @_disfavoredOverload @@ -650,16 +654,18 @@ public postfix func .+( @_disfavoredOverload public func oneOrMore( - _ component: Component + _ component: Component, + _ kind: QuantificationKind = .eager ) -> Regex { - .init(node: .quantification(.oneOrMore, .eager, component.regex.root)) + .init(node: .quantification(.oneOrMore, kind.astKind, component.regex.root)) } @_disfavoredOverload public func oneOrMore( + _ kind: QuantificationKind = .eager, @RegexBuilder _ component: () -> Component ) -> Regex { - .init(node: .quantification(.oneOrMore, .eager, component().regex.root)) + .init(node: .quantification(.oneOrMore, kind.astKind, component().regex.root)) } @_disfavoredOverload @@ -672,16 +678,18 @@ public postfix func .*( public func optionally( - _ component: Component + _ component: Component, + _ kind: QuantificationKind = .eager ) -> Regex<(Substring, C0?)> where Component.Match == (W, C0) { - .init(node: .quantification(.zeroOrOne, .eager, component.regex.root)) + .init(node: .quantification(.zeroOrOne, kind.astKind, component.regex.root)) } public func optionally( + _ kind: QuantificationKind = .eager, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, C0?)> where Component.Match == (W, C0) { - .init(node: .quantification(.zeroOrOne, .eager, component().regex.root)) + .init(node: .quantification(.zeroOrOne, kind.astKind, component().regex.root)) } @@ -700,16 +708,18 @@ extension RegexBuilder { } public func many( - _ component: Component + _ component: Component, + _ kind: QuantificationKind = .eager ) -> Regex<(Substring, [C0])> where Component.Match == (W, C0) { - .init(node: .quantification(.zeroOrMore, .eager, component.regex.root)) + .init(node: .quantification(.zeroOrMore, kind.astKind, component.regex.root)) } public func many( + _ kind: QuantificationKind = .eager, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [C0])> where Component.Match == (W, C0) { - .init(node: .quantification(.zeroOrMore, .eager, component().regex.root)) + .init(node: .quantification(.zeroOrMore, kind.astKind, component().regex.root)) } @@ -722,16 +732,18 @@ public postfix func .+( public func oneOrMore( - _ component: Component + _ component: Component, + _ kind: QuantificationKind = .eager ) -> Regex<(Substring, [C0])> where Component.Match == (W, C0) { - .init(node: .quantification(.oneOrMore, .eager, component.regex.root)) + .init(node: .quantification(.oneOrMore, kind.astKind, component.regex.root)) } public func oneOrMore( + _ kind: QuantificationKind = .eager, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [C0])> where Component.Match == (W, C0) { - .init(node: .quantification(.oneOrMore, .eager, component().regex.root)) + .init(node: .quantification(.oneOrMore, kind.astKind, component().regex.root)) } @@ -744,16 +756,18 @@ public postfix func .*( public func optionally( - _ component: Component + _ component: Component, + _ kind: QuantificationKind = .eager ) -> Regex<(Substring, (C0, C1)?)> where Component.Match == (W, C0, C1) { - .init(node: .quantification(.zeroOrOne, .eager, component.regex.root)) + .init(node: .quantification(.zeroOrOne, kind.astKind, component.regex.root)) } public func optionally( + _ kind: QuantificationKind = .eager, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, (C0, C1)?)> where Component.Match == (W, C0, C1) { - .init(node: .quantification(.zeroOrOne, .eager, component().regex.root)) + .init(node: .quantification(.zeroOrOne, kind.astKind, component().regex.root)) } @@ -772,16 +786,18 @@ extension RegexBuilder { } public func many( - _ component: Component + _ component: Component, + _ kind: QuantificationKind = .eager ) -> Regex<(Substring, [(C0, C1)])> where Component.Match == (W, C0, C1) { - .init(node: .quantification(.zeroOrMore, .eager, component.regex.root)) + .init(node: .quantification(.zeroOrMore, kind.astKind, component.regex.root)) } public func many( + _ kind: QuantificationKind = .eager, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1)])> where Component.Match == (W, C0, C1) { - .init(node: .quantification(.zeroOrMore, .eager, component().regex.root)) + .init(node: .quantification(.zeroOrMore, kind.astKind, component().regex.root)) } @@ -794,16 +810,18 @@ public postfix func .+( public func oneOrMore( - _ component: Component + _ component: Component, + _ kind: QuantificationKind = .eager ) -> Regex<(Substring, [(C0, C1)])> where Component.Match == (W, C0, C1) { - .init(node: .quantification(.oneOrMore, .eager, component.regex.root)) + .init(node: .quantification(.oneOrMore, kind.astKind, component.regex.root)) } public func oneOrMore( + _ kind: QuantificationKind = .eager, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1)])> where Component.Match == (W, C0, C1) { - .init(node: .quantification(.oneOrMore, .eager, component().regex.root)) + .init(node: .quantification(.oneOrMore, kind.astKind, component().regex.root)) } @@ -816,16 +834,18 @@ public postfix func .*( public func optionally( - _ component: Component + _ component: Component, + _ kind: QuantificationKind = .eager ) -> Regex<(Substring, (C0, C1, C2)?)> where Component.Match == (W, C0, C1, C2) { - .init(node: .quantification(.zeroOrOne, .eager, component.regex.root)) + .init(node: .quantification(.zeroOrOne, kind.astKind, component.regex.root)) } public func optionally( + _ kind: QuantificationKind = .eager, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, (C0, C1, C2)?)> where Component.Match == (W, C0, C1, C2) { - .init(node: .quantification(.zeroOrOne, .eager, component().regex.root)) + .init(node: .quantification(.zeroOrOne, kind.astKind, component().regex.root)) } @@ -844,16 +864,18 @@ extension RegexBuilder { } public func many( - _ component: Component + _ component: Component, + _ kind: QuantificationKind = .eager ) -> Regex<(Substring, [(C0, C1, C2)])> where Component.Match == (W, C0, C1, C2) { - .init(node: .quantification(.zeroOrMore, .eager, component.regex.root)) + .init(node: .quantification(.zeroOrMore, kind.astKind, component.regex.root)) } public func many( + _ kind: QuantificationKind = .eager, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2)])> where Component.Match == (W, C0, C1, C2) { - .init(node: .quantification(.zeroOrMore, .eager, component().regex.root)) + .init(node: .quantification(.zeroOrMore, kind.astKind, component().regex.root)) } @@ -866,16 +888,18 @@ public postfix func .+( public func oneOrMore( - _ component: Component + _ component: Component, + _ kind: QuantificationKind = .eager ) -> Regex<(Substring, [(C0, C1, C2)])> where Component.Match == (W, C0, C1, C2) { - .init(node: .quantification(.oneOrMore, .eager, component.regex.root)) + .init(node: .quantification(.oneOrMore, kind.astKind, component.regex.root)) } public func oneOrMore( + _ kind: QuantificationKind = .eager, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2)])> where Component.Match == (W, C0, C1, C2) { - .init(node: .quantification(.oneOrMore, .eager, component().regex.root)) + .init(node: .quantification(.oneOrMore, kind.astKind, component().regex.root)) } @@ -888,16 +912,18 @@ public postfix func .*( public func optionally( - _ component: Component + _ component: Component, + _ kind: QuantificationKind = .eager ) -> Regex<(Substring, (C0, C1, C2, C3)?)> where Component.Match == (W, C0, C1, C2, C3) { - .init(node: .quantification(.zeroOrOne, .eager, component.regex.root)) + .init(node: .quantification(.zeroOrOne, kind.astKind, component.regex.root)) } public func optionally( + _ kind: QuantificationKind = .eager, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, (C0, C1, C2, C3)?)> where Component.Match == (W, C0, C1, C2, C3) { - .init(node: .quantification(.zeroOrOne, .eager, component().regex.root)) + .init(node: .quantification(.zeroOrOne, kind.astKind, component().regex.root)) } @@ -916,16 +942,18 @@ extension RegexBuilder { } public func many( - _ component: Component + _ component: Component, + _ kind: QuantificationKind = .eager ) -> Regex<(Substring, [(C0, C1, C2, C3)])> where Component.Match == (W, C0, C1, C2, C3) { - .init(node: .quantification(.zeroOrMore, .eager, component.regex.root)) + .init(node: .quantification(.zeroOrMore, kind.astKind, component.regex.root)) } public func many( + _ kind: QuantificationKind = .eager, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3)])> where Component.Match == (W, C0, C1, C2, C3) { - .init(node: .quantification(.zeroOrMore, .eager, component().regex.root)) + .init(node: .quantification(.zeroOrMore, kind.astKind, component().regex.root)) } @@ -938,16 +966,18 @@ public postfix func .+( public func oneOrMore( - _ component: Component + _ component: Component, + _ kind: QuantificationKind = .eager ) -> Regex<(Substring, [(C0, C1, C2, C3)])> where Component.Match == (W, C0, C1, C2, C3) { - .init(node: .quantification(.oneOrMore, .eager, component.regex.root)) + .init(node: .quantification(.oneOrMore, kind.astKind, component.regex.root)) } public func oneOrMore( + _ kind: QuantificationKind = .eager, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3)])> where Component.Match == (W, C0, C1, C2, C3) { - .init(node: .quantification(.oneOrMore, .eager, component().regex.root)) + .init(node: .quantification(.oneOrMore, kind.astKind, component().regex.root)) } @@ -960,16 +990,18 @@ public postfix func .*( public func optionally( - _ component: Component + _ component: Component, + _ kind: QuantificationKind = .eager ) -> Regex<(Substring, (C0, C1, C2, C3, C4)?)> where Component.Match == (W, C0, C1, C2, C3, C4) { - .init(node: .quantification(.zeroOrOne, .eager, component.regex.root)) + .init(node: .quantification(.zeroOrOne, kind.astKind, component.regex.root)) } public func optionally( + _ kind: QuantificationKind = .eager, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, (C0, C1, C2, C3, C4)?)> where Component.Match == (W, C0, C1, C2, C3, C4) { - .init(node: .quantification(.zeroOrOne, .eager, component().regex.root)) + .init(node: .quantification(.zeroOrOne, kind.astKind, component().regex.root)) } @@ -988,16 +1020,18 @@ extension RegexBuilder { } public func many( - _ component: Component + _ component: Component, + _ kind: QuantificationKind = .eager ) -> Regex<(Substring, [(C0, C1, C2, C3, C4)])> where Component.Match == (W, C0, C1, C2, C3, C4) { - .init(node: .quantification(.zeroOrMore, .eager, component.regex.root)) + .init(node: .quantification(.zeroOrMore, kind.astKind, component.regex.root)) } public func many( + _ kind: QuantificationKind = .eager, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3, C4)])> where Component.Match == (W, C0, C1, C2, C3, C4) { - .init(node: .quantification(.zeroOrMore, .eager, component().regex.root)) + .init(node: .quantification(.zeroOrMore, kind.astKind, component().regex.root)) } @@ -1010,16 +1044,18 @@ public postfix func .+( public func oneOrMore( - _ component: Component + _ component: Component, + _ kind: QuantificationKind = .eager ) -> Regex<(Substring, [(C0, C1, C2, C3, C4)])> where Component.Match == (W, C0, C1, C2, C3, C4) { - .init(node: .quantification(.oneOrMore, .eager, component.regex.root)) + .init(node: .quantification(.oneOrMore, kind.astKind, component.regex.root)) } public func oneOrMore( + _ kind: QuantificationKind = .eager, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3, C4)])> where Component.Match == (W, C0, C1, C2, C3, C4) { - .init(node: .quantification(.oneOrMore, .eager, component().regex.root)) + .init(node: .quantification(.oneOrMore, kind.astKind, component().regex.root)) } @@ -1032,16 +1068,18 @@ public postfix func .*( public func optionally( - _ component: Component + _ component: Component, + _ kind: QuantificationKind = .eager ) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { - .init(node: .quantification(.zeroOrOne, .eager, component.regex.root)) + .init(node: .quantification(.zeroOrOne, kind.astKind, component.regex.root)) } public func optionally( + _ kind: QuantificationKind = .eager, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { - .init(node: .quantification(.zeroOrOne, .eager, component().regex.root)) + .init(node: .quantification(.zeroOrOne, kind.astKind, component().regex.root)) } @@ -1060,16 +1098,18 @@ extension RegexBuilder { } public func many( - _ component: Component + _ component: Component, + _ kind: QuantificationKind = .eager ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { - .init(node: .quantification(.zeroOrMore, .eager, component.regex.root)) + .init(node: .quantification(.zeroOrMore, kind.astKind, component.regex.root)) } public func many( + _ kind: QuantificationKind = .eager, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { - .init(node: .quantification(.zeroOrMore, .eager, component().regex.root)) + .init(node: .quantification(.zeroOrMore, kind.astKind, component().regex.root)) } @@ -1082,16 +1122,18 @@ public postfix func .+( public func oneOrMore( - _ component: Component + _ component: Component, + _ kind: QuantificationKind = .eager ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { - .init(node: .quantification(.oneOrMore, .eager, component.regex.root)) + .init(node: .quantification(.oneOrMore, kind.astKind, component.regex.root)) } public func oneOrMore( + _ kind: QuantificationKind = .eager, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { - .init(node: .quantification(.oneOrMore, .eager, component().regex.root)) + .init(node: .quantification(.oneOrMore, kind.astKind, component().regex.root)) } @@ -1104,16 +1146,18 @@ public postfix func .*( public func optionally( - _ component: Component + _ component: Component, + _ kind: QuantificationKind = .eager ) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5, C6)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { - .init(node: .quantification(.zeroOrOne, .eager, component.regex.root)) + .init(node: .quantification(.zeroOrOne, kind.astKind, component.regex.root)) } public func optionally( + _ kind: QuantificationKind = .eager, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5, C6)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { - .init(node: .quantification(.zeroOrOne, .eager, component().regex.root)) + .init(node: .quantification(.zeroOrOne, kind.astKind, component().regex.root)) } @@ -1132,16 +1176,18 @@ extension RegexBuilder { } public func many( - _ component: Component + _ component: Component, + _ kind: QuantificationKind = .eager ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { - .init(node: .quantification(.zeroOrMore, .eager, component.regex.root)) + .init(node: .quantification(.zeroOrMore, kind.astKind, component.regex.root)) } public func many( + _ kind: QuantificationKind = .eager, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { - .init(node: .quantification(.zeroOrMore, .eager, component().regex.root)) + .init(node: .quantification(.zeroOrMore, kind.astKind, component().regex.root)) } @@ -1154,16 +1200,18 @@ public postfix func .+( public func oneOrMore( - _ component: Component + _ component: Component, + _ kind: QuantificationKind = .eager ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { - .init(node: .quantification(.oneOrMore, .eager, component.regex.root)) + .init(node: .quantification(.oneOrMore, kind.astKind, component.regex.root)) } public func oneOrMore( + _ kind: QuantificationKind = .eager, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { - .init(node: .quantification(.oneOrMore, .eager, component().regex.root)) + .init(node: .quantification(.oneOrMore, kind.astKind, component().regex.root)) } @@ -1176,16 +1224,18 @@ public postfix func .*( public func optionally( - _ component: Component + _ component: Component, + _ kind: QuantificationKind = .eager ) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5, C6, C7)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { - .init(node: .quantification(.zeroOrOne, .eager, component.regex.root)) + .init(node: .quantification(.zeroOrOne, kind.astKind, component.regex.root)) } public func optionally( + _ kind: QuantificationKind = .eager, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5, C6, C7)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { - .init(node: .quantification(.zeroOrOne, .eager, component().regex.root)) + .init(node: .quantification(.zeroOrOne, kind.astKind, component().regex.root)) } @@ -1204,16 +1254,18 @@ extension RegexBuilder { } public func many( - _ component: Component + _ component: Component, + _ kind: QuantificationKind = .eager ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { - .init(node: .quantification(.zeroOrMore, .eager, component.regex.root)) + .init(node: .quantification(.zeroOrMore, kind.astKind, component.regex.root)) } public func many( + _ kind: QuantificationKind = .eager, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { - .init(node: .quantification(.zeroOrMore, .eager, component().regex.root)) + .init(node: .quantification(.zeroOrMore, kind.astKind, component().regex.root)) } @@ -1226,16 +1278,18 @@ public postfix func .+( - _ component: Component + _ component: Component, + _ kind: QuantificationKind = .eager ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { - .init(node: .quantification(.oneOrMore, .eager, component.regex.root)) + .init(node: .quantification(.oneOrMore, kind.astKind, component.regex.root)) } public func oneOrMore( + _ kind: QuantificationKind = .eager, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { - .init(node: .quantification(.oneOrMore, .eager, component().regex.root)) + .init(node: .quantification(.oneOrMore, kind.astKind, component().regex.root)) } @@ -1248,16 +1302,18 @@ public postfix func .*( - _ component: Component + _ component: Component, + _ kind: QuantificationKind = .eager ) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5, C6, C7, C8)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { - .init(node: .quantification(.zeroOrOne, .eager, component.regex.root)) + .init(node: .quantification(.zeroOrOne, kind.astKind, component.regex.root)) } public func optionally( + _ kind: QuantificationKind = .eager, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5, C6, C7, C8)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { - .init(node: .quantification(.zeroOrOne, .eager, component().regex.root)) + .init(node: .quantification(.zeroOrOne, kind.astKind, component().regex.root)) } @@ -1276,16 +1332,18 @@ extension RegexBuilder { } public func many( - _ component: Component + _ component: Component, + _ kind: QuantificationKind = .eager ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7, C8)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { - .init(node: .quantification(.zeroOrMore, .eager, component.regex.root)) + .init(node: .quantification(.zeroOrMore, kind.astKind, component.regex.root)) } public func many( + _ kind: QuantificationKind = .eager, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7, C8)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { - .init(node: .quantification(.zeroOrMore, .eager, component().regex.root)) + .init(node: .quantification(.zeroOrMore, kind.astKind, component().regex.root)) } @@ -1298,16 +1356,18 @@ public postfix func .+( - _ component: Component + _ component: Component, + _ kind: QuantificationKind = .eager ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7, C8)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { - .init(node: .quantification(.oneOrMore, .eager, component.regex.root)) + .init(node: .quantification(.oneOrMore, kind.astKind, component.regex.root)) } public func oneOrMore( + _ kind: QuantificationKind = .eager, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7, C8)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { - .init(node: .quantification(.oneOrMore, .eager, component().regex.root)) + .init(node: .quantification(.oneOrMore, kind.astKind, component().regex.root)) } diff --git a/Tests/RegexTests/RegexDSLTests.swift b/Tests/RegexTests/RegexDSLTests.swift index 695153c1b..268e2a944 100644 --- a/Tests/RegexTests/RegexDSLTests.swift +++ b/Tests/RegexTests/RegexDSLTests.swift @@ -144,6 +144,40 @@ class RegexDSLTests: XCTestCase { oneOf { "k".capture(); "j".capture() } // (Substring?, Substring?) } } + + func testQuantificationKind() throws { + try _testDSLCaptures( + ("abc1def2", ("abc1def2", ["2"])), + captureType: (Substring, [Substring]).self, ==) + { + oneOrMore { + oneOrMore(.word) + CharacterClass.digit.capture() + } + } + + try _testDSLCaptures( + ("abc1def2", ("abc1def2", ["1", "2"])), + captureType: (Substring, [Substring]).self, ==) + { + oneOrMore { + oneOrMore(.word, .reluctant) + CharacterClass.digit.capture() + } + } + + try _testDSLCaptures( + ("abc1def2", ("abc1def2", ["1", "2"])), + captureType: (Substring, [Substring]).self, ==) + { + oneOrMore { + oneOrMore(.reluctant) { + CharacterClass.word + } + CharacterClass.digit.capture() + } + } + } func testNestedGroups() throws { try _testDSLCaptures( From 51c4f1c6cee68b4521a83ac1352ceab7ee2294c2 Mon Sep 17 00:00:00 2001 From: Nate Cook Date: Wed, 9 Feb 2022 14:24:25 -0600 Subject: [PATCH 5/7] Update naming (thanks to @rxwei) --- .../VariadicsGenerator.swift | 4 +- Sources/_StringProcessing/RegexDSL/DSL.swift | 34 ++--- .../RegexDSL/Variadics.swift | 120 +++++++++--------- Tests/RegexTests/RegexDSLTests.swift | 6 +- 4 files changed, 82 insertions(+), 82 deletions(-) diff --git a/Sources/VariadicsGenerator/VariadicsGenerator.swift b/Sources/VariadicsGenerator/VariadicsGenerator.swift index 204406579..d7cebc097 100644 --- a/Sources/VariadicsGenerator/VariadicsGenerator.swift +++ b/Sources/VariadicsGenerator/VariadicsGenerator.swift @@ -354,14 +354,14 @@ struct VariadicsGenerator: ParsableCommand { \(arity == 0 ? "@_disfavoredOverload" : "") public func \(kind.rawValue)<\(genericParams)>( _ component: Component, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> \(regexTypeName)<\(matchType)> \(whereClause) { .init(node: .quantification(.\(kind.astQuantifierAmount), kind.astKind, component.regex.root)) } \(arity == 0 ? "@_disfavoredOverload" : "") public func \(kind.rawValue)<\(genericParams)>( - _ kind: QuantificationKind = .eager, + _ kind: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> \(regexTypeName)<\(matchType)> \(whereClause) { .init(node: .quantification(.\(kind.astQuantifierAmount), kind.astKind, component().regex.root)) diff --git a/Sources/_StringProcessing/RegexDSL/DSL.swift b/Sources/_StringProcessing/RegexDSL/DSL.swift index 823cd2a27..efafe2ad9 100644 --- a/Sources/_StringProcessing/RegexDSL/DSL.swift +++ b/Sources/_StringProcessing/RegexDSL/DSL.swift @@ -63,40 +63,40 @@ extension CharacterClass: RegexProtocol { // Note: Quantifiers are currently gyb'd. /// Specifies how much to attempt to match when using a quantifier. -public struct QuantificationKind { +public struct QuantificationBehavior { internal enum Kind { - case eager - case reluctant - case possessive + case eagerly + case reluctantly + case possessively } var kind: Kind internal var astKind: AST.Quantification.Kind { switch kind { - case .eager: return .eager - case .reluctant: return .reluctant - case .possessive: return .possessive + case .eagerly: return .eager + case .reluctantly: return .reluctant + case .possessively: return .possessive } } } -extension QuantificationKind { +extension QuantificationBehavior { /// Match as much of the input string as possible, backtracking when /// necessary. - public static var eager: QuantificationKind { - .init(kind: .eager) + public static var eagerly: QuantificationBehavior { + .init(kind: .eagerly) } /// Match as little of the input string as possible, expanding the matched /// region as necessary to complete a match. - public static var reluctant: QuantificationKind { - .init(kind: .reluctant) + public static var reluctantly: QuantificationBehavior { + .init(kind: .reluctantly) } /// Match as much of the input string as possible, performing no backtracking. - public static var possessive: QuantificationKind { - .init(kind: .possessive) + public static var possessively: QuantificationBehavior { + .init(kind: .possessively) } } @@ -139,21 +139,21 @@ postfix operator .+ // Overloads for quantifying over a character class. public func zeroOrOne( _ cc: CharacterClass, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex { .init(node: .quantification(.zeroOrOne, kind.astKind, cc.regex.root)) } public func many( _ cc: CharacterClass, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex { .init(node: .quantification(.zeroOrMore, kind.astKind, cc.regex.root)) } public func oneOrMore( _ cc: CharacterClass, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex { .init(node: .quantification(.oneOrMore, kind.astKind, cc.regex.root)) } diff --git a/Sources/_StringProcessing/RegexDSL/Variadics.swift b/Sources/_StringProcessing/RegexDSL/Variadics.swift index 698c858c3..97862d76d 100644 --- a/Sources/_StringProcessing/RegexDSL/Variadics.swift +++ b/Sources/_StringProcessing/RegexDSL/Variadics.swift @@ -601,14 +601,14 @@ extension RegexBuilder { @_disfavoredOverload public func optionally( _ component: Component, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex { .init(node: .quantification(.zeroOrOne, kind.astKind, component.regex.root)) } @_disfavoredOverload public func optionally( - _ kind: QuantificationKind = .eager, + _ kind: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex { .init(node: .quantification(.zeroOrOne, kind.astKind, component().regex.root)) @@ -631,14 +631,14 @@ extension RegexBuilder { @_disfavoredOverload public func many( _ component: Component, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex { .init(node: .quantification(.zeroOrMore, kind.astKind, component.regex.root)) } @_disfavoredOverload public func many( - _ kind: QuantificationKind = .eager, + _ kind: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex { .init(node: .quantification(.zeroOrMore, kind.astKind, component().regex.root)) @@ -655,14 +655,14 @@ public postfix func .+( @_disfavoredOverload public func oneOrMore( _ component: Component, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex { .init(node: .quantification(.oneOrMore, kind.astKind, component.regex.root)) } @_disfavoredOverload public func oneOrMore( - _ kind: QuantificationKind = .eager, + _ kind: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex { .init(node: .quantification(.oneOrMore, kind.astKind, component().regex.root)) @@ -679,14 +679,14 @@ public postfix func .*( public func optionally( _ component: Component, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex<(Substring, C0?)> where Component.Match == (W, C0) { .init(node: .quantification(.zeroOrOne, kind.astKind, component.regex.root)) } public func optionally( - _ kind: QuantificationKind = .eager, + _ kind: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, C0?)> where Component.Match == (W, C0) { .init(node: .quantification(.zeroOrOne, kind.astKind, component().regex.root)) @@ -709,14 +709,14 @@ extension RegexBuilder { public func many( _ component: Component, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [C0])> where Component.Match == (W, C0) { .init(node: .quantification(.zeroOrMore, kind.astKind, component.regex.root)) } public func many( - _ kind: QuantificationKind = .eager, + _ kind: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [C0])> where Component.Match == (W, C0) { .init(node: .quantification(.zeroOrMore, kind.astKind, component().regex.root)) @@ -733,14 +733,14 @@ public postfix func .+( public func oneOrMore( _ component: Component, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [C0])> where Component.Match == (W, C0) { .init(node: .quantification(.oneOrMore, kind.astKind, component.regex.root)) } public func oneOrMore( - _ kind: QuantificationKind = .eager, + _ kind: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [C0])> where Component.Match == (W, C0) { .init(node: .quantification(.oneOrMore, kind.astKind, component().regex.root)) @@ -757,14 +757,14 @@ public postfix func .*( public func optionally( _ component: Component, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex<(Substring, (C0, C1)?)> where Component.Match == (W, C0, C1) { .init(node: .quantification(.zeroOrOne, kind.astKind, component.regex.root)) } public func optionally( - _ kind: QuantificationKind = .eager, + _ kind: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, (C0, C1)?)> where Component.Match == (W, C0, C1) { .init(node: .quantification(.zeroOrOne, kind.astKind, component().regex.root)) @@ -787,14 +787,14 @@ extension RegexBuilder { public func many( _ component: Component, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1)])> where Component.Match == (W, C0, C1) { .init(node: .quantification(.zeroOrMore, kind.astKind, component.regex.root)) } public func many( - _ kind: QuantificationKind = .eager, + _ kind: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1)])> where Component.Match == (W, C0, C1) { .init(node: .quantification(.zeroOrMore, kind.astKind, component().regex.root)) @@ -811,14 +811,14 @@ public postfix func .+( public func oneOrMore( _ component: Component, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1)])> where Component.Match == (W, C0, C1) { .init(node: .quantification(.oneOrMore, kind.astKind, component.regex.root)) } public func oneOrMore( - _ kind: QuantificationKind = .eager, + _ kind: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1)])> where Component.Match == (W, C0, C1) { .init(node: .quantification(.oneOrMore, kind.astKind, component().regex.root)) @@ -835,14 +835,14 @@ public postfix func .*( public func optionally( _ component: Component, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex<(Substring, (C0, C1, C2)?)> where Component.Match == (W, C0, C1, C2) { .init(node: .quantification(.zeroOrOne, kind.astKind, component.regex.root)) } public func optionally( - _ kind: QuantificationKind = .eager, + _ kind: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, (C0, C1, C2)?)> where Component.Match == (W, C0, C1, C2) { .init(node: .quantification(.zeroOrOne, kind.astKind, component().regex.root)) @@ -865,14 +865,14 @@ extension RegexBuilder { public func many( _ component: Component, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1, C2)])> where Component.Match == (W, C0, C1, C2) { .init(node: .quantification(.zeroOrMore, kind.astKind, component.regex.root)) } public func many( - _ kind: QuantificationKind = .eager, + _ kind: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2)])> where Component.Match == (W, C0, C1, C2) { .init(node: .quantification(.zeroOrMore, kind.astKind, component().regex.root)) @@ -889,14 +889,14 @@ public postfix func .+( public func oneOrMore( _ component: Component, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1, C2)])> where Component.Match == (W, C0, C1, C2) { .init(node: .quantification(.oneOrMore, kind.astKind, component.regex.root)) } public func oneOrMore( - _ kind: QuantificationKind = .eager, + _ kind: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2)])> where Component.Match == (W, C0, C1, C2) { .init(node: .quantification(.oneOrMore, kind.astKind, component().regex.root)) @@ -913,14 +913,14 @@ public postfix func .*( public func optionally( _ component: Component, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex<(Substring, (C0, C1, C2, C3)?)> where Component.Match == (W, C0, C1, C2, C3) { .init(node: .quantification(.zeroOrOne, kind.astKind, component.regex.root)) } public func optionally( - _ kind: QuantificationKind = .eager, + _ kind: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, (C0, C1, C2, C3)?)> where Component.Match == (W, C0, C1, C2, C3) { .init(node: .quantification(.zeroOrOne, kind.astKind, component().regex.root)) @@ -943,14 +943,14 @@ extension RegexBuilder { public func many( _ component: Component, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1, C2, C3)])> where Component.Match == (W, C0, C1, C2, C3) { .init(node: .quantification(.zeroOrMore, kind.astKind, component.regex.root)) } public func many( - _ kind: QuantificationKind = .eager, + _ kind: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3)])> where Component.Match == (W, C0, C1, C2, C3) { .init(node: .quantification(.zeroOrMore, kind.astKind, component().regex.root)) @@ -967,14 +967,14 @@ public postfix func .+( public func oneOrMore( _ component: Component, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1, C2, C3)])> where Component.Match == (W, C0, C1, C2, C3) { .init(node: .quantification(.oneOrMore, kind.astKind, component.regex.root)) } public func oneOrMore( - _ kind: QuantificationKind = .eager, + _ kind: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3)])> where Component.Match == (W, C0, C1, C2, C3) { .init(node: .quantification(.oneOrMore, kind.astKind, component().regex.root)) @@ -991,14 +991,14 @@ public postfix func .*( public func optionally( _ component: Component, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex<(Substring, (C0, C1, C2, C3, C4)?)> where Component.Match == (W, C0, C1, C2, C3, C4) { .init(node: .quantification(.zeroOrOne, kind.astKind, component.regex.root)) } public func optionally( - _ kind: QuantificationKind = .eager, + _ kind: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, (C0, C1, C2, C3, C4)?)> where Component.Match == (W, C0, C1, C2, C3, C4) { .init(node: .quantification(.zeroOrOne, kind.astKind, component().regex.root)) @@ -1021,14 +1021,14 @@ extension RegexBuilder { public func many( _ component: Component, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1, C2, C3, C4)])> where Component.Match == (W, C0, C1, C2, C3, C4) { .init(node: .quantification(.zeroOrMore, kind.astKind, component.regex.root)) } public func many( - _ kind: QuantificationKind = .eager, + _ kind: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3, C4)])> where Component.Match == (W, C0, C1, C2, C3, C4) { .init(node: .quantification(.zeroOrMore, kind.astKind, component().regex.root)) @@ -1045,14 +1045,14 @@ public postfix func .+( public func oneOrMore( _ component: Component, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1, C2, C3, C4)])> where Component.Match == (W, C0, C1, C2, C3, C4) { .init(node: .quantification(.oneOrMore, kind.astKind, component.regex.root)) } public func oneOrMore( - _ kind: QuantificationKind = .eager, + _ kind: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3, C4)])> where Component.Match == (W, C0, C1, C2, C3, C4) { .init(node: .quantification(.oneOrMore, kind.astKind, component().regex.root)) @@ -1069,14 +1069,14 @@ public postfix func .*( public func optionally( _ component: Component, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { .init(node: .quantification(.zeroOrOne, kind.astKind, component.regex.root)) } public func optionally( - _ kind: QuantificationKind = .eager, + _ kind: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { .init(node: .quantification(.zeroOrOne, kind.astKind, component().regex.root)) @@ -1099,14 +1099,14 @@ extension RegexBuilder { public func many( _ component: Component, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { .init(node: .quantification(.zeroOrMore, kind.astKind, component.regex.root)) } public func many( - _ kind: QuantificationKind = .eager, + _ kind: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { .init(node: .quantification(.zeroOrMore, kind.astKind, component().regex.root)) @@ -1123,14 +1123,14 @@ public postfix func .+( public func oneOrMore( _ component: Component, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { .init(node: .quantification(.oneOrMore, kind.astKind, component.regex.root)) } public func oneOrMore( - _ kind: QuantificationKind = .eager, + _ kind: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { .init(node: .quantification(.oneOrMore, kind.astKind, component().regex.root)) @@ -1147,14 +1147,14 @@ public postfix func .*( public func optionally( _ component: Component, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5, C6)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { .init(node: .quantification(.zeroOrOne, kind.astKind, component.regex.root)) } public func optionally( - _ kind: QuantificationKind = .eager, + _ kind: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5, C6)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { .init(node: .quantification(.zeroOrOne, kind.astKind, component().regex.root)) @@ -1177,14 +1177,14 @@ extension RegexBuilder { public func many( _ component: Component, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { .init(node: .quantification(.zeroOrMore, kind.astKind, component.regex.root)) } public func many( - _ kind: QuantificationKind = .eager, + _ kind: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { .init(node: .quantification(.zeroOrMore, kind.astKind, component().regex.root)) @@ -1201,14 +1201,14 @@ public postfix func .+( public func oneOrMore( _ component: Component, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { .init(node: .quantification(.oneOrMore, kind.astKind, component.regex.root)) } public func oneOrMore( - _ kind: QuantificationKind = .eager, + _ kind: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { .init(node: .quantification(.oneOrMore, kind.astKind, component().regex.root)) @@ -1225,14 +1225,14 @@ public postfix func .*( public func optionally( _ component: Component, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5, C6, C7)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { .init(node: .quantification(.zeroOrOne, kind.astKind, component.regex.root)) } public func optionally( - _ kind: QuantificationKind = .eager, + _ kind: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5, C6, C7)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { .init(node: .quantification(.zeroOrOne, kind.astKind, component().regex.root)) @@ -1255,14 +1255,14 @@ extension RegexBuilder { public func many( _ component: Component, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { .init(node: .quantification(.zeroOrMore, kind.astKind, component.regex.root)) } public func many( - _ kind: QuantificationKind = .eager, + _ kind: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { .init(node: .quantification(.zeroOrMore, kind.astKind, component().regex.root)) @@ -1279,14 +1279,14 @@ public postfix func .+( _ component: Component, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { .init(node: .quantification(.oneOrMore, kind.astKind, component.regex.root)) } public func oneOrMore( - _ kind: QuantificationKind = .eager, + _ kind: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { .init(node: .quantification(.oneOrMore, kind.astKind, component().regex.root)) @@ -1303,14 +1303,14 @@ public postfix func .*( _ component: Component, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5, C6, C7, C8)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { .init(node: .quantification(.zeroOrOne, kind.astKind, component.regex.root)) } public func optionally( - _ kind: QuantificationKind = .eager, + _ kind: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5, C6, C7, C8)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { .init(node: .quantification(.zeroOrOne, kind.astKind, component().regex.root)) @@ -1333,14 +1333,14 @@ extension RegexBuilder { public func many( _ component: Component, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7, C8)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { .init(node: .quantification(.zeroOrMore, kind.astKind, component.regex.root)) } public func many( - _ kind: QuantificationKind = .eager, + _ kind: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7, C8)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { .init(node: .quantification(.zeroOrMore, kind.astKind, component().regex.root)) @@ -1357,14 +1357,14 @@ public postfix func .+( _ component: Component, - _ kind: QuantificationKind = .eager + _ kind: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7, C8)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { .init(node: .quantification(.oneOrMore, kind.astKind, component.regex.root)) } public func oneOrMore( - _ kind: QuantificationKind = .eager, + _ kind: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7, C8)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { .init(node: .quantification(.oneOrMore, kind.astKind, component().regex.root)) diff --git a/Tests/RegexTests/RegexDSLTests.swift b/Tests/RegexTests/RegexDSLTests.swift index 268e2a944..e67c8e5c7 100644 --- a/Tests/RegexTests/RegexDSLTests.swift +++ b/Tests/RegexTests/RegexDSLTests.swift @@ -145,7 +145,7 @@ class RegexDSLTests: XCTestCase { } } - func testQuantificationKind() throws { + func testQuantificationBehavior() throws { try _testDSLCaptures( ("abc1def2", ("abc1def2", ["2"])), captureType: (Substring, [Substring]).self, ==) @@ -161,7 +161,7 @@ class RegexDSLTests: XCTestCase { captureType: (Substring, [Substring]).self, ==) { oneOrMore { - oneOrMore(.word, .reluctant) + oneOrMore(.word, .reluctantly) CharacterClass.digit.capture() } } @@ -171,7 +171,7 @@ class RegexDSLTests: XCTestCase { captureType: (Substring, [Substring]).self, ==) { oneOrMore { - oneOrMore(.reluctant) { + oneOrMore(.reluctantly) { CharacterClass.word } CharacterClass.digit.capture() From c1a6f0c968aaf4fde74c3c9fd20f9237b6c9b6cf Mon Sep 17 00:00:00 2001 From: Nate Cook Date: Wed, 9 Feb 2022 17:21:16 -0600 Subject: [PATCH 6/7] Update parameter names --- .../VariadicsGenerator.swift | 8 +- Sources/_StringProcessing/RegexDSL/DSL.swift | 12 +- .../RegexDSL/Variadics.swift | 240 +++++++++--------- 3 files changed, 130 insertions(+), 130 deletions(-) diff --git a/Sources/VariadicsGenerator/VariadicsGenerator.swift b/Sources/VariadicsGenerator/VariadicsGenerator.swift index d7cebc097..6372e229c 100644 --- a/Sources/VariadicsGenerator/VariadicsGenerator.swift +++ b/Sources/VariadicsGenerator/VariadicsGenerator.swift @@ -354,17 +354,17 @@ struct VariadicsGenerator: ParsableCommand { \(arity == 0 ? "@_disfavoredOverload" : "") public func \(kind.rawValue)<\(genericParams)>( _ component: Component, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> \(regexTypeName)<\(matchType)> \(whereClause) { - .init(node: .quantification(.\(kind.astQuantifierAmount), kind.astKind, component.regex.root)) + .init(node: .quantification(.\(kind.astQuantifierAmount), behavior.astKind, component.regex.root)) } \(arity == 0 ? "@_disfavoredOverload" : "") public func \(kind.rawValue)<\(genericParams)>( - _ kind: QuantificationBehavior = .eagerly, + _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> \(regexTypeName)<\(matchType)> \(whereClause) { - .init(node: .quantification(.\(kind.astQuantifierAmount), kind.astKind, component().regex.root)) + .init(node: .quantification(.\(kind.astQuantifierAmount), behavior.astKind, component().regex.root)) } \(arity == 0 ? "@_disfavoredOverload" : "") diff --git a/Sources/_StringProcessing/RegexDSL/DSL.swift b/Sources/_StringProcessing/RegexDSL/DSL.swift index efafe2ad9..c2d707da5 100644 --- a/Sources/_StringProcessing/RegexDSL/DSL.swift +++ b/Sources/_StringProcessing/RegexDSL/DSL.swift @@ -139,23 +139,23 @@ postfix operator .+ // Overloads for quantifying over a character class. public func zeroOrOne( _ cc: CharacterClass, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex { - .init(node: .quantification(.zeroOrOne, kind.astKind, cc.regex.root)) + .init(node: .quantification(.zeroOrOne, behavior.astKind, cc.regex.root)) } public func many( _ cc: CharacterClass, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex { - .init(node: .quantification(.zeroOrMore, kind.astKind, cc.regex.root)) + .init(node: .quantification(.zeroOrMore, behavior.astKind, cc.regex.root)) } public func oneOrMore( _ cc: CharacterClass, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex { - .init(node: .quantification(.oneOrMore, kind.astKind, cc.regex.root)) + .init(node: .quantification(.oneOrMore, behavior.astKind, cc.regex.root)) } // MARK: Alternation diff --git a/Sources/_StringProcessing/RegexDSL/Variadics.swift b/Sources/_StringProcessing/RegexDSL/Variadics.swift index 97862d76d..21a69256e 100644 --- a/Sources/_StringProcessing/RegexDSL/Variadics.swift +++ b/Sources/_StringProcessing/RegexDSL/Variadics.swift @@ -601,17 +601,17 @@ extension RegexBuilder { @_disfavoredOverload public func optionally( _ component: Component, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex { - .init(node: .quantification(.zeroOrOne, kind.astKind, component.regex.root)) + .init(node: .quantification(.zeroOrOne, behavior.astKind, component.regex.root)) } @_disfavoredOverload public func optionally( - _ kind: QuantificationBehavior = .eagerly, + _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex { - .init(node: .quantification(.zeroOrOne, kind.astKind, component().regex.root)) + .init(node: .quantification(.zeroOrOne, behavior.astKind, component().regex.root)) } @_disfavoredOverload @@ -631,17 +631,17 @@ extension RegexBuilder { @_disfavoredOverload public func many( _ component: Component, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex { - .init(node: .quantification(.zeroOrMore, kind.astKind, component.regex.root)) + .init(node: .quantification(.zeroOrMore, behavior.astKind, component.regex.root)) } @_disfavoredOverload public func many( - _ kind: QuantificationBehavior = .eagerly, + _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex { - .init(node: .quantification(.zeroOrMore, kind.astKind, component().regex.root)) + .init(node: .quantification(.zeroOrMore, behavior.astKind, component().regex.root)) } @_disfavoredOverload @@ -655,17 +655,17 @@ public postfix func .+( @_disfavoredOverload public func oneOrMore( _ component: Component, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex { - .init(node: .quantification(.oneOrMore, kind.astKind, component.regex.root)) + .init(node: .quantification(.oneOrMore, behavior.astKind, component.regex.root)) } @_disfavoredOverload public func oneOrMore( - _ kind: QuantificationBehavior = .eagerly, + _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex { - .init(node: .quantification(.oneOrMore, kind.astKind, component().regex.root)) + .init(node: .quantification(.oneOrMore, behavior.astKind, component().regex.root)) } @_disfavoredOverload @@ -679,17 +679,17 @@ public postfix func .*( public func optionally( _ component: Component, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex<(Substring, C0?)> where Component.Match == (W, C0) { - .init(node: .quantification(.zeroOrOne, kind.astKind, component.regex.root)) + .init(node: .quantification(.zeroOrOne, behavior.astKind, component.regex.root)) } public func optionally( - _ kind: QuantificationBehavior = .eagerly, + _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, C0?)> where Component.Match == (W, C0) { - .init(node: .quantification(.zeroOrOne, kind.astKind, component().regex.root)) + .init(node: .quantification(.zeroOrOne, behavior.astKind, component().regex.root)) } @@ -709,17 +709,17 @@ extension RegexBuilder { public func many( _ component: Component, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [C0])> where Component.Match == (W, C0) { - .init(node: .quantification(.zeroOrMore, kind.astKind, component.regex.root)) + .init(node: .quantification(.zeroOrMore, behavior.astKind, component.regex.root)) } public func many( - _ kind: QuantificationBehavior = .eagerly, + _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [C0])> where Component.Match == (W, C0) { - .init(node: .quantification(.zeroOrMore, kind.astKind, component().regex.root)) + .init(node: .quantification(.zeroOrMore, behavior.astKind, component().regex.root)) } @@ -733,17 +733,17 @@ public postfix func .+( public func oneOrMore( _ component: Component, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [C0])> where Component.Match == (W, C0) { - .init(node: .quantification(.oneOrMore, kind.astKind, component.regex.root)) + .init(node: .quantification(.oneOrMore, behavior.astKind, component.regex.root)) } public func oneOrMore( - _ kind: QuantificationBehavior = .eagerly, + _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [C0])> where Component.Match == (W, C0) { - .init(node: .quantification(.oneOrMore, kind.astKind, component().regex.root)) + .init(node: .quantification(.oneOrMore, behavior.astKind, component().regex.root)) } @@ -757,17 +757,17 @@ public postfix func .*( public func optionally( _ component: Component, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex<(Substring, (C0, C1)?)> where Component.Match == (W, C0, C1) { - .init(node: .quantification(.zeroOrOne, kind.astKind, component.regex.root)) + .init(node: .quantification(.zeroOrOne, behavior.astKind, component.regex.root)) } public func optionally( - _ kind: QuantificationBehavior = .eagerly, + _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, (C0, C1)?)> where Component.Match == (W, C0, C1) { - .init(node: .quantification(.zeroOrOne, kind.astKind, component().regex.root)) + .init(node: .quantification(.zeroOrOne, behavior.astKind, component().regex.root)) } @@ -787,17 +787,17 @@ extension RegexBuilder { public func many( _ component: Component, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1)])> where Component.Match == (W, C0, C1) { - .init(node: .quantification(.zeroOrMore, kind.astKind, component.regex.root)) + .init(node: .quantification(.zeroOrMore, behavior.astKind, component.regex.root)) } public func many( - _ kind: QuantificationBehavior = .eagerly, + _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1)])> where Component.Match == (W, C0, C1) { - .init(node: .quantification(.zeroOrMore, kind.astKind, component().regex.root)) + .init(node: .quantification(.zeroOrMore, behavior.astKind, component().regex.root)) } @@ -811,17 +811,17 @@ public postfix func .+( public func oneOrMore( _ component: Component, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1)])> where Component.Match == (W, C0, C1) { - .init(node: .quantification(.oneOrMore, kind.astKind, component.regex.root)) + .init(node: .quantification(.oneOrMore, behavior.astKind, component.regex.root)) } public func oneOrMore( - _ kind: QuantificationBehavior = .eagerly, + _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1)])> where Component.Match == (W, C0, C1) { - .init(node: .quantification(.oneOrMore, kind.astKind, component().regex.root)) + .init(node: .quantification(.oneOrMore, behavior.astKind, component().regex.root)) } @@ -835,17 +835,17 @@ public postfix func .*( public func optionally( _ component: Component, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex<(Substring, (C0, C1, C2)?)> where Component.Match == (W, C0, C1, C2) { - .init(node: .quantification(.zeroOrOne, kind.astKind, component.regex.root)) + .init(node: .quantification(.zeroOrOne, behavior.astKind, component.regex.root)) } public func optionally( - _ kind: QuantificationBehavior = .eagerly, + _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, (C0, C1, C2)?)> where Component.Match == (W, C0, C1, C2) { - .init(node: .quantification(.zeroOrOne, kind.astKind, component().regex.root)) + .init(node: .quantification(.zeroOrOne, behavior.astKind, component().regex.root)) } @@ -865,17 +865,17 @@ extension RegexBuilder { public func many( _ component: Component, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1, C2)])> where Component.Match == (W, C0, C1, C2) { - .init(node: .quantification(.zeroOrMore, kind.astKind, component.regex.root)) + .init(node: .quantification(.zeroOrMore, behavior.astKind, component.regex.root)) } public func many( - _ kind: QuantificationBehavior = .eagerly, + _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2)])> where Component.Match == (W, C0, C1, C2) { - .init(node: .quantification(.zeroOrMore, kind.astKind, component().regex.root)) + .init(node: .quantification(.zeroOrMore, behavior.astKind, component().regex.root)) } @@ -889,17 +889,17 @@ public postfix func .+( public func oneOrMore( _ component: Component, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1, C2)])> where Component.Match == (W, C0, C1, C2) { - .init(node: .quantification(.oneOrMore, kind.astKind, component.regex.root)) + .init(node: .quantification(.oneOrMore, behavior.astKind, component.regex.root)) } public func oneOrMore( - _ kind: QuantificationBehavior = .eagerly, + _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2)])> where Component.Match == (W, C0, C1, C2) { - .init(node: .quantification(.oneOrMore, kind.astKind, component().regex.root)) + .init(node: .quantification(.oneOrMore, behavior.astKind, component().regex.root)) } @@ -913,17 +913,17 @@ public postfix func .*( public func optionally( _ component: Component, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex<(Substring, (C0, C1, C2, C3)?)> where Component.Match == (W, C0, C1, C2, C3) { - .init(node: .quantification(.zeroOrOne, kind.astKind, component.regex.root)) + .init(node: .quantification(.zeroOrOne, behavior.astKind, component.regex.root)) } public func optionally( - _ kind: QuantificationBehavior = .eagerly, + _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, (C0, C1, C2, C3)?)> where Component.Match == (W, C0, C1, C2, C3) { - .init(node: .quantification(.zeroOrOne, kind.astKind, component().regex.root)) + .init(node: .quantification(.zeroOrOne, behavior.astKind, component().regex.root)) } @@ -943,17 +943,17 @@ extension RegexBuilder { public func many( _ component: Component, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1, C2, C3)])> where Component.Match == (W, C0, C1, C2, C3) { - .init(node: .quantification(.zeroOrMore, kind.astKind, component.regex.root)) + .init(node: .quantification(.zeroOrMore, behavior.astKind, component.regex.root)) } public func many( - _ kind: QuantificationBehavior = .eagerly, + _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3)])> where Component.Match == (W, C0, C1, C2, C3) { - .init(node: .quantification(.zeroOrMore, kind.astKind, component().regex.root)) + .init(node: .quantification(.zeroOrMore, behavior.astKind, component().regex.root)) } @@ -967,17 +967,17 @@ public postfix func .+( public func oneOrMore( _ component: Component, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1, C2, C3)])> where Component.Match == (W, C0, C1, C2, C3) { - .init(node: .quantification(.oneOrMore, kind.astKind, component.regex.root)) + .init(node: .quantification(.oneOrMore, behavior.astKind, component.regex.root)) } public func oneOrMore( - _ kind: QuantificationBehavior = .eagerly, + _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3)])> where Component.Match == (W, C0, C1, C2, C3) { - .init(node: .quantification(.oneOrMore, kind.astKind, component().regex.root)) + .init(node: .quantification(.oneOrMore, behavior.astKind, component().regex.root)) } @@ -991,17 +991,17 @@ public postfix func .*( public func optionally( _ component: Component, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex<(Substring, (C0, C1, C2, C3, C4)?)> where Component.Match == (W, C0, C1, C2, C3, C4) { - .init(node: .quantification(.zeroOrOne, kind.astKind, component.regex.root)) + .init(node: .quantification(.zeroOrOne, behavior.astKind, component.regex.root)) } public func optionally( - _ kind: QuantificationBehavior = .eagerly, + _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, (C0, C1, C2, C3, C4)?)> where Component.Match == (W, C0, C1, C2, C3, C4) { - .init(node: .quantification(.zeroOrOne, kind.astKind, component().regex.root)) + .init(node: .quantification(.zeroOrOne, behavior.astKind, component().regex.root)) } @@ -1021,17 +1021,17 @@ extension RegexBuilder { public func many( _ component: Component, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1, C2, C3, C4)])> where Component.Match == (W, C0, C1, C2, C3, C4) { - .init(node: .quantification(.zeroOrMore, kind.astKind, component.regex.root)) + .init(node: .quantification(.zeroOrMore, behavior.astKind, component.regex.root)) } public func many( - _ kind: QuantificationBehavior = .eagerly, + _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3, C4)])> where Component.Match == (W, C0, C1, C2, C3, C4) { - .init(node: .quantification(.zeroOrMore, kind.astKind, component().regex.root)) + .init(node: .quantification(.zeroOrMore, behavior.astKind, component().regex.root)) } @@ -1045,17 +1045,17 @@ public postfix func .+( public func oneOrMore( _ component: Component, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1, C2, C3, C4)])> where Component.Match == (W, C0, C1, C2, C3, C4) { - .init(node: .quantification(.oneOrMore, kind.astKind, component.regex.root)) + .init(node: .quantification(.oneOrMore, behavior.astKind, component.regex.root)) } public func oneOrMore( - _ kind: QuantificationBehavior = .eagerly, + _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3, C4)])> where Component.Match == (W, C0, C1, C2, C3, C4) { - .init(node: .quantification(.oneOrMore, kind.astKind, component().regex.root)) + .init(node: .quantification(.oneOrMore, behavior.astKind, component().regex.root)) } @@ -1069,17 +1069,17 @@ public postfix func .*( public func optionally( _ component: Component, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { - .init(node: .quantification(.zeroOrOne, kind.astKind, component.regex.root)) + .init(node: .quantification(.zeroOrOne, behavior.astKind, component.regex.root)) } public func optionally( - _ kind: QuantificationBehavior = .eagerly, + _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { - .init(node: .quantification(.zeroOrOne, kind.astKind, component().regex.root)) + .init(node: .quantification(.zeroOrOne, behavior.astKind, component().regex.root)) } @@ -1099,17 +1099,17 @@ extension RegexBuilder { public func many( _ component: Component, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { - .init(node: .quantification(.zeroOrMore, kind.astKind, component.regex.root)) + .init(node: .quantification(.zeroOrMore, behavior.astKind, component.regex.root)) } public func many( - _ kind: QuantificationBehavior = .eagerly, + _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { - .init(node: .quantification(.zeroOrMore, kind.astKind, component().regex.root)) + .init(node: .quantification(.zeroOrMore, behavior.astKind, component().regex.root)) } @@ -1123,17 +1123,17 @@ public postfix func .+( public func oneOrMore( _ component: Component, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { - .init(node: .quantification(.oneOrMore, kind.astKind, component.regex.root)) + .init(node: .quantification(.oneOrMore, behavior.astKind, component.regex.root)) } public func oneOrMore( - _ kind: QuantificationBehavior = .eagerly, + _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5) { - .init(node: .quantification(.oneOrMore, kind.astKind, component().regex.root)) + .init(node: .quantification(.oneOrMore, behavior.astKind, component().regex.root)) } @@ -1147,17 +1147,17 @@ public postfix func .*( public func optionally( _ component: Component, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5, C6)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { - .init(node: .quantification(.zeroOrOne, kind.astKind, component.regex.root)) + .init(node: .quantification(.zeroOrOne, behavior.astKind, component.regex.root)) } public func optionally( - _ kind: QuantificationBehavior = .eagerly, + _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5, C6)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { - .init(node: .quantification(.zeroOrOne, kind.astKind, component().regex.root)) + .init(node: .quantification(.zeroOrOne, behavior.astKind, component().regex.root)) } @@ -1177,17 +1177,17 @@ extension RegexBuilder { public func many( _ component: Component, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { - .init(node: .quantification(.zeroOrMore, kind.astKind, component.regex.root)) + .init(node: .quantification(.zeroOrMore, behavior.astKind, component.regex.root)) } public func many( - _ kind: QuantificationBehavior = .eagerly, + _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { - .init(node: .quantification(.zeroOrMore, kind.astKind, component().regex.root)) + .init(node: .quantification(.zeroOrMore, behavior.astKind, component().regex.root)) } @@ -1201,17 +1201,17 @@ public postfix func .+( public func oneOrMore( _ component: Component, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { - .init(node: .quantification(.oneOrMore, kind.astKind, component.regex.root)) + .init(node: .quantification(.oneOrMore, behavior.astKind, component.regex.root)) } public func oneOrMore( - _ kind: QuantificationBehavior = .eagerly, + _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) { - .init(node: .quantification(.oneOrMore, kind.astKind, component().regex.root)) + .init(node: .quantification(.oneOrMore, behavior.astKind, component().regex.root)) } @@ -1225,17 +1225,17 @@ public postfix func .*( public func optionally( _ component: Component, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5, C6, C7)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { - .init(node: .quantification(.zeroOrOne, kind.astKind, component.regex.root)) + .init(node: .quantification(.zeroOrOne, behavior.astKind, component.regex.root)) } public func optionally( - _ kind: QuantificationBehavior = .eagerly, + _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5, C6, C7)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { - .init(node: .quantification(.zeroOrOne, kind.astKind, component().regex.root)) + .init(node: .quantification(.zeroOrOne, behavior.astKind, component().regex.root)) } @@ -1255,17 +1255,17 @@ extension RegexBuilder { public func many( _ component: Component, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { - .init(node: .quantification(.zeroOrMore, kind.astKind, component.regex.root)) + .init(node: .quantification(.zeroOrMore, behavior.astKind, component.regex.root)) } public func many( - _ kind: QuantificationBehavior = .eagerly, + _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { - .init(node: .quantification(.zeroOrMore, kind.astKind, component().regex.root)) + .init(node: .quantification(.zeroOrMore, behavior.astKind, component().regex.root)) } @@ -1279,17 +1279,17 @@ public postfix func .+( _ component: Component, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { - .init(node: .quantification(.oneOrMore, kind.astKind, component.regex.root)) + .init(node: .quantification(.oneOrMore, behavior.astKind, component.regex.root)) } public func oneOrMore( - _ kind: QuantificationBehavior = .eagerly, + _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) { - .init(node: .quantification(.oneOrMore, kind.astKind, component().regex.root)) + .init(node: .quantification(.oneOrMore, behavior.astKind, component().regex.root)) } @@ -1303,17 +1303,17 @@ public postfix func .*( _ component: Component, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5, C6, C7, C8)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { - .init(node: .quantification(.zeroOrOne, kind.astKind, component.regex.root)) + .init(node: .quantification(.zeroOrOne, behavior.astKind, component.regex.root)) } public func optionally( - _ kind: QuantificationBehavior = .eagerly, + _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, (C0, C1, C2, C3, C4, C5, C6, C7, C8)?)> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { - .init(node: .quantification(.zeroOrOne, kind.astKind, component().regex.root)) + .init(node: .quantification(.zeroOrOne, behavior.astKind, component().regex.root)) } @@ -1333,17 +1333,17 @@ extension RegexBuilder { public func many( _ component: Component, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7, C8)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { - .init(node: .quantification(.zeroOrMore, kind.astKind, component.regex.root)) + .init(node: .quantification(.zeroOrMore, behavior.astKind, component.regex.root)) } public func many( - _ kind: QuantificationBehavior = .eagerly, + _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7, C8)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { - .init(node: .quantification(.zeroOrMore, kind.astKind, component().regex.root)) + .init(node: .quantification(.zeroOrMore, behavior.astKind, component().regex.root)) } @@ -1357,17 +1357,17 @@ public postfix func .+( _ component: Component, - _ kind: QuantificationBehavior = .eagerly + _ behavior: QuantificationBehavior = .eagerly ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7, C8)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { - .init(node: .quantification(.oneOrMore, kind.astKind, component.regex.root)) + .init(node: .quantification(.oneOrMore, behavior.astKind, component.regex.root)) } public func oneOrMore( - _ kind: QuantificationBehavior = .eagerly, + _ behavior: QuantificationBehavior = .eagerly, @RegexBuilder _ component: () -> Component ) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7, C8)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) { - .init(node: .quantification(.oneOrMore, kind.astKind, component().regex.root)) + .init(node: .quantification(.oneOrMore, behavior.astKind, component().regex.root)) } From fd9438f7127e8f8c88108476d1b4870211561bc8 Mon Sep 17 00:00:00 2001 From: Nate Cook Date: Thu, 10 Feb 2022 10:11:25 -0600 Subject: [PATCH 7/7] Catch a few captures I missed --- Tests/RegexTests/RegexDSLTests.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/RegexTests/RegexDSLTests.swift b/Tests/RegexTests/RegexDSLTests.swift index 6255735d8..aa7b89d32 100644 --- a/Tests/RegexTests/RegexDSLTests.swift +++ b/Tests/RegexTests/RegexDSLTests.swift @@ -154,7 +154,7 @@ class RegexDSLTests: XCTestCase { { oneOrMore { oneOrMore(.word) - CharacterClass.digit.capture() + capture(CharacterClass.digit) } } @@ -164,7 +164,7 @@ class RegexDSLTests: XCTestCase { { oneOrMore { oneOrMore(.word, .reluctantly) - CharacterClass.digit.capture() + capture(CharacterClass.digit) } } @@ -176,7 +176,7 @@ class RegexDSLTests: XCTestCase { oneOrMore(.reluctantly) { CharacterClass.word } - CharacterClass.digit.capture() + capture(CharacterClass.digit) } } }