Skip to content

Commit 15f4238

Browse files
committed
Clarify the .multilineCompilerLiteral syntax option
This should always be set in a multi-line literal, with extended syntax potentially being set and unset as we parse.
1 parent bd8368a commit 15f4238

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
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: 2 additions & 2 deletions
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
}
@@ -609,7 +609,7 @@ fileprivate func defaultSyntaxOptions(
609609
// For an extended syntax forward slash e.g #/.../#, extended syntax is
610610
// permitted if it spans multiple lines.
611611
if delim.poundCount > 0 && contents.spansMultipleLinesInRegexLiteral {
612-
return .multilineExtendedSyntax
612+
return [.multilineCompilerLiteral, .extendedSyntax]
613613
}
614614
return .traditional
615615
case .reSingleQuote:

Sources/_RegexParser/Regex/Parse/SyntaxOptions.swift

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

61-
/// The default syntax for a multi-line regex literal.
62-
public static var multilineExtendedSyntax: Self {
63-
return [Self(1 << 6), .extendedSyntax]
64-
}
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) }
6565

6666
/// `(?n)`
6767
public static var namedCapturesOnly: Self { Self(1 << 7) }

0 commit comments

Comments
 (0)