Skip to content

Commit 2637691

Browse files
authored
Merge pull request #69 from rxwei/regex-string-initializer
Add 'init(_regexString:)' for compiler integration.
2 parents 67c4de8 + 32a945f commit 2637691

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
@@ -12,9 +12,11 @@ public protocol RegexProtocol {
1212
}
1313

1414
/// A regular expression.
15+
@frozen
1516
public struct Regex<Capture>: RegexProtocol {
1617
/// A program representation that caches any lowered representation for
1718
/// execution.
19+
@usableFromInline
1820
internal class Program {
1921
/// The underlying AST.
2022
let ast: AST
@@ -34,13 +36,20 @@ public struct Regex<Capture>: RegexProtocol {
3436
}
3537
}
3638

39+
@usableFromInline
3740
let program: Program
3841
var ast: AST { program.ast }
3942

4043
init(ast: AST) {
4144
self.program = Program(ast: ast)
4245
}
4346

47+
// Compiler interface. Do not change independently.
48+
@usableFromInline
49+
init(_regexString pattern: String) {
50+
self.init(ast: try! parse(pattern, .traditional))
51+
}
52+
4453
public init<Content: RegexProtocol>(
4554
_ content: Content
4655
) where Content.Capture == Capture {

0 commit comments

Comments
 (0)