Skip to content

Commit d6201a4

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 1d1d7bb commit d6201a4

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
@@ -846,6 +846,11 @@ extension Parser {
846846
/// | MatchingOption* '-' MatchingOption*
847847
///
848848
mutating func lexMatchingOptionSequence() -> AST.MatchingOptionSequence? {
849+
// PCRE accepts '(?)'
850+
// TODO: This is a no-op, should we warn?
851+
if peek() == ")" {
852+
return .init(caretLoc: nil, adding: [], minusLoc: nil, removing: [])
853+
}
849854
let caret = tryEatWithLoc("^")
850855

851856
// 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
@@ -970,6 +970,9 @@ extension RegexTests {
970970
concat("a", atomicScriptRun("b"), "c"), unsupported: true)
971971

972972
// Matching option changing groups.
973+
parseTest("(?)", changeMatchingOptions(
974+
matchingOptions()
975+
))
973976
parseTest("(?-)", changeMatchingOptions(
974977
matchingOptions()
975978
))

0 commit comments

Comments
 (0)