Skip to content

Eliminate extra public API #256

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 3 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 4 additions & 4 deletions Sources/Exercises/Participants/RegexParticipant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ private func graphemeBreakPropertyData<RP: RegexComponent>(
private func graphemeBreakPropertyDataLiteral(
forLine line: String
) -> GraphemeBreakEntry? {
return graphemeBreakPropertyData(
forLine: line,
using: r(#"([0-9A-F]+)(?:\.\.([0-9A-F]+))?\s+;\s+(\w+).*"#,
matching: (Substring, Substring, Substring?, Substring).self))
let regex = try! Regex(
compiling: #"([0-9A-F]+)(?:\.\.([0-9A-F]+))?\s+;\s+(\w+).*"#,
as: (Substring, Substring, Substring?, Substring).self)
return graphemeBreakPropertyData(forLine: line, using: regex)
}

// MARK: - Builder DSL
Expand Down
2 changes: 1 addition & 1 deletion Sources/PatternConverter/PatternConverter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import ArgumentParser
import _RegexParser
import _StringProcessing
@_spi(PatternConverter) import _StringProcessing

@main
struct PatternConverter: ParsableCommand {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//

public struct PredicateConsumer<Consumed: Collection> {
struct PredicateConsumer<Consumed: Collection> {
let predicate: (Consumed.Element) -> Bool
}

Expand All @@ -29,7 +29,7 @@ extension PredicateConsumer: CollectionConsumer {
extension PredicateConsumer: BidirectionalCollectionConsumer
where Consumed: BidirectionalCollection
{
public func consumingBack(
func consumingBack(
_ consumed: Consumed,
in range: Range<Consumed.Index>
) -> Consumed.Index? {
Expand Down Expand Up @@ -59,9 +59,9 @@ extension PredicateConsumer: BackwardCollectionSearcher,
BackwardStatelessCollectionSearcher
where Searched: BidirectionalCollection
{
public typealias BackwardSearched = Consumed
typealias BackwardSearched = Consumed

public func searchBack(
func searchBack(
_ searched: BackwardSearched,
in range: Range<BackwardSearched.Index>
) -> Range<BackwardSearched.Index>? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
//
//===----------------------------------------------------------------------===//

public struct RegexConsumer<
struct RegexConsumer<
R: RegexComponent, Consumed: BidirectionalCollection
> where Consumed.SubSequence == Substring {
// TODO: Should `Regex` itself implement these protocols?
let regex: R

public init(_ regex: R) {
init(_ regex: R) {
self.regex = regex
}
}
Expand All @@ -36,9 +36,9 @@ extension RegexConsumer {
// well, taking advantage of the fact that the captures can be ignored

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

public func matchingConsuming(
func matchingConsuming(
_ consumed: Consumed, in range: Range<Consumed.Index>
) -> (upperBound: String.Index, match: Match)? {
_matchingConsuming(consumed[...], in: range)
Expand All @@ -47,7 +47,7 @@ extension RegexConsumer: MatchingCollectionConsumer {

// TODO: We'll want to bake backwards into the engine
extension RegexConsumer: BidirectionalMatchingCollectionConsumer {
public func matchingConsumingBack(
func matchingConsumingBack(
_ consumed: Consumed, in range: Range<Consumed.Index>
) -> (lowerBound: String.Index, match: Match)? {
var i = range.lowerBound
Expand All @@ -67,12 +67,12 @@ extension RegexConsumer: BidirectionalMatchingCollectionConsumer {
}

extension RegexConsumer: MatchingStatelessCollectionSearcher {
public typealias Searched = Consumed
typealias Searched = Consumed

// TODO: We'll want to bake search into the engine so it can
// take advantage of the structure of the regex itself and
// its own internal state
public func matchingSearch(
func matchingSearch(
_ searched: Searched, in range: Range<Searched.Index>
) -> (range: Range<String.Index>, match: Match)? {
ConsumerSearcher(consumer: self).matchingSearch(searched, in: range)
Expand All @@ -81,9 +81,9 @@ extension RegexConsumer: MatchingStatelessCollectionSearcher {

// TODO: Bake in search-back to engine too
extension RegexConsumer: BackwardMatchingStatelessCollectionSearcher {
public typealias BackwardSearched = Consumed
typealias BackwardSearched = Consumed

public func matchingSearchBack(
func matchingSearchBack(
_ searched: BackwardSearched, in range: Range<Searched.Index>
) -> (range: Range<String.Index>, match: Match)? {
ConsumerSearcher(consumer: self).matchingSearchBack(searched, in: range)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//

public struct TwoWaySearcher<Searched: BidirectionalCollection>
struct TwoWaySearcher<Searched: BidirectionalCollection>
where Searched.Element: Comparable
{
// TODO: Be generic over the pattern?
Expand All @@ -36,14 +36,14 @@ public struct TwoWaySearcher<Searched: BidirectionalCollection>
}

extension TwoWaySearcher: CollectionSearcher {
public struct State {
struct State {
let end: Searched.Index
var index: Searched.Index
var criticalIndex: Searched.Index
var memory: (offset: Int, index: Searched.Index)?
}

public func state(
func state(
for searched: Searched,
in range: Range<Searched.Index>
) -> State {
Expand All @@ -57,7 +57,7 @@ extension TwoWaySearcher: CollectionSearcher {
memory: nil)
}

public func search(
func search(
_ searched: Searched,
_ state: inout State
) -> Range<Searched.Index>? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
//
//===----------------------------------------------------------------------===//

public struct ZSearcher<Searched: Collection> {
struct ZSearcher<Searched: Collection> {
let pattern: [Searched.Element]
let z: [Int]
let areEquivalent: (Searched.Element, Searched.Element) -> Bool

public init(
init(
pattern: [Searched.Element],
by areEquivalent: @escaping (Searched.Element, Searched.Element
) -> Bool) {
Expand All @@ -25,7 +25,7 @@ public struct ZSearcher<Searched: Collection> {
}

extension ZSearcher: StatelessCollectionSearcher {
public func search(
func search(
_ searched: Searched,
in range: Range<Searched.Index>
) -> Range<Searched.Index>? {
Expand Down
1 change: 1 addition & 0 deletions Sources/_StringProcessing/PrintAsPattern.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import _RegexParser

extension AST {
/// Render as a Pattern DSL
@_spi(PatternConverter)
public func renderAsBuilderDSL(
maxTopDownLevels: Int? = nil,
minBottomUpLevels: Int? = nil
Expand Down
21 changes: 0 additions & 21 deletions Sources/_StringProcessing/Regex/Core.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,3 @@ extension UnicodeScalar: RegexComponent {
.init(node: .atom(.scalar(self)))
}
}

// MARK: - Testing

public struct MockRegexLiteral<Output>: RegexComponent {
public typealias MatchValue = Substring
public let regex: Regex<Output>

public init(
_ string: String,
_ syntax: SyntaxOptions = .traditional,
matching: Output.Type = Output.self
) throws {
regex = Regex(ast: try parse(string, syntax))
}
}

public func r<Output>(
_ s: String, matching matchType: Output.Type = Output.self
) -> MockRegexLiteral<Output> {
try! MockRegexLiteral(s, matching: matchType)
}
8 changes: 4 additions & 4 deletions Sources/_StringProcessing/Utility/ASTBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,16 @@ func negativeLookahead(_ child: AST.Node) -> AST.Node {
func negativeLookbehind(_ child: AST.Node) -> AST.Node {
group(.negativeLookbehind, child)
}
public func nonAtomicLookahead(_ child: AST.Node) -> AST.Node {
func nonAtomicLookahead(_ child: AST.Node) -> AST.Node {
group(.nonAtomicLookahead, child)
}
public func nonAtomicLookbehind(_ child: AST.Node) -> AST.Node {
func nonAtomicLookbehind(_ child: AST.Node) -> AST.Node {
group(.nonAtomicLookbehind, child)
}
public func scriptRun(_ child: AST.Node) -> AST.Node {
func scriptRun(_ child: AST.Node) -> AST.Node {
group(.scriptRun, child)
}
public func atomicScriptRun(_ child: AST.Node) -> AST.Node {
func atomicScriptRun(_ child: AST.Node) -> AST.Node {
group(.atomicScriptRun, child)
}
func changeMatchingOptions(
Expand Down
6 changes: 3 additions & 3 deletions Tests/RegexBuilderTests/RegexDSLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -611,9 +611,9 @@ class RegexDSLTests: XCTestCase {
}

do {
let regexLiteral = try MockRegexLiteral(
#"([0-9A-F]+)(?:\.\.([0-9A-F]+))?\s+;\s+(\w+).*"#,
matching: (Substring, Substring, Substring?, Substring).self)
let regexLiteral = try Regex(
compiling: #"([0-9A-F]+)(?:\.\.([0-9A-F]+))?\s+;\s+(\w+).*"#,
as: (Substring, Substring, Substring?, Substring).self)
let maybeMatchResult = line.matchWhole(regexLiteral)
let matchResult = try XCTUnwrap(maybeMatchResult)
let (wholeMatch, lower, upper, propertyString) = matchResult.output
Expand Down