Skip to content

Commit 7bdc6c6

Browse files
committed
Differentiate between .multilineLiteral and .multilineExtendedSyntax
The former should always be set in a multi-line literal, the latter may be partially unset when extended syntax is disabled in a multi-line literal.
1 parent 917d30d commit 7bdc6c6

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

Sources/_RegexParser/Regex/Parse/LexicalAnalysis.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ extension Source {
597597
}.value
598598

599599
// In multi-line literals, the quote may not span multiple lines.
600-
if context.syntax.contains(.multilineExtendedSyntax),
600+
if context.syntax.contains(.multilineLiteral),
601601
contents.spansMultipleLinesInRegexLiteral {
602602
throw ParseError.quoteMayNotSpanMultipleLines
603603
}
@@ -836,8 +836,7 @@ extension Source {
836836
throw ParseError.cannotRemoveSemanticsOptions
837837
}
838838
// Extended syntax may not be removed if in multi-line mode.
839-
if context.syntax.contains(.multilineExtendedSyntax) &&
840-
opt.isAnyExtended {
839+
if context.syntax.contains(.multilineLiteral) && opt.isAnyExtended {
841840
throw ParseError.cannotRemoveExtendedSyntaxInMultilineMode
842841
}
843842
removing.append(opt)

Sources/_RegexParser/Regex/Parse/Parse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ extension Parser {
317317
// engines such as Oniguruma, Java, and ICU do this under (?x). Therefore,
318318
// treat (?x) and (?xx) as the same option here. If we ever get a strict
319319
// PCRE mode, we will need to change this to handle that.
320-
if !context.syntax.contains(.multilineExtendedSyntax) {
320+
if !context.syntax.contains(.multilineLiteral) {
321321
mapOption(.extendedSyntax, \.isAnyExtended)
322322
}
323323
}

Sources/_RegexParser/Regex/Parse/SyntaxOptions.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,14 @@ public struct SyntaxOptions: OptionSet {
5858
/// `(_: .*)` == `(?:.*)`
5959
public static var experimentalCaptures: Self { Self(1 << 5) }
6060

61+
/// The syntax kind of a multi-line literal. This will always be set when
62+
/// parsing a multi-line literal. Note this does not imply extended syntax,
63+
/// as that may be temporarily disabled while parsing.
64+
public static var multilineLiteral: Self { Self(1 << 6) }
65+
6166
/// The default syntax for a multi-line regex literal.
6267
public static var multilineExtendedSyntax: Self {
63-
return [Self(1 << 6), .extendedSyntax]
68+
return [.multilineLiteral, .extendedSyntax]
6469
}
6570

6671
/// `(?n)`

0 commit comments

Comments
 (0)