1515// an AST, but this isn't a natural thing to produce in the context
1616// of parsing or to store in an AST
1717
18- @_spi ( RegexBuilder)
19- public struct _CharacterClassModel : Hashable {
18+ struct _CharacterClassModel : Hashable {
2019 /// The actual character class to match.
2120 var cc : Representation
2221
@@ -28,7 +27,7 @@ public struct _CharacterClassModel: Hashable {
2827 var isInverted : Bool = false
2928
3029 // TODO: Split out builtin character classes into their own type?
31- public enum Representation : Hashable {
30+ enum Representation : Hashable {
3231 /// Any character
3332 case any
3433 /// Any grapheme cluster
@@ -85,7 +84,7 @@ public struct _CharacterClassModel: Hashable {
8584 }
8685
8786 /// Inverts a character class.
88- public var inverted : Self {
87+ var inverted : Self {
8988 return withInversion ( true )
9089 }
9190
@@ -161,51 +160,50 @@ public struct _CharacterClassModel: Hashable {
161160 }
162161}
163162
164- @_spi ( RegexBuilder)
165163extension _CharacterClassModel {
166- public static var any : _CharacterClassModel {
164+ static var any : _CharacterClassModel {
167165 . init( cc: . any, matchLevel: . graphemeCluster)
168166 }
169167
170- public static var anyGrapheme : _CharacterClassModel {
168+ static var anyGrapheme : _CharacterClassModel {
171169 . init( cc: . anyGrapheme, matchLevel: . graphemeCluster)
172170 }
173171
174- public static var anyUnicodeScalar : _CharacterClassModel {
172+ static var anyUnicodeScalar : _CharacterClassModel {
175173 . init( cc: . any, matchLevel: . unicodeScalar)
176174 }
177175
178- public static var whitespace : _CharacterClassModel {
176+ static var whitespace : _CharacterClassModel {
179177 . init( cc: . whitespace, matchLevel: . graphemeCluster)
180178 }
181179
182- public static var digit : _CharacterClassModel {
180+ static var digit : _CharacterClassModel {
183181 . init( cc: . digit, matchLevel: . graphemeCluster)
184182 }
185183
186- public static var hexDigit : _CharacterClassModel {
184+ static var hexDigit : _CharacterClassModel {
187185 . init( cc: . hexDigit, matchLevel: . graphemeCluster)
188186 }
189187
190- public static var horizontalWhitespace : _CharacterClassModel {
188+ static var horizontalWhitespace : _CharacterClassModel {
191189 . init( cc: . horizontalWhitespace, matchLevel: . graphemeCluster)
192190 }
193191
194- public static var newlineSequence : _CharacterClassModel {
192+ static var newlineSequence : _CharacterClassModel {
195193 . init( cc: . newlineSequence, matchLevel: . graphemeCluster)
196194 }
197195
198- public static var verticalWhitespace : _CharacterClassModel {
196+ static var verticalWhitespace : _CharacterClassModel {
199197 . init( cc: . verticalWhitespace, matchLevel: . graphemeCluster)
200198 }
201199
202- public static var word : _CharacterClassModel {
200+ static var word : _CharacterClassModel {
203201 . init( cc: . word, matchLevel: . graphemeCluster)
204202 }
205203}
206204
207205extension _CharacterClassModel . Representation : CustomStringConvertible {
208- public var description : String {
206+ var description : String {
209207 switch self {
210208 case . any: return " <any> "
211209 case . anyGrapheme: return " <any grapheme> "
@@ -222,73 +220,11 @@ extension _CharacterClassModel.Representation: CustomStringConvertible {
222220}
223221
224222extension _CharacterClassModel : CustomStringConvertible {
225- public var description : String {
223+ var description : String {
226224 return " \( isInverted ? " not " : " " ) \( cc) "
227225 }
228226}
229227
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-
292228extension _CharacterClassModel {
293229 func withMatchLevel(
294230 _ level: _CharacterClassModel . MatchLevel
0 commit comments