Ignore:
Timestamp:
Oct 4, 2016, 3:26:12 PM (3 years ago)
Author:
xwa163
Message:

Support BRE and ERE for regex syntax.

File:
1 edited

Legend:

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

    r5167 r5180  
    3232static cl::OptionCategory LegacyGrepOptions("A. Standard Grep Options",
    3333                                       "These are standard grep options intended for compatibility with typical grep usage.");
    34 enum RE_Syntax {FixedStrings, BRE, ERE, PCRE};
    3534
    3635#ifdef FUTURE
    3736static cl::OptionCategory RegexpOptions("Regular Expression Interpretation", "These options control regular expression interpretation");
    38 static cl::opt<RE_Syntax> RegexpSyntax(cl::desc("Regular expression syntax:"),
     37static cl::opt<re::RE_Syntax> RegexpSyntax(cl::desc("Regular expression syntax:"),
    3938    cl::values(
    40         clEnumValN(FixedStrings, "F", "Fixed strings, separated by newlines"),
    41         clEnumValN(BRE, "G", "Posix basic regular expression (BRE) syntax"),
    42         clEnumValN(ERE, "E", "Posix extened regular expression (ERE) syntax"),
    43         clEnumValN(PCRE, "P", "Perl-compatible regular expression (PCRE) syntax - default"),
    44                clEnumValEnd), cl::cat(LegacyGrepOptions), cl::Grouping, cl::init(PCRE));
     39        clEnumValN(re::RE_Syntax::FixedStrings, "F", "Fixed strings, separated by newlines"),
     40        clEnumValN(re::RE_Syntax::BRE, "G", "Posix basic regular expression (BRE) syntax"),
     41        clEnumValN(re::RE_Syntax::ERE, "E", "Posix extended regular expression (ERE) syntax"),
     42        clEnumValN(re::RE_Syntax::PCRE, "P", "Perl-compatible regular expression (PCRE) syntax - default"),
     43               clEnumValEnd), cl::cat(LegacyGrepOptions), cl::Grouping, cl::init(re::RE_Syntax::PCRE));
    4544#endif
    4645
     
    120119    re::RE * re_ast = nullptr;
    121120    for (unsigned i = 0; i < regexVector.size(); i++) {
     121#ifdef FUTURE
     122        re_ast = re::RE_Parser::parse(regexVector[i], globalFlags, RegexpSyntax);
     123#else
    122124        re_ast = re::RE_Parser::parse(regexVector[i], globalFlags);
     125#endif
    123126        REs.push_back(re_ast);
    124127        allREs += regexVector[i] + "\n";
     
    181184// Filters out the command line strings that shouldn't be passed on to Grep
    182185bool isArgUnwantedForGrep(char *argument) {
     186#ifdef FUTURE
     187    std::vector<std::string> unwantedFlags = {"-n", "-P", "-G", "-E"};
     188#else
    183189    std::vector<std::string> unwantedFlags = {"-n"};
    184 
    185     for (unsigned i = 0; i < inputFiles.size(); ++i){
     190#endif
     191
     192    for (unsigned i = 0; i < unwantedFlags.size(); ++i){
    186193        if (strcmp(argument, unwantedFlags[i].c_str()) == 0) {
    187194            return true;
     
    240247    }
    241248
     249#ifdef FUTURE
     250    switch (RegexpSyntax) {
     251        case re::RE_Syntax::BRE:
     252            grepArguments.append("\"-G\" ");
     253            break;
     254        case re::RE_Syntax::ERE:
     255            grepArguments.append("\"-E\" ");
     256            break;
     257        case re::RE_Syntax::PCRE:
     258            grepArguments.append("\"-P\" ");
     259            break;
     260        default:
     261            //TODO: handle fix string
     262            break;
     263    }
     264#endif
     265
    242266    std::string systemCall = argv[0];
    243267    systemCall.append(" ");
    244268    systemCall.append(icGrepArguments);
    245269    systemCall.append(" ");
     270#ifdef FUTURE
     271    systemCall.append(" | grep --color=always ");
     272#else
    246273    systemCall.append(" | grep --color=always -P ");
     274#endif
    247275    systemCall.append(grepArguments);
    248276
     
    296324    cl::ParseCommandLineOptions(argc, argv);
    297325#ifdef FUTURE
    298     if (RegexpSyntax != RE_Syntax::PCRE) {
    299         llvm::report_fatal_error("Sorry, only PCRE syntax is fully supported\n.");
     326    if (RegexpSyntax == re::RE_Syntax::FixedStrings) {
     327        llvm::report_fatal_error("Sorry, FixedStrings syntax is not fully supported\n.");
    300328    }
    301329#endif
Note: See TracChangeset for help on using the changeset viewer.