Mercurial > hg > Applications > Grep
changeset 264:ef95a7f1bc03
implement tSearch
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 27 Jan 2016 17:41:01 +0900 |
parents | 292753bb31e4 |
children | 1e2c12ec25b7 |
files | regexParser/regexParser.h regexParser/sequentialSearch.cc regexParser/subsetConstruction.cc regexParser/threadedSearch.cc |
diffstat | 4 files changed, 27 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- 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;
--- 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); }
--- 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;
--- 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 (c<ccv->begin) { - 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); } }