# HG changeset patch # User Masataka Kohagura # Date 1453884061 -32400 # Node ID ef95a7f1bc03f4467b0b8de68ba8e2bf78d1b5a4 # Parent 292753bb31e475943c8bd0f21ff5b7393490857f implement tSearch diff -r 292753bb31e4 -r ef95a7f1bc03 regexParser/regexParser.h --- a/regexParser/regexParser.h Wed Jan 27 16:37:42 2016 +0900 +++ b/regexParser/regexParser.h Wed Jan 27 17:41:01 2016 +0900 @@ -60,8 +60,8 @@ typedef struct tState { State *state; - void (*stateSkip)(tsValue); - void (*stateMatch)(tsValue); + tsValue (*stateSkip)(tsValue); + tsValue (*stateContinue)(tsValue); int ccvSize; CCVPtr ccv; } TState, *TStatePtr; diff -r 292753bb31e4 -r ef95a7f1bc03 regexParser/sequentialSearch.cc --- a/regexParser/sequentialSearch.cc Wed Jan 27 16:37:42 2016 +0900 +++ b/regexParser/sequentialSearch.cc Wed Jan 27 17:41:01 2016 +0900 @@ -17,6 +17,7 @@ void stateMatch(Buffer buff) { fwrite(buff.matchBegin,buff.buffptr-buff.matchBegin-1,1,stdout); puts(""); + buff.buffptr--; stateSkip(buff); } diff -r 292753bb31e4 -r ef95a7f1bc03 regexParser/subsetConstruction.cc --- a/regexParser/subsetConstruction.cc Wed Jan 27 16:37:42 2016 +0900 +++ b/regexParser/subsetConstruction.cc Wed Jan 27 17:41:01 2016 +0900 @@ -398,7 +398,10 @@ unsigned long baseNum = 1 << (bitPosition-1); // printf("bit %lx pos %d baseNum %lx\n",bi.bitContainer,bitPosition,baseNum); bi.bitContainer ^= baseNum; - if (baseNum==2) continue; // EOF case + if (baseNum==2) { + s->accept = true; + continue; // EOF case + } StatePtr base = tg->stateArray[baseNum]; if (base == NULL) { errorMassege("No base state",__LINE__,__FILE__); break; diff -r 292753bb31e4 -r ef95a7f1bc03 regexParser/threadedSearch.cc --- a/regexParser/threadedSearch.cc Wed Jan 27 16:37:42 2016 +0900 +++ b/regexParser/threadedSearch.cc Wed Jan 27 17:41:01 2016 +0900 @@ -7,17 +7,28 @@ void tSearch(TSValue tsv); -void stateSkip(TSValue tsv) { - tsv.buff.matchBegin = tsv.buff.buffptr; +TSValue stateNothing(TSValue tsv) { + return tsv; } -void stateMatch(TSValue tsv) { +TSValue stateSkip(TSValue tsv) { + tsv.buff.matchBegin = tsv.buff.buffptr; + return tsv; +} + +TSValue stateMatch(TSValue tsv) { fwrite(tsv.buff.matchBegin,tsv.buff.buffptr-tsv.buff.matchBegin-1,1,stdout); - puts("\n"); + puts(""); + tsv.current = tsv.tg->stateList->tState; + tsv.buff.buffptr--; + tsv = stateSkip(tsv); + return tsv; } TStatePtr generateTState(StatePtr state) { TStatePtr tState = NEW(TState); + tState->state = state; + state->tState = tState; int ccvSize = 0; CharClassWalkerPtr ccw = createCharClassWalker(state->cc); while (hasNext(ccw)) { @@ -43,10 +54,10 @@ free(ccw); if (state->accept) { tState->stateSkip = stateMatch; - tState->stateMatch = stateSkip; + tState->stateContinue = stateNothing; } else { tState->stateSkip = stateSkip; - tState->stateMatch = stateMatch; + tState->stateContinue = stateNothing; } return tState; } @@ -57,7 +68,7 @@ for (int i = 0; i < tsv.current->ccvSize; i++) { CCVPtr ccv = &tsv.current->ccv[i]; if (cbegin) { - tsv.current->stateSkip(tsv); + tsv = tsv.current->stateSkip(tsv); goto next; } else if (c<=ccv->end) { // range matched. @@ -83,13 +94,11 @@ } } tsv.current = ccv->tState; - if (tsv.current->state->bitState.bitContainer & 2) { - tsv.current->stateMatch(tsv); - } + // tsv = tsv.current->stateContinue(tsv); goto next; } } - tsv.current->stateSkip(tsv); + tsv = tsv.current->stateSkip(tsv); } }