Пример #1
0
        SearchEntry top; //stack entry

        #endregion Fields

        #region Constructors

        internal Matcher(Pattern regex)
        {
            this.re=regex;

            int memregCount, counterCount, lookaheadCount;
            if((memregCount=regex.memregs)>0) {
                MemReg[] memregs = new MemReg[memregCount];
                for(int i=0;i<memregCount;i++){
                    memregs[i]=new MemReg(-1); //unlikely to SearchEntry, in this case we know memreg indicies by definition
                }
                this.memregs=memregs;
            }

            if((counterCount=regex.counters)>0) counters = new int[counterCount];

            if((lookaheadCount=regex.lookaheads)>0) {
                LAEntry[] lookaheads=new LAEntry[lookaheadCount];
                for(int i=0;i<lookaheadCount;i++){
                    lookaheads[i] = new LAEntry();
                }
                this.lookaheads = lookaheads;
            }

            first = new SearchEntry();
            defaultEntry = new SearchEntry();
            minQueueLength = regex.stringRepr.Length/2;  // just evaluation!!!
        }
Пример #2
0
 private MemReg Bounds(int id)
 {
     MemReg mr;
     if(id>=0){
         mr=memregs[id];
     } else switch(id) {
         case PREFIX:
             mr=prefixBounds;
             if(mr==null) prefixBounds=mr=new MemReg(PREFIX);
             mr._in=offset;
             mr._out=wOffset;
             break;
         case SUFFIX:
             mr=suffixBounds;
             if(mr==null) suffixBounds=mr=new MemReg(SUFFIX);
             mr._in=wEnd;
             mr._out=end;
             break;
         case TARGET:
             mr=targetBounds;
             if(mr==null) targetBounds=mr=new MemReg(TARGET);
             mr._in=offset;
             mr._out=end;
             break;
         default:
             throw new ArgumentException("illegal group id: "+id+"; must either nonnegative int, or MatchResult.PREFIX, or MatchResult.SUFFIX");
         }
     int _in;
     if((_in=mr._in)<0 || mr._out<_in) return null;
     return mr;
 }
Пример #3
0
 internal static void SaveMemregState(SearchEntry entry, int memreg, MemReg mr)
 {
     entry.isState=true;
     MState current=entry.mCurrent;
     if(current==null) {
         MState head=entry.mHead;
         if(head==null) entry.mHead=entry.mCurrent=current=new MState();
         else current=head;
     } else {
         MState next=current.next;
         if(next==null){
             current.next=next=new MState();
             next.prev=current;
         }
         current=next;
     }
     current.index=memreg;
     current._in=mr._in;
     current._out=mr._out;
     entry.mCurrent=current;
 }
Пример #4
0
 internal static void PopState(SearchEntry entry, MemReg[] memregs, int[] counters)
 {
     MState ms=entry.mCurrent;
     while(ms!=null){
         MemReg mr=memregs[ms.index];
         mr._in=ms._in;
         mr._out=ms._out;
         ms=ms.prev;
     }
     CState cs=entry.cCurrent;
     while(cs!=null) {
         counters[cs.index]=cs.value;
         cs=cs.prev;
     }
     entry.mCurrent=null;
     entry.cCurrent=null;
     entry.isState=false;
 }