Skip to content

Commit d8d1d9c

Browse files
committed
Allow (?)
This is accepted by PCRE, and forms an empty option change sequence. We probably ought to warn on it though as it's a no-op.
1 parent a82c63f commit d8d1d9c

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

Sources/_RegexParser/Regex/Parse/LexicalAnalysis.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,11 @@ extension Source {
802802
mutating func lexMatchingOptionSequence(
803803
context: ParsingContext
804804
) throws -> AST.MatchingOptionSequence? {
805+
// PCRE accepts '(?)'
806+
// TODO: This is a no-op, should we warn?
807+
if peek() == ")" {
808+
return .init(caretLoc: nil, adding: [], minusLoc: nil, removing: [])
809+
}
805810
let ateCaret = recordLoc { $0.tryEat("^") }
806811

807812
// TODO: Warn on duplicate options, and options appearing in both adding

Tests/RegexTests/ParseTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,9 @@ extension RegexTests {
10021002
concat("a", atomicScriptRun("b"), "c"), throwsError: .unsupported)
10031003

10041004
// Matching option changing groups.
1005+
parseTest("(?)", changeMatchingOptions(
1006+
matchingOptions()
1007+
))
10051008
parseTest("(?-)", changeMatchingOptions(
10061009
matchingOptions()
10071010
))

0 commit comments

Comments
 (0)