Skip to content

Add SwiftStdlib 5.7 availability #276

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 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
33 changes: 24 additions & 9 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

import PackageDescription

let availabilityDefinition = PackageDescription.SwiftSetting.unsafeFlags([
"-Xfrontend",
"-define-availability",
"-Xfrontend",
#""SwiftStdlib 5.7:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999""#
])

let package = Package(
name: "swift-experimental-string-processing",
products: [
Expand Down Expand Up @@ -30,12 +37,14 @@ let package = Package(
name: "_RegexParser",
dependencies: [],
swiftSettings: [
.unsafeFlags(["-enable-library-evolution"])
.unsafeFlags(["-enable-library-evolution"]),
availabilityDefinition
]),
.testTarget(
name: "MatchingEngineTests",
dependencies: [
"_RegexParser", "_StringProcessing"]),
"_RegexParser", "_StringProcessing"
]),
.target(
name: "_CUnicode",
dependencies: []),
Expand All @@ -44,26 +53,31 @@ let package = Package(
dependencies: ["_RegexParser", "_CUnicode"],
swiftSettings: [
.unsafeFlags(["-enable-library-evolution"]),
availabilityDefinition
]),
.target(
name: "RegexBuilder",
dependencies: ["_StringProcessing", "_RegexParser"],
swiftSettings: [
.unsafeFlags(["-enable-library-evolution"]),
.unsafeFlags(["-Xfrontend", "-enable-experimental-pairwise-build-block"])
.unsafeFlags(["-Xfrontend", "-enable-experimental-pairwise-build-block"]),
availabilityDefinition
]),
.testTarget(
name: "RegexTests",
dependencies: ["_StringProcessing"]),
dependencies: ["_StringProcessing"],
swiftSettings: [availabilityDefinition]),
.testTarget(
name: "RegexBuilderTests",
dependencies: ["_StringProcessing", "RegexBuilder"],
swiftSettings: [
.unsafeFlags(["-Xfrontend", "-enable-experimental-pairwise-build-block"])
.unsafeFlags(["-Xfrontend", "-enable-experimental-pairwise-build-block"]),
availabilityDefinition
]),
.target(
name: "Prototypes",
dependencies: ["_RegexParser", "_StringProcessing"]),
dependencies: ["_RegexParser", "_StringProcessing"],
swiftSettings: [availabilityDefinition]),

// MARK: Scripts
.executableTarget(
Expand All @@ -84,11 +98,12 @@ let package = Package(
name: "Exercises",
dependencies: ["_RegexParser", "Prototypes", "_StringProcessing", "RegexBuilder"],
swiftSettings: [
.unsafeFlags(["-Xfrontend", "-enable-experimental-pairwise-build-block"])
.unsafeFlags(["-Xfrontend", "-enable-experimental-pairwise-build-block"]),
availabilityDefinition
]),
.testTarget(
name: "ExercisesTests",
dependencies: ["Exercises"]),
dependencies: ["Exercises"],
swiftSettings: [availabilityDefinition]),
]
)

2 changes: 2 additions & 0 deletions Sources/RegexBuilder/Anchor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import _RegexParser
@_spi(RegexBuilder) import _StringProcessing

@available(SwiftStdlib 5.7, *)
public struct Anchor {
internal enum Kind {
case startOfSubject
Expand Down Expand Up @@ -107,6 +108,7 @@ extension Anchor {
}
}

@available(SwiftStdlib 5.7, *)
public struct Lookahead<Output>: _BuiltinRegexComponent {
public var regex: Regex<Output>

Expand Down
1 change: 1 addition & 0 deletions Sources/RegexBuilder/Builder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

@_spi(RegexBuilder) import _StringProcessing

@available(SwiftStdlib 5.7, *)
@resultBuilder
public enum RegexComponentBuilder {
public static func buildBlock() -> Regex<Substring> {
Expand Down
3 changes: 3 additions & 0 deletions Sources/RegexBuilder/CharacterClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import _RegexParser
@_spi(RegexBuilder) import _StringProcessing

@available(SwiftStdlib 5.7, *)
public struct CharacterClass {
internal var ccc: DSLTree.CustomCharacterClass

Expand Down Expand Up @@ -122,6 +123,7 @@ extension CharacterClass {
}

/// Range syntax for characters in `CharacterClass`es.
@available(SwiftStdlib 5.7, *)
public func ...(lhs: Character, rhs: Character) -> CharacterClass {
let range: DSLTree.CustomCharacterClass.Member = .range(.char(lhs), .char(rhs))
let ccc = DSLTree.CustomCharacterClass(members: [range], isInverted: false)
Expand All @@ -130,6 +132,7 @@ public func ...(lhs: Character, rhs: Character) -> CharacterClass {

/// Range syntax for unicode scalars in `CharacterClass`es.
@_disfavoredOverload
@available(SwiftStdlib 5.7, *)
public func ...(lhs: UnicodeScalar, rhs: UnicodeScalar) -> CharacterClass {
let range: DSLTree.CustomCharacterClass.Member = .range(.scalar(lhs), .scalar(rhs))
let ccc = DSLTree.CustomCharacterClass(members: [range], isInverted: false)
Expand Down
11 changes: 11 additions & 0 deletions Sources/RegexBuilder/DSL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ extension _BuiltinRegexComponent {
// Note: Quantifiers are currently gyb'd.

/// Specifies how much to attempt to match when using a quantifier.
@available(SwiftStdlib 5.7, *)
public struct QuantificationBehavior {
internal enum Kind {
case eagerly
Expand Down Expand Up @@ -121,6 +122,7 @@ extension QuantificationBehavior {
}
}

@available(SwiftStdlib 5.7, *)
public struct OneOrMore<Output>: _BuiltinRegexComponent {
public var regex: Regex<Output>

Expand All @@ -132,6 +134,7 @@ public struct OneOrMore<Output>: _BuiltinRegexComponent {
// Variadics.swift.
}

@available(SwiftStdlib 5.7, *)
public struct ZeroOrMore<Output>: _BuiltinRegexComponent {
public var regex: Regex<Output>

Expand All @@ -143,6 +146,7 @@ public struct ZeroOrMore<Output>: _BuiltinRegexComponent {
// Variadics.swift.
}

@available(SwiftStdlib 5.7, *)
public struct Optionally<Output>: _BuiltinRegexComponent {
public var regex: Regex<Output>

Expand All @@ -154,6 +158,7 @@ public struct Optionally<Output>: _BuiltinRegexComponent {
// Variadics.swift.
}

@available(SwiftStdlib 5.7, *)
public struct Repeat<Output>: _BuiltinRegexComponent {
public var regex: Regex<Output>

Expand All @@ -179,6 +184,7 @@ public struct Repeat<Output>: _BuiltinRegexComponent {
// ) -> R where R.Match == (W, C...)
// }

@available(SwiftStdlib 5.7, *)
@resultBuilder
public struct AlternationBuilder {
@_disfavoredOverload
Expand All @@ -201,6 +207,7 @@ public struct AlternationBuilder {
}
}

@available(SwiftStdlib 5.7, *)
public struct ChoiceOf<Output>: _BuiltinRegexComponent {
public var regex: Regex<Output>

Expand All @@ -215,6 +222,7 @@ public struct ChoiceOf<Output>: _BuiltinRegexComponent {

// MARK: - Capture

@available(SwiftStdlib 5.7, *)
public struct Capture<Output>: _BuiltinRegexComponent {
public var regex: Regex<Output>

Expand All @@ -225,6 +233,7 @@ public struct Capture<Output>: _BuiltinRegexComponent {
// Note: Public initializers are currently gyb'd. See Variadics.swift.
}

@available(SwiftStdlib 5.7, *)
public struct TryCapture<Output>: _BuiltinRegexComponent {
public var regex: Regex<Output>

Expand All @@ -239,6 +248,7 @@ public struct TryCapture<Output>: _BuiltinRegexComponent {

/// An atomic group, i.e. opens a local backtracking scope which, upon successful exit,
/// discards any remaining backtracking points from within the scope
@available(SwiftStdlib 5.7, *)
public struct Local<Output>: _BuiltinRegexComponent {
public var regex: Regex<Output>

Expand All @@ -249,6 +259,7 @@ public struct Local<Output>: _BuiltinRegexComponent {

// MARK: - Backreference

@available(SwiftStdlib 5.7, *)
public struct Reference<Capture>: RegexComponent {
let id = ReferenceID()

Expand Down
4 changes: 4 additions & 0 deletions Sources/RegexBuilder/Match.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
import _StringProcessing

extension String {
@available(SwiftStdlib 5.7, *)
public func wholeMatch<R: RegexComponent>(
@RegexComponentBuilder of content: () -> R
) -> Regex<R.Output>.Match? {
wholeMatch(of: content())
}

@available(SwiftStdlib 5.7, *)
public func prefixMatch<R: RegexComponent>(
@RegexComponentBuilder of content: () -> R
) -> Regex<R.Output>.Match? {
Expand All @@ -26,12 +28,14 @@ extension String {
}

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

@available(SwiftStdlib 5.7, *)
public func prefixMatch<R: RegexComponent>(
@RegexComponentBuilder of content: () -> R
) -> Regex<R.Output>.Match? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ extension Collection where Element: Equatable {
/// - Parameter other: A sequence to search for within this collection.
/// - Returns: `true` if the collection contains the specified sequence,
/// otherwise `false`.
@available(SwiftStdlib 5.7, *)
public func contains<S: Sequence>(_ other: S) -> Bool
where S.Element == Element
{
Expand All @@ -50,6 +51,7 @@ extension BidirectionalCollection where SubSequence == Substring {
/// - Parameter regex: A regex to search for within this collection.
/// - Returns: `true` if the regex was found in the collection, otherwise
/// `false`.
@available(SwiftStdlib 5.7, *)
public func contains<R: RegexComponent>(_ regex: R) -> Bool {
contains(RegexConsumer(regex))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ extension Collection where Element: Equatable {
/// - Parameter sequence: The sequence to search for.
/// - Returns: A range in the collection of the first occurrence of `sequence`.
/// Returns nil if `sequence` is not found.
@available(SwiftStdlib 5.7, *)
public func firstRange<S: Sequence>(
of sequence: S
) -> Range<Index>? where S.Element == Element {
Expand All @@ -52,6 +53,7 @@ extension BidirectionalCollection where Element: Comparable {
/// - Parameter other: The sequence to search for.
/// - Returns: A range in the collection of the first occurrence of `sequence`.
/// Returns `nil` if `sequence` is not found.
@available(SwiftStdlib 5.7, *)
public func firstRange<S: Sequence>(
of other: S
) -> Range<Index>? where S.Element == Element {
Expand All @@ -71,6 +73,7 @@ extension BidirectionalCollection where SubSequence == Substring {
/// - Parameter regex: The regex to search for.
/// - Returns: A range in the collection of the first occurrence of `regex`.
/// Returns `nil` if `regex` is not found.
@available(SwiftStdlib 5.7, *)
public func firstRange<R: RegexComponent>(of regex: R) -> Range<Index>? {
firstRange(of: RegexConsumer(regex))
}
Expand Down
6 changes: 6 additions & 0 deletions Sources/_StringProcessing/Algorithms/Algorithms/Replace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ extension RangeReplaceableCollection where Element: Equatable {
/// to replace. Default is `Int.max`.
/// - Returns: A new collection in which all occurrences of `other` in
/// `subrange` of the collection are replaced by `replacement`.
@available(SwiftStdlib 5.7, *)
public func replacing<S: Sequence, Replacement: Collection>(
_ other: S,
with replacement: Replacement,
Expand All @@ -99,6 +100,7 @@ extension RangeReplaceableCollection where Element: Equatable {
/// to replace. Default is `Int.max`.
/// - Returns: A new collection in which all occurrences of `other` in
/// `subrange` of the collection are replaced by `replacement`.
@available(SwiftStdlib 5.7, *)
public func replacing<S: Sequence, Replacement: Collection>(
_ other: S,
with replacement: Replacement,
Expand All @@ -117,6 +119,7 @@ extension RangeReplaceableCollection where Element: Equatable {
/// - replacement: The new elements to add to the collection.
/// - maxReplacements: A number specifying how many occurrences of `other`
/// to replace. Default is `Int.max`.
@available(SwiftStdlib 5.7, *)
public mutating func replace<S: Sequence, Replacement: Collection>(
_ other: S,
with replacement: Replacement,
Expand Down Expand Up @@ -184,6 +187,7 @@ extension RangeReplaceableCollection where SubSequence == Substring {
/// sequence matching `regex` to replace. Default is `Int.max`.
/// - Returns: A new collection in which all occurrences of subsequence
/// matching `regex` in `subrange` are replaced by `replacement`.
@available(SwiftStdlib 5.7, *)
public func replacing<R: RegexComponent, Replacement: Collection>(
_ regex: R,
with replacement: Replacement,
Expand All @@ -206,6 +210,7 @@ extension RangeReplaceableCollection where SubSequence == Substring {
/// sequence matching `regex` to replace. Default is `Int.max`.
/// - Returns: A new collection in which all occurrences of subsequence
/// matching `regex` are replaced by `replacement`.
@available(SwiftStdlib 5.7, *)
public func replacing<R: RegexComponent, Replacement: Collection>(
_ regex: R,
with replacement: Replacement,
Expand All @@ -225,6 +230,7 @@ extension RangeReplaceableCollection where SubSequence == Substring {
/// - replacement: The new elements to add to the collection.
/// - maxReplacements: A number specifying how many occurrences of the
/// sequence matching `regex` to replace. Default is `Int.max`.
@available(SwiftStdlib 5.7, *)
public mutating func replace<R: RegexComponent, Replacement: Collection>(
_ regex: R,
with replacement: Replacement,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ extension BidirectionalCollection where SubSequence == Substring {
/// - Parameter regex: A regex to compare to this sequence.
/// - Returns: `true` if the initial elements of the sequence matches the
/// beginning of `regex`; otherwise, `false`.
@available(SwiftStdlib 5.7, *)
public func starts<R: RegexComponent>(with regex: R) -> Bool {
starts(with: RegexConsumer(regex))
}
Expand Down
Loading