@@ -28,13 +28,6 @@ internal protocol _BuiltinRegexComponent: RegexComponent {
28
28
init ( _ regex: Regex < RegexOutput > )
29
29
}
30
30
31
- @available ( SwiftStdlib 5 . 7 , * )
32
- extension _BuiltinRegexComponent {
33
- init ( node: DSLTree . Node ) {
34
- self . init ( Regex ( node: node) )
35
- }
36
- }
37
-
38
31
// MARK: - Primitive regex components
39
32
40
33
@available ( SwiftStdlib 5 . 7 , * )
@@ -56,7 +49,7 @@ extension Character: RegexComponent {
56
49
public typealias Output = Substring
57
50
58
51
public var regex : Regex < Output > {
59
- . init ( node : . atom ( . char( self ) ) )
52
+ _RegexFactory ( ) . char ( self )
60
53
}
61
54
}
62
55
@@ -65,7 +58,7 @@ extension UnicodeScalar: RegexComponent {
65
58
public typealias Output = Substring
66
59
67
60
public var regex : Regex < Output > {
68
- . init ( node : . atom ( . scalar( self ) ) )
61
+ _RegexFactory ( ) . scalar ( self )
69
62
}
70
63
}
71
64
@@ -90,39 +83,6 @@ extension UnicodeScalar: RegexComponent {
90
83
91
84
// Note: Quantifiers are currently gyb'd.
92
85
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
-
126
86
/// A regex component that matches exactly one occurrence of its underlying
127
87
/// component.
128
88
@available ( SwiftStdlib 5 . 7 , * )
@@ -140,6 +100,7 @@ public struct One<Output>: RegexComponent {
140
100
public struct OneOrMore < Output> : _BuiltinRegexComponent {
141
101
public var regex : Regex < Output >
142
102
103
+ @usableFromInline
143
104
internal init ( _ regex: Regex < Output > ) {
144
105
self . regex = regex
145
106
}
@@ -152,6 +113,7 @@ public struct OneOrMore<Output>: _BuiltinRegexComponent {
152
113
public struct ZeroOrMore < Output> : _BuiltinRegexComponent {
153
114
public var regex : Regex < Output >
154
115
116
+ @usableFromInline
155
117
internal init ( _ regex: Regex < Output > ) {
156
118
self . regex = regex
157
119
}
@@ -164,6 +126,7 @@ public struct ZeroOrMore<Output>: _BuiltinRegexComponent {
164
126
public struct Optionally < Output> : _BuiltinRegexComponent {
165
127
public var regex : Regex < Output >
166
128
129
+ @usableFromInline
167
130
internal init ( _ regex: Regex < Output > ) {
168
131
self . regex = regex
169
132
}
@@ -176,6 +139,7 @@ public struct Optionally<Output>: _BuiltinRegexComponent {
176
139
public struct Repeat < Output> : _BuiltinRegexComponent {
177
140
public var regex : Regex < Output >
178
141
142
+ @usableFromInline
179
143
internal init ( _ regex: Regex < Output > ) {
180
144
self . regex = regex
181
145
}
@@ -217,6 +181,7 @@ public struct AlternationBuilder {
217
181
public struct ChoiceOf < Output> : _BuiltinRegexComponent {
218
182
public var regex : Regex < Output >
219
183
184
+ @usableFromInline
220
185
internal init ( _ regex: Regex < Output > ) {
221
186
self . regex = regex
222
187
}
@@ -232,6 +197,7 @@ public struct ChoiceOf<Output>: _BuiltinRegexComponent {
232
197
public struct Capture < Output> : _BuiltinRegexComponent {
233
198
public var regex : Regex < Output >
234
199
200
+ @usableFromInline
235
201
internal init ( _ regex: Regex < Output > ) {
236
202
self . regex = regex
237
203
}
@@ -243,6 +209,7 @@ public struct Capture<Output>: _BuiltinRegexComponent {
243
209
public struct TryCapture < Output> : _BuiltinRegexComponent {
244
210
public var regex : Regex < Output >
245
211
212
+ @usableFromInline
246
213
internal init ( _ regex: Regex < Output > ) {
247
214
self . regex = regex
248
215
}
@@ -260,6 +227,7 @@ public struct TryCapture<Output>: _BuiltinRegexComponent {
260
227
public struct Local < Output> : _BuiltinRegexComponent {
261
228
public var regex : Regex < Output >
262
229
230
+ @usableFromInline
263
231
internal init ( _ regex: Regex < Output > ) {
264
232
self . regex = regex
265
233
}
@@ -274,8 +242,13 @@ public struct Reference<Capture>: RegexComponent {
274
242
275
243
public init ( _ captureType: Capture . Type = Capture . self) { }
276
244
245
+ @usableFromInline
246
+ var _raw : Int {
247
+ id. _raw
248
+ }
249
+
277
250
public var regex : Regex < Capture > {
278
- . init ( node : . atom ( . symbolicReference( id) ) )
251
+ _RegexFactory ( ) . symbolicReference ( id)
279
252
}
280
253
}
281
254
@@ -285,3 +258,12 @@ extension Regex.Match {
285
258
self [ reference. id]
286
259
}
287
260
}
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