Mercurial > hg > Applications > Grep
comparison regexParser/threadedSearch.cc @ 293:948428caf616
NFA maximum match worked
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 02 Feb 2016 10:38:45 +0900 |
parents | 868f01f1ba8e |
children | 63213964502a |
comparison
equal
deleted
inserted
replaced
292:868f01f1ba8e | 293:948428caf616 |
---|---|
80 generateTState(state,tg); | 80 generateTState(state,tg); |
81 } | 81 } |
82 return state->tState; | 82 return state->tState; |
83 } | 83 } |
84 | 84 |
85 #define DEBUG 0 | |
86 | |
85 TSValue tSearch(TSValue tsv) { | 87 TSValue tSearch(TSValue tsv) { |
86 TSValuePtr tsvp = &tsv; | 88 #if DEBUG |
89 TSValuePtr tsvp = &tsv; // make tsv visible in lldb | |
90 #endif | |
87 next: while (tsv.buff.buffptr < tsv.buff.buffend) { | 91 next: while (tsv.buff.buffptr < tsv.buff.buffend) { |
88 unsigned char c = *tsv.buff.buffptr++; | 92 unsigned char c = *tsv.buff.buffptr++; |
89 // printState(tsv.current->state); | 93 // printState(tsv.current->state); |
90 for (int i = 0; i < tsv.current->ccvSize; i++) { | 94 for (int i = 0; i < tsv.current->ccvSize; i++) { |
91 CCVPtr ccv = &tsv.current->ccv[i]; | 95 CCVPtr ccv = &tsv.current->ccv[i]; |
97 // range matched. | 101 // range matched. |
98 if (ccv->w.word) { | 102 if (ccv->w.word) { |
99 // match the word. | 103 // match the word. |
100 // if (not match) continue; | 104 // if (not match) continue; |
101 } | 105 } |
106 tsv = tsv.current->stateMatch(tsv); | |
102 if (ccv->tState) { | 107 if (ccv->tState) { |
103 tsv.current = ccv->tState; | 108 tsv.current = ccv->tState; |
104 } else { | 109 } else { |
105 tsv.current = nextTState(ccv->state,tsv.tg); | 110 tsv.current = nextTState(ccv->state,tsv.tg); |
106 ccv->tState = tsv.current; | 111 ccv->tState = tsv.current; |
107 } | 112 } |
108 tsv = tsv.current->stateMatch(tsv); | |
109 goto next; | 113 goto next; |
110 } | 114 } |
111 } | 115 } |
112 tsv = tsv.current->stateSkip(tsv); | 116 tsv = tsv.current->stateSkip(tsv); |
113 tsv.matchBegin = tsv.buff.buffptr; | 117 tsv.matchBegin = tsv.buff.buffptr; |
114 } | 118 } |
119 #if DEBUG | |
115 *tsvp = tsv; | 120 *tsvp = tsv; |
116 return *tsvp; | 121 return *tsvp; |
122 #else | |
123 return tsv; | |
124 #endif | |
117 } | 125 } |
118 | 126 |
119 void threadedSearch(TransitionGeneratorPtr tg, Buffer buff) { | 127 void threadedSearch(TransitionGeneratorPtr tg, Buffer buff) { |
120 TSValue tsv; | 128 TSValue tsv; |
121 tsv.buff = buff; | 129 tsv.buff = buff; |
122 tsv.tg = tg; | 130 tsv.tg = tg; |
123 tsv.blk = NULL; | 131 tsv.blk = NULL; |
124 tsv.tg->stateSkip = stateSkip; | 132 tsv.tg->stateSkip = stateSkip; |
125 tsv.tg->stateMatch = stateMatch; | 133 tsv.tg->stateMatch = stateMatch; |
126 tsv.tg->stateNothing = stateNothing; | 134 tsv.tg->stateNothing = stateNothing; |
127 tsv.matchBegin = tsv.matchEnd = NULL; | 135 tsv.matchBegin = buff.buffptr; |
136 tsv.matchEnd = NULL; | |
128 tsv.current = generateTState(tg->stateList,tg); | 137 tsv.current = generateTState(tg->stateList,tg); |
129 tg->stateStart = NEW(State); | 138 tg->stateStart = NEW(State); |
130 *tg->stateStart = *tg->stateList; | 139 *tg->stateStart = *tg->stateList; |
131 tg->stateStart->accept = false; // Start state never accept | 140 tg->stateStart->accept = false; // Start state never accept |
132 generateTState(tg->stateStart,tg); | 141 generateTState(tg->stateStart,tg); |