Changeset 4173


Ignore:
Timestamp:
Sep 13, 2014, 11:26:56 AM (5 years ago)
Author:
cameron
Message:

Add UCD::Binary, UCD:CCC fix, add header wrappers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/charsetcompiler/UCD/UCD_properties.py

    r4172 r4173  
    5656
    5757
     58header_template = r"""#ifndef %s
     59#define %s
     60/*
     61 *  Copyright (c) 2014 International Characters, Inc.
     62 *  This software is licensed to the public under the Open Software License 3.0.
     63 *  icgrep is a trademark of International Characters, Inc.
     64 *
     65 *  This file is generated by UCD_properties.y - manual edits may be lost.
     66 */
     67
     68#include <string>
     69#include <unordered_map>
     70
     71"""
     72
     73def open_header_file_for_write(filename):
     74   f = open(filename + '.h', 'w')
     75   hname = filename.upper() + '_H'
     76   f.write(header_template % (hname, hname))
     77   return f
     78
     79def close_header_file(f):
     80   f.write("#endif\n")
     81   f.close()
     82
    5883PropertyAliases_template = r"""
    59 #include <unordered_map>
    6084namespace UCD {
    6185  enum property_t {
     
    84108def generate_PropertyAliases_h():
    85109   (property_enum_name_list, full_name_map, property_lookup_map) = parse_PropertyAlias_txt()
    86    f = open('PropertyAliases.h', 'w')
     110   f = open_header_file_for_write('PropertyAliases')
    87111   enum_text = multiline_join([e.lower() for e in property_enum_name_list], enums_per_line, ',')
    88112   full_name_text = multiline_join(['"%s"' % full_name_map[e] for e in property_enum_name_list], 2, ',')
    89113   map_text = multiline_join(['{"%s", %s}' % (k, property_lookup_map[k].lower()) for k in sorted(property_lookup_map.keys())], 2, ',')
    90114   f.write(PropertyAliases_template % (enum_text, full_name_text, map_text))
    91    f.close()
     115   close_header_file(f)
    92116   
    93117#
     
    157181
    158182PropertyValueAliases_template = r"""
    159 #include <unordered_map>
    160183namespace UCD {
    161184  namespace %s {
     
    176199   (property_enum_name_list, full_name_map, property_lookup_map) = parse_PropertyAlias_txt()
    177200   (property_value_list, property_value_enum_integer, property_value_full_name_map, property_value_lookup_map) = parse_PropertyValueAlias_txt()
    178    f = open('PropertyValueAliases.h', 'w')
     201   f = open_header_file_for_write('PropertyValueAliases')
     202   #  Generate the aliases for all Binary properties.
     203   enum_text = multiline_join(['N', 'Y'], 4, ',','', 6)
     204   full_name_text = multiline_join(['"No"', '"Yes"'], 4, ',',  '', 6)
     205   map_text = multiline_join(['{"n", N}', '{"y", Y}', '{"no", N}', '{"yes", Y}', '{"f", N}', '{"t", Y}', '{"false", N}', '{"true", Y}'], 4, ',', '', 6)
     206   f.write(PropertyValueAliases_template % ('Boolean', enum_text, full_name_text, map_text))
     207   #
    179208   for p in property_enum_name_list:
    180209     if property_value_list.has_key(p):
    181210       if property_value_list[p] == ['N', 'Y']: continue # skip boolean properties
    182        if p == 'ccc':
    183          enum_text = multiline_join(["%s = %s" % (e, property_value_enum_integer[p][e]) for e in property_value_list['ccc']], 4, ',', '', 6)
    184        else: enum_text = multiline_join(property_value_list[p], 4, ',')
     211       enum_text = multiline_join(property_value_list[p], 4, ',','', 6)
     212       if p == 'ccc': # Special case: add numeric value information for ccc.
     213         enum_text += r"""
     214    };
     215    const uint8_t enum_val[] = {
     216"""
     217         enum_text += multiline_join(["%s" % (property_value_enum_integer[p][e]) for e in property_value_list['ccc']], 4, ',', '', 6)
    185218       full_name_text = multiline_join(['"%s"' % (property_value_full_name_map[p][e]) for e in property_value_list[p]], 4, ',',  '', 6)
    186219       map_text = multiline_join(['{"%s", %s}' % (k, property_value_lookup_map[p][k]) for k in sorted(property_value_lookup_map[p].keys())], 4, ',', '', 6)
    187220       f.write(PropertyValueAliases_template % (p.upper(), enum_text, full_name_text, map_text))
    188    f.close()
     221   close_header_file(f)
    189222   
    190223
     
    221254def generate_PropList_h():
    222255   (props, prop_map) = parse_UCD_codepoint_name_map('PropList.txt')
    223    f = open('PropList.h', 'w')
     256   f = open_header_file_for_write('PropList')
    224257   for k in props:
    225258     f.write(prop_map[k].showC(k))
    226    f.close()
     259   close_header_file(f)
    227260
    228261def generate_Blocks_h():
    229262   (blocks, block_map) = parse_UCD_codepoint_name_map('Blocks.txt')
    230    f = open('Blocks.h', 'w')
     263   f = open_header_file_for_write('Blocks')
    231264   for k in blocks:
    232265     f.write(block_map[k].showC('block["%s"]' % k))
    233    f.close()
     266   close_header_file(f)
    234267
    235268def generate_Scripts_h():
    236269   (scripts, script_map) = parse_UCD_codepoint_name_map('Scripts.txt')
    237    f = open('Scripts.h', 'w')
     270   f = open_header_file_for_write('Scripts')
    238271   for k in scripts:
    239272     f.write(script_map[k].showC('script["%s"]' % k))
    240    f.close()
     273   close_header_file(f)
    241274   
    242275def generate_ScriptExtensions_h():
    243276   (scx_sets, scx_map) = parse_UCD_codepoint_name_map('ScriptExtensions.txt')
    244277   map2 = {}
    245    f = open('ScriptExtensions.h', 'w')
     278   f = open_header_file_for_write('ScriptExtensions')
    246279   for scx_list in scx_sets:
    247280     scx_items = scx_list.split(" ")
     
    252285   for k in sorted(map2.keys()):
    253286     f.write(map2[k].showC('scx["%s"]' % k))
    254    f.close()
     287   close_header_file(f)
    255288
    256289def generate_DerivedGeneralCategory_h():
    257290   (categories, cat_map) = parse_UCD_codepoint_name_map('extracted/DerivedGeneralCategory.txt')
    258    f = open('DerivedGeneralCategory.h', 'w')
     291   f = open_header_file_for_write('DerivedGeneralCategory')
    259292   for k in categories:
    260293     f.write(cat_map[k].showC('GC["%s"]' % k))
    261    f.close()
     294   close_header_file(f)
    262295
    263296def generate_DerivedCoreProperties_h():
    264297   (properties, prop_map) = parse_UCD_codepoint_name_map('DerivedCoreProperties.txt')
    265    f = open('DerivedCoreProperties.h', 'w')
     298   f = open_header_file_for_write('DerivedCoreProperties')
    266299   for k in properties:
    267300     f.write(prop_map[k].showC(k))
    268    f.close()
    269 
    270 
     301   close_header_file(f)
     302
     303
Note: See TracChangeset for help on using the changeset viewer.