@@ -33,6 +33,8 @@ public struct _CharacterClassModel: Hashable {
33
33
case any
34
34
/// Any grapheme cluster
35
35
case anyGrapheme
36
+ /// Any Unicode scalar
37
+ case anyScalar
36
38
/// Character.isDigit
37
39
case digit
38
40
/// Character.isHexDigit
@@ -159,8 +161,12 @@ public struct _CharacterClassModel: Hashable {
159
161
case . graphemeCluster:
160
162
let c = str [ i]
161
163
var matched : Bool
164
+ var next = str. index ( after: i)
162
165
switch cc {
163
166
case . any, . anyGrapheme: matched = true
167
+ case . anyScalar:
168
+ matched = true
169
+ next = str. unicodeScalars. index ( after: i)
164
170
case . digit:
165
171
matched = c. isNumber && ( c. isASCII || !options. usesASCIIDigits)
166
172
case . hexDigit:
@@ -178,12 +184,13 @@ public struct _CharacterClassModel: Hashable {
178
184
if isInverted {
179
185
matched. toggle ( )
180
186
}
181
- return matched ? str . index ( after : i ) : nil
187
+ return matched ? next : nil
182
188
case . unicodeScalar:
183
189
let c = str. unicodeScalars [ i]
184
190
var matched : Bool
185
191
switch cc {
186
192
case . any: matched = true
193
+ case . anyScalar: matched = true
187
194
case . anyGrapheme: fatalError ( " Not matched in this mode " )
188
195
case . digit:
189
196
matched = c. properties. numericType != nil && ( c. isASCII || !options. usesASCIIDigits)
@@ -228,6 +235,10 @@ extension _CharacterClassModel {
228
235
. init( cc: . anyGrapheme, matchLevel: . graphemeCluster)
229
236
}
230
237
238
+ public static var anyUnicodeScalar : _CharacterClassModel {
239
+ . init( cc: . any, matchLevel: . unicodeScalar)
240
+ }
241
+
231
242
public static var whitespace : _CharacterClassModel {
232
243
. init( cc: . whitespace, matchLevel: . graphemeCluster)
233
244
}
@@ -279,6 +290,7 @@ extension _CharacterClassModel.Representation: CustomStringConvertible {
279
290
switch self {
280
291
case . any: return " <any> "
281
292
case . anyGrapheme: return " <any grapheme> "
293
+ case . anyScalar: return " <any scalar> "
282
294
case . digit: return " <digit> "
283
295
case . hexDigit: return " <hex digit> "
284
296
case . horizontalWhitespace: return " <horizontal whitespace> "
@@ -445,6 +457,7 @@ extension AST.Atom.EscapedBuiltin {
445
457
case . notWordCharacter: return . word. inverted
446
458
447
459
case . graphemeCluster: return . anyGrapheme
460
+ case . trueAnychar: return . anyUnicodeScalar
448
461
449
462
default :
450
463
return nil
0 commit comments