Ignore:
Timestamp:
Nov 5, 2017, 11:52:18 AM (20 months ago)
Author:
cameron
Message:

Utility functions for regular expression transformations

Location:
icGREP/icgrep-devel/icgrep/re
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/re/re_assertion.h

    r5493 r5725  
    11/*
    2  *  Copyright (c) 2015 International Characters.
     2 *  Copyright (c) 2017 International Characters.
    33 *  This software is licensed to the public under the Open Software License 3.0.
    44 *  icgrep is a trademark of International Characters.
     
    99
    1010#include <re/re_re.h>
     11#include <re/re_nullable.h>
     12#include <re/re_seq.h>
    1113
    1214namespace re {
     
    3234
    3335protected:
    34     friend Assertion * makeAssertion(RE * asserted, Kind k, Sense s);
     36    friend RE * makeAssertion(RE * asserted, Kind k, Sense s);
    3537    Assertion(RE * r, Kind k, Sense s) : RE(ClassTypeId::Assertion), mAsserted(r), mKind(k), mSense(s) {}
    3638    virtual ~Assertion() {}
     
    5153}
    5254
    53 inline Assertion * makeAssertion(RE * asserted, Assertion::Kind k, Assertion::Sense s) {
     55inline RE * makeAssertion(RE * asserted, Assertion::Kind k, Assertion::Sense s) {
     56    if (RE_Nullable::isNullable(asserted)) return makeSeq();
    5457    return new Assertion(asserted, k, s);
    5558}
     
    7881    return makeAssertion(r, Assertion::Kind::Boundary, Assertion::Sense::Negative);
    7982}
    80    
     83
     84RE * expandBoundaryAssertion(RE * r);
    8185}
    8286
  • icGREP/icgrep-devel/icgrep/re/re_rep.cpp

    r5646 r5725  
    9393}
    9494
     95RE * unrollFirst(Rep * rep) {
     96    RE * e = rep->getRE();
     97    auto lb = rep->getLB();
     98    auto ub = rep->getUB();
     99    if (ub == 0) return makeAlt();  // Can't unroll - return unmatchable regexp.
     100    // Unroll one copy of the loop and simplify.
     101    RE * reduced = makeRep(e, lb == 0 ? lb : lb - 1, ub == Rep::UNBOUNDED_REP ? ub : ub - 1);
     102    RE * unrolled = makeSeq({e, reduced});
     103    if (lb == 0) return makeAlt({makeSeq(), unrolled});
     104    else return unrolled;
    95105}
     106RE * unrollLast(Rep * rep) {
     107    RE * e = rep->getRE();
     108    auto lb = rep->getLB();
     109    auto ub = rep->getUB();
     110    if (ub == 0) return makeAlt();  // Can't unroll - return unmatchable regexp.
     111    // Unroll one copy of the loop and simplify.
     112    RE * reduced = makeRep(e, lb == 0 ? lb : lb - 1, ub == Rep::UNBOUNDED_REP ? ub : ub - 1);
     113    RE * unrolled = makeSeq({reduced, e});
     114    if (lb == 0) return makeAlt({makeSeq(), unrolled});
     115    else return unrolled;
     116}
     117}
  • icGREP/icgrep-devel/icgrep/re/re_rep.h

    r4516 r5725  
    7575
    7676RE * makeRep(RE * re, const int lower_bound, const int upper_bound);
     77   
     78RE * unrollFirst(Rep * re);
     79
     80RE * unrollLast(Rep * re);
    7781
    7882}
  • icGREP/icgrep-devel/icgrep/re/re_seq.h

    r5267 r5725  
    5555    if (LLVM_UNLIKELY(std::distance(begin, end) == 0)) {
    5656        return makeSeq();
    57     } else if (std::distance(begin, end) == 1) {
    58         return *begin;
    5957    } else {
    6058        Seq * seq = makeSeq();
Note: See TracChangeset for help on using the changeset viewer.