Skip to content

Commit 7edce9a

Browse files
committed
Differentiate between .multilineCompilerLiteral 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 ec4aca6 commit 7edce9a

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

Sources/_RegexParser/Regex/Parse/LexicalAnalysis.swift

Lines changed: 2 additions & 2 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(.multilineCompilerLiteral),
601601
contents.spansMultipleLinesInRegexLiteral {
602602
throw ParseError.quoteMayNotSpanMultipleLines
603603
}
@@ -841,7 +841,7 @@ extension Source {
841841
throw ParseError.cannotRemoveSemanticsOptions
842842
}
843843
// Extended syntax may not be removed if in multi-line mode.
844-
if context.syntax.contains(.multilineExtendedSyntax) &&
844+
if context.syntax.contains(.multilineCompilerLiteral) &&
845845
opt.isAnyExtended {
846846
throw ParseError.cannotRemoveExtendedSyntaxInMultilineMode
847847
}

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(.multilineCompilerLiteral) {
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
63+
/// syntax, as that may be temporarily disabled while parsing.
64+
public static var multilineCompilerLiteral: 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 [.multilineCompilerLiteral, .extendedSyntax]
6469
}
6570

6671
/// `(?n)`

0 commit comments

Comments
 (0)