Ignore:
Timestamp:
Aug 22, 2015, 12:37:38 PM (4 years ago)
Author:
cameron
Message:

Handle arbitrary enumerated properties without special casing; improve error reporting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/UCD/resolve_properties.cpp

    r4735 r4737  
    2121using namespace re;
    2222
    23 class UnicodePropertyExpressionError : public std::exception {
    24 public:
    25     UnicodePropertyExpressionError(const std::string && msg) noexcept : _msg(msg) {}
    26     const char* what() const noexcept { return _msg.c_str();}
    27 private:
    28     inline UnicodePropertyExpressionError() noexcept {}
    29     const std::string _msg;
    30 };
    3123
    3224inline int GetPropertyValueEnumCode(const UCD::property_t type, const std::string & value) {
     
    4537
    4638    auto theprop = propit->second;
    47     if (theprop == gc) {
    48         // General Category
    49         int valcode = GetPropertyValueEnumCode(gc, value);
     39   
     40   
     41    if (EnumeratedPropertyObject * p = dyn_cast<EnumeratedPropertyObject>(property_object_table[theprop])){
     42        int valcode = p->GetPropertyValueEnumCode(value);
    5043        if (valcode < 0) {
    51             throw UnicodePropertyExpressionError("Erroneous property value for general_category property");
    52         }
    53         property->setFunctionName("__get_gc_" + GC_ns::enum_names[valcode]);
    54     }
    55     else if (theprop == sc) {
    56         // Script property identified
    57         int valcode = GetPropertyValueEnumCode(sc, value);
    58         if (valcode < 0) {
    59             throw UnicodePropertyExpressionError("Erroneous property value for script property");
    60         }
    61         property->setFunctionName("__get_sc_" + SC_ns::enum_names[valcode]);
     44            throw UnicodePropertyExpressionError("Erroneous property value '" + value + "' for " + property_full_name[theprop] + " property");
     45        }
     46        property->setFunctionName("__get_" + property_enum_name[theprop] + "_" + p->GetValueEnumName(valcode));
    6247    }
    6348    else if (theprop == scx) {
     
    6954        property->setFunctionName("__get_scx_" + SC_ns::enum_names[valcode]);
    7055    }
    71     else if (theprop == blk) {
    72         // Block property identified
    73         int valcode = GetPropertyValueEnumCode(blk, value);
    74         if (valcode < 0) {
    75              throw UnicodePropertyExpressionError("Erroneous property value for block property");
    76         }
    77         property->setFunctionName("__get_blk_" + BLK_ns::enum_names[valcode]);
    78     }
    79     else if (theprop == GCB) {
    80         // Grapheme Cluster Break property identified
    81         int valcode = GetPropertyValueEnumCode(GCB, value);
    82         if (valcode < 0) {
    83              throw UnicodePropertyExpressionError("Erroneous property value for grapheme cluster break property");
    84         }
    85         property->setFunctionName("__get_gcb_" + GCB_ns::enum_names[valcode]);
    86     }
    87     else if (theprop == WB) {
    88         // Word Break property identified
    89         int valcode = GetPropertyValueEnumCode(WB, value);
    90         if (valcode < 0) {
    91              throw UnicodePropertyExpressionError("Erroneous property value for word break property");
    92         }
    93         property->setFunctionName("__get_wb_" + WB_ns::enum_names[valcode]);
    94     }
    95     else if (theprop == lb) {
    96         // Line Break property identified
    97         int valcode = GetPropertyValueEnumCode(lb, value);
    98         if (valcode < 0) {
    99              throw UnicodePropertyExpressionError("Erroneous property value for line break property");
    100         }
    101         property->setFunctionName("__get_lb_" + LB_ns::enum_names[valcode]);
    102     }
    103     else if (theprop == SB) {
    104         // Sentence Break property identified
    105         int valcode = GetPropertyValueEnumCode(SB, value);
    106         if (valcode < 0) {
    107              throw UnicodePropertyExpressionError("Erroneous property value for sentence break property");
    108         }
    109         property->setFunctionName("__get_lb_" + SB_ns::enum_names[valcode]);
    110     }
    11156    else if (isa<BinaryPropertyObject>(property_object_table[theprop])){
    11257        auto valit = Binary_ns::aliases_only_map.find(value);
     
    12570        throw UnicodePropertyExpressionError("Property " + property_full_name[theprop] + " recognized but not supported in icgrep 1.0");
    12671    }
    127 
    12872    return property;
    12973}
Note: See TracChangeset for help on using the changeset viewer.