Skip to content

Commit 033c4bb

Browse files
committed
Allow empty comments
`expectQuoted` expects non-empty contents, which doesn't apply to comments.
1 parent b721ea7 commit 033c4bb

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

Sources/_RegexParser/Regex/Parse/LexicalAnalysis.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,10 +630,10 @@ extension Source {
630630
mutating func lexComment(context: ParsingContext) throws -> AST.Trivia? {
631631
let trivia: Located<String>? = try recordLoc { src in
632632
if src.tryEat(sequence: "(?#") {
633-
return try src.expectQuoted(endingWith: ")").value
633+
return try src.lexUntil(eating: ")").value
634634
}
635635
if context.experimentalComments, src.tryEat(sequence: "/*") {
636-
return try src.expectQuoted(endingWith: "*/").value
636+
return try src.lexUntil(eating: "*/").value
637637
}
638638
if context.endOfLineComments, src.tryEat("#") {
639639
// Try eat until we either exhaust the input, or hit a newline. Note

Tests/RegexTests/ParseTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,9 @@ extension RegexTests {
16481648
parseTest("[(?#abc)]", charClass("(", "?", "#", "a", "b", "c", ")"))
16491649
parseTest("# abc", concat("#", " ", "a", "b", "c"))
16501650

1651+
parseTest("(?#)", empty())
1652+
parseTest("/**/", empty(), syntax: .experimental)
1653+
16511654
// MARK: Matching option changing
16521655

16531656
parseTest(

0 commit comments

Comments
 (0)