Skip to content

Commit 780ba3c

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 7b1ede0 commit 780ba3c

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
@@ -861,6 +861,11 @@ extension Parser {
861861
/// | MatchingOption* '-' MatchingOption*
862862
///
863863
mutating func lexMatchingOptionSequence() -> AST.MatchingOptionSequence? {
864+
// PCRE accepts '(?)'
865+
// TODO: This is a no-op, should we warn?
866+
if peek() == ")" {
867+
return .init(caretLoc: nil, adding: [], minusLoc: nil, removing: [])
868+
}
864869
let caret = tryEatWithLoc("^")
865870

866871
// 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
@@ -978,6 +978,9 @@ extension RegexTests {
978978
concat("a", atomicScriptRun("b"), "c"), unsupported: true)
979979

980980
// Matching option changing groups.
981+
parseTest("(?)", changeMatchingOptions(
982+
matchingOptions()
983+
))
981984
parseTest("(?-)", changeMatchingOptions(
982985
matchingOptions()
983986
))

0 commit comments

Comments
 (0)