Skip to content

Commit fe5f2d8

Browse files
committed
delete stuff
1 parent 9abdbea commit fe5f2d8

File tree

4 files changed

+2
-195
lines changed

4 files changed

+2
-195
lines changed

Sources/_RegexParser/Regex/Parse/CaptureList.swift

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,3 @@ extension CaptureList.Capture {
139139
return base
140140
}
141141
}
142-
143-
/*
144-
Let's replace this now
145-
146-
We want literals to produce 1-level deep optional tops
147-
We want DSL tree to...
148-
149-
Cap structure should be an array of explicit captures present, which
150-
may have a name, an optional depth counter, and an optional type
151-
152-
153-
154-
*/

Sources/_RegexParser/Regex/Parse/CaptureStructure.swift

Lines changed: 0 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -24,169 +24,6 @@ public enum CaptureStructure: Equatable {
2424
}
2525
}
2626

27-
// TODO: Below are all flattening constructors. Instead create
28-
// a builder/visitor that can store the structuralization
29-
// approach
30-
31-
extension CaptureStructure {
32-
public struct Constructor {
33-
var strategy: Strategy
34-
35-
public init(_ strategy: Strategy = .flatten) {
36-
guard strategy == .flatten else {
37-
fatalError("TODO: adjust creator methods")
38-
}
39-
self.strategy = strategy
40-
}
41-
}
42-
}
43-
44-
extension CaptureStructure.Constructor {
45-
public mutating func alternating<C: Collection>(
46-
_ children: C
47-
) -> CaptureStructure where C.Element: _TreeNode {
48-
return children.map {
49-
$0._captureStructure(&self)
50-
}.reduce(.empty, +)
51-
.map(CaptureStructure.optional)
52-
}
53-
public mutating func concatenating<C: Collection>(
54-
_ children: C
55-
) -> CaptureStructure where C.Element: _TreeNode {
56-
return children.map {
57-
$0._captureStructure(&self)
58-
}.reduce(.empty, +)
59-
}
60-
61-
public mutating func grouping<T: _TreeNode>(
62-
_ child: T,
63-
as kind: AST.Group.Kind
64-
) -> CaptureStructure {
65-
switch kind {
66-
case .capture:
67-
return capturing(child)
68-
case .namedCapture(let name):
69-
return capturing(name: name.value, child)
70-
case .balancedCapture(let b):
71-
return capturing(name: b.name?.value, child)
72-
default:
73-
precondition(!kind.isCapturing)
74-
return child._captureStructure(&self)
75-
}
76-
}
77-
78-
public mutating func capturing<T: _TreeNode>(
79-
name: String? = nil,
80-
_ child: T,
81-
withType type: AnyType? = nil
82-
) -> CaptureStructure {
83-
.atom(name: name, type: type)
84-
+ child._captureStructure(&self)
85-
}
86-
87-
// TODO: We'll likely want/need a generalization of
88-
// conditional's condition kind.
89-
public mutating func condition<T: _TreeNode>(
90-
_ condition: AST.Conditional.Condition.Kind,
91-
trueBranch: T,
92-
falseBranch: T
93-
) -> CaptureStructure {
94-
// A conditional's capture structure is effectively that of an alternation
95-
// between the true and false branches. However the condition may also
96-
// have captures in the case of a group condition.
97-
var captures = CaptureStructure.empty
98-
switch condition {
99-
case .group(let g):
100-
captures = captures + AST.Node.group(g)._captureStructure(&self)
101-
default:
102-
break
103-
}
104-
let branchCaptures = trueBranch._captureStructure(&self) +
105-
falseBranch._captureStructure(&self)
106-
return captures + branchCaptures.map(CaptureStructure.optional)
107-
}
108-
109-
public mutating func quantifying<T: _TreeNode>(
110-
_ child: T, amount: AST.Quantification.Amount
111-
) -> CaptureStructure {
112-
let result = child._captureStructure(&self)
113-
return amount.bounds.atLeast == 0
114-
? result.map(CaptureStructure.optional) : result
115-
}
116-
117-
// TODO: Will need to adjust for DSLTree support, and
118-
// "absent" isn't the best name for these.
119-
public mutating func absent(
120-
_ kind: AST.AbsentFunction.Kind
121-
) -> CaptureStructure {
122-
// Only the child of an expression absent function is relevant, as the
123-
// other expressions don't actually get matched against.
124-
switch kind {
125-
case .expression(_, _, let child):
126-
return child._captureStructure(&self)
127-
case .clearer, .repeater, .stopper:
128-
return .empty
129-
}
130-
}
131-
}
132-
133-
extension AST.Node {
134-
public func _captureStructure(
135-
_ constructor: inout CaptureStructure.Constructor
136-
) -> CaptureStructure {
137-
guard constructor.strategy == .flatten else {
138-
fatalError("TODO")
139-
}
140-
return _captureList._captureStructure(nestOptionals: true)
141-
}
142-
}
143-
144-
// MARK: - Combination and transformation
145-
146-
extension CaptureStructure {
147-
/// Returns a capture structure by concatenating any tuples in `self` and
148-
/// `other`.
149-
func concatenating(with other: CaptureStructure) -> CaptureStructure {
150-
switch (self, other) {
151-
// (T...) + (U...) ==> (T..., U...)
152-
case let (.tuple(lhs), .tuple(rhs)):
153-
return .tuple(lhs + rhs)
154-
// T + () ==> T
155-
case (_, .tuple(let rhs)) where rhs.isEmpty:
156-
return self
157-
// () + T ==> T
158-
case (.tuple(let lhs), _) where lhs.isEmpty:
159-
return other
160-
// (T...) + U ==> (T..., U)
161-
case let (.tuple(lhs), _):
162-
return .tuple(lhs + [other])
163-
// T + (U...) ==> (T, U...)
164-
case let (_, .tuple(rhs)):
165-
return .tuple([self] + rhs)
166-
// T + U ==> (T, U)
167-
default:
168-
return .tuple([self, other])
169-
}
170-
}
171-
172-
static func + (
173-
lhs: CaptureStructure, rhs: CaptureStructure
174-
) -> CaptureStructure {
175-
lhs.concatenating(with: rhs)
176-
}
177-
178-
/// Returns a capture structure by transforming any tuple element of `self`
179-
/// or transforming `self` directly if it is not a tuple.
180-
func map(
181-
_ transform: (CaptureStructure) -> CaptureStructure
182-
) -> CaptureStructure {
183-
if case .tuple(let children) = self {
184-
return .tuple(children.map(transform))
185-
}
186-
return transform(self)
187-
}
188-
}
189-
19027
// MARK: - Common properties
19128

19229
extension CaptureStructure {
@@ -415,11 +252,3 @@ extension CaptureStructure: CustomStringConvertible {
415252
}
416253
}
417254
}
418-
419-
extension CaptureStructure.Constructor {
420-
public enum Strategy {
421-
case flatten
422-
case nest
423-
// case drop(after: Int)...
424-
}
425-
}

Sources/_RegexParser/Regex/TreeProtocols.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
public protocol _TreeNode {
44
var children: [Self]? { get }
5-
6-
func _captureStructure(
7-
_: inout CaptureStructure.Constructor
8-
) -> CaptureStructure
95
}
106

117
extension _TreeNode {

Sources/_StringProcessing/Regex/DSLTree.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,7 @@ extension DSLTree.Node {
345345

346346
extension DSLTree {
347347
var captureStructure: CaptureStructure {
348-
// TODO: nesting
349-
var constructor = CaptureStructure.Constructor(.flatten)
350-
return _Tree(root)._captureStructure(&constructor)
348+
root._captureList._captureStructure(nestOptionals: true)
351349
}
352350
}
353351
extension DSLTree.Node {
@@ -538,7 +536,6 @@ extension DSLTree.Node {
538536
self._addCaptures(to: &list, optionalNesting: 0)
539537
return list
540538
}
541-
542539
}
543540

544541
extension DSLTree {
@@ -578,9 +575,7 @@ extension DSLTree {
578575
}
579576
}
580577

581-
func _captureStructure(
582-
_ constructor: inout CaptureStructure.Constructor
583-
) -> CaptureStructure {
578+
func _captureStructure() -> CaptureStructure {
584579
self.node._captureList._captureStructure(nestOptionals: true)
585580
}
586581
}

0 commit comments

Comments
 (0)