Ignore:
Timestamp:
Jul 15, 2015, 12:30:25 PM (4 years ago)
Author:
nmedfort
Message:

Moved resolveProperty responsibilities out of RE_Parser but kept expansion of Name objects with definitions in it.

Location:
icGREP/icgrep-devel/icgrep/re
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/re/re_compiler.cpp

    r4660 r4673  
    279279        }
    280280        else {
    281             var = mUCDCompiler.generateWithDefaultIfHierarchy(resolveUnicodeSet(name), pb);
     281            var = mUCDCompiler.generateWithDefaultIfHierarchy(UCD::resolveUnicodeSet(name), pb);
    282282        }
    283283    }
  • icGREP/icgrep-devel/icgrep/re/re_parser.cpp

    r4671 r4673  
    1616#include <re/re_assertion.h>
    1717#include <re/parsefailure.h>
     18#include <UCD/resolve_properties.h>
    1819#include <UCD/CaseFolding_txt.h>
    1920#include <sstream>
     
    486487        }
    487488        // We have a property-name = value expression
    488         return resolvePropertyExpression(canonicalize(start, prop_end), canonicalize(val_start, _cursor));
    489     }
    490     return resolvePropertyExpression(canonicalize(start, _cursor));
    491 }
    492 
    493 Name * RE_Parser::resolvePropertyExpression(std::string value) {
     489        return createName(canonicalize(start, prop_end), canonicalize(val_start, _cursor));
     490    }
     491    return createName(canonicalize(start, _cursor));
     492}
     493
     494Name * RE_Parser::createName(const std::string value) {
    494495
    495496    auto key = std::make_pair("", value);
     
    499500    }
    500501
    501     Name * property = makeName(value, Name::Type::UnicodeProperty);
    502 
    503     // Try special cases of Unicode TR #18
    504     if (value == "any") {
    505         property->setDefinition(makeAny());
    506     }
    507     else if (value == "ascii") {
    508         property->setDefinition(resolvePropertyExpression("blk", "ascii"));
    509     }
    510     else if (value == "assigned") {
    511         Name * unassigned = resolvePropertyExpression("cn");
    512         property->setDefinition(makeDiff(makeAny(), unassigned));
    513     }
    514     // Now compatibility properties of UTR #18 Annex C
    515     else if (value == "xdigit") {
    516         Name * digit = resolvePropertyExpression("nd");
    517         Name * hexdigit = resolvePropertyExpression("hexdigit");
    518         property->setDefinition(makeAlt({digit, hexdigit}));
    519     }
    520     else if (value == "alnum") {
    521         Name * digit = resolvePropertyExpression("nd");
    522         Name * alpha = resolvePropertyExpression("alphabetic");
    523         property->setDefinition(makeAlt({digit, alpha}));
    524     }
    525     else if (value == "blank") {
    526         Name * space_sep = resolvePropertyExpression("space_separator");
    527         CC * tab = makeCC(0x09);
    528         property->setDefinition(makeAlt({space_sep, tab}));
    529     }
    530     else if (value == "graph") {
    531         Name * space = resolvePropertyExpression("space");
    532         Name * ctrl = resolvePropertyExpression("control");
    533         Name * surr = resolvePropertyExpression("surrogate");
    534         Name * unassigned = resolvePropertyExpression("cn");
    535         property->setDefinition(makeDiff(makeAny(), makeAlt({space, ctrl, surr, unassigned})));
    536     }
    537     else if (value == "print") {
    538         Name * graph = resolvePropertyExpression("graph");
    539         Name * space_sep = resolvePropertyExpression("space_separator");
    540         property->setDefinition(makeAlt({graph, space_sep}));
    541     }
    542     else if (value == "word") {
    543         Name * alnum = resolvePropertyExpression("alnum");
    544         Name * mark = resolvePropertyExpression("mark");
    545         Name * conn = resolvePropertyExpression("connectorpunctuation");
    546         Name * join = resolvePropertyExpression("joincontrol");
    547         property->setDefinition(makeAlt({alnum, mark, conn, join}));
    548     }
    549 
    550     mNameMap.emplace(std::move(key), property);
     502    Name * property = UCD::resolveProperty(value, this);
     503
     504    mNameMap.insert(std::make_pair(std::move(key), property));
    551505
    552506    return property;
    553507}
    554508
    555 Name * RE_Parser::resolvePropertyExpression(std::string namespaceValue, std::string nameValue) {
    556 
    557     auto key = std::make_pair(namespaceValue, nameValue);
     509Name * RE_Parser::createName(const std::string prop, const std::string value) {
     510
     511    auto key = std::make_pair(prop, value);
    558512
    559513    auto f = mNameMap.find(key);
     
    562516    }
    563517
    564 
    565 
    566     Name * property = makeName(namespaceValue, nameValue, Name::Type::UnicodeProperty);
    567 
    568     mNameMap.emplace(std::move(key), property);
     518    Name * property = UCD::resolveProperty(prop, value, this);
     519
     520    mNameMap.insert(std::make_pair(std::move(key), property));
    569521
    570522    return property;
     
    969921
    970922inline Name * RE_Parser::makeDigitSet() {
    971     return resolvePropertyExpression("nd");
     923    return createName("nd");
    972924}
    973925
    974926inline Name * RE_Parser::makeAlphaNumeric() {
    975     return resolvePropertyExpression("alnum");
     927    return createName("alnum");
    976928}
    977929
    978930inline Name * RE_Parser::makeWhitespaceSet() {
    979     return resolvePropertyExpression("whitespace");
     931    return createName("whitespace");
    980932}
    981933
    982934inline Name * RE_Parser::makeWordSet() {
    983     return resolvePropertyExpression("word");
    984 }
    985 
    986 }
     935    return createName("word");
     936}
     937
     938}
  • icGREP/icgrep-devel/icgrep/re/re_parser.h

    r4671 r4673  
    88#define RE_PARSER_H
    99
    10 #include "re_re.h"
    11 #include "re_any.h"
    12 #include "re_name.h"
    13 
     10#include <re/re_re.h>
     11#include <re/re_any.h>
     12#include <re/re_name.h>
     13#include <UCD/resolve_properties.h>
    1414#include <string>
    1515#include <list>
     
    1717#include <map>
    1818
     19
    1920namespace re {
    20        
     21
    2122enum CharsetOperatorKind
    2223        {intersectOp, setDiffOp, ampChar, hyphenChar, rangeHyphen, posixPropertyOpener, setOpener, setCloser, backSlash, emptyOperator};
     
    3738{
    3839public:
     40
     41    friend Name * UCD::resolveProperty(const std::string, RE_Parser *);
     42    friend Name * UCD::resolveProperty(const std::string, const std::string, RE_Parser *);
    3943
    4044    static RE * parse(const std::string &input_string, ModeFlagSet initialFlags);
     
    7579       
    7680    RE * makeComplement(RE * s);
    77     RE * makeWordBoundary ();
    78     RE * makeWordNonBoundary ();
     81    RE * makeWordBoundary();
     82    RE * makeWordNonBoundary();
    7983    Name * makeDigitSet();
    8084    Name * makeAlphaNumeric();
    8185    Name * makeWhitespaceSet();
    8286    Name * makeWordSet();
    83     Name * resolvePropertyExpression(std::string nameValue);
    8487
    85     Name * resolvePropertyExpression(std::string namespaceValue, std::string nameValue);
     88    Name * createName(const std::string value);
     89    Name * createName(const std::string prop, const std::string value);
    8690
    8791        CharsetOperatorKind getCharsetOperator();
Note: See TracChangeset for help on using the changeset viewer.