15
15
// an AST, but this isn't a natural thing to produce in the context
16
16
// of parsing or to store in an AST
17
17
18
- @_spi ( RegexBuilder)
19
- public struct _CharacterClassModel : Hashable {
18
+ struct _CharacterClassModel : Hashable {
20
19
/// The actual character class to match.
21
20
var cc : Representation
22
21
@@ -28,7 +27,7 @@ public struct _CharacterClassModel: Hashable {
28
27
var isInverted : Bool = false
29
28
30
29
// TODO: Split out builtin character classes into their own type?
31
- public enum Representation : Hashable {
30
+ enum Representation : Hashable {
32
31
/// Any character
33
32
case any
34
33
/// Any grapheme cluster
@@ -85,7 +84,7 @@ public struct _CharacterClassModel: Hashable {
85
84
}
86
85
87
86
/// Inverts a character class.
88
- public var inverted : Self {
87
+ var inverted : Self {
89
88
return withInversion ( true )
90
89
}
91
90
@@ -161,51 +160,50 @@ public struct _CharacterClassModel: Hashable {
161
160
}
162
161
}
163
162
164
- @_spi ( RegexBuilder)
165
163
extension _CharacterClassModel {
166
- public static var any : _CharacterClassModel {
164
+ static var any : _CharacterClassModel {
167
165
. init( cc: . any, matchLevel: . graphemeCluster)
168
166
}
169
167
170
- public static var anyGrapheme : _CharacterClassModel {
168
+ static var anyGrapheme : _CharacterClassModel {
171
169
. init( cc: . anyGrapheme, matchLevel: . graphemeCluster)
172
170
}
173
171
174
- public static var anyUnicodeScalar : _CharacterClassModel {
172
+ static var anyUnicodeScalar : _CharacterClassModel {
175
173
. init( cc: . any, matchLevel: . unicodeScalar)
176
174
}
177
175
178
- public static var whitespace : _CharacterClassModel {
176
+ static var whitespace : _CharacterClassModel {
179
177
. init( cc: . whitespace, matchLevel: . graphemeCluster)
180
178
}
181
179
182
- public static var digit : _CharacterClassModel {
180
+ static var digit : _CharacterClassModel {
183
181
. init( cc: . digit, matchLevel: . graphemeCluster)
184
182
}
185
183
186
- public static var hexDigit : _CharacterClassModel {
184
+ static var hexDigit : _CharacterClassModel {
187
185
. init( cc: . hexDigit, matchLevel: . graphemeCluster)
188
186
}
189
187
190
- public static var horizontalWhitespace : _CharacterClassModel {
188
+ static var horizontalWhitespace : _CharacterClassModel {
191
189
. init( cc: . horizontalWhitespace, matchLevel: . graphemeCluster)
192
190
}
193
191
194
- public static var newlineSequence : _CharacterClassModel {
192
+ static var newlineSequence : _CharacterClassModel {
195
193
. init( cc: . newlineSequence, matchLevel: . graphemeCluster)
196
194
}
197
195
198
- public static var verticalWhitespace : _CharacterClassModel {
196
+ static var verticalWhitespace : _CharacterClassModel {
199
197
. init( cc: . verticalWhitespace, matchLevel: . graphemeCluster)
200
198
}
201
199
202
- public static var word : _CharacterClassModel {
200
+ static var word : _CharacterClassModel {
203
201
. init( cc: . word, matchLevel: . graphemeCluster)
204
202
}
205
203
}
206
204
207
205
extension _CharacterClassModel . Representation : CustomStringConvertible {
208
- public var description : String {
206
+ var description : String {
209
207
switch self {
210
208
case . any: return " <any> "
211
209
case . anyGrapheme: return " <any grapheme> "
@@ -222,73 +220,11 @@ extension _CharacterClassModel.Representation: CustomStringConvertible {
222
220
}
223
221
224
222
extension _CharacterClassModel : CustomStringConvertible {
225
- public var description : String {
223
+ var description : String {
226
224
return " \( isInverted ? " not " : " " ) \( cc) "
227
225
}
228
226
}
229
227
230
- extension _CharacterClassModel {
231
- public func makeDSLTreeCharacterClass( ) -> DSLTree . CustomCharacterClass ? {
232
- // FIXME: Implement in DSLTree instead of wrapping an AST atom
233
- switch makeAST ( ) {
234
- case . atom( let atom) :
235
- return . init( members: [ . atom( . unconverted( . init( ast: atom) ) ) ] )
236
- default :
237
- return nil
238
- }
239
- }
240
-
241
- internal func makeAST( ) -> AST . Node ? {
242
- let inv = isInverted
243
-
244
- func esc( _ b: AST . Atom . EscapedBuiltin ) -> AST . Node {
245
- escaped ( b)
246
- }
247
-
248
- switch cc {
249
- case . any: return atom ( . any)
250
-
251
- case . digit:
252
- return esc ( inv ? . notDecimalDigit : . decimalDigit)
253
-
254
- case . horizontalWhitespace:
255
- return esc (
256
- inv ? . notHorizontalWhitespace : . horizontalWhitespace)
257
-
258
- // FIXME: newline sequence is not same as \n
259
- case . newlineSequence:
260
- return esc ( inv ? . notNewline : . newline)
261
-
262
- case . whitespace:
263
- return esc ( inv ? . notWhitespace : . whitespace)
264
-
265
- case . verticalWhitespace:
266
- return esc ( inv ? . notVerticalTab : . verticalTab)
267
-
268
- case . word:
269
- return esc ( inv ? . notWordCharacter : . wordCharacter)
270
-
271
- case . anyGrapheme:
272
- return esc ( . graphemeCluster)
273
-
274
- case . hexDigit:
275
- let members : [ AST . CustomCharacterClass . Member ] = [
276
- range_m ( . char( " a " ) , . char( " f " ) ) ,
277
- range_m ( . char( " A " ) , . char( " F " ) ) ,
278
- range_m ( . char( " 0 " ) , . char( " 9 " ) ) ,
279
- ]
280
- let ccc = AST . CustomCharacterClass (
281
- . init( faking: inv ? . inverted : . normal) ,
282
- members,
283
- . fake)
284
-
285
- return . customCharacterClass( ccc)
286
-
287
- default : return nil
288
- }
289
- }
290
- }
291
-
292
228
extension _CharacterClassModel {
293
229
func withMatchLevel(
294
230
_ level: _CharacterClassModel . MatchLevel
0 commit comments