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

AST support for Lookahead/Lookbehind? assertions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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)) {
Note: See TracChangeset for help on using the changeset viewer.