]> git.proxmox.com Git - rustc.git/blob - src/etc/unicode.py
Imported Upstream version 1.0.0~beta.3
[rustc.git] / src / etc / unicode.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2011-2013 The Rust Project Developers. See the COPYRIGHT
4 # file at the top-level directory of this distribution and at
5 # http://rust-lang.org/COPYRIGHT.
6 #
7 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
8 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
9 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
10 # option. This file may not be copied, modified, or distributed
11 # except according to those terms.
12
13 # This script uses the following Unicode tables:
14 # - DerivedCoreProperties.txt
15 # - DerivedNormalizationProps.txt
16 # - EastAsianWidth.txt
17 # - auxiliary/GraphemeBreakProperty.txt
18 # - PropList.txt
19 # - ReadMe.txt
20 # - Scripts.txt
21 # - UnicodeData.txt
22 #
23 # Since this should not require frequent updates, we just store this
24 # out-of-line and check the unicode.rs file into git.
25
26 import fileinput, re, os, sys, operator
27
28 preamble = '''// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
29 // file at the top-level directory of this distribution and at
30 // http://rust-lang.org/COPYRIGHT.
31 //
32 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
33 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
34 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
35 // option. This file may not be copied, modified, or distributed
36 // except according to those terms.
37
38 // NOTE: The following code was generated by "src/etc/unicode.py", do not edit directly
39
40 #![allow(missing_docs, non_upper_case_globals, non_snake_case)]
41 '''
42
43 # Mapping taken from Table 12 from:
44 # http://www.unicode.org/reports/tr44/#General_Category_Values
45 expanded_categories = {
46 'Lu': ['LC', 'L'], 'Ll': ['LC', 'L'], 'Lt': ['LC', 'L'],
47 'Lm': ['L'], 'Lo': ['L'],
48 'Mn': ['M'], 'Mc': ['M'], 'Me': ['M'],
49 'Nd': ['N'], 'Nl': ['N'], 'No': ['No'],
50 'Pc': ['P'], 'Pd': ['P'], 'Ps': ['P'], 'Pe': ['P'],
51 'Pi': ['P'], 'Pf': ['P'], 'Po': ['P'],
52 'Sm': ['S'], 'Sc': ['S'], 'Sk': ['S'], 'So': ['S'],
53 'Zs': ['Z'], 'Zl': ['Z'], 'Zp': ['Z'],
54 'Cc': ['C'], 'Cf': ['C'], 'Cs': ['C'], 'Co': ['C'], 'Cn': ['C'],
55 }
56
57 # these are the surrogate codepoints, which are not valid rust characters
58 surrogate_codepoints = (0xd800, 0xdfff)
59
60 def fetch(f):
61 if not os.path.exists(os.path.basename(f)):
62 os.system("curl -O http://www.unicode.org/Public/UNIDATA/%s"
63 % f)
64
65 if not os.path.exists(os.path.basename(f)):
66 sys.stderr.write("cannot load %s" % f)
67 exit(1)
68
69 def is_surrogate(n):
70 return surrogate_codepoints[0] <= n <= surrogate_codepoints[1]
71
72 def load_unicode_data(f):
73 fetch(f)
74 gencats = {}
75 upperlower = {}
76 lowerupper = {}
77 combines = {}
78 canon_decomp = {}
79 compat_decomp = {}
80
81 udict = {};
82 range_start = -1;
83 for line in fileinput.input(f):
84 data = line.split(';');
85 if len(data) != 15:
86 continue
87 cp = int(data[0], 16);
88 if is_surrogate(cp):
89 continue
90 if range_start >= 0:
91 for i in xrange(range_start, cp):
92 udict[i] = data;
93 range_start = -1;
94 if data[1].endswith(", First>"):
95 range_start = cp;
96 continue;
97 udict[cp] = data;
98
99 for code in udict:
100 [code_org, name, gencat, combine, bidi,
101 decomp, deci, digit, num, mirror,
102 old, iso, upcase, lowcase, titlecase ] = udict[code];
103
104 # generate char to char direct common and simple conversions
105 # uppercase to lowercase
106 if gencat == "Lu" and lowcase != "" and code_org != lowcase:
107 upperlower[code] = int(lowcase, 16)
108
109 # lowercase to uppercase
110 if gencat == "Ll" and upcase != "" and code_org != upcase:
111 lowerupper[code] = int(upcase, 16)
112
113 # store decomposition, if given
114 if decomp != "":
115 if decomp.startswith('<'):
116 seq = []
117 for i in decomp.split()[1:]:
118 seq.append(int(i, 16))
119 compat_decomp[code] = seq
120 else:
121 seq = []
122 for i in decomp.split():
123 seq.append(int(i, 16))
124 canon_decomp[code] = seq
125
126 # place letter in categories as appropriate
127 for cat in [gencat, "Assigned"] + expanded_categories.get(gencat, []):
128 if cat not in gencats:
129 gencats[cat] = []
130 gencats[cat].append(code)
131
132 # record combining class, if any
133 if combine != "0":
134 if combine not in combines:
135 combines[combine] = []
136 combines[combine].append(code)
137
138 # generate Not_Assigned from Assigned
139 gencats["Cn"] = gen_unassigned(gencats["Assigned"])
140 # Assigned is not a real category
141 del(gencats["Assigned"])
142 # Other contains Not_Assigned
143 gencats["C"].extend(gencats["Cn"])
144 gencats = group_cats(gencats)
145 combines = to_combines(group_cats(combines))
146
147 return (canon_decomp, compat_decomp, gencats, combines, lowerupper, upperlower)
148
149 def group_cats(cats):
150 cats_out = {}
151 for cat in cats:
152 cats_out[cat] = group_cat(cats[cat])
153 return cats_out
154
155 def group_cat(cat):
156 cat_out = []
157 letters = sorted(set(cat))
158 cur_start = letters.pop(0)
159 cur_end = cur_start
160 for letter in letters:
161 assert letter > cur_end, \
162 "cur_end: %s, letter: %s" % (hex(cur_end), hex(letter))
163 if letter == cur_end + 1:
164 cur_end = letter
165 else:
166 cat_out.append((cur_start, cur_end))
167 cur_start = cur_end = letter
168 cat_out.append((cur_start, cur_end))
169 return cat_out
170
171 def ungroup_cat(cat):
172 cat_out = []
173 for (lo, hi) in cat:
174 while lo <= hi:
175 cat_out.append(lo)
176 lo += 1
177 return cat_out
178
179 def gen_unassigned(assigned):
180 assigned = set(assigned)
181 return ([i for i in range(0, 0xd800) if i not in assigned] +
182 [i for i in range(0xe000, 0x110000) if i not in assigned])
183
184 def to_combines(combs):
185 combs_out = []
186 for comb in combs:
187 for (lo, hi) in combs[comb]:
188 combs_out.append((lo, hi, comb))
189 combs_out.sort(key=lambda comb: comb[0])
190 return combs_out
191
192 def format_table_content(f, content, indent):
193 line = " "*indent
194 first = True
195 for chunk in content.split(","):
196 if len(line) + len(chunk) < 98:
197 if first:
198 line += chunk
199 else:
200 line += ", " + chunk
201 first = False
202 else:
203 f.write(line + ",\n")
204 line = " "*indent + chunk
205 f.write(line)
206
207 def load_properties(f, interestingprops):
208 fetch(f)
209 props = {}
210 re1 = re.compile("^([0-9A-F]+) +; (\w+)")
211 re2 = re.compile("^([0-9A-F]+)\.\.([0-9A-F]+) +; (\w+)")
212
213 for line in fileinput.input(os.path.basename(f)):
214 prop = None
215 d_lo = 0
216 d_hi = 0
217 m = re1.match(line)
218 if m:
219 d_lo = m.group(1)
220 d_hi = m.group(1)
221 prop = m.group(2)
222 else:
223 m = re2.match(line)
224 if m:
225 d_lo = m.group(1)
226 d_hi = m.group(2)
227 prop = m.group(3)
228 else:
229 continue
230 if interestingprops and prop not in interestingprops:
231 continue
232 d_lo = int(d_lo, 16)
233 d_hi = int(d_hi, 16)
234 if prop not in props:
235 props[prop] = []
236 props[prop].append((d_lo, d_hi))
237 return props
238
239 # load all widths of want_widths, except those in except_cats
240 def load_east_asian_width(want_widths, except_cats):
241 f = "EastAsianWidth.txt"
242 fetch(f)
243 widths = {}
244 re1 = re.compile("^([0-9A-F]+);(\w+) +# (\w+)")
245 re2 = re.compile("^([0-9A-F]+)\.\.([0-9A-F]+);(\w+) +# (\w+)")
246
247 for line in fileinput.input(f):
248 width = None
249 d_lo = 0
250 d_hi = 0
251 cat = None
252 m = re1.match(line)
253 if m:
254 d_lo = m.group(1)
255 d_hi = m.group(1)
256 width = m.group(2)
257 cat = m.group(3)
258 else:
259 m = re2.match(line)
260 if m:
261 d_lo = m.group(1)
262 d_hi = m.group(2)
263 width = m.group(3)
264 cat = m.group(4)
265 else:
266 continue
267 if cat in except_cats or width not in want_widths:
268 continue
269 d_lo = int(d_lo, 16)
270 d_hi = int(d_hi, 16)
271 if width not in widths:
272 widths[width] = []
273 widths[width].append((d_lo, d_hi))
274 return widths
275
276 def escape_char(c):
277 return "'\\u{%x}'" % c
278
279 def emit_bsearch_range_table(f):
280 f.write("""
281 fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
282 use core::cmp::Ordering::{Equal, Less, Greater};
283 use core::slice::SliceExt;
284 r.binary_search_by(|&(lo,hi)| {
285 if lo <= c && c <= hi { Equal }
286 else if hi < c { Less }
287 else { Greater }
288 }).is_ok()
289 }\n
290 """)
291
292 def emit_table(f, name, t_data, t_type = "&'static [(char, char)]", is_pub=True,
293 pfun=lambda x: "(%s,%s)" % (escape_char(x[0]), escape_char(x[1]))):
294 pub_string = ""
295 if is_pub:
296 pub_string = "pub "
297 f.write(" %sconst %s: %s = &[\n" % (pub_string, name, t_type))
298 data = ""
299 first = True
300 for dat in t_data:
301 if not first:
302 data += ","
303 first = False
304 data += pfun(dat)
305 format_table_content(f, data, 8)
306 f.write("\n ];\n\n")
307
308 def emit_property_module(f, mod, tbl, emit):
309 f.write("pub mod %s {\n" % mod)
310 for cat in sorted(emit):
311 emit_table(f, "%s_table" % cat, tbl[cat])
312 f.write(" pub fn %s(c: char) -> bool {\n" % cat)
313 f.write(" super::bsearch_range_table(c, %s_table)\n" % cat)
314 f.write(" }\n\n")
315 f.write("}\n\n")
316
317 def emit_conversions_module(f, lowerupper, upperlower):
318 f.write("pub mod conversions {")
319 f.write("""
320 use core::cmp::Ordering::{Equal, Less, Greater};
321 use core::slice::SliceExt;
322 use core::option::Option;
323 use core::option::Option::{Some, None};
324 use core::result::Result::{Ok, Err};
325
326 pub fn to_lower(c: char) -> char {
327 match bsearch_case_table(c, LuLl_table) {
328 None => c,
329 Some(index) => LuLl_table[index].1
330 }
331 }
332
333 pub fn to_upper(c: char) -> char {
334 match bsearch_case_table(c, LlLu_table) {
335 None => c,
336 Some(index) => LlLu_table[index].1
337 }
338 }
339
340 fn bsearch_case_table(c: char, table: &'static [(char, char)]) -> Option<usize> {
341 match table.binary_search_by(|&(key, _)| {
342 if c == key { Equal }
343 else if key < c { Less }
344 else { Greater }
345 }) {
346 Ok(i) => Some(i),
347 Err(_) => None,
348 }
349 }
350
351 """)
352 emit_table(f, "LuLl_table",
353 sorted(upperlower.iteritems(), key=operator.itemgetter(0)), is_pub=False)
354 emit_table(f, "LlLu_table",
355 sorted(lowerupper.iteritems(), key=operator.itemgetter(0)), is_pub=False)
356 f.write("}\n\n")
357
358 def emit_grapheme_module(f, grapheme_table, grapheme_cats):
359 f.write("""pub mod grapheme {
360 use core::slice::SliceExt;
361 pub use self::GraphemeCat::*;
362 use core::result::Result::{Ok, Err};
363
364 #[allow(non_camel_case_types)]
365 #[derive(Clone, Copy)]
366 pub enum GraphemeCat {
367 """)
368 for cat in grapheme_cats + ["Any"]:
369 f.write(" GC_" + cat + ",\n")
370 f.write(""" }
371
372 fn bsearch_range_value_table(c: char, r: &'static [(char, char, GraphemeCat)]) -> GraphemeCat {
373 use core::cmp::Ordering::{Equal, Less, Greater};
374 match r.binary_search_by(|&(lo, hi, _)| {
375 if lo <= c && c <= hi { Equal }
376 else if hi < c { Less }
377 else { Greater }
378 }) {
379 Ok(idx) => {
380 let (_, _, cat) = r[idx];
381 cat
382 }
383 Err(_) => GC_Any
384 }
385 }
386
387 pub fn grapheme_category(c: char) -> GraphemeCat {
388 bsearch_range_value_table(c, grapheme_cat_table)
389 }
390
391 """)
392
393 emit_table(f, "grapheme_cat_table", grapheme_table, "&'static [(char, char, GraphemeCat)]",
394 pfun=lambda x: "(%s,%s,GC_%s)" % (escape_char(x[0]), escape_char(x[1]), x[2]),
395 is_pub=False)
396 f.write("}\n")
397
398 def emit_charwidth_module(f, width_table):
399 f.write("pub mod charwidth {\n")
400 f.write(" use core::option::Option;\n")
401 f.write(" use core::option::Option::{Some, None};\n")
402 f.write(" use core::slice::SliceExt;\n")
403 f.write(" use core::result::Result::{Ok, Err};\n")
404 f.write("""
405 fn bsearch_range_value_table(c: char, is_cjk: bool, r: &'static [(char, char, u8, u8)]) -> u8 {
406 use core::cmp::Ordering::{Equal, Less, Greater};
407 match r.binary_search_by(|&(lo, hi, _, _)| {
408 if lo <= c && c <= hi { Equal }
409 else if hi < c { Less }
410 else { Greater }
411 }) {
412 Ok(idx) => {
413 let (_, _, r_ncjk, r_cjk) = r[idx];
414 if is_cjk { r_cjk } else { r_ncjk }
415 }
416 Err(_) => 1
417 }
418 }
419 """)
420
421 f.write("""
422 pub fn width(c: char, is_cjk: bool) -> Option<usize> {
423 match c as usize {
424 _c @ 0 => Some(0), // null is zero width
425 cu if cu < 0x20 => None, // control sequences have no width
426 cu if cu < 0x7F => Some(1), // ASCII
427 cu if cu < 0xA0 => None, // more control sequences
428 _ => Some(bsearch_range_value_table(c, is_cjk, charwidth_table) as usize)
429 }
430 }
431
432 """)
433
434 f.write(" // character width table. Based on Markus Kuhn's free wcwidth() implementation,\n")
435 f.write(" // http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c\n")
436 emit_table(f, "charwidth_table", width_table, "&'static [(char, char, u8, u8)]", is_pub=False,
437 pfun=lambda x: "(%s,%s,%s,%s)" % (escape_char(x[0]), escape_char(x[1]), x[2], x[3]))
438 f.write("}\n\n")
439
440 def emit_norm_module(f, canon, compat, combine, norm_props):
441 canon_keys = canon.keys()
442 canon_keys.sort()
443
444 compat_keys = compat.keys()
445 compat_keys.sort()
446
447 canon_comp = {}
448 comp_exclusions = norm_props["Full_Composition_Exclusion"]
449 for char in canon_keys:
450 if True in map(lambda (lo, hi): lo <= char <= hi, comp_exclusions):
451 continue
452 decomp = canon[char]
453 if len(decomp) == 2:
454 if not canon_comp.has_key(decomp[0]):
455 canon_comp[decomp[0]] = []
456 canon_comp[decomp[0]].append( (decomp[1], char) )
457 canon_comp_keys = canon_comp.keys()
458 canon_comp_keys.sort()
459
460 f.write("pub mod normalization {\n")
461
462 def mkdata_fun(table):
463 def f(char):
464 data = "(%s,&[" % escape_char(char)
465 first = True
466 for d in table[char]:
467 if not first:
468 data += ","
469 first = False
470 data += escape_char(d)
471 data += "])"
472 return data
473 return f
474
475 f.write(" // Canonical decompositions\n")
476 emit_table(f, "canonical_table", canon_keys, "&'static [(char, &'static [char])]",
477 pfun=mkdata_fun(canon))
478
479 f.write(" // Compatibility decompositions\n")
480 emit_table(f, "compatibility_table", compat_keys, "&'static [(char, &'static [char])]",
481 pfun=mkdata_fun(compat))
482
483 def comp_pfun(char):
484 data = "(%s,&[" % escape_char(char)
485 canon_comp[char].sort(lambda x, y: x[0] - y[0])
486 first = True
487 for pair in canon_comp[char]:
488 if not first:
489 data += ","
490 first = False
491 data += "(%s,%s)" % (escape_char(pair[0]), escape_char(pair[1]))
492 data += "])"
493 return data
494
495 f.write(" // Canonical compositions\n")
496 emit_table(f, "composition_table", canon_comp_keys,
497 "&'static [(char, &'static [(char, char)])]", pfun=comp_pfun)
498
499 f.write("""
500 fn bsearch_range_value_table(c: char, r: &'static [(char, char, u8)]) -> u8 {
501 use core::cmp::Ordering::{Equal, Less, Greater};
502 use core::slice::SliceExt;
503 use core::result::Result::{Ok, Err};
504 match r.binary_search_by(|&(lo, hi, _)| {
505 if lo <= c && c <= hi { Equal }
506 else if hi < c { Less }
507 else { Greater }
508 }) {
509 Ok(idx) => {
510 let (_, _, result) = r[idx];
511 result
512 }
513 Err(_) => 0
514 }
515 }\n
516 """)
517
518 emit_table(f, "combining_class_table", combine, "&'static [(char, char, u8)]", is_pub=False,
519 pfun=lambda x: "(%s,%s,%s)" % (escape_char(x[0]), escape_char(x[1]), x[2]))
520
521 f.write(" pub fn canonical_combining_class(c: char) -> u8 {\n"
522 + " bsearch_range_value_table(c, combining_class_table)\n"
523 + " }\n")
524
525 f.write("""
526 }
527
528 """)
529
530 def remove_from_wtable(wtable, val):
531 wtable_out = []
532 while wtable:
533 if wtable[0][1] < val:
534 wtable_out.append(wtable.pop(0))
535 elif wtable[0][0] > val:
536 break
537 else:
538 (wt_lo, wt_hi, width, width_cjk) = wtable.pop(0)
539 if wt_lo == wt_hi == val:
540 continue
541 elif wt_lo == val:
542 wtable_out.append((wt_lo+1, wt_hi, width, width_cjk))
543 elif wt_hi == val:
544 wtable_out.append((wt_lo, wt_hi-1, width, width_cjk))
545 else:
546 wtable_out.append((wt_lo, val-1, width, width_cjk))
547 wtable_out.append((val+1, wt_hi, width, width_cjk))
548 if wtable:
549 wtable_out.extend(wtable)
550 return wtable_out
551
552
553
554 def optimize_width_table(wtable):
555 wtable_out = []
556 w_this = wtable.pop(0)
557 while wtable:
558 if w_this[1] == wtable[0][0] - 1 and w_this[2:3] == wtable[0][2:3]:
559 w_tmp = wtable.pop(0)
560 w_this = (w_this[0], w_tmp[1], w_tmp[2], w_tmp[3])
561 else:
562 wtable_out.append(w_this)
563 w_this = wtable.pop(0)
564 wtable_out.append(w_this)
565 return wtable_out
566
567 if __name__ == "__main__":
568 r = "tables.rs"
569 if os.path.exists(r):
570 os.remove(r)
571 with open(r, "w") as rf:
572 # write the file's preamble
573 rf.write(preamble)
574
575 # download and parse all the data
576 fetch("ReadMe.txt")
577 with open("ReadMe.txt") as readme:
578 pattern = "for Version (\d+)\.(\d+)\.(\d+) of the Unicode"
579 unicode_version = re.search(pattern, readme.read()).groups()
580 rf.write("""
581 /// The version of [Unicode](http://www.unicode.org/)
582 /// that the unicode parts of `CharExt` and `UnicodeStrPrelude` traits are based on.
583 pub const UNICODE_VERSION: (u64, u64, u64) = (%s, %s, %s);
584 """ % unicode_version)
585 (canon_decomp, compat_decomp, gencats, combines,
586 lowerupper, upperlower) = load_unicode_data("UnicodeData.txt")
587 want_derived = ["XID_Start", "XID_Continue", "Alphabetic", "Lowercase", "Uppercase"]
588 derived = load_properties("DerivedCoreProperties.txt", want_derived)
589 scripts = load_properties("Scripts.txt", [])
590 props = load_properties("PropList.txt",
591 ["White_Space", "Join_Control", "Noncharacter_Code_Point"])
592 norm_props = load_properties("DerivedNormalizationProps.txt",
593 ["Full_Composition_Exclusion"])
594
595 # bsearch_range_table is used in all the property modules below
596 emit_bsearch_range_table(rf)
597
598 # category tables
599 for (name, cat, pfuns) in ("general_category", gencats, ["N", "Cc"]), \
600 ("derived_property", derived, want_derived), \
601 ("property", props, ["White_Space"]):
602 emit_property_module(rf, name, cat, pfuns)
603
604 # normalizations and conversions module
605 emit_norm_module(rf, canon_decomp, compat_decomp, combines, norm_props)
606 emit_conversions_module(rf, lowerupper, upperlower)
607
608 ### character width module
609 width_table = []
610 for zwcat in ["Me", "Mn", "Cf"]:
611 width_table.extend(map(lambda (lo, hi): (lo, hi, 0, 0), gencats[zwcat]))
612 width_table.append((4448, 4607, 0, 0))
613
614 # get widths, except those that are explicitly marked zero-width above
615 ea_widths = load_east_asian_width(["W", "F", "A"], ["Me", "Mn", "Cf"])
616 # these are doublewidth
617 for dwcat in ["W", "F"]:
618 width_table.extend(map(lambda (lo, hi): (lo, hi, 2, 2), ea_widths[dwcat]))
619 width_table.extend(map(lambda (lo, hi): (lo, hi, 1, 2), ea_widths["A"]))
620
621 width_table.sort(key=lambda w: w[0])
622
623 # soft hyphen is not zero width in preformatted text; it's used to indicate
624 # a hyphen inserted to facilitate a linebreak.
625 width_table = remove_from_wtable(width_table, 173)
626
627 # optimize the width table by collapsing adjacent entities when possible
628 width_table = optimize_width_table(width_table)
629 emit_charwidth_module(rf, width_table)
630
631 ### grapheme cluster module
632 # from http://www.unicode.org/reports/tr29/#Grapheme_Cluster_Break_Property_Values
633 grapheme_cats = load_properties("auxiliary/GraphemeBreakProperty.txt", [])
634
635 # Control
636 # Note 1:
637 # This category also includes Cs (surrogate codepoints), but Rust's `char`s are
638 # Unicode Scalar Values only, and surrogates are thus invalid `char`s.
639 # Thus, we have to remove Cs from the Control category
640 # Note 2:
641 # 0x0a and 0x0d (CR and LF) are not in the Control category for Graphemes.
642 # However, the Graphemes iterator treats these as a special case, so they
643 # should be included in grapheme_cats["Control"] for our implementation.
644 grapheme_cats["Control"] = group_cat(list(
645 (set(ungroup_cat(grapheme_cats["Control"]))
646 | set(ungroup_cat(grapheme_cats["CR"]))
647 | set(ungroup_cat(grapheme_cats["LF"])))
648 - set(ungroup_cat([surrogate_codepoints]))))
649 del(grapheme_cats["CR"])
650 del(grapheme_cats["LF"])
651
652 grapheme_table = []
653 for cat in grapheme_cats:
654 grapheme_table.extend([(x, y, cat) for (x, y) in grapheme_cats[cat]])
655 grapheme_table.sort(key=lambda w: w[0])
656 emit_grapheme_module(rf, grapheme_table, grapheme_cats.keys())