Changeset 4405


Ignore:
Timestamp:
Jan 6, 2015, 6:29:25 PM (4 years ago)
Author:
cameron
Message:

AST support for Lookahead/Lookbehind? assertions

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

Legend:

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

    r4337 r4405  
    1919#include <re/re_diff.h>
    2020#include <re/re_intersect.h>
     21#include <re/re_assertion.h>
    2122
    2223using namespace re;
     
    6263        retVal += "\" ";
    6364    }
     65    else if (const Assertion * a = dyn_cast<const Assertion>(re)) {
     66        retVal = (a->getSense() == Assertion::Sense::Positive) ? "" : "Negative";
     67        retVal += (a->getKind() == Assertion::Kind::Lookahead) ? "Lookahead" : "Lookbehind";
     68        retVal += "Assertion(";
     69        retVal += PrintRE(a->getAsserted());
     70        retVal += ") ";
     71    }
    6472    else if (const Diff* diff = dyn_cast<const Diff>(re))
    6573    {
     
    93101        }
    94102        else {
    95             retVal.append(std::to_string(re_rep->getUB()));           
     103            retVal.append(std::to_string(re_rep->getUB()));
    96104        }
    97105        retVal.append(")");
  • icGREP/icgrep-devel/icgrep/re/re_analysis.cpp

    r4393 r4405  
    1010#include "re_diff.h"
    1111#include "re_intersect.h"
     12#include "re_assertion.h"
    1213
    1314namespace re {
     
    2627    else if (Rep * rep = dyn_cast<Rep>(re)) {
    2728        return (rep->getLB() == 1) && (rep->getUB() == 1) && isByteLength(rep->getRE());
     29    }
     30    else if (Assertion * a = dyn_cast<Assertion>(re)) {
     31        return false;
    2832    }
    2933    else if (Diff * diff = dyn_cast<Diff>(re)) {
     
    5458        return (rep->getLB() == 1) && (rep->getUB() == 1) && isUnicodeUnitLength(rep->getRE());
    5559    }
     60    else if (Assertion * a = dyn_cast<Assertion>(re)) {
     61        return false;
     62    }
    5663    else if (Diff * diff = dyn_cast<Diff>(re)) {
    5764        return isUnicodeUnitLength(diff->getLH()) && isUnicodeUnitLength(diff->getRH());
  • icGREP/icgrep-devel/icgrep/re/re_compiler.cpp

    r4404 r4405  
    1717#include <re/re_diff.h>
    1818#include <re/re_intersect.h>
     19#include <re/re_assertion.h>
    1920#include <re/re_analysis.h>
    2021#include <cc/cc_namemap.hpp>
     
    3132    return MarkerType{PostPosition, pb.createAssign(marker_name, s)};
    3233}
    33    
     34
    3435MarkerType wrapPostPositionMarker(Assign * s) {
    3536    return MarkerType{PostPosition, s};
    3637}
    37    
     38
    3839MarkerType makeFinalPositionMarker(std::string marker_name, PabloAST * s, PabloBlock & pb) {
    3940    return MarkerType{FinalByte, pb.createAssign(marker_name, s)};
     
    7172#define UNICODE_LINE_BREAK true
    7273
    73    
     74
    7475void RE_Compiler::initializeRequiredStreams(cc::CC_Compiler & ccc) {
    7576
    7677    const std::string initial = "initial";
    7778    const std::string nonfinal = "nonfinal";
    78    
     79
    7980    Assign * LF = mCG.createAssign("LF", ccc.compileCC(makeCC(0x0A)));
    8081    mLineFeed = mCG.createVar(LF);
     
    9091    mCRLF = mCG.createVar(acrlf);
    9192#endif
    92    
     93
    9394#ifndef USE_IF_FOR_NONFINAL
    9495    PabloAST * u8single = ccc.compileCC(makeCC(0x00, 0x7F));
     
    9899    PabloAST * u8pfx = mCG.createOr(mCG.createOr(u8pfx2, u8pfx3), u8pfx4);
    99100    mInitial = mCG.createVar(mCG.createAssign(initial, mCG.createOr(u8pfx, u8single)));
    100    
     101
    101102    PabloAST * u8scope32 = mCG.createAdvance(u8pfx3, 1);
    102103    PabloAST * u8scope42 = mCG.createAdvance(u8pfx4, 1);
     
    141142    mCG.createAssign("lf", mCG.createAnd(lb, mCG.createNot(mCRLF)), 1);
    142143}
    143    
     144
    144145MarkerType RE_Compiler::compile(RE * re, PabloBlock & pb) {
    145146    return process(re, makePostPositionMarker("start", pb.createOnes(), pb), pb);
    146147}
    147        
     148
    148149PabloAST * RE_Compiler::character_class_strm(Name * name, PabloBlock & pb) {
    149150    Var * var = name->getCompiled();
     
    174175        //return pb.createAdvanceThenScanThru(pb.createVar(markerVar(m), pb), mNonFinal);
    175176        return pb.createScanThru(pb.createAnd(mInitial, pb.createAdvance(pb.createVar(markerVar(m, pb)), 1)), mNonFinal);
    176        
    177     }
    178 }
    179    
     177    }
     178}
    180179
    181180MarkerType RE_Compiler::process(RE * re, MarkerType marker, PabloBlock & pb) {
     
    191190    else if (Rep * rep = dyn_cast<Rep>(re)) {
    192191        return process(rep, marker, pb);
     192    }
     193    else if (Assertion * a = dyn_cast<Assertion>(re)) {
     194        return process(a, marker, pb);
    193195    }
    194196    else if (isa<Any>(re)) {
     
    265267}
    266268
     269MarkerType RE_Compiler::process(Assertion * a, MarkerType marker, PabloBlock & pb) {
     270    throw std::runtime_error("Assertions not implemented.");
     271}
     272
    267273MarkerType RE_Compiler::process(Diff * diff, MarkerType marker, PabloBlock & pb) {
    268274    RE * lh = diff->getLH();
     
    300306    else { // if (rep->getUB() != Rep::UNBOUNDED_REP)
    301307        return processBoundedRep(rep->getRE(), ub - lb, marker, pb);
    302     }   
     308    }
    303309}
    304310
     
    308314   |repeat_count| consecutive occurrences of such items.
    309315*/
    310        
     316
    311317inline Assign * RE_Compiler::consecutive(Assign * repeated, int repeated_lgth, int repeat_count, pablo::PabloBlock & pb) {
    312318        int i = repeated_lgth;
     
    324330        return consecutive_i;
    325331}
    326                
     332
    327333MarkerType RE_Compiler::processLowerBound(RE * repeated, int lb, MarkerType marker, PabloBlock & pb) {
    328334    if (isByteLength(repeated)) {
  • icGREP/icgrep-devel/icgrep/re/re_compiler.h

    r4358 r4405  
    8383    MarkerType process(Seq * seq, MarkerType marker, pablo::PabloBlock & pb);
    8484    MarkerType process(Alt * alt, MarkerType marker, pablo::PabloBlock & pb);
     85    MarkerType process(Assertion * a, MarkerType marker, pablo::PabloBlock & pb);
    8586    MarkerType process(Rep * rep, MarkerType marker, pablo::PabloBlock & pb);
    8687    MarkerType process(Diff * diff, MarkerType marker, pablo::PabloBlock & cg);
  • icGREP/icgrep-devel/icgrep/re/re_parser.cpp

    r4402 r4405  
    1414#include <re/re_diff.h>
    1515#include <re/re_intersect.h>
     16#include <re/re_assertion.h>
    1617#include <re/parsefailure.h>
    1718#include <UCD/CaseFolding_txt.h>
     
    4748
    4849RE * makeLookAheadAssertion(RE * r) {
    49     throw ParseFailure("Lookahead assertion not supported.");
     50    return makeAssertion(r, Assertion::Kind::Lookahead, Assertion::Sense::Positive);
    5051}
    5152
    5253RE * makeNegativeLookAheadAssertion(RE * r) {
    53     throw ParseFailure("Lookahead assertion not supported.");
     54    return makeAssertion(r, Assertion::Kind::Lookahead, Assertion::Sense::Negative);
    5455}
    5556
    5657RE * makeLookBehindAssertion(RE * r) {
    57     throw ParseFailure("Lookbehind assertion not supported.");
     58    return makeAssertion(r, Assertion::Kind::Lookbehind, Assertion::Sense::Positive);
    5859}
    5960
    6061RE * makeNegativeLookBehindAssertion(RE * r) {
    61     throw ParseFailure("Lookbehind assertion not supported.");
     62    return makeAssertion(r, Assertion::Kind::Lookbehind, Assertion::Sense::Negative);
    6263}
    6364
     
    198199                throw_incomplete_expression_error_if_end_of_stream();
    199200                if (*_cursor == '=') {
     201                    ++_cursor;
    200202                    subexpr = parse_alt();
    201203                    group_expr = makeLookBehindAssertion(subexpr);
    202204                }
    203205                else if (*_cursor == '!') {
     206                    ++_cursor;
    204207                    subexpr = parse_alt();
    205208                    group_expr = makeNegativeLookBehindAssertion(subexpr);
  • icGREP/icgrep-devel/icgrep/re/re_re.h

    r4272 r4405  
    2222class Alt;
    2323class Any;
     24class Assertion;
    2425class CC;
    2526class Diff;
     
    4041        Alt
    4142        , Any
     43        , Assertion
    4244        , CC
    4345        , Diff
  • icGREP/icgrep-devel/icgrep/re/re_simplifier.cpp

    r4308 r4405  
    99#include "re_diff.h"
    1010#include "re_intersect.h"
     11#include "re_assertion.h"
    1112#include <algorithm>
    1213#include <memory>
     
    3233        re = makeSeq(list.begin(), list.end());
    3334    }
     35    else if (Assertion * a = dyn_cast<Assertion>(re)) {
     36        re = makeAssertion(simplify(a->getAsserted()), a->getKind(), a->getSense());
     37    }
    3438    else if (Rep * rep = dyn_cast<Rep>(re)) {
    3539        re = makeRep(simplify(rep->getRE()), rep->getLB(), rep->getUB());
Note: See TracChangeset for help on using the changeset viewer.