Skip to content

Commit 665e51f

Browse files
authored
chore: cleanup for v2 (#99)
1 parent 603cc6e commit 665e51f

13 files changed

Lines changed: 456 additions & 1034 deletions

UnicodeBasic.lean

Lines changed: 72 additions & 218 deletions
Large diffs are not rendered by default.

UnicodeBasic/CharacterDatabase.lean

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
-/
55
module
66

7-
public section
8-
97
namespace Unicode
108

119
/-- Stream type for Unicode Character Database (UCD) files
@@ -15,31 +13,31 @@ namespace Unicode
1513
around field values are not significant. Line comments are prefixed with a
1614
number sign `#` (U+0023).
1715
-/
18-
structure UCDStream extends String.Slice where
16+
public structure UCDStream extends String.Slice where
1917
/-- `isUnihan` is true if the records are tab separated -/
2018
isUnihan := false
2119
deriving Inhabited
2220

2321
namespace UCDStream
2422

2523
/-- Make a `UCDStream` from a string slice -/
26-
def ofStringSlice (str : String.Slice) : UCDStream := { str with }
24+
public def ofStringSlice (str : String.Slice) : UCDStream := { str with }
2725

2826
/-- Make a `UCDStream` from a string -/
29-
def ofString (str : String) : UCDStream := ofStringSlice str.toSlice
27+
public def ofString (str : String) : UCDStream := ofStringSlice str.toSlice
3028

3129
/-- Make a `UCDStream` from a substring -/
32-
def ofSubstring (str : Substring.Raw) : UCDStream := ofStringSlice str.toString.toSlice
30+
public def ofSubstring (str : Substring.Raw) : UCDStream := ofStringSlice str.toString.toSlice
3331

3432
/-- Make a `UCDStream` from a file -/
35-
def ofFile (path : System.FilePath) : IO UCDStream :=
33+
public def ofFile (path : System.FilePath) : IO UCDStream :=
3634
ofString <$> IO.FS.readFile path
3735

3836
/-- Get the next line from the `UCDStream`
3937
4038
Line comments are stripped and blank lines are skipped.
4139
-/
42-
protected partial def nextLine? (stream : UCDStream) : Option (String.Slice × UCDStream) := do
40+
public protected partial def nextLine? (stream : UCDStream) : Option (String.Slice × UCDStream) := do
4341
let line := stream.trimAsciiEnd.takeWhile (.!='\n')
4442
if h : line.rawEndPos < stream.rawEndPos then
4543
let nextPos := stream.posGT line.rawEndPos h
@@ -54,13 +52,13 @@ protected partial def nextLine? (stream : UCDStream) : Option (String.Slice × U
5452
5553
Spaces around field values are trimmed.
5654
-/
57-
protected def next? (stream : UCDStream) : Option (Array String.Slice × UCDStream) := do
55+
public protected def next? (stream : UCDStream) : Option (Array String.Slice × UCDStream) := do
5856
let sep := if stream.isUnihan then "\t" else ";"
5957
let mut arr := #[]
6058
let (line, table) ← stream.nextLine?
6159
for item in line.split sep do
6260
arr := arr.push item.trimAscii
6361
return (arr, table)
6462

65-
instance : Std.Stream UCDStream (Array String.Slice) where
63+
public instance : Std.Stream UCDStream (Array String.Slice) where
6664
next? := UCDStream.next?

UnicodeBasic/Hangul.lean

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,67 +4,65 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
-/
55
module
66

7-
public section
8-
97
namespace Unicode.Hangul
108

11-
def shortNameL : Array String :=
9+
public def shortNameL : Array String :=
1210
#["G", "GG", "N", "D", "DD", "R", "M", "B", "BB", "S",
1311
"SS", "", "J", "JJ", "C", "K", "T", "P", "H"]
1412

15-
def shortNameV : Array String :=
13+
public def shortNameV : Array String :=
1614
#["A", "AE", "YA", "YAE", "EO", "E", "YEO", "YE", "O", "WA",
1715
"WAE", "OE", "YO", "U", "WEO", "WE", "WI", "YU", "EU", "YI",
1816
"I"]
1917

20-
def shortNameT : Array String :=
18+
public def shortNameT : Array String :=
2119
#["", "G", "GG", "GS", "N", "NJ", "NH", "D", "L", "LG",
2220
"LM", "LB", "LS", "LT", "LP", "LH", "M", "B", "BS", "S",
2321
"SS", "NG", "J", "C", "K", "T", "P", "H"]
2422

25-
abbrev sizeL := shortNameL.size -- 19
26-
abbrev sizeV := shortNameV.size -- 21
27-
abbrev sizeT := shortNameT.size -- 28
28-
abbrev sizeLV := sizeL * sizeV -- 399
29-
abbrev sizeVT := sizeV * sizeT -- 588
30-
abbrev sizeLVT := sizeL * sizeV * sizeT -- 11172
23+
public abbrev sizeL := shortNameL.size -- 19
24+
public abbrev sizeV := shortNameV.size -- 21
25+
public abbrev sizeT := shortNameT.size -- 28
26+
public abbrev sizeLV := sizeL * sizeV -- 399
27+
public abbrev sizeVT := sizeV * sizeT -- 588
28+
public abbrev sizeLVT := sizeL * sizeV * sizeT -- 11172
3129

32-
abbrev baseL : UInt32 := 0x1100
33-
abbrev baseV : UInt32 := 0x1161
34-
abbrev baseT : UInt32 := 0x11A7
30+
public abbrev baseL : UInt32 := 0x1100
31+
public abbrev baseV : UInt32 := 0x1161
32+
public abbrev baseT : UInt32 := 0x11A7
3533

3634
/-- Number of Hangul syllables -/
37-
def Syllable.size := sizeLVT
35+
public def Syllable.size := sizeLVT
3836

3937
/-- Starting code point for Hangul syllables -/
40-
def Syllable.base : UInt32 := 0xAC00
38+
public def Syllable.base : UInt32 := 0xAC00
4139

4240
/-- Stopping code point for Hangul syllables -/
43-
def Syllable.last : UInt32 := ⟨0xAC00 + Syllable.size - 1, by decide⟩
41+
public def Syllable.last : UInt32 := ⟨0xAC00 + Syllable.size - 1, by decide⟩
4442

4543
/-- Hangul syllable type -/
46-
structure Syllable where
44+
public structure Syllable where
4745
/-- L part of syllable -/
48-
toL : Fin sizeL
46+
public toL : Fin sizeL
4947
/-- V part of syllable -/
50-
toV : Fin sizeV
48+
public toV : Fin sizeV
5149
/-- T part of syllable (0 means none) -/
52-
toT : Fin sizeT := ⟨0, by decide⟩
50+
public toT : Fin sizeT := ⟨0, by decide⟩
5351
deriving DecidableEq, Repr
5452

55-
instance : Inhabited Syllable where
53+
public instance : Inhabited Syllable where
5654
default := ⟨⟨0, by decide⟩, ⟨0, by decide⟩, ⟨0, by decide⟩⟩
5755

5856
/-- LV part of syllable -/
59-
def Syllable.toLV : Syllable → Fin sizeLV
57+
public def Syllable.toLV : Syllable → Fin sizeLV
6058
| ⟨⟨l, hl⟩, ⟨v, hv⟩, _⟩ =>
6159
have : l * sizeV + v < sizeLV := calc
6260
_ < l * sizeV + sizeV := by apply Nat.add_lt_add_left; exact hv
6361
_ = (l + 1) * sizeV := by rw [Nat.add_one_mul]
6462
_ ≤ sizeL * sizeV := by apply Nat.mul_le_mul_right; exact hl
6563
⟨l * sizeV + v, this⟩
6664

67-
def Syllable.index (s : Syllable) : Fin Syllable.size :=
65+
public def Syllable.index (s : Syllable) : Fin Syllable.size :=
6866
match s.toLV, s.toT with
6967
| ⟨lv, hlv⟩, ⟨t, ht⟩ =>
7068
have : lv * sizeT + t < sizeL * sizeV * sizeT := calc
@@ -75,27 +73,27 @@ def Syllable.index (s : Syllable) : Fin Syllable.size :=
7573

7674
/-- Get short name for Hangul syllable -/
7775
@[inline]
78-
def Syllable.getShortName (s : Syllable) : String := shortNameL[s.toL] ++ shortNameV[s.toV] ++ shortNameT[s.toT]
76+
public def Syllable.getShortName (s : Syllable) : String := shortNameL[s.toL] ++ shortNameV[s.toV] ++ shortNameT[s.toT]
7977

8078
/-- Get L part character for syllable -/
81-
def Syllable.getLChar (s : Syllable) : Char :=
79+
public def Syllable.getLChar (s : Syllable) : Char :=
8280
.ofNat (baseL.toNat + s.toL)
8381

8482
/-- Get V part character for syllable -/
85-
def Syllable.getVChar (s : Syllable) : Char :=
83+
public def Syllable.getVChar (s : Syllable) : Char :=
8684
.ofNat (baseV.toNat + s.toV)
8785

8886
/-- Get LV part character for syllable -/
89-
def Syllable.getLVChar (s : Syllable) : Char :=
87+
public def Syllable.getLVChar (s : Syllable) : Char :=
9088
.ofNat (base.toNat + sizeT * s.toLV)
9189

9290
/-- Get T part character for syllable -/
93-
def Syllable.getTChar? (s : Syllable) : Option Char :=
91+
public def Syllable.getTChar? (s : Syllable) : Option Char :=
9492
if s.toT.val == 0 then none else
9593
return .ofNat (baseT.toNat + s.toT)
9694

9795
/-- Get Hangul syllable from code point -/
98-
def getSyllable? (code : UInt32) : Option Syllable :=
96+
public def getSyllable? (code : UInt32) : Option Syllable :=
9997
if code < 0xAC00 then none else
10098
let index := (code - 0xAC00).toNat
10199
if h : index ≥ Syllable.size then none else
@@ -111,7 +109,7 @@ def getSyllable? (code : UInt32) : Option Syllable :=
111109
some ⟨⟨lpart, lislt⟩, ⟨vpart, vislt⟩, ⟨tpart, tislt⟩⟩
112110

113111
@[inherit_doc getSyllable?]
114-
def getSyllable! (code : UInt32) : Syllable :=
112+
public def getSyllable! (code : UInt32) : Syllable :=
115113
match getSyllable? code with
116114
| some s => s
117115
| none => panic! "not a Hangul syllable"

0 commit comments

Comments
 (0)