Skip to content

Commit 7cc7c3b

Browse files
committed
Add delimiter parsing support to Regex(_regexString:version:)
Add a new overload of the compiler intrinsic initializer for Regex initialization that allows for a versioned argument, and use it to start parsing a string with delimiters, which allows the syntax options to be picked up at runtime.
1 parent ae12822 commit 7cc7c3b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Sources/_StringProcessing/RegexDSL/Core.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ public struct Regex<Capture>: RegexProtocol {
4747
self.init(ast: try! parse(pattern, .traditional))
4848
}
4949

50+
// Compiler interface. Do not change independently.
51+
@usableFromInline
52+
init(_regexString pattern: String, version: Int) {
53+
assert(version == currentRegexLiteralFormatVersion)
54+
// The version argument is passed by the compiler using the value defined
55+
// in libswiftParseRegexLiteral.
56+
self.init(ast: try! parseWithDelimiters(pattern))
57+
}
58+
5059
public init<Content: RegexProtocol>(
5160
_ content: Content
5261
) where Content.Capture == Capture {

0 commit comments

Comments
 (0)