Skip to content

Commit eb0f44f

Browse files
committed
Fold (?R) into (?0)
1 parent cf54fe6 commit eb0f44f

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

Sources/_MatchingEngine/Regex/AST/Atom.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,8 @@ extension AST.Atom {
400400
// (?(<name>)... (?('name')... (?(name)...
401401
case named(String)
402402

403-
// ?(R) (?(R)...
404-
case recurseWholePattern
403+
/// (?R), (?(R)..., which are equivalent to (?0), (?(0)...
404+
static var recurseWholePattern: Kind { .absolute(0) }
405405
}
406406
public var kind: Kind
407407

@@ -413,6 +413,10 @@ extension AST.Atom {
413413
self.kind = kind
414414
self.innerLoc = innerLoc
415415
}
416+
417+
/// Whether this is a reference that recurses the whole pattern, rather than
418+
/// a group.
419+
public var recursesWholePattern: Bool { kind == .recurseWholePattern }
416420
}
417421
}
418422

Sources/_MatchingEngine/Regex/Parse/LexicalAnalysis.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ extension Source {
10141014
return .subpattern(try src.expectNamedReference(endingWith: ")"))
10151015
}
10161016

1017-
// Whole-pattern recursion.
1017+
// Whole-pattern recursion, which is equivalent to (?0).
10181018
if src.tryEat("R") {
10191019
let loc = Location(_start ..< src.currentPosition)
10201020
try src.expect(")")

0 commit comments

Comments
 (0)