Skip to content

Commit 8019923

Browse files
authored
Merge pull request #156 from rxwei/dsl-minor-renaming
DSL minor renaming: `choiceOf` and `zeroOrMore`.
2 parents bbe756b + b4266b0 commit 8019923

File tree

5 files changed

+40
-40
lines changed

5 files changed

+40
-40
lines changed

Sources/Exercises/Participants/RegexParticipant.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private func graphemeBreakPropertyData(
8989
";"
9090
oneOrMore(.whitespace)
9191
tryCapture(oneOrMore(.word)) { Unicode.GraphemeBreakProperty($0) }
92-
many(.any)
92+
zeroOrMore(.any)
9393
}.map {
9494
let (_, lower, upper, property) = $0.match
9595
return GraphemeBreakEntry(lower...(upper ?? lower), property)

Sources/VariadicsGenerator/VariadicsGenerator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ struct VariadicsGenerator: ParsableCommand {
288288

289289
enum QuantifierKind: String, CaseIterable {
290290
case zeroOrOne = "optionally"
291-
case zeroOrMore = "many"
291+
case zeroOrMore = "zeroOrMore"
292292
case oneOrMore = "oneOrMore"
293293

294294
var operatorName: String {

Sources/_StringProcessing/RegexDSL/DSL.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public struct AlternationBuilder {
179179
}
180180
}
181181

182-
public func oneOf<R: RegexProtocol>(
182+
public func choiceOf<R: RegexProtocol>(
183183
@AlternationBuilder builder: () -> R
184184
) -> R {
185185
builder()

Sources/_StringProcessing/RegexDSL/Variadics.swift

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -501,15 +501,15 @@ extension RegexBuilder {
501501
}
502502
}
503503
@_disfavoredOverload
504-
public func many<Component: RegexProtocol>(
504+
public func zeroOrMore<Component: RegexProtocol>(
505505
_ component: Component,
506506
_ behavior: QuantificationBehavior = .eagerly
507507
) -> Regex<Substring> {
508508
.init(node: .quantification(.zeroOrMore, behavior.astKind, component.regex.root))
509509
}
510510

511511
@_disfavoredOverload
512-
public func many<Component: RegexProtocol>(
512+
public func zeroOrMore<Component: RegexProtocol>(
513513
_ behavior: QuantificationBehavior = .eagerly,
514514
@RegexBuilder _ component: () -> Component
515515
) -> Regex<Substring> {
@@ -579,15 +579,15 @@ extension RegexBuilder {
579579
}
580580
}
581581

582-
public func many<W, C0, Component: RegexProtocol>(
582+
public func zeroOrMore<W, C0, Component: RegexProtocol>(
583583
_ component: Component,
584584
_ behavior: QuantificationBehavior = .eagerly
585585
) -> Regex<(Substring, [C0])> where Component.Match == (W, C0) {
586586
.init(node: .quantification(.zeroOrMore, behavior.astKind, component.regex.root))
587587
}
588588

589589

590-
public func many<W, C0, Component: RegexProtocol>(
590+
public func zeroOrMore<W, C0, Component: RegexProtocol>(
591591
_ behavior: QuantificationBehavior = .eagerly,
592592
@RegexBuilder _ component: () -> Component
593593
) -> Regex<(Substring, [C0])> where Component.Match == (W, C0) {
@@ -657,15 +657,15 @@ extension RegexBuilder {
657657
}
658658
}
659659

660-
public func many<W, C0, C1, Component: RegexProtocol>(
660+
public func zeroOrMore<W, C0, C1, Component: RegexProtocol>(
661661
_ component: Component,
662662
_ behavior: QuantificationBehavior = .eagerly
663663
) -> Regex<(Substring, [(C0, C1)])> where Component.Match == (W, C0, C1) {
664664
.init(node: .quantification(.zeroOrMore, behavior.astKind, component.regex.root))
665665
}
666666

667667

668-
public func many<W, C0, C1, Component: RegexProtocol>(
668+
public func zeroOrMore<W, C0, C1, Component: RegexProtocol>(
669669
_ behavior: QuantificationBehavior = .eagerly,
670670
@RegexBuilder _ component: () -> Component
671671
) -> Regex<(Substring, [(C0, C1)])> where Component.Match == (W, C0, C1) {
@@ -735,15 +735,15 @@ extension RegexBuilder {
735735
}
736736
}
737737

738-
public func many<W, C0, C1, C2, Component: RegexProtocol>(
738+
public func zeroOrMore<W, C0, C1, C2, Component: RegexProtocol>(
739739
_ component: Component,
740740
_ behavior: QuantificationBehavior = .eagerly
741741
) -> Regex<(Substring, [(C0, C1, C2)])> where Component.Match == (W, C0, C1, C2) {
742742
.init(node: .quantification(.zeroOrMore, behavior.astKind, component.regex.root))
743743
}
744744

745745

746-
public func many<W, C0, C1, C2, Component: RegexProtocol>(
746+
public func zeroOrMore<W, C0, C1, C2, Component: RegexProtocol>(
747747
_ behavior: QuantificationBehavior = .eagerly,
748748
@RegexBuilder _ component: () -> Component
749749
) -> Regex<(Substring, [(C0, C1, C2)])> where Component.Match == (W, C0, C1, C2) {
@@ -813,15 +813,15 @@ extension RegexBuilder {
813813
}
814814
}
815815

816-
public func many<W, C0, C1, C2, C3, Component: RegexProtocol>(
816+
public func zeroOrMore<W, C0, C1, C2, C3, Component: RegexProtocol>(
817817
_ component: Component,
818818
_ behavior: QuantificationBehavior = .eagerly
819819
) -> Regex<(Substring, [(C0, C1, C2, C3)])> where Component.Match == (W, C0, C1, C2, C3) {
820820
.init(node: .quantification(.zeroOrMore, behavior.astKind, component.regex.root))
821821
}
822822

823823

824-
public func many<W, C0, C1, C2, C3, Component: RegexProtocol>(
824+
public func zeroOrMore<W, C0, C1, C2, C3, Component: RegexProtocol>(
825825
_ behavior: QuantificationBehavior = .eagerly,
826826
@RegexBuilder _ component: () -> Component
827827
) -> Regex<(Substring, [(C0, C1, C2, C3)])> where Component.Match == (W, C0, C1, C2, C3) {
@@ -891,15 +891,15 @@ extension RegexBuilder {
891891
}
892892
}
893893

894-
public func many<W, C0, C1, C2, C3, C4, Component: RegexProtocol>(
894+
public func zeroOrMore<W, C0, C1, C2, C3, C4, Component: RegexProtocol>(
895895
_ component: Component,
896896
_ behavior: QuantificationBehavior = .eagerly
897897
) -> Regex<(Substring, [(C0, C1, C2, C3, C4)])> where Component.Match == (W, C0, C1, C2, C3, C4) {
898898
.init(node: .quantification(.zeroOrMore, behavior.astKind, component.regex.root))
899899
}
900900

901901

902-
public func many<W, C0, C1, C2, C3, C4, Component: RegexProtocol>(
902+
public func zeroOrMore<W, C0, C1, C2, C3, C4, Component: RegexProtocol>(
903903
_ behavior: QuantificationBehavior = .eagerly,
904904
@RegexBuilder _ component: () -> Component
905905
) -> Regex<(Substring, [(C0, C1, C2, C3, C4)])> where Component.Match == (W, C0, C1, C2, C3, C4) {
@@ -969,15 +969,15 @@ extension RegexBuilder {
969969
}
970970
}
971971

972-
public func many<W, C0, C1, C2, C3, C4, C5, Component: RegexProtocol>(
972+
public func zeroOrMore<W, C0, C1, C2, C3, C4, C5, Component: RegexProtocol>(
973973
_ component: Component,
974974
_ behavior: QuantificationBehavior = .eagerly
975975
) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5) {
976976
.init(node: .quantification(.zeroOrMore, behavior.astKind, component.regex.root))
977977
}
978978

979979

980-
public func many<W, C0, C1, C2, C3, C4, C5, Component: RegexProtocol>(
980+
public func zeroOrMore<W, C0, C1, C2, C3, C4, C5, Component: RegexProtocol>(
981981
_ behavior: QuantificationBehavior = .eagerly,
982982
@RegexBuilder _ component: () -> Component
983983
) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5) {
@@ -1047,15 +1047,15 @@ extension RegexBuilder {
10471047
}
10481048
}
10491049

1050-
public func many<W, C0, C1, C2, C3, C4, C5, C6, Component: RegexProtocol>(
1050+
public func zeroOrMore<W, C0, C1, C2, C3, C4, C5, C6, Component: RegexProtocol>(
10511051
_ component: Component,
10521052
_ behavior: QuantificationBehavior = .eagerly
10531053
) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) {
10541054
.init(node: .quantification(.zeroOrMore, behavior.astKind, component.regex.root))
10551055
}
10561056

10571057

1058-
public func many<W, C0, C1, C2, C3, C4, C5, C6, Component: RegexProtocol>(
1058+
public func zeroOrMore<W, C0, C1, C2, C3, C4, C5, C6, Component: RegexProtocol>(
10591059
_ behavior: QuantificationBehavior = .eagerly,
10601060
@RegexBuilder _ component: () -> Component
10611061
) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6) {
@@ -1125,15 +1125,15 @@ extension RegexBuilder {
11251125
}
11261126
}
11271127

1128-
public func many<W, C0, C1, C2, C3, C4, C5, C6, C7, Component: RegexProtocol>(
1128+
public func zeroOrMore<W, C0, C1, C2, C3, C4, C5, C6, C7, Component: RegexProtocol>(
11291129
_ component: Component,
11301130
_ behavior: QuantificationBehavior = .eagerly
11311131
) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) {
11321132
.init(node: .quantification(.zeroOrMore, behavior.astKind, component.regex.root))
11331133
}
11341134

11351135

1136-
public func many<W, C0, C1, C2, C3, C4, C5, C6, C7, Component: RegexProtocol>(
1136+
public func zeroOrMore<W, C0, C1, C2, C3, C4, C5, C6, C7, Component: RegexProtocol>(
11371137
_ behavior: QuantificationBehavior = .eagerly,
11381138
@RegexBuilder _ component: () -> Component
11391139
) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) {
@@ -1203,15 +1203,15 @@ extension RegexBuilder {
12031203
}
12041204
}
12051205

1206-
public func many<W, C0, C1, C2, C3, C4, C5, C6, C7, C8, Component: RegexProtocol>(
1206+
public func zeroOrMore<W, C0, C1, C2, C3, C4, C5, C6, C7, C8, Component: RegexProtocol>(
12071207
_ component: Component,
12081208
_ behavior: QuantificationBehavior = .eagerly
12091209
) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7, C8)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) {
12101210
.init(node: .quantification(.zeroOrMore, behavior.astKind, component.regex.root))
12111211
}
12121212

12131213

1214-
public func many<W, C0, C1, C2, C3, C4, C5, C6, C7, C8, Component: RegexProtocol>(
1214+
public func zeroOrMore<W, C0, C1, C2, C3, C4, C5, C6, C7, C8, Component: RegexProtocol>(
12151215
_ behavior: QuantificationBehavior = .eagerly,
12161216
@RegexBuilder _ component: () -> Component
12171217
) -> Regex<(Substring, [(C0, C1, C2, C3, C4, C5, C6, C7, C8)])> where Component.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) {

Tests/RegexTests/RegexDSLTests.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ class RegexDSLTests: XCTestCase {
6767

6868
func testAlternation() throws {
6969
do {
70-
let regex = oneOf {
70+
let regex = choiceOf {
7171
"aaa"
7272
}
7373
XCTAssertTrue("aaa".match(regex)?.match == "aaa")
7474
XCTAssertNil("aab".match(regex)?.match)
7575
}
7676
do {
77-
let regex = oneOf {
77+
let regex = choiceOf {
7878
"aaa"
7979
"bbb"
8080
"ccc"
@@ -88,7 +88,7 @@ class RegexDSLTests: XCTestCase {
8888
let regex = Regex {
8989
"ab"
9090
capture {
91-
oneOf {
91+
choiceOf {
9292
"c"
9393
"def"
9494
}
@@ -98,7 +98,7 @@ class RegexDSLTests: XCTestCase {
9898
try XCTUnwrap("abc".match(regex)?.match) == ("abc", ["c"]))
9999
}
100100
do {
101-
let regex = oneOf {
101+
let regex = choiceOf {
102102
"aaa"
103103
"bbb"
104104
"ccc"
@@ -109,15 +109,15 @@ class RegexDSLTests: XCTestCase {
109109
XCTAssertTrue("ccc".match(regex)?.match == "ccc")
110110
}
111111
do {
112-
let regex = oneOf {
112+
let regex = choiceOf {
113113
capture("aaa")
114114
}
115115
XCTAssertTrue(
116116
try XCTUnwrap("aaa".match(regex)?.match) == ("aaa", "aaa"))
117117
XCTAssertNil("aab".match(regex)?.match)
118118
}
119119
do {
120-
let regex = oneOf {
120+
let regex = choiceOf {
121121
capture("aaa")
122122
capture("bbb")
123123
capture("ccc")
@@ -139,11 +139,11 @@ class RegexDSLTests: XCTestCase {
139139
{
140140
"a".+
141141
capture(oneOrMore(Character("b"))) // Substring
142-
capture(many("c")) // Substring
142+
capture(zeroOrMore("c")) // Substring
143143
capture(.hexDigit).* // [Substring]
144144
"e".?
145145
capture("t" | "k") // Substring
146-
oneOf { capture("k"); capture("j") } // (Substring?, Substring?)
146+
choiceOf { capture("k"); capture("j") } // (Substring?, Substring?)
147147
}
148148
}
149149

@@ -189,7 +189,7 @@ class RegexDSLTests: XCTestCase {
189189
"a".+
190190
oneOrMore {
191191
capture(oneOrMore("b"))
192-
capture(many("c"))
192+
capture(zeroOrMore("c"))
193193
capture("d").*
194194
"e".?
195195
}
@@ -201,7 +201,7 @@ class RegexDSLTests: XCTestCase {
201201
// straight out of the quantifier (without being wrapped in a builder), is
202202
// able to produce a regex whose `Match` type does not contain any sort of
203203
// void.
204-
let regex = many(.digit)
204+
let regex = zeroOrMore(.digit)
205205
// Assert the inferred capture type.
206206
let _: Substring.Type = type(of: regex).Match.self
207207
let input = "123123"
@@ -236,7 +236,7 @@ class RegexDSLTests: XCTestCase {
236236
optionally {
237237
capture(oneOrMore(.digit)) { Int($0)! }
238238
}
239-
many {
239+
zeroOrMore {
240240
oneOrMore(.whitespace)
241241
capture(oneOrMore(.word)) { Word($0)! }
242242
}
@@ -266,7 +266,7 @@ class RegexDSLTests: XCTestCase {
266266
"a".+
267267
capture {
268268
tryCapture("b") { Int($0) }
269-
many {
269+
zeroOrMore {
270270
tryCapture("c") { Double($0) }
271271
}
272272
"e".?
@@ -279,7 +279,7 @@ class RegexDSLTests: XCTestCase {
279279
capture {
280280
oneOrMore {
281281
capture(oneOrMore("b"))
282-
capture(many("c"))
282+
capture(zeroOrMore("c"))
283283
capture("d").*
284284
"e".?
285285
}
@@ -292,7 +292,7 @@ class RegexDSLTests: XCTestCase {
292292

293293
func testUnicodeScalarPostProcessing() throws {
294294
let spaces = Regex {
295-
many {
295+
zeroOrMore {
296296
.whitespace
297297
}
298298
}
@@ -320,7 +320,7 @@ class RegexDSLTests: XCTestCase {
320320
}
321321
}
322322

323-
many {
323+
zeroOrMore {
324324
.any
325325
}
326326
}
@@ -354,7 +354,7 @@ class RegexDSLTests: XCTestCase {
354354
";"
355355
oneOrMore(.whitespace)
356356
capture(oneOrMore(.word))
357-
many(.any)
357+
zeroOrMore(.any)
358358
} // Regex<(Substring, Unicode.Scalar?, Unicode.Scalar??, Substring)>
359359
do {
360360
// Assert the inferred capture type.
@@ -389,7 +389,7 @@ class RegexDSLTests: XCTestCase {
389389
";"
390390
oneOrMore(.whitespace)
391391
capture(oneOrMore(.word))
392-
many(.any)
392+
zeroOrMore(.any)
393393
} // Regex<(Substring, Unicode.Scalar, Unicode.Scalar?, Substring)>
394394
do {
395395
// Assert the inferred capture type.

0 commit comments

Comments
 (0)