Ignore:
Timestamp:
Jan 2, 2015, 9:29:15 AM (5 years ago)
Author:
cameron
Message:

Generating binary properties, reformatting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/charsetcompiler/generate_UCD_property_functions.py

    r4387 r4389  
    44#
    55# Robert D. Cameron
    6 # December 28, 2014
     6# January 2, 2015
    77#
    88# Licensed under Open Software License 3.0.
     
    5959 
    6060    def load_property_name_info(self):
    61        (self.property_enum_name_list, self.full_name_map, self.property_lookup_map, self.property_kind_map) = parse_PropertyAlias_txt()
     61        (self.property_enum_name_list, self.full_name_map, self.property_lookup_map, self.property_kind_map) = parse_PropertyAlias_txt()
    6262
    6363    def load_property_value_info(self):
    64        (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)
     64        (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)
    6565
    6666    def generate_enumerated_property_template(self, filename_root, property_code):
    67        f = cformat.open_header_file_for_write(os.path.basename("ucd_precompiled_%s" % property_code))
    68        cformat.write_imports(f, ['"pablo/pablo_compiler.h"'])
    69        f.write(Unicode_pablo_template)
    70        pc = property_code.lower()
    71        vlist = self.property_value_list[property_code]
    72        for v in vlist:
    73           f.write(Unicode_property_fn_template.substitute({'property': pc, 'value': v}))
    74        install_stmt = "  p.InstallExternalFunction(\"__get_%s_%%s\", (void *) & __get_%s_%%s);\n" % (pc, pc)
    75        install_list = [install_stmt % (k, k) for k in vlist]
    76        f.write(install_fn % (pc, "".join(install_list)))
    77        cformat.close_header_file(f)
     67        f = cformat.open_header_file_for_write(os.path.basename("ucd_precompiled_%s" % property_code), 'generate_UCD_property_functions.py')
     68        cformat.write_imports(f, ['"pablo/pablo_compiler.h"'])
     69        f.write(Unicode_pablo_template)
     70        pc = property_code.lower()
     71        vlist = self.property_value_list[property_code]
     72        for v in vlist:
     73            f.write(Unicode_property_fn_template.substitute({'property': pc, 'value': v}))
     74        install_stmt = "  p.InstallExternalFunction(\"__get_%s_%%s\", (void *) & __get_%s_%%s);\n" % (pc, pc)
     75        install_list = [install_stmt % (k, k) for k in vlist]
     76        f.write(install_fn % (pc, "".join(install_list)))
     77        cformat.close_header_file(f)
    7878       
    7979    def generate_enumerated_property_file(self, filename_root, property_code):
    80        vlist = self.property_value_list[property_code]
    81        canon_map = self.property_value_lookup_map[property_code]
    82        (prop_values, value_map) = parse_UCD_enumerated_property_map(property_code, vlist, canon_map, filename_root + '.txt')
    83        basename = os.path.basename(filename_root)
    84        f = open(basename + ".pablo", "wb")
    85        for k in vlist:
    86          parms = {'property' : property_code.lower(), 'value' : k}
    87          f.write(Unicode_CC_struct.substitute(parms))
    88          f.write(Unicode_CC_header.substitute(parms))
    89          template_var = Unicode_template_var.substitute(parms)
    90          f.write(generateCharClassDefs(defaultIfRangeList, {k: uset_to_range_list(value_map[k])},  template_var))
    91        f.write(Unicode_dummy_main)
    92        cformat.close_header_file(f)
     80        vlist = self.property_value_list[property_code]
     81        canon_map = self.property_value_lookup_map[property_code]
     82        (prop_values, value_map) = parse_UCD_enumerated_property_map(property_code, vlist, canon_map, filename_root + '.txt')
     83        basename = os.path.basename(filename_root)
     84        f = open(basename + ".pablo", "wb")
     85        for k in vlist:
     86            parms = {'property' : property_code.lower(), 'value' : k}
     87            f.write(Unicode_CC_struct.substitute(parms))
     88            f.write(Unicode_CC_header.substitute(parms))
     89            template_var = Unicode_template_var.substitute(parms)
     90            f.write(generateCharClassDefs(defaultIfRangeList, {k: uset_to_range_list(value_map[k])},  template_var))
     91        f.write(Unicode_dummy_main)
     92        cformat.close_header_file(f)
    9393
    9494    def generate_ScriptExtensions_pablo(self):
    95        filename_root = 'ScriptExtensions'
    96        property_code = 'scx'
    97        vlist = self.property_value_list['sc']
    98        (prop_values, value_map) = parse_ScriptExtensions_txt(vlist, self.property_value_lookup_map['sc'])
    99        basename = os.path.basename(filename_root)
    100        f = open(basename + ".pablo", "wb")
    101        for k in vlist:
    102          parms = {'property' : 'scx', 'value' : k}
    103          f.write(Unicode_CC_struct.substitute(parms))
    104          f.write(Unicode_CC_header.substitute(parms))
    105          template_var = Unicode_template_var.substitute(parms)
    106          f.write(generateCharClassDefs(defaultIfRangeList, {k: uset_to_range_list(value_map[k])},  template_var))
    107        f.write(Unicode_dummy_main)
    108        cformat.close_header_file(f)
     95        filename_root = 'ScriptExtensions'
     96        property_code = 'scx'
     97        vlist = self.property_value_list['sc']
     98        (prop_values, value_map) = parse_ScriptExtensions_txt(vlist, self.property_value_lookup_map['sc'])
     99        basename = os.path.basename(filename_root)
     100        f = open(basename + ".pablo", "wb")
     101        for k in vlist:
     102            parms = {'property' : 'scx', 'value' : k}
     103            f.write(Unicode_CC_struct.substitute(parms))
     104            f.write(Unicode_CC_header.substitute(parms))
     105            template_var = Unicode_template_var.substitute(parms)
     106            f.write(generateCharClassDefs(defaultIfRangeList, {k: uset_to_range_list(value_map[k])},  template_var))
     107        f.write(Unicode_dummy_main)
     108        cformat.close_header_file(f)
    109109
     110    def generate_binary_property_template(self, filename_root):
     111        (props, prop_map) = parse_UCD_codepoint_name_map(filename_root + '.txt', self.property_lookup_map)
     112        lprops = [p.lower() for p in props]
     113        f = cformat.open_header_file_for_write(os.path.basename("ucd_precompiled_%s" % filename_root.lower()), 'generate_UCD_property_functions.py')
     114        cformat.write_imports(f, ['"pablo/pablo_compiler.h"'])
     115        f.write(Unicode_pablo_template)
     116        for p in lprops:
     117            f.write(Unicode_property_fn_template.substitute({'property': p, 'value': 'Y'}))
     118        install_stmt = "  p.InstallExternalFunction(\"__get_%s_Y\", (void *) & __get_%s_Y);\n"
     119        install_list = [install_stmt % (p, p) for p in lprops]
     120        f.write(install_fn % (filename_root, "".join(install_list)))
     121        cformat.close_header_file(f)
     122       
     123    def generate_binary_properties_file(self, filename_root):
     124        (props, prop_map) = parse_UCD_codepoint_name_map(filename_root + '.txt', self.property_lookup_map)
     125        basename = os.path.basename(filename_root)
     126        f = open(basename + ".pablo", "wb")
     127        for p in props:
     128            parms = {'property' : p.lower(), 'value' : 'Y'}
     129            f.write(Unicode_CC_struct.substitute(parms))
     130            f.write(Unicode_CC_header.substitute(parms))
     131            template_var = Unicode_template_var.substitute(parms)
     132            f.write(generateCharClassDefs(defaultIfRangeList, {'Y': uset_to_range_list(prop_map[p])},  template_var))
     133        f.write(Unicode_dummy_main)
     134        cformat.close_header_file(f)
    110135
    111136
    112137def UCD_main():
    113    ucd = UCD_generator()
     138    ucd = UCD_generator()
    114139
    115    # First parse all property names and their aliases
    116    ucd.load_property_name_info()
    117    #
    118    # Next parse all property value names and their aliases.  Generate the data.
    119    ucd.load_property_value_info()
    120    #
    121    # The Block property
    122    ucd.generate_enumerated_property_template('Blocks', 'blk')
    123    ucd.generate_enumerated_property_file('Blocks', 'blk')
    124    #
    125    # Scripts
    126    ucd.generate_enumerated_property_template('Scripts', 'sc')
    127    ucd.generate_enumerated_property_file('Scripts', 'sc')
    128    #
    129    # Script Extensions
    130    ucd.generate_enumerated_property_template('ScriptExtensions', 'scx')
    131    ucd.generate_ScriptExtensions_pablo()
    132    #
    133    # General Category
    134    ucd.generate_enumerated_property_template('GeneralCategory', 'gc')
    135    ucd.generate_enumerated_property_file('extracted/DerivedGeneralCategory', 'gc')
    136    #
     140    # First parse all property names and their aliases
     141    ucd.load_property_name_info()
     142    #
     143    # Next parse all property value names and their aliases.  Generate the data.
     144    ucd.load_property_value_info()
     145    #
     146    # The Block property
     147    ucd.generate_enumerated_property_template('Blocks', 'blk')
     148    ucd.generate_enumerated_property_file('Blocks', 'blk')
     149    #
     150    # Scripts
     151    ucd.generate_enumerated_property_template('Scripts', 'sc')
     152    ucd.generate_enumerated_property_file('Scripts', 'sc')
     153    #
     154    # Script Extensions
     155    ucd.generate_enumerated_property_template('ScriptExtensions', 'scx')
     156    ucd.generate_ScriptExtensions_pablo()
     157    #
     158    # General Category
     159    ucd.generate_enumerated_property_template('GeneralCategory', 'gc')
     160    ucd.generate_enumerated_property_file('extracted/DerivedGeneralCategory', 'gc')
     161    #
     162    # Core Properties
     163    ucd.generate_binary_property_template('DerivedCoreProperties')
     164    ucd.generate_binary_properties_file('DerivedCoreProperties')
     165    #ucd.generate_binary_properties_file('PropList')
    137166
    138167if __name__ == "__main__":
    139   set_UCD_dir('UCD/7.0.0')
    140   UCD_main()
     168    set_UCD_dir('UCD/7.0.0')
     169    UCD_main()
Note: See TracChangeset for help on using the changeset viewer.