Skip to content

Commit ee31d51

Browse files
committed
DSL free functions -> types
Replace free functions such as `oneOrMore` with types such as `OneOrMore`. This hides overloads of free functions as initializers within those types. It also makes the DSL consistent with SwiftUI. - `oneOrMore` -> `OneOrMore` - `zeroOrMore` -> `ZeroOrMore` - `optionally` -> `Optionally` - `repeating` -> `Repeat` - `choiceOf` -> `ChoiceOf` - `capture` -> `Capture` - `tryCapture` -> `TryCapture` Note: The reason we didn't realize this was possible (e.g. in #126) was because we were narrowly focused on including the subpattern type in the quantifier/combinator's generic parameter, i.e. `OneOrMore<Component: RegexComponent>`, which made it impossible to deduce each type's `typealias Match` from `Component`. Now we have an unconstrained generic parameter (e.g. `OneOrMore<Match>`) which gives us the full flexibility to hide `Match` deduction rules in initializers' type signatures.
1 parent cd3ad6d commit ee31d51

File tree

7 files changed

+3252
-2650
lines changed

7 files changed

+3252
-2650
lines changed

Sources/Exercises/Participants/RegexParticipant.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,16 @@ private func graphemeBreakPropertyData(
8080
forLine line: String
8181
) -> GraphemeBreakEntry? {
8282
line.match {
83-
tryCapture(oneOrMore(.hexDigit)) { Unicode.Scalar(hex: $0) }
84-
optionally {
83+
TryCapture(OneOrMore(.hexDigit)) { Unicode.Scalar(hex: $0) }
84+
Optionally {
8585
".."
86-
tryCapture(oneOrMore(.hexDigit)) { Unicode.Scalar(hex: $0) }
86+
TryCapture(OneOrMore(.hexDigit)) { Unicode.Scalar(hex: $0) }
8787
}
88-
oneOrMore(.whitespace)
88+
OneOrMore(.whitespace)
8989
";"
90-
oneOrMore(.whitespace)
91-
tryCapture(oneOrMore(.word)) { Unicode.GraphemeBreakProperty($0) }
92-
zeroOrMore(.any)
90+
OneOrMore(.whitespace)
91+
TryCapture(OneOrMore(.word)) { Unicode.GraphemeBreakProperty($0) }
92+
ZeroOrMore(.any)
9393
}.map {
9494
let (_, lower, upper, property) = $0.match
9595
return GraphemeBreakEntry(lower...(upper ?? lower), property)

0 commit comments

Comments
 (0)