Skip to content

Commit 1dfb1a6

Browse files
committed
Remove nestOptionals param from _captureStructure
This is no longer needed as the capture list has the right nesting information.
1 parent d8ce370 commit 1dfb1a6

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

Sources/_RegexParser/Regex/Parse/CaptureStructure.swift

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -225,33 +225,27 @@ extension CaptureStructure: CustomStringConvertible {
225225
extension AST {
226226
/// The capture structure of this AST for compiler communication.
227227
var captureStructure: CaptureStructure {
228-
captureList._captureStructure(nestOptionals: true)
228+
captureList._captureStructure
229229
}
230230
}
231231

232232
// MARK: Convert CaptureList into CaptureStructure
233233

234234
extension CaptureList {
235-
func _captureStructure(nestOptionals: Bool) -> CaptureStructure {
235+
var _captureStructure: CaptureStructure {
236236
if captures.isEmpty { return .empty }
237237
if captures.count == 1 {
238-
return captures.first!._captureStructure(nestOptionals: nestOptionals)
238+
return captures.first!._captureStructure
239239
}
240-
return .tuple(captures.map {
241-
$0._captureStructure(nestOptionals: nestOptionals)
242-
})
240+
return .tuple(captures.map(\._captureStructure))
243241
}
244242
}
245243

246244
extension CaptureList.Capture {
247-
func _captureStructure(nestOptionals: Bool) -> CaptureStructure {
248-
if optionalDepth == 0 {
249-
return .atom(name: name, type: type == Substring.self ? nil : .init(type))
250-
}
251-
var copy = self
252-
copy.optionalDepth = 0
253-
var base = copy._captureStructure(nestOptionals: false)
254-
for _ in 0..<(nestOptionals ? optionalDepth : 1) {
245+
var _captureStructure: CaptureStructure {
246+
var base = CaptureStructure.atom(
247+
name: name, type: type == Substring.self ? nil : .init(type))
248+
for _ in 0 ..< optionalDepth {
255249
base = .optional(base)
256250
}
257251
return base

Tests/RegexTests/ParseTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func parseTest(
9090
}
9191

9292
// Test capture structure round trip serialization.
93-
let capStruct = captures._captureStructure(nestOptionals: true)
93+
let capStruct = captures._captureStructure
9494
let serializedCapturesSize = CaptureStructure.serializationBufferSize(
9595
forInputUTF8CodeUnitCount: input.utf8.count)
9696
let serializedCaptures = UnsafeMutableRawBufferPointer.allocate(

0 commit comments

Comments
 (0)