Ignore:
Timestamp:
Dec 29, 2016, 12:03:21 AM (3 years ago)
Author:
nmedfort
Message:

Potential fix for '\p{script=/.*hir.*/}'

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

Legend:

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

    r5234 r5241  
    3636
    3737struct NameResolver {
    38 
    3938    RE * resolve(RE * re) {
    4039        if (Name * name = dyn_cast<Name>(re)) {
  • icGREP/icgrep-devel/icgrep/re/re_parser.cpp

    r5234 r5241  
    2727#include <string>
    2828#include <algorithm>
     29#include <iostream>
    2930
    3031namespace re {
     
    3334RE * RE_Parser::parse(const std::string & regular_expression, ModeFlagSet initialFlags, RE_Syntax syntax) {
    3435    std::unique_ptr<RE_Parser> parser = nullptr;
    35 
    3636    switch (syntax) {
    3737        case RE_Syntax::PCRE:
     
    5252            break;
    5353    }
    54 
    55 
    5654    parser->fModeFlagSet = initialFlags;
    5755    parser->fNested = false;
     
    634632}
    635633
    636 RE * RE_Parser::parseRegexPropertyValue(const std::string& propName, const std::string& regexValue) {
    637     auto regexValueForGrep = "^" + regexValue + "$";
    638     RE* propValueRe = RE_Parser::parse(regexValueForGrep, fModeFlagSet, mReSyntax);
     634RE * RE_Parser::parseRegexPropertyValue(const std::string & propName, const std::string& regexValue) {
     635    RE * propValueRe = RE_Parser::parse("^" + regexValue + "$", fModeFlagSet, mReSyntax);
    639636    GrepEngine engine;
    640637    engine.grepCodeGen("NamePattern", propValueRe, false, false, GrepType::PropertyValue);
    641     auto grepValue = engine.grepPropertyValues(propName);
    642 
    643     auto grepValueSize = grepValue.size();
    644     if (!grepValueSize) {
     638    const auto matches = engine.grepPropertyValues(propName);
     639    if (matches.empty()) {
    645640        ParseFailure("regex " + regexValue + " match no property values");
    646     } else if (grepValueSize == 1) {
    647         // handle right value
    648         return createName(std::string(propName), std::string(grepValue[0]));
     641    } else if (matches.size() == 1) {
     642        return createName(propName, matches.front());
    649643    } else {
    650         std::vector<re::RE*> valueRes;
    651         for (auto iter = grepValue.begin(); iter != grepValue.end(); ++iter) {
    652             valueRes.push_back(createName(std::string(propName), std::string(*iter)));
    653         }
    654 
    655         return makeAlt(valueRes.begin(), valueRes.end());
     644        std::vector<re::RE *> alt;
     645        for (auto value : matches) {
     646            alt.push_back(createName(propName, value));
     647        }
     648        return makeAlt(alt.begin(), alt.end());
    656649    }
    657650}
     
    11131106}
    11141107
    1115 Name * RE_Parser::createName(std::string && value) {
     1108Name * RE_Parser::createName(std::string value) {
    11161109    auto key = std::make_pair("", value);
    11171110    auto f = mNameMap.find(key);
     
    11241117    }
    11251118
    1126 Name * RE_Parser::createName(std::string && prop, std::string && value) {
     1119Name * RE_Parser::createName(std::string prop, std::string value) {
    11271120    auto key = std::make_pair(prop, value);
    11281121    auto f = mNameMap.find(key);
  • icGREP/icgrep-devel/icgrep/re/re_parser.h

    r5218 r5241  
    164164    Name * makeWordSet();
    165165   
    166     Name * createName(std::string && value);
    167     Name * createName(std::string && prop, std::string && value);
     166    Name * createName(std::string value);
     167    Name * createName(std::string prop, std::string value);
    168168
    169169    virtual bool isUnsupportChartsetOperator(char c);
Note: See TracChangeset for help on using the changeset viewer.