Skip to content

Commit e4ccd09

Browse files
committed
Allow expectQuoted to not eat terminator
This will be used by conditional parsing logic.
1 parent eacc954 commit e4ccd09

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

Sources/_MatchingEngine/Regex/Parse/LexicalAnalysis.swift

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -420,25 +420,30 @@ extension Source {
420420
/// delimiter. If `ignoreEscaped` is true, escaped characters will not be
421421
/// considered for the ending delimiter.
422422
private mutating func expectQuoted(
423-
endingWith end: String, ignoreEscaped: Bool = false
423+
endingWith end: String, ignoreEscaped: Bool = false, eatEnding: Bool = true
424424
) throws -> Located<String> {
425-
try recordLoc { src in
426-
let result = try src.lexUntil { src in
427-
if try src.tryEatNonEmpty(sequence: end) {
425+
let result = try recordLoc { src -> String in
426+
try src.lexUntil { src in
427+
if src.starts(with: end) {
428428
return true
429429
}
430+
try src.expectNonEmpty(.expected(end))
431+
430432
// Ignore escapes if we're allowed to. lexUntil will consume the next
431433
// character.
432434
if ignoreEscaped, src.tryEat("\\") {
433435
try src.expectNonEmpty(.expectedEscape)
434436
}
435437
return false
436438
}.value
437-
guard !result.isEmpty else {
438-
throw ParseError.expectedNonEmptyContents
439-
}
440-
return result
441439
}
440+
guard !result.value.isEmpty else {
441+
throw ParseError.expectedNonEmptyContents
442+
}
443+
if eatEnding {
444+
try expect(sequence: end)
445+
}
446+
return result
442447
}
443448

444449
/// Try to consume quoted content

0 commit comments

Comments
 (0)