Skip to content

Commit 2d9de48

Browse files
authored
Merge pull request #1 from milseman/5_7_azoy
Remove compiling argument label
2 parents 3cd65cd + 51756fb commit 2d9de48

File tree

9 files changed

+24
-24
lines changed

9 files changed

+24
-24
lines changed

Documentation/Evolution/RegexSyntaxRunTimeConstruction.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ We propose run-time construction of `Regex` from a best-in-class treatment of fa
5454

5555
```swift
5656
let pattern = #"(\w+)\s\s+(\S+)\s\s+((?:(?!\s\s).)*)\s\s+(.*)"#
57-
let regex = try! Regex(compiling: pattern)
57+
let regex = try! Regex(pattern)
5858
// regex: Regex<AnyRegexOutput>
5959

6060
let regex: Regex<(Substring, Substring, Substring, Substring, Substring)> =
61-
try! Regex(compiling: pattern)
61+
try! Regex(pattern)
6262
```
6363

6464
### Syntax

Documentation/Evolution/RegexTypeOverview.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ Regexes can be created at run time from a string containing familiar regex synta
134134

135135
```swift
136136
let pattern = #"(\w+)\s\s+(\S+)\s\s+((?:(?!\s\s).)*)\s\s+(.*)"#
137-
let regex = try! Regex(compiling: pattern)
137+
let regex = try! Regex(pattern)
138138
// regex: Regex<AnyRegexOutput>
139139

140140
let regex: Regex<(Substring, Substring, Substring, Substring, Substring)> =
141-
try! Regex(compiling: pattern)
141+
try! Regex(pattern)
142142
```
143143

144144
*Note*: The syntax accepted and further details on run-time compilation, including `AnyRegexOutput` and extended syntaxes, are discussed in [Run-time Regex Construction][pitches].
@@ -300,7 +300,7 @@ Regex targets [UTS\#18 Level 2](https://www.unicode.org/reports/tr18/#Extended_U
300300
```swift
301301
/// A regex represents a string processing algorithm.
302302
///
303-
/// let regex = try Regex(compiling: "a(.*)b")
303+
/// let regex = try Regex("a(.*)b")
304304
/// let match = "cbaxb".firstMatch(of: regex)
305305
/// print(match.0) // "axb"
306306
/// print(match.1) // "x"

Sources/Exercises/Participants/RegexParticipant.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ private func graphemeBreakPropertyDataLiteral(
7070
forLine line: String
7171
) -> GraphemeBreakEntry? {
7272
let regex = try! Regex(
73-
compiling: #"([0-9A-F]+)(?:\.\.([0-9A-F]+))?\s+;\s+(\w+).*"#,
73+
#"([0-9A-F]+)(?:\.\.([0-9A-F]+))?\s+;\s+(\w+).*"#,
7474
as: (Substring, Substring, Substring?, Substring).self)
7575
return graphemeBreakPropertyData(forLine: line, using: regex)
7676
}

Sources/_StringProcessing/Regex/AnyRegexOutput.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
@available(SwiftStdlib 5.7, *)
1515
extension Regex where Output == AnyRegexOutput {
1616
/// Parse and compile `pattern`, resulting in an existentially-typed capture list.
17-
public init(compiling pattern: String) throws {
17+
public init(_ pattern: String) throws {
1818
self.init(ast: try parse(pattern, .traditional))
1919
}
2020
}
@@ -23,7 +23,7 @@ extension Regex where Output == AnyRegexOutput {
2323
extension Regex {
2424
/// Parse and compile `pattern`, resulting in a strongly-typed capture list.
2525
public init(
26-
compiling pattern: String,
26+
_ pattern: String,
2727
as: Output.Type = Output.self
2828
) throws {
2929
self.init(ast: try parse(pattern, .traditional))

Sources/_StringProcessing/Regex/Core.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public protocol RegexComponent {
2121

2222
/// A regex represents a string processing algorithm.
2323
///
24-
/// let regex = try Regex(compiling: "a(.*)b")
24+
/// let regex = try Regex("a(.*)b")
2525
/// let match = "cbaxb".firstMatch(of: regex)
2626
/// print(match.0) // "axb"
2727
/// print(match.1) // "x"

Tests/RegexBuilderTests/MotivationTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private func processWithRuntimeDynamicRegex(
139139
_ line: String
140140
) -> Transaction? {
141141
// FIXME: Shouldn't this init throw?
142-
let regex = try! Regex(compiling: pattern)
142+
let regex = try! Regex(pattern)
143143

144144
// guard let result = line.match(regex) else { return nil }
145145
//
@@ -156,7 +156,7 @@ private func processWithRuntimeDynamicRegex(
156156
@available(macOS 12.0, *)
157157
private func processWithRuntimeStaticRegex(_ line: String) -> Transaction? {
158158
let regex: Regex<(Substring, Substring, Substring, Substring, Substring)>
159-
= try! Regex(compiling: pattern)
159+
= try! Regex(pattern)
160160

161161
return process(line, using: regex)
162162
}

Tests/RegexBuilderTests/RegexDSLTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ class RegexDSLTests: XCTestCase {
666666

667667
do {
668668
let regexLiteral = try Regex(
669-
compiling: #"([0-9A-F]+)(?:\.\.([0-9A-F]+))?\s+;\s+(\w+).*"#,
669+
#"([0-9A-F]+)(?:\.\.([0-9A-F]+))?\s+;\s+(\w+).*"#,
670670
as: (Substring, Substring, Substring?, Substring).self)
671671
let maybeMatchResult = line.wholeMatch(of: regexLiteral)
672672
let matchResult = try XCTUnwrap(maybeMatchResult)
@@ -680,7 +680,7 @@ class RegexDSLTests: XCTestCase {
680680

681681
func testDynamicCaptures() throws {
682682
do {
683-
let regex = try Regex(compiling: "aabcc.")
683+
let regex = try Regex("aabcc.")
684684
let line = "aabccd"
685685
let match = try XCTUnwrap(line.wholeMatch(of: regex))
686686
XCTAssertEqual(match.0, line[...])
@@ -689,7 +689,7 @@ class RegexDSLTests: XCTestCase {
689689
}
690690
do {
691691
let regex = try Regex(
692-
compiling: #"([0-9A-F]+)(?:\.\.([0-9A-F]+))?\s+;\s+(\w+).*"#)
692+
#"([0-9A-F]+)(?:\.\.([0-9A-F]+))?\s+;\s+(\w+).*"#)
693693
let line = """
694694
A6F0..A6F1 ; Extend # Mn [2] BAMUM COMBINING MARK KOQNDON..BAMUM \
695695
COMBINING MARK TUKWENTIS

Tests/RegexTests/AlgorithmsTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class RegexConsumerTests: XCTestCase {
3232
_ expected: [Range<Int>],
3333
file: StaticString = #file, line: UInt = #line
3434
) {
35-
let regex = try! Regex(compiling: regex)
35+
let regex = try! Regex(regex)
3636

3737
let actualSeq: [Range<Int>] = string[...].ranges(of: regex).map(string.offsets(of:))
3838
XCTAssertEqual(actualSeq, expected, file: file, line: line)
@@ -69,7 +69,7 @@ class RegexConsumerTests: XCTestCase {
6969
_ expected: [Substring],
7070
file: StaticString = #file, line: UInt = #line
7171
) {
72-
let regex = try! Regex(compiling: regex)
72+
let regex = try! Regex(regex)
7373
let actual = Array(string.split(by: regex))
7474
XCTAssertEqual(actual, expected, file: file, line: line)
7575
}
@@ -89,7 +89,7 @@ class RegexConsumerTests: XCTestCase {
8989
_ expected: String,
9090
file: StaticString = #file, line: UInt = #line
9191
) {
92-
let regex = try! Regex(compiling: regex)
92+
let regex = try! Regex(regex)
9393
let actual = string.replacing(regex, with: replacement)
9494
XCTAssertEqual(actual, expected, file: file, line: line)
9595
}
@@ -108,7 +108,7 @@ class RegexConsumerTests: XCTestCase {
108108
}
109109

110110
func testAdHoc() {
111-
let r = try! Regex(compiling: "a|b+")
111+
let r = try! Regex("a|b+")
112112

113113
XCTAssert("palindrome".contains(r))
114114
XCTAssert("botany".contains(r))
@@ -142,7 +142,7 @@ class RegexConsumerTests: XCTestCase {
142142
let s = "aaa | aaaaaa | aaaaaaaaaa"
143143
let s1 = s.dropFirst(6) // "aaaaaa | aaaaaaaaaa"
144144
let s2 = s1.dropLast(17) // "aa"
145-
let regex = try! Regex(compiling: "a+")
145+
let regex = try! Regex("a+")
146146

147147
XCTAssertEqual(s.firstMatch(of: regex)?.0, "aaa")
148148
XCTAssertEqual(s1.firstMatch(of: regex)?.0, "aaaaaa")

Tests/RegexTests/MatchTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,11 +1272,11 @@ extension RegexTests {
12721272
04: Arkansas
12731273
05: California
12741274
"""
1275-
XCTAssertTrue(string.contains(try Regex(compiling: #"^\d+"#)))
1276-
XCTAssertEqual(string.ranges(of: try Regex(compiling: #"^\d+"#)).count, 1)
1277-
XCTAssertEqual(string.ranges(of: try Regex(compiling: #"(?m)^\d+"#)).count, 5)
1275+
XCTAssertTrue(string.contains(try Regex(#"^\d+"#)))
1276+
XCTAssertEqual(string.ranges(of: try Regex(#"^\d+"#)).count, 1)
1277+
XCTAssertEqual(string.ranges(of: try Regex(#"(?m)^\d+"#)).count, 5)
12781278

1279-
let regex = try Regex(compiling: #"^\d+: [\w ]+$"#)
1279+
let regex = try Regex(#"^\d+: [\w ]+$"#)
12801280
XCTAssertFalse(string.contains(regex))
12811281
let allRanges = string.ranges(of: regex.anchorsMatchLineEndings())
12821282
XCTAssertEqual(allRanges.count, 5)
@@ -1304,7 +1304,7 @@ extension RegexTests {
13041304
}
13051305

13061306
func testOptionMethods() throws {
1307-
let regex = try Regex(compiling: "c.f.")
1307+
let regex = try Regex("c.f.")
13081308
XCTAssertTrue ("cafe".contains(regex))
13091309
XCTAssertFalse("CaFe".contains(regex))
13101310

0 commit comments

Comments
 (0)