Mercurial > hg > Applications > Grep
diff regexParser/threadedSearch.cc @ 298:63213964502a
refactoring ....
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 03 Feb 2016 12:24:34 +0900 |
parents | 948428caf616 |
children | bdfe0a32c48f |
line wrap: on
line diff
--- a/regexParser/threadedSearch.cc Tue Feb 02 11:58:59 2016 +0900 +++ b/regexParser/threadedSearch.cc Wed Feb 03 12:24:34 2016 +0900 @@ -18,12 +18,13 @@ puts(""); tsv.matchEnd = NULL; } + tsv.matchBegin = tsv.buff.buffptr; // next char may be matchBegin return tsv; } static TSValue stateMatch(TSValue tsv) { - tsv.matchEnd = tsv.buff.buffptr; // next char of the match + tsv.matchEnd = tsv.buff.buffptr; // next char of the match return tsv; } @@ -38,11 +39,11 @@ } tState->ccvSize = ccvSize; if (state->accept) { - tState->stateSkip = tg->stateSkip; - tState->stateMatch = tg->stateMatch; + tState->stateMatch = tg->stateMatch; + tState->stateSkip = tg->stateSkip; } else { - tState->stateSkip = tg->stateSkip; - tState->stateMatch = tg->stateNothing; + tState->stateMatch = tg->stateNothing; + tState->stateSkip = tg->stateSkip; } if (ccvSize == 0) { tState->ccv = NULL; @@ -89,13 +90,17 @@ TSValuePtr tsvp = &tsv; // make tsv visible in lldb #endif next: while (tsv.buff.buffptr < tsv.buff.buffend) { + tsv = tsv.current->stateMatch(tsv); + if (tsv.current->ccvSize==0) { + // matched start again + tsv.current = tsv.tg->stateStart->tState; + } unsigned char c = *tsv.buff.buffptr++; // printState(tsv.current->state); for (int i = 0; i < tsv.current->ccvSize; i++) { CCVPtr ccv = &tsv.current->ccv[i]; if (c<ccv->begin) { tsv = tsv.current->stateSkip(tsv); - tsv.matchBegin = tsv.buff.buffptr; goto next; } else if (c<=ccv->end) { // range matched. @@ -103,7 +108,6 @@ // match the word. // if (not match) continue; } - tsv = tsv.current->stateMatch(tsv); if (ccv->tState) { tsv.current = ccv->tState; } else { @@ -114,7 +118,6 @@ } } tsv = tsv.current->stateSkip(tsv); - tsv.matchBegin = tsv.buff.buffptr; } #if DEBUG *tsvp = tsv; @@ -124,21 +127,32 @@ #endif } -void threadedSearch(TransitionGeneratorPtr tg, Buffer buff) { +TSValue +createTSValue(TransitionGeneratorPtr tg, Buffer buff) { TSValue tsv; + if (!tg) { + tg = createTransitionGenerator(); + } tsv.buff = buff; tsv.tg = tg; tsv.blk = NULL; + tsv.matchBegin = buff.buffptr; + tsv.matchEnd = NULL; tsv.tg->stateSkip = stateSkip; tsv.tg->stateMatch = stateMatch; tsv.tg->stateNothing = stateNothing; - tsv.matchBegin = buff.buffptr; - tsv.matchEnd = NULL; + return tsv; +} + + +void threadedSearch(TransitionGeneratorPtr tg, Buffer buff) { + TSValue tsv = createTSValue(tg,buff); tsv.current = generateTState(tg->stateList,tg); tg->stateStart = NEW(State); *tg->stateStart = *tg->stateList; tg->stateStart->accept = false; // Start state never accept generateTState(tg->stateStart,tg); - tSearch(tsv); } + +/* end */