Skip to content

Commit 1079533

Browse files
Azoyhamishknight
authored andcommitted
Merge pull request swiftlang#576 from Azoy/options-regex
Move options from RegexComponent to Regex
1 parent 863aebe commit 1079533

File tree

2 files changed

+44
-27
lines changed

2 files changed

+44
-27
lines changed

Sources/_StringProcessing/Regex/Options.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
@_implementationOnly import _RegexParser
1313

1414
@available(SwiftStdlib 5.7, *)
15-
extension RegexComponent {
15+
extension Regex {
1616
/// Returns a regular expression that ignores case when matching.
1717
///
1818
/// - Parameter ignoresCase: A Boolean value indicating whether to ignore case.

Tests/RegexBuilderTests/RegexDSLTests.swift

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,10 @@ class RegexDSLTests: XCTestCase {
234234
("abcabc", "abcabc"),
235235
("abcABCaBc", "abcABCaBc"),
236236
matchType: Substring.self, ==) {
237-
OneOrMore {
238-
"abc"
237+
Regex {
238+
OneOrMore {
239+
"abc"
240+
}
239241
}.ignoresCase(true)
240242
}
241243

@@ -247,8 +249,10 @@ class RegexDSLTests: XCTestCase {
247249
("abcabc", "abcabc"),
248250
("abcABCaBc", "abcABCaBc"),
249251
matchType: Substring.self, ==) {
250-
OneOrMore {
251-
"abc"
252+
Regex {
253+
OneOrMore {
254+
"abc"
255+
}
252256
}
253257
.ignoresCase(true)
254258
.ignoresCase(false)
@@ -264,9 +268,13 @@ class RegexDSLTests: XCTestCase {
264268
("abcabc", "abcabc"),
265269
("abcdeABCdeaBcde", "abcdeABCdeaBcde"),
266270
matchType: Substring.self, ==) {
267-
OneOrMore {
268-
"abc".ignoresCase(true)
269-
Optionally("de")
271+
Regex {
272+
OneOrMore {
273+
Regex {
274+
"abc"
275+
}.ignoresCase(true)
276+
Optionally("de")
277+
}
270278
}
271279
.ignoresCase(false)
272280
}
@@ -303,11 +311,13 @@ class RegexDSLTests: XCTestCase {
303311
"stop"
304312
" "
305313

306-
Capture {
307-
OneOrMore(.word)
308-
Anchor.wordBoundary
309-
}
310-
.wordBoundaryKind(.simple)
314+
Regex {
315+
Capture {
316+
OneOrMore(.word)
317+
Anchor.wordBoundary
318+
}
319+
}.wordBoundaryKind(.simple)
320+
311321
OneOrMore(.any, .reluctant)
312322
"stop"
313323
}
@@ -317,15 +327,17 @@ class RegexDSLTests: XCTestCase {
317327
matchType: (Substring, Substring, Substring).self, ==) {
318328
Capture {
319329
// Reluctant behavior due to option
320-
OneOrMore(.anyOf("abcd"))
321-
.repetitionBehavior(.reluctant)
330+
Regex {
331+
OneOrMore(.anyOf("abcd"))
332+
}.repetitionBehavior(.reluctant)
322333
}
323334
ZeroOrMore("a"..."z")
324335

325336
Capture {
326337
// Eager behavior due to explicit parameter, despite option
327-
OneOrMore(.digit, .eager)
328-
.repetitionBehavior(.reluctant)
338+
Regex {
339+
OneOrMore(.digit, .eager)
340+
}.repetitionBehavior(.reluctant)
329341
}
330342
ZeroOrMore(.digit)
331343
}
@@ -334,10 +346,11 @@ class RegexDSLTests: XCTestCase {
334346
("abcdefg", ("abcdefg", "abcdefg")),
335347
("abcdéfg", ("abcdéfg", "abcd")),
336348
matchType: (Substring, Substring).self, ==) {
337-
Capture {
338-
OneOrMore(.word)
339-
}
340-
.asciiOnlyWordCharacters()
349+
Regex {
350+
Capture {
351+
OneOrMore(.word)
352+
}
353+
}.asciiOnlyWordCharacters()
341354

342355
ZeroOrMore(.any)
343356
}
@@ -368,8 +381,10 @@ class RegexDSLTests: XCTestCase {
368381
("abc1def2", ("abc1def2", "1")),
369382
matchType: (Substring, Substring).self, ==)
370383
{
371-
OneOrMore(.reluctant) {
372-
One(.word)
384+
Regex {
385+
OneOrMore(.reluctant) {
386+
One(.word)
387+
}
373388
}.repetitionBehavior(.possessive)
374389
Capture(.digit)
375390
ZeroOrMore(.any)
@@ -421,8 +436,9 @@ class RegexDSLTests: XCTestCase {
421436
{
422437
Regex {
423438
Capture {
424-
OneOrMore("a")
425-
.repetitionBehavior(.eager)
439+
Regex {
440+
OneOrMore("a")
441+
}.repetitionBehavior(.eager)
426442
}
427443
OneOrMore("a")
428444
}.repetitionBehavior(.possessive)
@@ -434,8 +450,9 @@ class RegexDSLTests: XCTestCase {
434450
{
435451
Regex {
436452
Capture {
437-
OneOrMore("a")
438-
.repetitionBehavior(.reluctant)
453+
Regex {
454+
OneOrMore("a")
455+
}.repetitionBehavior(.reluctant)
439456
}
440457
OneOrMore("a")
441458
}.repetitionBehavior(.possessive)

0 commit comments

Comments
 (0)