source: proto/charsetcompiler/generate_UCD_property_functions.py @ 4375

Last change on this file since 4375 was 4375, checked in by cameron, 4 years ago

Update to UCD 7.0.0, have UCD parsers return totally-defined value maps

File size: 3.2 KB
Line 
1#
2# generate_UCD_property_functions.py -
3# generating Python pablo functions for various Unicode properties
4#
5# Robert D. Cameron
6# December 28, 2014
7#
8# Licensed under Open Software License 3.0.
9#
10#
11import re, string, os.path, UCD.cformat
12from UCD.unicode_set import *
13from UCD.UCD_parser import *
14from if_hierarchy import *
15
16
17
18
19Unicode_CC_struct = "class struct_%s_%s:\n\tcc = 0\n\n"
20
21Unicode_CC_header = "def %s_%s(basis_bits, struct_%s):\n"
22
23Unicode_dummy_main = "\n\ndef Main(basis_bits):\n    pass\n"
24
25Unicode_template_var = "struct_%s.cc"
26
27
28
29
30
31
32
33class UCD_generator():
34    def __init__(self): 
35       pass
36 
37    def load_property_name_info(self):
38       (self.property_enum_name_list, self.full_name_map, self.property_lookup_map, self.property_kind_map) = parse_PropertyAlias_txt()
39
40    def load_property_value_info(self):
41       (self.property_value_list, self.property_value_enum_integer, self.property_value_full_name_map, self.property_value_lookup_map, self.missing_specs) = parse_PropertyValueAlias_txt(self.property_lookup_map)
42
43
44
45    def generate_property_file(self, filename_root, property_code, default_value = None):
46       vlist = self.property_value_list[property_code]
47       canon_map = self.property_value_lookup_map[property_code]
48       (prop_values, value_map) = parse_UCD_enumerated_property_map(property_code, vlist, canon_map, filename_root + '.txt', default_value)
49       basename = os.path.basename(filename_root)
50       f = open(basename + ".pablo", "wb")
51       for k in value_map.keys():
52         f.write(Unicode_CC_struct % (property_code, k))
53         f.write(Unicode_CC_header % (property_code, k, k))
54         template_var = "struct_%s_%%s.cc" % property_code
55         f.write(generateCharClassDefs(defaultIfRangeList, {k: uset_to_range_list(value_map[k])},  template_var))
56       f.write(Unicode_dummy_main)
57       cformat.close_header_file(f)
58
59    def generate_ScriptExtensions_pablo(self):
60       filename_root = 'ScriptExtensions'
61       property_code = 'scx'
62       (prop_values, value_map) = parse_ScriptExtensions_txt(self.property_value_list['sc'], self.property_value_lookup_map['sc'])
63       basename = os.path.basename(filename_root)
64       f = open(basename + ".pablo", "wb")
65       for k in value_map.keys():
66         f.write(Unicode_CC_struct % (property_code, k))
67         f.write(Unicode_CC_header % (property_code, k, k))
68         template_var = "struct_%s_%%s.cc" % property_code
69         f.write(generateCharClassDefs(defaultIfRangeList, {k: uset_to_range_list(value_map[k])},  template_var))
70       f.write(Unicode_dummy_main)
71       cformat.close_header_file(f)
72
73
74
75def UCD_main():
76   ucd = UCD_generator()
77
78   # First parse all property names and their aliases
79   ucd.load_property_name_info()
80   #
81   # Next parse all property value names and their aliases.  Generate the data.
82   ucd.load_property_value_info()
83   #
84   # The Block property
85   #ucd.generate_property_file('Blocks', 'blk')
86   #
87   # Scripts
88   ucd.generate_property_file('Scripts', 'sc')
89   #
90   # Script Extensions
91   ucd.generate_ScriptExtensions_pablo()
92   #
93   # General Category
94   ucd.generate_property_file('extracted/DerivedGeneralCategory', 'gc')
95   #
96
97if __name__ == "__main__":
98  set_UCD_dir('UCD/7.0.0')
99  UCD_main()
Note: See TracBrowser for help on using the repository browser.