@@ -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
@@ -155,8 +157,12 @@ public struct _CharacterClassModel: Hashable {
155
157
case . graphemeCluster:
156
158
let c = str [ i]
157
159
var matched : Bool
160
+ var next = str. index ( after: i)
158
161
switch cc {
159
162
case . any, . anyGrapheme: matched = true
163
+ case . anyScalar:
164
+ matched = true
165
+ next = str. unicodeScalars. index ( after: i)
160
166
case . digit:
161
167
matched = c. isNumber && ( c. isASCII || !options. usesASCIIDigits)
162
168
case . hexDigit:
@@ -174,12 +180,13 @@ public struct _CharacterClassModel: Hashable {
174
180
if isInverted {
175
181
matched. toggle ( )
176
182
}
177
- return matched ? str . index ( after : i ) : nil
183
+ return matched ? next : nil
178
184
case . unicodeScalar:
179
185
let c = str. unicodeScalars [ i]
180
186
var matched : Bool
181
187
switch cc {
182
188
case . any: matched = true
189
+ case . anyScalar: matched = true
183
190
case . anyGrapheme: fatalError ( " Not matched in this mode " )
184
191
case . digit:
185
192
matched = c. properties. numericType != nil && ( c. isASCII || !options. usesASCIIDigits)
@@ -224,6 +231,10 @@ extension _CharacterClassModel {
224
231
. init( cc: . anyGrapheme, matchLevel: . graphemeCluster)
225
232
}
226
233
234
+ public static var anyUnicodeScalar : _CharacterClassModel {
235
+ . init( cc: . any, matchLevel: . unicodeScalar)
236
+ }
237
+
227
238
public static var whitespace : _CharacterClassModel {
228
239
. init( cc: . whitespace, matchLevel: . graphemeCluster)
229
240
}
@@ -275,6 +286,7 @@ extension _CharacterClassModel.Representation: CustomStringConvertible {
275
286
switch self {
276
287
case . any: return " <any> "
277
288
case . anyGrapheme: return " <any grapheme> "
289
+ case . anyScalar: return " <any scalar> "
278
290
case . digit: return " <digit> "
279
291
case . hexDigit: return " <hex digit> "
280
292
case . horizontalWhitespace: return " <horizontal whitespace> "
@@ -431,6 +443,7 @@ extension AST.Atom.EscapedBuiltin {
431
443
case . notWordCharacter: return . word. inverted
432
444
433
445
case . graphemeCluster: return . anyGrapheme
446
+ case . trueAnychar: return . anyUnicodeScalar
434
447
435
448
default :
436
449
return nil
0 commit comments