Skip to content

Switch back to Swift tuples for typed captures #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions Sources/Exercises/Participants/RegexParticipant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct RegexLiteralParticipant: Participant {
// MARK: - Regex literal

private func extractFromCaptures(
_ match: Tuple4<Substring, Substring, Substring?, Substring>
_ match: (Substring, Substring, Substring?, Substring)
) -> GraphemeBreakEntry? {
guard let lowerScalar = Unicode.Scalar(hex: match.1),
let upperScalar = match.2.map(Unicode.Scalar.init(hex:)) ?? lowerScalar,
Expand All @@ -61,7 +61,7 @@ private func extractFromCaptures(
private func graphemeBreakPropertyData<RP: RegexProtocol>(
forLine line: String,
using regex: RP
) -> GraphemeBreakEntry? where RP.Match == Tuple4<Substring, Substring, Substring?, Substring> {
) -> GraphemeBreakEntry? where RP.Match == (Substring, Substring, Substring?, Substring) {
line.match(regex).map(\.match).flatMap(extractFromCaptures)
}

Expand All @@ -71,7 +71,7 @@ private func graphemeBreakPropertyDataLiteral(
return graphemeBreakPropertyData(
forLine: line,
using: r(#"([0-9A-F]+)(?:\.\.([0-9A-F]+))?\s+;\s+(\w+).*"#,
matching: Tuple4<Substring, Substring, Substring?, Substring>.self))
matching: (Substring, Substring, Substring?, Substring).self))
}

// MARK: - Builder DSL
Expand All @@ -80,18 +80,18 @@ private func graphemeBreakPropertyData(
forLine line: String
) -> GraphemeBreakEntry? {
line.match {
OneOrMore(.hexDigit).tryCapture(Unicode.Scalar.init(hex:))
Optionally {
oneOrMore(.hexDigit).tryCapture(Unicode.Scalar.init(hex:))
optionally {
".."
OneOrMore(.hexDigit).tryCapture(Unicode.Scalar.init(hex:))
oneOrMore(.hexDigit).tryCapture(Unicode.Scalar.init(hex:))
}
OneOrMore(.whitespace)
oneOrMore(.whitespace)
";"
OneOrMore(.whitespace)
OneOrMore(.word).tryCapture(Unicode.GraphemeBreakProperty.init)
Repeat(.any)
oneOrMore(.whitespace)
oneOrMore(.word).tryCapture(Unicode.GraphemeBreakProperty.init)
many(.any)
}.map {
let (_, lower, upper, property) = $0.match.tuple
let (_, lower, upper, property) = $0.match
return GraphemeBreakEntry(lower...(upper ?? lower), property)
}
}
Loading