Skip to content

Commit 469785a

Browse files
committed
Support auto-possessification of nested quantifiers
1 parent c6fad9d commit 469785a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Sources/_StringProcessing/Regex/DSLList.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,17 @@ extension DSLList {
216216

217217
switch nodes[position] {
218218
case .quantification(let amount, _, _):
219+
let quantPosition = position
219220
position += 1
221+
222+
// Do a search within this quantification's contents
223+
// FIXME: How to handle an inner quantification surfacing here?
224+
var innerPosition = position
225+
_ = autoPossessifyNextQuantification(&innerPosition)
226+
220227
switch _requiredAtomImpl(&position) {
221228
case .some(let atom?):
222-
return (position - 1, atom)
229+
return (quantPosition, atom)
223230
case .none, .some(.none):
224231
return nil
225232
}

Tests/RegexTests/OptimizationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import Testing
3131
}
3232

3333
@available(macOS 9999, *)
34-
@Test(arguments: [#/a+b/#, #/a*b/#, #/\w+\s/#, #/(?:a+b|b+a)/#]) // , #/\d+a/#
34+
@Test(arguments: [#/a+b/#, #/a*b/#, #/\w+\s/#, #/(?:a+b|b+a)/#, #/(?:(?:a+b)+b)/#])
3535
func autoPossessify(pattern: Regex<Substring>) throws {
3636
var list = DSLList(tree: pattern.program.tree)
3737
list.autoPossessify()

0 commit comments

Comments
 (0)