Skip to content

Commit 044be96

Browse files
authored
Merge pull request swiftlang#235 from rxwei/main-integration-d2ff78f6
[Integration] main (d2ff78f) -> swift/main
2 parents 79066a8 + 9e330ba commit 044be96

File tree

76 files changed

+221
-672
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+221
-672
lines changed

Package.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ let package = Package(
1414
name: "Prototypes",
1515
targets: ["Prototypes"]),
1616
.library(
17-
name: "_MatchingEngine",
18-
targets: ["_MatchingEngine"]),
17+
name: "_RegexParser",
18+
targets: ["_RegexParser"]),
1919
.executable(
2020
name: "VariadicsGenerator",
2121
targets: ["VariadicsGenerator"])
@@ -27,27 +27,27 @@ let package = Package(
2727
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
2828
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
2929
.target(
30-
name: "_MatchingEngine",
30+
name: "_RegexParser",
3131
dependencies: [],
3232
swiftSettings: [
3333
.unsafeFlags(["-enable-library-evolution"])
3434
]),
3535
.testTarget(
3636
name: "MatchingEngineTests",
3737
dependencies: [
38-
"_MatchingEngine", "_StringProcessing"]),
38+
"_RegexParser", "_StringProcessing"]),
3939
.target(
4040
name: "_CUnicode",
4141
dependencies: []),
4242
.target(
4343
name: "_StringProcessing",
44-
dependencies: ["_MatchingEngine", "_CUnicode"],
44+
dependencies: ["_RegexParser", "_CUnicode"],
4545
swiftSettings: [
4646
.unsafeFlags(["-enable-library-evolution"]),
4747
]),
4848
.target(
4949
name: "RegexBuilder",
50-
dependencies: ["_StringProcessing", "_MatchingEngine"],
50+
dependencies: ["_StringProcessing", "_RegexParser"],
5151
swiftSettings: [
5252
.unsafeFlags(["-enable-library-evolution"]),
5353
.unsafeFlags(["-Xfrontend", "-enable-experimental-pairwise-build-block"])
@@ -63,7 +63,7 @@ let package = Package(
6363
]),
6464
.target(
6565
name: "Prototypes",
66-
dependencies: ["_MatchingEngine", "_StringProcessing"]),
66+
dependencies: ["_RegexParser", "_StringProcessing"]),
6767

6868
// MARK: Scripts
6969
.executableTarget(
@@ -75,14 +75,14 @@ let package = Package(
7575
name: "PatternConverter",
7676
dependencies: [
7777
.product(name: "ArgumentParser", package: "swift-argument-parser"),
78-
"_MatchingEngine",
78+
"_RegexParser",
7979
"_StringProcessing"
8080
]),
8181

8282
// MARK: Exercises
8383
.target(
8484
name: "Exercises",
85-
dependencies: ["_MatchingEngine", "Prototypes", "_StringProcessing", "RegexBuilder"],
85+
dependencies: ["_RegexParser", "Prototypes", "_StringProcessing", "RegexBuilder"],
8686
swiftSettings: [
8787
.unsafeFlags(["-Xfrontend", "-enable-experimental-pairwise-build-block"])
8888
]),

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ See [Declarative String Processing Overview][decl-string]
1212

1313
## Integration with Swift
1414

15-
`_MatchingEngine`, `_CUnicode` and `_StringProcessing` are specially integrated modules that are built as part of apple/swift.
15+
`_RegexParser` and `_StringProcessing` are specially integrated modules that are built as part of apple/swift.
1616

17-
Specifically, `_MatchingEngine` contains the parser for regular expression literals and is built both as part of the compiler and as a core library. `_CUnicode` and `_StringProcessing` are built together as a core library named `_StringProcessing`.
17+
Specifically, `_RegexParser` contains the parser for regular expression literals and is built both as part of the compiler and as a core library. `_CUnicode` and `_StringProcessing` are built together as a core library named `_StringProcessing`.
1818

1919
| Module | Swift toolchain component |
2020
| ------------------- | ------------------------------------------------------------------------------------ |
21-
| `_MatchingEngine` | `SwiftCompilerSources/Sources/ExperimentalRegex` and `stdlib/public/_MatchingEngine` |
21+
| `_RegexParser` | `SwiftCompilerSources/Sources/_RegexParser` and `stdlib/public/_RegexParser` |
2222
| `_CUnicode` | `stdlib/public/_StringProcessing` |
2323
| `_StringProcessing` | `stdlib/public/_StringProcessing` |
2424

@@ -65,10 +65,9 @@ To integrate the latest changes in apple/swift-experimental-string-processing to
6565
6666
### Development notes
6767
68-
Compiler integration can be tricky. Use special caution when developing `_MatchingEngine`, `_CUnicode` and `_StringProcessing` modules.
68+
Compiler integration can be tricky. Use special caution when developing `_RegexParser` and `_StringProcessing` modules.
6969
7070
- Do not change the names of these modules without due approval from compiler and infrastructure teams.
7171
- Do not modify the existing ABI (e.g. C API, serialization format) between the regular expression parser and the Swift compiler unless absolutely necessary.
7272
- Always minimize the number of lockstep integrations, i.e. when apple/swift-experimental-string-processing and apple/swift have to change together. Whenever possible, introduce new API first, migrate Swift compiler onto it, and then deprecate old API. Use versioning if helpful.
7373
- In `_StringProcessing`, do not write fully qualified references to symbols in `_CUnicode`, and always wrap `import _CUnicode` in a `#if canImport(_CUnicode)`. This is because `_CUnicode` is built as part of `_StringProcessing` with CMake.
74-
- In `_MatchingEngine`, do not write fully qualified references to `_MatchingEngine` itself. This is because `_MatchingEngine` is built as `ExperimentalRegex` in `SwiftCompilerSources/` with CMake.

Sources/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
add_subdirectory(_Unicode)
3-
add_subdirectory(_MatchingEngine)
2+
add_subdirectory(RegexBuilder)
3+
add_subdirectory(_RegexParser)
44
add_subdirectory(_StringProcessing)
55
add_subdirectory(Prototypes)
66
add_subdirectory(VariadicsGenerator)

Sources/Exercises/Participant.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,25 @@ public protocol Participant {
2929
// ...
3030
}
3131

32+
// Errors that may be thrown from default implementations
33+
private enum ParticipantError: Error {
34+
case unsupported
35+
}
36+
3237
// Default impls
3338
extension Participant {
34-
static var unsupported: Error { "Unsupported" }
35-
3639
// Produce a function that will parse a grapheme break entry from a line
3740
public static func graphemeBreakProperty() throws -> (String) -> GraphemeBreakEntry? {
38-
throw unsupported
41+
throw ParticipantError.unsupported
3942
}
4043

4144
// Produce a function that will extract the bodies of C-style comments from its input
4245
public static func cComments() throws -> (String) -> [Substring] {
43-
throw unsupported
46+
throw ParticipantError.unsupported
4447
}
4548

4649
// Produce a function that will extract the bodies of Swift-style comments from its input
4750
public static func swiftComments() throws -> (String) -> [Substring] {
48-
throw unsupported
51+
throw ParticipantError.unsupported
4952
}
5053
}

Sources/PatternConverter/PatternConverter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// swift run PatternConverter <regex>
1313

1414
import ArgumentParser
15-
import _MatchingEngine
15+
import _RegexParser
1616
import _StringProcessing
1717

1818
@main
@@ -52,7 +52,7 @@ struct PatternConverter: ParsableCommand {
5252
let delim = experimentalSyntax ? "|" : "/"
5353
print("Converting '\(delim)\(regex)\(delim)'")
5454

55-
let ast = try _MatchingEngine.parse(
55+
let ast = try _RegexParser.parse(
5656
regex,
5757
experimentalSyntax ? .experimental : .traditional)
5858

Sources/Prototypes/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ add_library(Prototypes
1515
TourOfTypes/CharacterClass.swift
1616
TourOfTypes/Literal.swift)
1717
target_link_libraries(Prototypes PUBLIC
18-
_MatchingEngine)
18+
_RegexParser)

Sources/Prototypes/Combinators/Combinators.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
import _MatchingEngine
12+
import _RegexParser
1313

1414
/*
1515

Sources/RegexBuilder/Anchor.swift

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
import _MatchingEngine
12+
import _RegexParser
1313
@_spi(RegexBuilder) import _StringProcessing
1414

1515
public struct Anchor {
@@ -107,16 +107,26 @@ extension Anchor {
107107
}
108108
}
109109

110-
public func lookahead<R: RegexComponent>(
111-
negative: Bool = false,
112-
@RegexComponentBuilder _ content: () -> R
113-
) -> Regex<R.Output> {
114-
Regex(node: .nonCapturingGroup(negative ? .negativeLookahead : .lookahead, content().regex.root))
115-
}
116-
117-
public func lookahead<R: RegexComponent>(
118-
_ component: R,
119-
negative: Bool = false
120-
) -> Regex<R.Output> {
121-
Regex(node: .nonCapturingGroup(negative ? .negativeLookahead : .lookahead, component.regex.root))
110+
public struct Lookahead<Output>: _BuiltinRegexComponent {
111+
public var regex: Regex<Output>
112+
113+
init(_ regex: Regex<Output>) {
114+
self.regex = regex
115+
}
116+
117+
public init<R: RegexComponent>(
118+
_ component: R,
119+
negative: Bool = false
120+
) where R.Output == Output {
121+
self.init(node: .nonCapturingGroup(
122+
negative ? .negativeLookahead : .lookahead, component.regex.root))
123+
}
124+
125+
public init<R: RegexComponent>(
126+
negative: Bool = false,
127+
@RegexComponentBuilder _ component: () -> R
128+
) where R.Output == Output {
129+
self.init(node: .nonCapturingGroup(
130+
negative ? .negativeLookahead : .lookahead, component().regex.root))
131+
}
122132
}

Sources/RegexBuilder/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
add_library(RegexBuilder
3+
Anchor.swift
4+
Builder.swift
5+
DSL.swift
6+
Match.swift
7+
Variadics.swift)
8+
target_compile_options(RegexBuilder PRIVATE
9+
-enable-library-evolution
10+
-Xfrontend -enable-experimental-pairwise-build-block)

Sources/RegexBuilder/DSL.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
import _MatchingEngine
12+
import _RegexParser
1313
@_spi(RegexBuilder) import _StringProcessing
1414

1515
extension Regex {
1616
public init<Content: RegexComponent>(
1717
@RegexComponentBuilder _ content: () -> Content
1818
) where Content.Output == Output {
19-
self.init(content())
19+
self = content().regex
2020
}
2121
}
2222

@@ -165,10 +165,6 @@ public struct Repeat<Output>: _BuiltinRegexComponent {
165165
// Variadics.swift.
166166
}
167167

168-
postfix operator .?
169-
postfix operator .*
170-
postfix operator .+
171-
172168
// MARK: Alternation
173169

174170
// TODO: Variadic generics

0 commit comments

Comments
 (0)