Skip to content

Commit 9406996

Browse files
committed
more cleanup
1 parent cbd2277 commit 9406996

File tree

2 files changed

+10
-41
lines changed

2 files changed

+10
-41
lines changed

Sources/_RegexParser/Regex/AST/AST.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ public struct AST: Hashable {
2424
extension AST {
2525
/// Whether this AST tree has nested somewhere inside it a capture.
2626
public var hasCapture: Bool { root.hasCapture }
27-
28-
/// The capture structure of this AST tree.
29-
var captureStructure: CaptureStructure {
30-
root._captureList._captureStructure(nestOptionals: true)
31-
}
3227
}
3328

3429
extension AST {

Sources/_RegexParser/Regex/Parse/CaptureStructure.swift

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

12+
// TODO: Remove and serialize CaptureList instead
13+
1214
// A tree representing the type of some captures.
1315
enum CaptureStructure: Equatable {
1416
case atom(name: String? = nil, type: AnyType? = nil)
@@ -29,47 +31,12 @@ enum CaptureStructure: Equatable {
2931
extension CaptureStructure {
3032
/// Returns a Boolean indicating whether the structure does not contain any
3133
/// captures.
32-
var isEmpty: Bool {
34+
private var isEmpty: Bool {
3335
if case .tuple(let elements) = self, elements.isEmpty {
3436
return true
3537
}
3638
return false
3739
}
38-
39-
func type(withAtomType atomType: Any.Type) -> Any.Type {
40-
switch self {
41-
case .atom(_, type: nil):
42-
return atomType
43-
case .atom(_, type: let type?):
44-
return type.base
45-
case .optional(let child):
46-
return TypeConstruction.optionalType(of: child.type(withAtomType: atomType))
47-
case .tuple(let children):
48-
return TypeConstruction.tupleType(of: children.map {
49-
$0.type(withAtomType: atomType)
50-
})
51-
}
52-
}
53-
54-
typealias DefaultAtomType = Substring
55-
56-
var type: Any.Type {
57-
type(withAtomType: DefaultAtomType.self)
58-
}
59-
60-
var atomType: AnyType {
61-
switch self {
62-
case .atom(_, type: nil):
63-
return .init(Substring.self)
64-
case .atom(_, type: let type?):
65-
return type
66-
case .optional(let child):
67-
return child.atomType
68-
case .tuple:
69-
fatalError("Recursive nesting has no single atom type")
70-
}
71-
72-
}
7340
}
7441

7542
// MARK: - Serialization
@@ -252,3 +219,10 @@ extension CaptureStructure: CustomStringConvertible {
252219
}
253220
}
254221
}
222+
223+
extension AST {
224+
/// The capture structure of this AST tree.
225+
var captureStructure: CaptureStructure {
226+
root._captureList._captureStructure(nestOptionals: true)
227+
}
228+
}

0 commit comments

Comments
 (0)