Skip to content

Commit da89bf7

Browse files
authored
Rename RegexComponent.Output (#281)
1 parent 34da2b6 commit da89bf7

18 files changed

+471
-471
lines changed

Sources/Exercises/Participants/RegexParticipant.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private func extractFromCaptures(
6262
private func graphemeBreakPropertyData<RP: RegexComponent>(
6363
forLine line: String,
6464
using regex: RP
65-
) -> GraphemeBreakEntry? where RP.Output == (Substring, Substring, Substring?, Substring) {
65+
) -> GraphemeBreakEntry? where RP.RegexOutput == (Substring, Substring, Substring?, Substring) {
6666
line.wholeMatch(of: regex).map(\.output).flatMap(extractFromCaptures)
6767
}
6868

Sources/RegexBuilder/Anchor.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,15 @@ public struct Lookahead<Output>: _BuiltinRegexComponent {
119119
public init<R: RegexComponent>(
120120
_ component: R,
121121
negative: Bool = false
122-
) where R.Output == Output {
122+
) where R.RegexOutput == Output {
123123
self.init(node: .nonCapturingGroup(
124124
negative ? .negativeLookahead : .lookahead, component.regex.root))
125125
}
126126

127127
public init<R: RegexComponent>(
128128
negative: Bool = false,
129129
@RegexComponentBuilder _ component: () -> R
130-
) where R.Output == Output {
130+
) where R.RegexOutput == Output {
131131
self.init(node: .nonCapturingGroup(
132132
negative ? .negativeLookahead : .lookahead, component().regex.root))
133133
}

Sources/RegexBuilder/DSL.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ import _RegexParser
1515
extension Regex {
1616
public init<Content: RegexComponent>(
1717
@RegexComponentBuilder _ content: () -> Content
18-
) where Content.Output == Output {
18+
) where Content.RegexOutput == Output {
1919
self = content().regex
2020
}
2121
}
2222

2323
// A convenience protocol for builtin regex components that are initialized with
2424
// a `DSLTree` node.
2525
internal protocol _BuiltinRegexComponent: RegexComponent {
26-
init(_ regex: Regex<Output>)
26+
init(_ regex: Regex<RegexOutput>)
2727
}
2828

2929
extension _BuiltinRegexComponent {
@@ -224,7 +224,7 @@ public struct AlternationBuilder {
224224
@_disfavoredOverload
225225
public static func buildPartialBlock<R: RegexComponent>(
226226
first component: R
227-
) -> ChoiceOf<R.Output> {
227+
) -> ChoiceOf<R.RegexOutput> {
228228
.init(component.regex)
229229
}
230230

Sources/RegexBuilder/Match.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ extension String {
1515
@available(SwiftStdlib 5.7, *)
1616
public func wholeMatch<R: RegexComponent>(
1717
@RegexComponentBuilder of content: () -> R
18-
) -> Regex<R.Output>.Match? {
18+
) -> Regex<R.RegexOutput>.Match? {
1919
wholeMatch(of: content())
2020
}
2121

2222
@available(SwiftStdlib 5.7, *)
2323
public func prefixMatch<R: RegexComponent>(
2424
@RegexComponentBuilder of content: () -> R
25-
) -> Regex<R.Output>.Match? {
25+
) -> Regex<R.RegexOutput>.Match? {
2626
prefixMatch(of: content())
2727
}
2828
}
@@ -31,14 +31,14 @@ extension Substring {
3131
@available(SwiftStdlib 5.7, *)
3232
public func wholeMatch<R: RegexComponent>(
3333
@RegexComponentBuilder of content: () -> R
34-
) -> Regex<R.Output>.Match? {
34+
) -> Regex<R.RegexOutput>.Match? {
3535
wholeMatch(of: content())
3636
}
3737

3838
@available(SwiftStdlib 5.7, *)
3939
public func prefixMatch<R: RegexComponent>(
4040
@RegexComponentBuilder of content: () -> R
41-
) -> Regex<R.Output>.Match? {
41+
) -> Regex<R.RegexOutput>.Match? {
4242
prefixMatch(of: content())
4343
}
4444
}

Sources/RegexBuilder/Variadics.swift

+414-414
Large diffs are not rendered by default.

Sources/VariadicsGenerator/VariadicsGenerator.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ var standardError = StandardErrorStream()
9090

9191
typealias Counter = Int64
9292
let regexComponentProtocolName = "RegexComponent"
93-
let outputAssociatedTypeName = "Output"
93+
let outputAssociatedTypeName = "RegexOutput"
9494
let patternProtocolRequirementName = "regex"
9595
let regexTypeName = "Regex"
9696
let baseMatchTypeName = "Substring"

Sources/_StringProcessing/Algorithms/Consumers/RegexConsumer.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ extension RegexConsumer {
3737
// well, taking advantage of the fact that the captures can be ignored
3838

3939
extension RegexConsumer: MatchingCollectionConsumer {
40-
typealias Match = R.Output
40+
typealias Match = R.RegexOutput
4141

4242
func matchingConsuming(
4343
_ consumed: Consumed, in range: Range<Consumed.Index>

Sources/_StringProcessing/Algorithms/Matching/FirstMatch.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ extension BidirectionalCollection where SubSequence == Substring {
5656
/// there isn't a match.
5757
public func firstMatch<R: RegexComponent>(
5858
of r: R
59-
) -> Regex<R.Output>.Match? {
59+
) -> Regex<R.RegexOutput>.Match? {
6060
let slice = self[...]
6161
return try? r.regex.firstMatch(in: slice.base)
6262
}

Sources/_StringProcessing/Algorithms/Matching/MatchReplace.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ extension RangeReplaceableCollection where SubSequence == Substring {
125125
@available(SwiftStdlib 5.7, *)
126126
public func replacing<R: RegexComponent, Replacement: Collection>(
127127
_ regex: R,
128-
with replacement: (Regex<R.Output>.Match) throws -> Replacement,
128+
with replacement: (Regex<R.RegexOutput>.Match) throws -> Replacement,
129129
subrange: Range<Index>,
130130
maxReplacements: Int = .max
131131
) rethrows -> Self where Replacement.Element == Element {
@@ -161,7 +161,7 @@ extension RangeReplaceableCollection where SubSequence == Substring {
161161
@available(SwiftStdlib 5.7, *)
162162
public func replacing<R: RegexComponent, Replacement: Collection>(
163163
_ regex: R,
164-
with replacement: (Regex<R.Output>.Match) throws -> Replacement,
164+
with replacement: (Regex<R.RegexOutput>.Match) throws -> Replacement,
165165
maxReplacements: Int = .max
166166
) rethrows -> Self where Replacement.Element == Element {
167167
try replacing(
@@ -182,7 +182,7 @@ extension RangeReplaceableCollection where SubSequence == Substring {
182182
@available(SwiftStdlib 5.7, *)
183183
public mutating func replace<R: RegexComponent, Replacement: Collection>(
184184
_ regex: R,
185-
with replacement: (Regex<R.Output>.Match) throws -> Replacement,
185+
with replacement: (Regex<R.RegexOutput>.Match) throws -> Replacement,
186186
maxReplacements: Int = .max
187187
) rethrows where Replacement.Element == Element {
188188
self = try replacing(

Sources/_StringProcessing/Algorithms/Matching/Matches.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,13 @@ extension BidirectionalCollection where SubSequence == Substring {
202202

203203
// FIXME: Replace the returned value as `some Collection<Regex<R.Output>.Match>
204204
// when SE-0346 is enabled
205-
func _matches<R: RegexComponent>(of r: R) -> [Regex<R.Output>.Match] {
205+
func _matches<R: RegexComponent>(of r: R) -> [Regex<R.RegexOutput>.Match] {
206206
let slice = self[...]
207207
var start = self.startIndex
208208
let end = self.endIndex
209209
let regex = r.regex
210210

211-
var result = [Regex<R.Output>.Match]()
211+
var result = [Regex<R.RegexOutput>.Match]()
212212
while start < end {
213213
guard let match = try? regex._firstMatch(
214214
slice.base, in: start..<end

Sources/_StringProcessing/Regex/Core.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import _RegexParser
1515
/// A type that represents a regular expression.
1616
@available(SwiftStdlib 5.7, *)
1717
public protocol RegexComponent {
18-
associatedtype Output
19-
var regex: Regex<Output> { get }
18+
associatedtype RegexOutput
19+
var regex: Regex<RegexOutput> { get }
2020
}
2121

2222
/// A regex represents a string processing algorithm.

Sources/_StringProcessing/Regex/DSLConsumers.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ public protocol CustomRegexComponent: RegexComponent {
1515
_ input: String,
1616
startingAt index: String.Index,
1717
in bounds: Range<String.Index>
18-
) -> (upperBound: String.Index, output: Output)?
18+
) -> (upperBound: String.Index, output: RegexOutput)?
1919
}
2020

2121
extension CustomRegexComponent {
22-
public var regex: Regex<Output> {
23-
Regex(node: .matcher(.init(Output.self), { input, index, bounds in
22+
public var regex: Regex<RegexOutput> {
23+
Regex(node: .matcher(.init(RegexOutput.self), { input, index, bounds in
2424
match(input, startingAt: index, in: bounds)
2525
}))
2626
}

Sources/_StringProcessing/Regex/Match.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -155,24 +155,24 @@ extension Regex {
155155
extension String {
156156
public func wholeMatch<R: RegexComponent>(
157157
of r: R
158-
) -> Regex<R.Output>.Match? {
158+
) -> Regex<R.RegexOutput>.Match? {
159159
try? r.regex.wholeMatch(in: self)
160160
}
161161
public func prefixMatch<R: RegexComponent>(
162162
of r: R
163-
) -> Regex<R.Output>.Match? {
163+
) -> Regex<R.RegexOutput>.Match? {
164164
try? r.regex.prefixMatch(in: self)
165165
}
166166
}
167167
extension Substring {
168168
public func wholeMatch<R: RegexComponent>(
169169
of r: R
170-
) -> Regex<R.Output>.Match? {
170+
) -> Regex<R.RegexOutput>.Match? {
171171
try? r.regex.wholeMatch(in: self)
172172
}
173173
public func prefixMatch<R: RegexComponent>(
174174
of r: R
175-
) -> Regex<R.Output>.Match? {
175+
) -> Regex<R.RegexOutput>.Match? {
176176
try? r.regex.prefixMatch(in: self)
177177
}
178178
}

Sources/_StringProcessing/Regex/Options.swift

+11-11
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,30 @@ import _RegexParser
1313

1414
extension RegexComponent {
1515
/// Returns a regular expression that ignores casing when matching.
16-
public func ignoringCase(_ ignoreCase: Bool = true) -> Regex<Output> {
16+
public func ignoringCase(_ ignoreCase: Bool = true) -> Regex<RegexOutput> {
1717
wrapInOption(.caseInsensitive, addingIf: ignoreCase)
1818
}
1919

2020
/// Returns a regular expression that only matches ASCII characters as "word
2121
/// characters".
22-
public func usingASCIIWordCharacters(_ useASCII: Bool = true) -> Regex<Output> {
22+
public func usingASCIIWordCharacters(_ useASCII: Bool = true) -> Regex<RegexOutput> {
2323
wrapInOption(.asciiOnlyDigit, addingIf: useASCII)
2424
}
2525

2626
/// Returns a regular expression that only matches ASCII characters as digits.
27-
public func usingASCIIDigits(_ useASCII: Bool = true) -> Regex<Output> {
27+
public func usingASCIIDigits(_ useASCII: Bool = true) -> Regex<RegexOutput> {
2828
wrapInOption(.asciiOnlyDigit, addingIf: useASCII)
2929
}
3030

3131
/// Returns a regular expression that only matches ASCII characters as space
3232
/// characters.
33-
public func usingASCIISpaces(_ useASCII: Bool = true) -> Regex<Output> {
33+
public func usingASCIISpaces(_ useASCII: Bool = true) -> Regex<RegexOutput> {
3434
wrapInOption(.asciiOnlySpace, addingIf: useASCII)
3535
}
3636

3737
/// Returns a regular expression that only matches ASCII characters when
3838
/// matching character classes.
39-
public func usingASCIICharacterClasses(_ useASCII: Bool = true) -> Regex<Output> {
39+
public func usingASCIICharacterClasses(_ useASCII: Bool = true) -> Regex<RegexOutput> {
4040
wrapInOption(.asciiOnlyPOSIXProps, addingIf: useASCII)
4141
}
4242

@@ -45,7 +45,7 @@ extension RegexComponent {
4545
///
4646
/// This option is enabled by default; pass `false` to disable use of
4747
/// Unicode's word boundary algorithm.
48-
public func usingUnicodeWordBoundaries(_ useUnicodeWordBoundaries: Bool = true) -> Regex<Output> {
48+
public func usingUnicodeWordBoundaries(_ useUnicodeWordBoundaries: Bool = true) -> Regex<RegexOutput> {
4949
wrapInOption(.unicodeWordBoundaries, addingIf: useUnicodeWordBoundaries)
5050
}
5151

@@ -54,7 +54,7 @@ extension RegexComponent {
5454
///
5555
/// - Parameter dotMatchesNewlines: A Boolean value indicating whether `.`
5656
/// should match a newline character.
57-
public func dotMatchesNewlines(_ dotMatchesNewlines: Bool = true) -> Regex<Output> {
57+
public func dotMatchesNewlines(_ dotMatchesNewlines: Bool = true) -> Regex<RegexOutput> {
5858
wrapInOption(.singleLine, addingIf: dotMatchesNewlines)
5959
}
6060

@@ -95,7 +95,7 @@ extension RegexComponent {
9595
/// // Prints "true"
9696
/// print(decomposed.contains(queRegexScalar))
9797
/// // Prints "false"
98-
public func matchingSemantics(_ semanticLevel: RegexSemanticLevel) -> Regex<Output> {
98+
public func matchingSemantics(_ semanticLevel: RegexSemanticLevel) -> Regex<RegexOutput> {
9999
switch semanticLevel.base {
100100
case .graphemeCluster:
101101
return wrapInOption(.graphemeClusterSemantics, addingIf: true)
@@ -139,7 +139,7 @@ extension RegexComponent {
139139
///
140140
/// - Parameter matchLineEndings: A Boolean value indicating whether `^` and
141141
/// `$` should match the start and end of lines, respectively.
142-
public func anchorsMatchLineEndings(_ matchLineEndings: Bool = true) -> Regex<Output> {
142+
public func anchorsMatchLineEndings(_ matchLineEndings: Bool = true) -> Regex<RegexOutput> {
143143
wrapInOption(.multiline, addingIf: matchLineEndings)
144144
}
145145

@@ -153,7 +153,7 @@ extension RegexComponent {
153153
///
154154
/// - Parameter useReluctantCaptures: A Boolean value indicating whether
155155
/// quantifiers should be reluctant by default.
156-
public func reluctantCaptures(_ useReluctantCaptures: Bool = true) -> Regex<Output> {
156+
public func reluctantCaptures(_ useReluctantCaptures: Bool = true) -> Regex<RegexOutput> {
157157
wrapInOption(.reluctantByDefault, addingIf: useReluctantCaptures)
158158
}
159159
}
@@ -162,7 +162,7 @@ extension RegexComponent {
162162
extension RegexComponent {
163163
fileprivate func wrapInOption(
164164
_ option: AST.MatchingOption.Kind,
165-
addingIf shouldAdd: Bool) -> Regex<Output>
165+
addingIf shouldAdd: Bool) -> Regex<RegexOutput>
166166
{
167167
let sequence = shouldAdd
168168
? AST.MatchingOptionSequence(adding: [.init(option, location: .fake)])

Sources/_StringProcessing/_CharacterClassModel.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,9 @@ public struct _CharacterClassModel: Hashable {
206206
}
207207

208208
extension _CharacterClassModel: RegexComponent {
209-
public typealias Output = Substring
209+
public typealias RegexOutput = Substring
210210

211-
public var regex: Regex<Output> {
211+
public var regex: Regex<RegexOutput> {
212212
guard let ast = self.makeAST() else {
213213
fatalError("FIXME: extended AST?")
214214
}

Tests/RegexBuilderTests/AlgorithmsTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class RegexConsumerTests: XCTestCase {
2828
_ regex: R,
2929
input: String,
3030
result: String,
31-
_ replace: (Regex<R.Output>.Match) -> String,
31+
_ replace: (Regex<R.RegexOutput>.Match) -> String,
3232
file: StaticString = #file,
3333
line: UInt = #line
3434
) {

Tests/RegexBuilderTests/CustomTests.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import _StringProcessing
1515

1616
// A nibbler processes a single character from a string
1717
private protocol Nibbler: CustomRegexComponent {
18-
func nibble(_: Character) -> Output?
18+
func nibble(_: Character) -> RegexOutput?
1919
}
2020

2121
extension Nibbler {
@@ -24,7 +24,7 @@ extension Nibbler {
2424
_ input: String,
2525
startingAt index: String.Index,
2626
in bounds: Range<String.Index>
27-
) -> (upperBound: String.Index, output: Output)? {
27+
) -> (upperBound: String.Index, output: RegexOutput)? {
2828
guard index != bounds.upperBound, let res = nibble(input[index]) else {
2929
return nil
3030
}
@@ -35,15 +35,15 @@ extension Nibbler {
3535

3636
// A number nibbler
3737
private struct Numbler: Nibbler {
38-
typealias Output = Int
38+
typealias RegexOutput = Int
3939
func nibble(_ c: Character) -> Int? {
4040
c.wholeNumberValue
4141
}
4242
}
4343

4444
// An ASCII value nibbler
4545
private struct Asciibbler: Nibbler {
46-
typealias Output = UInt8
46+
typealias RegexOutput = UInt8
4747
func nibble(_ c: Character) -> UInt8? {
4848
c.asciiValue
4949
}

0 commit comments

Comments
 (0)