Skip to content

Rename RegexComponent.Output #281

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 1 commit into from
Apr 14, 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
2 changes: 1 addition & 1 deletion Sources/Exercises/Participants/RegexParticipant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private func extractFromCaptures(
private func graphemeBreakPropertyData<RP: RegexComponent>(
forLine line: String,
using regex: RP
) -> GraphemeBreakEntry? where RP.Output == (Substring, Substring, Substring?, Substring) {
) -> GraphemeBreakEntry? where RP.RegexOutput == (Substring, Substring, Substring?, Substring) {
line.wholeMatch(of: regex).map(\.output).flatMap(extractFromCaptures)
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/RegexBuilder/Anchor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ public struct Lookahead<Output>: _BuiltinRegexComponent {
public init<R: RegexComponent>(
_ component: R,
negative: Bool = false
) where R.Output == Output {
) where R.RegexOutput == Output {
self.init(node: .nonCapturingGroup(
negative ? .negativeLookahead : .lookahead, component.regex.root))
}

public init<R: RegexComponent>(
negative: Bool = false,
@RegexComponentBuilder _ component: () -> R
) where R.Output == Output {
) where R.RegexOutput == Output {
self.init(node: .nonCapturingGroup(
negative ? .negativeLookahead : .lookahead, component().regex.root))
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/RegexBuilder/DSL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import _RegexParser
extension Regex {
public init<Content: RegexComponent>(
@RegexComponentBuilder _ content: () -> Content
) where Content.Output == Output {
) where Content.RegexOutput == Output {
self = content().regex
}
}

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

extension _BuiltinRegexComponent {
Expand Down Expand Up @@ -184,7 +184,7 @@ public struct AlternationBuilder {
@_disfavoredOverload
public static func buildPartialBlock<R: RegexComponent>(
first component: R
) -> ChoiceOf<R.Output> {
) -> ChoiceOf<R.RegexOutput> {
.init(component.regex)
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/RegexBuilder/Match.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@ import _StringProcessing
extension String {
public func wholeMatch<R: RegexComponent>(
@RegexComponentBuilder of content: () -> R
) -> Regex<R.Output>.Match? {
) -> Regex<R.RegexOutput>.Match? {
wholeMatch(of: content())
}

public func prefixMatch<R: RegexComponent>(
@RegexComponentBuilder of content: () -> R
) -> Regex<R.Output>.Match? {
) -> Regex<R.RegexOutput>.Match? {
prefixMatch(of: content())
}
}

extension Substring {
public func wholeMatch<R: RegexComponent>(
@RegexComponentBuilder of content: () -> R
) -> Regex<R.Output>.Match? {
) -> Regex<R.RegexOutput>.Match? {
wholeMatch(of: content())
}

public func prefixMatch<R: RegexComponent>(
@RegexComponentBuilder of content: () -> R
) -> Regex<R.Output>.Match? {
) -> Regex<R.RegexOutput>.Match? {
prefixMatch(of: content())
}
}
828 changes: 414 additions & 414 deletions Sources/RegexBuilder/Variadics.swift

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Sources/VariadicsGenerator/VariadicsGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ var standardError = StandardErrorStream()

typealias Counter = Int64
let regexComponentProtocolName = "RegexComponent"
let outputAssociatedTypeName = "Output"
let outputAssociatedTypeName = "RegexOutput"
let patternProtocolRequirementName = "regex"
let regexTypeName = "Regex"
let baseMatchTypeName = "Substring"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ extension RegexConsumer {
// well, taking advantage of the fact that the captures can be ignored

extension RegexConsumer: MatchingCollectionConsumer {
typealias Match = R.Output
typealias Match = R.RegexOutput

func matchingConsuming(
_ consumed: Consumed, in range: Range<Consumed.Index>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ extension BidirectionalCollection where SubSequence == Substring {
/// there isn't a match.
public func firstMatch<R: RegexComponent>(
of r: R
) -> Regex<R.Output>.Match? {
) -> Regex<R.RegexOutput>.Match? {
let slice = self[...]
return try? r.regex.firstMatch(in: slice.base)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ extension RangeReplaceableCollection where SubSequence == Substring {
/// matching `regex` are replaced by `replacement`.
public func replacing<R: RegexComponent, Replacement: Collection>(
_ regex: R,
with replacement: (Regex<R.Output>.Match) throws -> Replacement,
with replacement: (Regex<R.RegexOutput>.Match) throws -> Replacement,
subrange: Range<Index>,
maxReplacements: Int = .max
) rethrows -> Self where Replacement.Element == Element {
Expand Down Expand Up @@ -159,7 +159,7 @@ extension RangeReplaceableCollection where SubSequence == Substring {
/// matching `regex` are replaced by `replacement`.
public func replacing<R: RegexComponent, Replacement: Collection>(
_ regex: R,
with replacement: (Regex<R.Output>.Match) throws -> Replacement,
with replacement: (Regex<R.RegexOutput>.Match) throws -> Replacement,
maxReplacements: Int = .max
) rethrows -> Self where Replacement.Element == Element {
try replacing(
Expand All @@ -179,7 +179,7 @@ extension RangeReplaceableCollection where SubSequence == Substring {
/// sequence matching `regex` to replace. Default is `Int.max`.
public mutating func replace<R: RegexComponent, Replacement: Collection>(
_ regex: R,
with replacement: (Regex<R.Output>.Match) throws -> Replacement,
with replacement: (Regex<R.RegexOutput>.Match) throws -> Replacement,
maxReplacements: Int = .max
) rethrows where Replacement.Element == Element {
self = try replacing(
Expand Down
4 changes: 2 additions & 2 deletions Sources/_StringProcessing/Algorithms/Matching/Matches.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ extension BidirectionalCollection where SubSequence == Substring {

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

var result = [Regex<R.Output>.Match]()
var result = [Regex<R.RegexOutput>.Match]()
while start < end {
guard let match = try? regex._firstMatch(
slice.base, in: start..<end
Expand Down
4 changes: 2 additions & 2 deletions Sources/_StringProcessing/Regex/Core.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import _RegexParser

/// A type that represents a regular expression.
public protocol RegexComponent {
associatedtype Output
var regex: Regex<Output> { get }
associatedtype RegexOutput
var regex: Regex<RegexOutput> { get }
}

/// A regex represents a string processing algorithm.
Expand Down
6 changes: 3 additions & 3 deletions Sources/_StringProcessing/Regex/DSLConsumers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public protocol CustomRegexComponent: RegexComponent {
_ input: String,
startingAt index: String.Index,
in bounds: Range<String.Index>
) -> (upperBound: String.Index, output: Output)?
) -> (upperBound: String.Index, output: RegexOutput)?
}

extension CustomRegexComponent {
public var regex: Regex<Output> {
Regex(node: .matcher(.init(Output.self), { input, index, bounds in
public var regex: Regex<RegexOutput> {
Regex(node: .matcher(.init(RegexOutput.self), { input, index, bounds in
match(input, startingAt: index, in: bounds)
}))
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/_StringProcessing/Regex/Match.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,24 +155,24 @@ extension Regex {
extension String {
public func wholeMatch<R: RegexComponent>(
of r: R
) -> Regex<R.Output>.Match? {
) -> Regex<R.RegexOutput>.Match? {
try? r.regex.wholeMatch(in: self)
}
public func prefixMatch<R: RegexComponent>(
of r: R
) -> Regex<R.Output>.Match? {
) -> Regex<R.RegexOutput>.Match? {
try? r.regex.prefixMatch(in: self)
}
}
extension Substring {
public func wholeMatch<R: RegexComponent>(
of r: R
) -> Regex<R.Output>.Match? {
) -> Regex<R.RegexOutput>.Match? {
try? r.regex.wholeMatch(in: self)
}
public func prefixMatch<R: RegexComponent>(
of r: R
) -> Regex<R.Output>.Match? {
) -> Regex<R.RegexOutput>.Match? {
try? r.regex.prefixMatch(in: self)
}
}
22 changes: 11 additions & 11 deletions Sources/_StringProcessing/Regex/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,30 @@ import _RegexParser

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

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

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

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

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

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

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

Expand Down Expand Up @@ -95,7 +95,7 @@ extension RegexComponent {
/// // Prints "true"
/// print(decomposed.contains(queRegexScalar))
/// // Prints "false"
public func matchingSemantics(_ semanticLevel: RegexSemanticLevel) -> Regex<Output> {
public func matchingSemantics(_ semanticLevel: RegexSemanticLevel) -> Regex<RegexOutput> {
switch semanticLevel.base {
case .graphemeCluster:
return wrapInOption(.graphemeClusterSemantics, addingIf: true)
Expand Down Expand Up @@ -139,7 +139,7 @@ extension RegexComponent {
///
/// - Parameter matchLineEndings: A Boolean value indicating whether `^` and
/// `$` should match the start and end of lines, respectively.
public func anchorsMatchLineEndings(_ matchLineEndings: Bool = true) -> Regex<Output> {
public func anchorsMatchLineEndings(_ matchLineEndings: Bool = true) -> Regex<RegexOutput> {
wrapInOption(.multiline, addingIf: matchLineEndings)
}

Expand All @@ -153,7 +153,7 @@ extension RegexComponent {
///
/// - Parameter useReluctantCaptures: A Boolean value indicating whether
/// quantifiers should be reluctant by default.
public func reluctantCaptures(_ useReluctantCaptures: Bool = true) -> Regex<Output> {
public func reluctantCaptures(_ useReluctantCaptures: Bool = true) -> Regex<RegexOutput> {
wrapInOption(.reluctantByDefault, addingIf: useReluctantCaptures)
}
}
Expand All @@ -162,7 +162,7 @@ extension RegexComponent {
extension RegexComponent {
fileprivate func wrapInOption(
_ option: AST.MatchingOption.Kind,
addingIf shouldAdd: Bool) -> Regex<Output>
addingIf shouldAdd: Bool) -> Regex<RegexOutput>
{
let sequence = shouldAdd
? AST.MatchingOptionSequence(adding: [.init(option, location: .fake)])
Expand Down
4 changes: 2 additions & 2 deletions Sources/_StringProcessing/_CharacterClassModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ public struct _CharacterClassModel: Hashable {
}

extension _CharacterClassModel: RegexComponent {
public typealias Output = Substring
public typealias RegexOutput = Substring

public var regex: Regex<Output> {
public var regex: Regex<RegexOutput> {
guard let ast = self.makeAST() else {
fatalError("FIXME: extended AST?")
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/RegexBuilderTests/AlgorithmsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class RegexConsumerTests: XCTestCase {
_ regex: R,
input: String,
result: String,
_ replace: (Regex<R.Output>.Match) -> String,
_ replace: (Regex<R.RegexOutput>.Match) -> String,
file: StaticString = #file,
line: UInt = #line
) {
Expand Down
8 changes: 4 additions & 4 deletions Tests/RegexBuilderTests/CustomTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import _StringProcessing

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

extension Nibbler {
Expand All @@ -24,7 +24,7 @@ extension Nibbler {
_ input: String,
startingAt index: String.Index,
in bounds: Range<String.Index>
) -> (upperBound: String.Index, output: Output)? {
) -> (upperBound: String.Index, output: RegexOutput)? {
guard index != bounds.upperBound, let res = nibble(input[index]) else {
return nil
}
Expand All @@ -35,15 +35,15 @@ extension Nibbler {

// A number nibbler
private struct Numbler: Nibbler {
typealias Output = Int
typealias RegexOutput = Int
func nibble(_ c: Character) -> Int? {
c.wholeNumberValue
}
}

// An ASCII value nibbler
private struct Asciibbler: Nibbler {
typealias Output = UInt8
typealias RegexOutput = UInt8
func nibble(_ c: Character) -> UInt8? {
c.asciiValue
}
Expand Down
Loading