@@ -28,13 +28,6 @@ internal protocol _BuiltinRegexComponent: RegexComponent {
2828 init ( _ regex: Regex < RegexOutput > )
2929}
3030
31- @available ( SwiftStdlib 5 . 7 , * )
32- extension _BuiltinRegexComponent {
33- init ( node: DSLTree . Node ) {
34- self . init ( Regex ( node: node) )
35- }
36- }
37-
3831// MARK: - Primitive regex components
3932
4033@available ( SwiftStdlib 5 . 7 , * )
@@ -56,7 +49,7 @@ extension Character: RegexComponent {
5649 public typealias Output = Substring
5750
5851 public var regex : Regex < Output > {
59- . init ( node : . atom ( . char( self ) ) )
52+ _RegexFactory ( ) . char ( self )
6053 }
6154}
6255
@@ -65,7 +58,7 @@ extension UnicodeScalar: RegexComponent {
6558 public typealias Output = Substring
6659
6760 public var regex : Regex < Output > {
68- . init ( node : . atom ( . scalar( self ) ) )
61+ _RegexFactory ( ) . scalar ( self )
6962 }
7063}
7164
@@ -90,39 +83,6 @@ extension UnicodeScalar: RegexComponent {
9083
9184// Note: Quantifiers are currently gyb'd.
9285
93- extension DSLTree . Node {
94- // Individual public API functions are in the generated Variadics.swift file.
95- /// Generates a DSL tree node for a repeated range of the given node.
96- @available ( SwiftStdlib 5 . 7 , * )
97- static func repeating(
98- _ range: Range < Int > ,
99- _ behavior: RegexRepetitionBehavior ? ,
100- _ node: DSLTree . Node
101- ) -> DSLTree . Node {
102- // TODO: Throw these as errors
103- assert ( range. lowerBound >= 0 , " Cannot specify a negative lower bound " )
104- assert ( !range. isEmpty, " Cannot specify an empty range " )
105-
106- let kind : DSLTree . QuantificationKind = behavior. map { . explicit( $0. dslTreeKind) } ?? . default
107-
108- switch ( range. lowerBound, range. upperBound) {
109- case ( 0 , Int . max) : // 0...
110- return . quantification( . zeroOrMore, kind, node)
111- case ( 1 , Int . max) : // 1...
112- return . quantification( . oneOrMore, kind, node)
113- case _ where range. count == 1 : // ..<1 or ...0 or any range with count == 1
114- // Note: `behavior` is ignored in this case
115- return . quantification( . exactly( range. lowerBound) , . default, node)
116- case ( 0 , _) : // 0..<n or 0...n or ..<n or ...n
117- return . quantification( . upToN( range. upperBound) , kind, node)
118- case ( _, Int . max) : // n...
119- return . quantification( . nOrMore( range. lowerBound) , kind, node)
120- default : // any other range
121- return . quantification( . range( range. lowerBound, range. upperBound) , kind, node)
122- }
123- }
124- }
125-
12686/// A regex component that matches exactly one occurrence of its underlying
12787/// component.
12888@available ( SwiftStdlib 5 . 7 , * )
@@ -140,6 +100,7 @@ public struct One<Output>: RegexComponent {
140100public struct OneOrMore < Output> : _BuiltinRegexComponent {
141101 public var regex : Regex < Output >
142102
103+ @usableFromInline
143104 internal init ( _ regex: Regex < Output > ) {
144105 self . regex = regex
145106 }
@@ -152,6 +113,7 @@ public struct OneOrMore<Output>: _BuiltinRegexComponent {
152113public struct ZeroOrMore < Output> : _BuiltinRegexComponent {
153114 public var regex : Regex < Output >
154115
116+ @usableFromInline
155117 internal init ( _ regex: Regex < Output > ) {
156118 self . regex = regex
157119 }
@@ -164,6 +126,7 @@ public struct ZeroOrMore<Output>: _BuiltinRegexComponent {
164126public struct Optionally < Output> : _BuiltinRegexComponent {
165127 public var regex : Regex < Output >
166128
129+ @usableFromInline
167130 internal init ( _ regex: Regex < Output > ) {
168131 self . regex = regex
169132 }
@@ -176,6 +139,7 @@ public struct Optionally<Output>: _BuiltinRegexComponent {
176139public struct Repeat < Output> : _BuiltinRegexComponent {
177140 public var regex : Regex < Output >
178141
142+ @usableFromInline
179143 internal init ( _ regex: Regex < Output > ) {
180144 self . regex = regex
181145 }
@@ -217,6 +181,7 @@ public struct AlternationBuilder {
217181public struct ChoiceOf < Output> : _BuiltinRegexComponent {
218182 public var regex : Regex < Output >
219183
184+ @usableFromInline
220185 internal init ( _ regex: Regex < Output > ) {
221186 self . regex = regex
222187 }
@@ -232,6 +197,7 @@ public struct ChoiceOf<Output>: _BuiltinRegexComponent {
232197public struct Capture < Output> : _BuiltinRegexComponent {
233198 public var regex : Regex < Output >
234199
200+ @usableFromInline
235201 internal init ( _ regex: Regex < Output > ) {
236202 self . regex = regex
237203 }
@@ -243,6 +209,7 @@ public struct Capture<Output>: _BuiltinRegexComponent {
243209public struct TryCapture < Output> : _BuiltinRegexComponent {
244210 public var regex : Regex < Output >
245211
212+ @usableFromInline
246213 internal init ( _ regex: Regex < Output > ) {
247214 self . regex = regex
248215 }
@@ -260,6 +227,7 @@ public struct TryCapture<Output>: _BuiltinRegexComponent {
260227public struct Local < Output> : _BuiltinRegexComponent {
261228 public var regex : Regex < Output >
262229
230+ @usableFromInline
263231 internal init ( _ regex: Regex < Output > ) {
264232 self . regex = regex
265233 }
@@ -274,8 +242,13 @@ public struct Reference<Capture>: RegexComponent {
274242
275243 public init ( _ captureType: Capture . Type = Capture . self) { }
276244
245+ @usableFromInline
246+ var _raw : Int {
247+ id. _raw
248+ }
249+
277250 public var regex : Regex < Capture > {
278- . init ( node : . atom ( . symbolicReference( id) ) )
251+ _RegexFactory ( ) . symbolicReference ( id)
279252 }
280253}
281254
@@ -285,3 +258,12 @@ extension Regex.Match {
285258 self [ reference. id]
286259 }
287260}
261+
262+ // RegexFactory's init is SPI, so we can't make an instance of one in AEIC, but
263+ // if we hide it behind a resilience barrier we can call this function instead
264+ // to get our instance of it.
265+ @available ( SwiftStdlib 5 . 7 , * )
266+ @usableFromInline
267+ internal func makeFactory( ) -> _RegexFactory {
268+ _RegexFactory ( )
269+ }
0 commit comments