Skip to content

Rename _MatchingEngine to _RegexParser and fix CMake. #232

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
Mar 29, 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
18 changes: 9 additions & 9 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ let package = Package(
name: "Prototypes",
targets: ["Prototypes"]),
.library(
name: "_MatchingEngine",
targets: ["_MatchingEngine"]),
name: "_RegexParser",
targets: ["_RegexParser"]),
.executable(
name: "VariadicsGenerator",
targets: ["VariadicsGenerator"])
Expand All @@ -27,27 +27,27 @@ let package = Package(
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "_MatchingEngine",
name: "_RegexParser",
dependencies: [],
swiftSettings: [
.unsafeFlags(["-enable-library-evolution"])
]),
.testTarget(
name: "MatchingEngineTests",
dependencies: [
"_MatchingEngine", "_StringProcessing"]),
"_RegexParser", "_StringProcessing"]),
.target(
name: "_CUnicode",
dependencies: []),
.target(
name: "_StringProcessing",
dependencies: ["_MatchingEngine", "_CUnicode"],
dependencies: ["_RegexParser", "_CUnicode"],
swiftSettings: [
.unsafeFlags(["-enable-library-evolution"]),
]),
.target(
name: "RegexBuilder",
dependencies: ["_StringProcessing", "_MatchingEngine"],
dependencies: ["_StringProcessing", "_RegexParser"],
swiftSettings: [
.unsafeFlags(["-enable-library-evolution"]),
.unsafeFlags(["-Xfrontend", "-enable-experimental-pairwise-build-block"])
Expand All @@ -63,7 +63,7 @@ let package = Package(
]),
.target(
name: "Prototypes",
dependencies: ["_MatchingEngine", "_StringProcessing"]),
dependencies: ["_RegexParser", "_StringProcessing"]),

// MARK: Scripts
.executableTarget(
Expand All @@ -75,14 +75,14 @@ let package = Package(
name: "PatternConverter",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
"_MatchingEngine",
"_RegexParser",
"_StringProcessing"
]),

// MARK: Exercises
.target(
name: "Exercises",
dependencies: ["_MatchingEngine", "Prototypes", "_StringProcessing", "RegexBuilder"],
dependencies: ["_RegexParser", "Prototypes", "_StringProcessing", "RegexBuilder"],
swiftSettings: [
.unsafeFlags(["-Xfrontend", "-enable-experimental-pairwise-build-block"])
]),
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ See [Declarative String Processing Overview][decl-string]

## Integration with Swift

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

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`.
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`.

| Module | Swift toolchain component |
| ------------------- | ------------------------------------------------------------------------------------ |
| `_MatchingEngine` | `SwiftCompilerSources/Sources/ExperimentalRegex` and `stdlib/public/_MatchingEngine` |
| `_RegexParser` | `SwiftCompilerSources/Sources/_RegexParser` and `stdlib/public/_RegexParser` |
| `_CUnicode` | `stdlib/public/_StringProcessing` |
| `_StringProcessing` | `stdlib/public/_StringProcessing` |

Expand Down Expand Up @@ -65,10 +65,9 @@ To integrate the latest changes in apple/swift-experimental-string-processing to

### Development notes

Compiler integration can be tricky. Use special caution when developing `_MatchingEngine`, `_CUnicode` and `_StringProcessing` modules.
Compiler integration can be tricky. Use special caution when developing `_RegexParser` and `_StringProcessing` modules.

- Do not change the names of these modules without due approval from compiler and infrastructure teams.
- Do not modify the existing ABI (e.g. C API, serialization format) between the regular expression parser and the Swift compiler unless absolutely necessary.
- 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.
- 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.
- In `_MatchingEngine`, do not write fully qualified references to `_MatchingEngine` itself. This is because `_MatchingEngine` is built as `ExperimentalRegex` in `SwiftCompilerSources/` with CMake.
4 changes: 2 additions & 2 deletions Sources/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

add_subdirectory(_Unicode)
add_subdirectory(_MatchingEngine)
add_subdirectory(RegexBuilder)
add_subdirectory(_RegexParser)
add_subdirectory(_StringProcessing)
add_subdirectory(Prototypes)
add_subdirectory(VariadicsGenerator)
4 changes: 2 additions & 2 deletions Sources/PatternConverter/PatternConverter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// swift run PatternConverter <regex>

import ArgumentParser
import _MatchingEngine
import _RegexParser
import _StringProcessing

@main
Expand Down Expand Up @@ -52,7 +52,7 @@ struct PatternConverter: ParsableCommand {
let delim = experimentalSyntax ? "|" : "/"
print("Converting '\(delim)\(regex)\(delim)'")

let ast = try _MatchingEngine.parse(
let ast = try _RegexParser.parse(
regex,
experimentalSyntax ? .experimental : .traditional)

Expand Down
2 changes: 1 addition & 1 deletion Sources/Prototypes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ add_library(Prototypes
TourOfTypes/CharacterClass.swift
TourOfTypes/Literal.swift)
target_link_libraries(Prototypes PUBLIC
_MatchingEngine)
_RegexParser)
2 changes: 1 addition & 1 deletion Sources/Prototypes/Combinators/Combinators.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//

import _MatchingEngine
import _RegexParser

/*

Expand Down
2 changes: 1 addition & 1 deletion Sources/RegexBuilder/Anchor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//

import _MatchingEngine
import _RegexParser
@_spi(RegexBuilder) import _StringProcessing

public struct Anchor {
Expand Down
10 changes: 10 additions & 0 deletions Sources/RegexBuilder/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

add_library(RegexBuilder
Anchor.swift
Builder.swift
DSL.swift
Match.swift
Variadics.swift)
target_compile_options(RegexBuilder PRIVATE
-enable-library-evolution
-Xfrontend -enable-experimental-pairwise-build-block)
2 changes: 1 addition & 1 deletion Sources/RegexBuilder/DSL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//

import _MatchingEngine
import _RegexParser
@_spi(RegexBuilder) import _StringProcessing

extension Regex {
Expand Down
2 changes: 1 addition & 1 deletion Sources/RegexBuilder/Variadics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

// BEGIN AUTO-GENERATED CONTENT

import _MatchingEngine
import _RegexParser
@_spi(RegexBuilder) import _StringProcessing

extension RegexComponentBuilder {
Expand Down
2 changes: 1 addition & 1 deletion Sources/VariadicsGenerator/VariadicsGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ struct VariadicsGenerator: ParsableCommand {

// BEGIN AUTO-GENERATED CONTENT

import _MatchingEngine
import _RegexParser
@_spi(RegexBuilder) import _StringProcessing


Expand Down
46 changes: 0 additions & 46 deletions Sources/_MatchingEngine/CMakeLists.txt

This file was deleted.

28 changes: 28 additions & 0 deletions Sources/_RegexParser/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

add_library(_RegexParser
AST/AST.swift
AST/ASTAction.swift
AST/ASTProtocols.swift
AST/Atom.swift
AST/Conditional.swift
AST/CustomCharClass.swift
AST/Group.swift
AST/MatchingOptions.swift
AST/Quantification.swift
Parse/CaptureStructure.swift
Parse/CharacterPropertyClassification.swift
Parse/DelimiterLexing.swift
Parse/Diagnostics.swift
Parse/LexicalAnalysis.swift
Parse/Mocking.swift
Parse/Parse.swift
Parse/Source.swift
Parse/SourceLocation.swift
Parse/SyntaxOptions.swift
Printing/DumpAST.swift
Printing/PrettyPrinter.swift
Printing/PrintAsCanonical.swift
Printing/RenderRanges.swift
TreeProtocols.swift)
target_compile_options(_RegexParser PRIVATE
-enable-library-evolution)
2 changes: 1 addition & 1 deletion Sources/_StringProcessing/ByteCodeGen.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _MatchingEngine
import _RegexParser

extension Compiler {
struct ByteCodeGen {
Expand Down
62 changes: 49 additions & 13 deletions Sources/_StringProcessing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,67 @@ add_library(_StringProcessing
Algorithms/Consumers/ManyConsumer.swift
Algorithms/Consumers/PredicateConsumer.swift
Algorithms/Consumers/RegexConsumer.swift
Algorithms/Matching/FirstMatch.swift
Algorithms/Matching/Matches.swift
Algorithms/Matching/MatchingCollectionConsumer.swift
Algorithms/Matching/MatchingCollectionSearcher.swift
Algorithms/Matching/MatchReplace.swift
Algorithms/Matching/MatchResult.swift
Algorithms/Searchers/CollectionSearcher.swift
Algorithms/Searchers/ConsumerSearcher.swift
Algorithms/Searchers/NaivePatternSearcher.swift
Algorithms/Searchers/PatternOrEmpty.swift
Algorithms/Searchers/PredicateSearcher.swift
Algorithms/Searchers/TwoWaySearcher.swift
Algorithms/Searchers/ZSearcher.swift
ASTBuilder.swift
Engine/Backtracking.swift
Engine/Consume.swift
Engine/Engine.swift
Engine/InstPayload.swift
Engine/Instruction.swift
Engine/MEBuilder.swift
Engine/MECapture.swift
Engine/MEProgram.swift
Engine/Processor.swift
Engine/Register.swift
Engine/Structuralize.swift
Engine/Tracing.swift
Regex/AnyRegexOutput.swift
Regex/ASTConversion.swift
Regex/Core.swift
Regex/DSLConsumers.swift
Regex/DSLTree.swift
Regex/Match.swift
Regex/Options.swift
Unicode/CaseConversion.swift
Unicode/CharacterProps.swift
Unicode/Comparison.swift
Unicode/Data.swift
Unicode/Decoding.swift
Unicode/Encodings.swift
Unicode/Formatting.swift
Unicode/Graphemes.swift
Unicode/NecessaryEvils.swift
Unicode/Normalization.swift
Unicode/NumberParsing.swift
Unicode/ScalarProps.swift
Unicode/Transcoding.swift
Unicode/UCD.swift
Unicode/Validation.swift
Utility/ASTBuilder.swift
Utility/Protocols.swift
Utility/Traced.swift
Utility/TypedIndex.swift
Utility/TypedInt.swift
ByteCodeGen.swift
Capture.swift
CharacterClass.swift
Compiler.swift
ConsumerInterface.swift
Executor.swift
Legacy/HareVM.swift
Legacy/LegacyCompile.swift
Legacy/RECode.swift
Legacy/TortoiseVM.swift
Legacy/VirtualMachine.swift
RegexDSL/Builder.swift
RegexDSL/Concatenation.swift
RegexDSL/Core.swift
RegexDSL/DSL.swift
RegexDSL/DSLCapture.swift
RegexDSL/DynamicCaptures.swift)
MatchingOptions.swift
PrintAsPattern.swift)
target_compile_options(_StringProcessing PRIVATE
-enable-library-evolution)
target_link_libraries(_StringProcessing PUBLIC
_MatchingEngine)
_RegexParser)
2 changes: 1 addition & 1 deletion Sources/_StringProcessing/Capture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//

import _MatchingEngine
import _RegexParser

/// A structured capture
struct StructuredCapture {
Expand Down
2 changes: 1 addition & 1 deletion Sources/_StringProcessing/CharacterClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//

import _MatchingEngine
import _RegexParser

// NOTE: This is a model type. We want to be able to get one from
// an AST, but this isn't a natural thing to produce in the context
Expand Down
2 changes: 1 addition & 1 deletion Sources/_StringProcessing/Compiler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//

import _MatchingEngine
import _RegexParser

class Compiler {
let tree: DSLTree
Expand Down
2 changes: 1 addition & 1 deletion Sources/_StringProcessing/ConsumerInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//

import _MatchingEngine
import _RegexParser

extension DSLTree.Node {
/// Attempt to generate a consumer from this AST node
Expand Down
2 changes: 1 addition & 1 deletion Sources/_StringProcessing/Engine/MEBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//

import _MatchingEngine // For errors
import _RegexParser // For errors

extension MEProgram where Input.Element: Hashable {
struct Builder {
Expand Down
Loading