Skip to content

Commit 875ab4f

Browse files
authored
Move MatchingEngine out of the _MatchingEngine module (#143)
1 parent a5df6f0 commit 875ab4f

30 files changed

+109
-115
lines changed

Package.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ let package = Package(
3434
]),
3535
.testTarget(
3636
name: "MatchingEngineTests",
37-
dependencies: ["_MatchingEngine"]),
37+
dependencies: [
38+
"_MatchingEngine", "_StringProcessing"]),
3839
.target(
3940
name: "_StringProcessing",
4041
dependencies: ["_MatchingEngine"],
@@ -50,7 +51,7 @@ let package = Package(
5051
]),
5152
.target(
5253
name: "Prototypes",
53-
dependencies: ["_MatchingEngine"]),
54+
dependencies: ["_MatchingEngine", "_StringProcessing"]),
5455

5556
// MARK: Scripts
5657
.executableTarget(

Sources/Exercises/Participants/PEGParticipant.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ private func graphemeBreakPropertyData(forLine line: String) -> GraphemeBreakEnt
4040
let program = PEG.Program(start: "Entry", environment: ["Entry": entry])
4141

4242
let vm = program.compile(for: String.self)
43-
let engine = try! program.transpile(for: String.self)
43+
let engine = try! program.transpile()
4444
_ = (vm, engine)
4545

4646
fatalError("Unsupported")

Sources/Prototypes/PEG/PEGCode.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 _StringProcessing
1313

1414
extension PEG.VM {
1515
struct Code {

Sources/Prototypes/PEG/PEGCompile.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 _StringProcessing
1313

1414
extension PEG.VM {
1515
typealias InIndex = Input.Index

Sources/Prototypes/PEG/PEGCore.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 _StringProcessing
1313
let emitComments = true
1414

1515
struct PEGCore<

Sources/Prototypes/PEG/PEGTranspile.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
import _MatchingEngine
13+
import _StringProcessing
1314

14-
extension PEG.VM {
15-
typealias MEProgram = _MatchingEngine.Program<Input>
16-
func transpile() throws -> MEProgram {
17-
typealias Builder = MEProgram.Builder
18-
var builder = MEProgram.Builder()
15+
extension PEG.VM where Input == String {
16+
typealias MEProg = MEProgram<String>
17+
func transpile() throws -> MEProg {
18+
typealias Builder = MEProg.Builder
19+
var builder = MEProg.Builder()
1920

2021
// Address token info
2122
//
@@ -110,10 +111,9 @@ extension PEG.VM {
110111
}
111112
}
112113

113-
extension PEG.Program {
114-
public func transpile<Input: Collection>(
115-
for input: Input.Type = Input.self
116-
) throws -> Engine<Input> where Input.Element == Element {
117-
try Engine(compile(for: input).vm.transpile())
114+
extension PEG.Program where Element == Character {
115+
public func transpile(
116+
) throws -> Engine<String> {
117+
try Engine(compile(for: String.self).vm.transpile())
118118
}
119119
}

Sources/Prototypes/PEG/PEGVM.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 _StringProcessing
1313

1414
extension PEG {
1515

Sources/Prototypes/PEG/Printing.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 _StringProcessing
1313

1414
extension PEGCore.Instruction: InstructionProtocol {
1515
var operandPC: InstructionAddress? { self.pc }

Sources/_StringProcessing/ByteCodeGen.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import _MatchingEngine
33
extension Compiler {
44
struct ByteCodeGen {
55
var options: MatchingOptions
6-
var builder = _MatchingEngine.Program<String>.Builder()
6+
var builder = Program.Builder()
77

88
mutating func finish(
9-
) throws -> _MatchingEngine.Program<String> {
9+
) throws -> Program {
1010
builder.buildAccept()
1111
return try builder.assemble()
1212
}

Sources/_StringProcessing/Compiler.swift

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

1212
import _MatchingEngine
1313

14-
struct RegexProgram {
15-
typealias Program = _MatchingEngine.Program<String>
16-
var program: Program
17-
}
18-
1914
class Compiler {
2015
let tree: DSLTree
2116

@@ -30,12 +25,12 @@ class Compiler {
3025
self.tree = tree
3126
}
3227

33-
__consuming func emit() throws -> RegexProgram {
28+
__consuming func emit() throws -> Program {
3429
// TODO: Handle global options
3530
var codegen = ByteCodeGen(options: options)
3631
try codegen.emitNode(tree.root)
3732
let program = try codegen.finish()
38-
return RegexProgram(program: program)
33+
return program
3934
}
4035
}
4136

0 commit comments

Comments
 (0)