22Copyright © 2023-2025 François G. Dorais. All rights reserved.
33Released under Apache 2.0 license as described in the file LICENSE.
44-/
5-
5+ module
6+ public section
67/-- Low-level conversion from `UInt32` to `Char` (*unsafe* )
78
89 This function translates to a no-op in the compiler. However, it does not
@@ -204,6 +205,7 @@ deriving DecidableEq
204205/-- General category (GC)
205206
206207 Unicode property: `General_Category` -/
208+ @[expose]
207209def GC := UInt32 deriving DecidableEq, Inhabited
208210
209211namespace GC
@@ -271,22 +273,22 @@ protected def Cn : GC := (0x20000000 : UInt32)
271273protected def C : GC := .Cc ||| .Cf ||| .Cs ||| .Co ||| .Cn
272274
273275def mk : (major : MajorGeneralCategory) → Option (MinorGeneralCategory major) → GC
274- | .letter, none => .L
276+ | .letter, . none => .L
275277| _, some .casedLetter => .LC
276278| _, some .uppercaseLetter => .Lu
277279| _, some .lowercaseLetter => .Ll
278280| _, some .titlecaseLetter => .Lt
279281| _, some .modifierLetter => .Lm
280282| _, some .otherLetter => .Lo
281- | .mark, none => .M
283+ | .mark, . none => .M
282284| _, some .nonspacingMark => .Mn
283285| _, some .spacingMark => .Mc
284286| _, some .enclosingMark => .Me
285- | .number, none => .N
287+ | .number, . none => .N
286288| _, some .decimalNumber => .Nd
287289| _, some .letterNumber => .Nl
288290| _, some .otherNumber => .No
289- | .punctuation, none => .P
291+ | .punctuation, . none => .P
290292| _, some .connectorPunctuation => .Pc
291293| _, some .dashPunctuation => .Pd
292294| _, some .groupPunctuation => .PG
@@ -296,16 +298,16 @@ def mk : (major : MajorGeneralCategory) → Option (MinorGeneralCategory major)
296298| _, some .initialPunctuation => .Pi
297299| _, some .finalPunctuation => .Pf
298300| _, some .otherPunctuation => .Po
299- | .symbol, none => .S
301+ | .symbol, . none => .S
300302| _, some .mathSymbol => .Sm
301303| _, some .currencySymbol => .Sc
302304| _, some .modifierSymbol => .Sk
303305| _, some .otherSymbol => .So
304- | .separator, none => .Z
306+ | .separator, . none => .Z
305307| _, some .spaceSeparator => .Zs
306308| _, some .lineSeparator => .Zl
307309| _, some .paragraphSeparator => .Zp
308- | .other, none => .C
310+ | .other, . none => .C
309311| _, some .control => .Cc
310312| _, some .format => .Cf
311313| _, some .surrogate => .Cs
@@ -412,11 +414,12 @@ def toAbbrev! (x : GC) : String :=
412414 | [a] => a
413415 | _ => panic! "invalid general category"
414416
415- open Std.Format Repr in instance : Repr GC where
416- reprPrec x := addAppParen (group (joinSep (reprAux x |>.map (text "Unicode.GC." ++ text ·)) (text " |||" ++ line)) .fill)
417+ open Std.Format Repr in
418+ def reprPrec (x : GC) := addAppParen (group (joinSep (reprAux x |>.map (text "Unicode.GC." ++ text ·)) (text " |||" ++ line)) .fill)
419+ instance : Repr GC where reprPrec
417420
418- instance : ToString GC where
419- toString x := " | " .intercalate (reprAux x)
421+ def toString (x : GC) := " | " .intercalate (reprAux x)
422+ instance : ToString GC where toString
420423
421424def ofAbbrev? (s : String.Slice) : Option GC :=
422425 match s.chars.take 3 |>.toList with
@@ -464,8 +467,8 @@ def ofAbbrev? (s : String.Slice) : Option GC :=
464467
465468def ofAbbrev! (s : String.Slice) : GC :=
466469 match ofAbbrev? s with
467- | some c => c
468- | none => panic! "invalid general category"
470+ | . some c => c
471+ | . none => panic! "invalid general category"
469472
470473def ofString? (s : String.Slice) : Option GC := do
471474 let mut c := .none
@@ -475,8 +478,8 @@ def ofString? (s : String.Slice) : Option GC := do
475478
476479def ofString! (s : String.Slice) : GC :=
477480 match ofString? s with
478- | some c => c
479- | none => panic! "invalid general category"
481+ | . some c => c
482+ | . none => panic! "invalid general category"
480483
481484end GC
482485
@@ -1012,3 +1015,4 @@ instance : Repr BidiClass where
10121015 reprPrec bc _ := s! "Unicode.BidiClass.{ bc.toAbbrev} "
10131016
10141017end Unicode
1018+ end
0 commit comments