Mercurial > hg > Applications > Grep
comparison regexParser/threadedSearch.cc @ 322:62f4628d2c0d
tSearch loop unwind
author | Nozomi |
---|---|
date | Thu, 26 May 2016 19:57:44 +0900 |
parents | a1b65d39b947 |
children |
comparison
equal
deleted
inserted
replaced
321:a1b65d39b947 | 322:62f4628d2c0d |
---|---|
82 } | 82 } |
83 if (ccvSize == 0) { | 83 if (ccvSize == 0) { |
84 tState->ccv = NULL; | 84 tState->ccv = NULL; |
85 state->tState = tState; | 85 state->tState = tState; |
86 return tState; | 86 return tState; |
87 } else tState->ccv = (ccv*)malloc(sizeof(ccv)*ccvSize); | 87 } else tState->ccv = (ccv*)malloc(sizeof(ccv)*(ccvSize+1)); |
88 ccw = createCharClassWalker(state->cc); | 88 ccw = createCharClassWalker(state->cc); |
89 int i = 0; | 89 int i = 0; |
90 while (hasNext(ccw)) { | 90 while (hasNext(ccw)) { |
91 CharClassPtr cc = getNext(ccw); | 91 CharClassPtr cc = getNext(ccw); |
92 unsigned long begin = cc->cond.range.begin; | 92 unsigned long begin = cc->cond.range.begin; |
96 ccv->end = end; | 96 ccv->end = end; |
97 ccv->tState = NULL; | 97 ccv->tState = NULL; |
98 ccv->state = cc->nextState; | 98 ccv->state = cc->nextState; |
99 ccv->w = cc->cond.w; | 99 ccv->w = cc->cond.w; |
100 } | 100 } |
101 struct ccv *ccv = &tState->ccv[i]; | |
102 ccv->begin = MAXCHAR+1; | |
103 ccv->end = ccv->begin; | |
104 ccv->tState = NULL; | |
101 free(ccw); | 105 free(ccw); |
102 state->tState = tState; | 106 state->tState = tState; |
103 return tState; | 107 return tState; |
104 } | 108 } |
105 | 109 |
119 } | 123 } |
120 | 124 |
121 #define DEBUG 0 | 125 #define DEBUG 0 |
122 | 126 |
123 TSValue tSearch(TSValue tsv) { | 127 TSValue tSearch(TSValue tsv) { |
124 #if DEBUG | |
125 TSValuePtr tsvp = &tsv; // make tsv visible in lldb | |
126 #endif | |
127 next: while (tsv.buff.buffptr < tsv.buff.buffend) { | 128 next: while (tsv.buff.buffptr < tsv.buff.buffend) { |
128 tsv = tsv.current->stateMatch(tsv); | 129 tsv = tsv.current->stateMatch(tsv); |
129 if (tsv.current->ccvSize==0) { | 130 if (tsv.current->ccvSize==0) { |
130 // matched start again | 131 // matched start again |
131 tsv.current = tsv.tg->stateStart->tState; | 132 tsv.current = tsv.tg->stateStart->tState; |
132 } | 133 } |
133 unsigned char c = *tsv.buff.buffptr++; | 134 unsigned char c = *tsv.buff.buffptr++; |
134 // printState(tsv.current->state); | 135 // printState(tsv.current->state); |
135 for (int i = 0; i < tsv.current->ccvSize; i++) { | 136 CCVPtr ccv = &tsv.current->ccv[0]; |
136 CCVPtr ccv = &tsv.current->ccv[i]; | 137 for (;;) { |
137 if (c<ccv->begin) { | 138 if (c<ccv[0].begin) goto noMatch; |
138 tsv.current = tsv.tg->stateStart->tState; | 139 else if (c<=ccv[0].end) goto match; |
139 tsv = tsv.current->stateSkip(tsv); | 140 if (c<ccv[1].begin) goto noMatch; |
140 goto next; | 141 else if (c<=ccv[1].end) goto match; |
141 } else if (c<=ccv->end) { | 142 if (c<ccv[2].begin) goto noMatch; |
142 // range matched. | 143 else if (c<=ccv[2].end) goto match; |
143 if (ccv->w.word) { | 144 if (c<ccv[3].begin) goto noMatch; |
144 WordPtr w; | 145 else if (c<=ccv[3].end) goto match; |
145 for (w = &ccv->w;w;w = w->next) { | 146 if (c<ccv[4].begin) goto noMatch; |
146 // match the word. | 147 else if (c<=ccv[4].end) goto match; |
147 if (strncmp((const char *)w->word,(const char *)tsv.buff.buffptr-1,w->length)==0) break; | 148 ccv += 5; |
148 } | 149 } |
149 if (!w) continue; // if (not match) continue; | 150 match: |
150 tsv.buff.buffptr += w->length - 1; | 151 // range matched. |
152 if (ccv->w.word) { | |
153 WordPtr w; | |
154 for (w = &ccv->w;w;w = w->next) { | |
155 // match the word. | |
156 if (strncmp((const char *)w->word,(const char *)tsv.buff.buffptr-1,w->length)==0) break; | |
151 } | 157 } |
152 if (ccv->tState) { | 158 if (!w) continue; // if (not match) continue; |
153 tsv.current = ccv->tState; | 159 tsv.buff.buffptr += w->length - 1; |
154 } else { | |
155 tsv.current = nextTState(ccv->state,tsv.tg); | |
156 ccv->tState = tsv.current; | |
157 } | |
158 goto next; | |
159 } | 160 } |
160 } | 161 if (ccv->tState) { |
161 tsv.current = tsv.tg->stateStart->tState; | 162 tsv.current = ccv->tState; |
162 tsv = tsv.current->stateSkip(tsv); | 163 } else { |
163 } | 164 tsv.current = nextTState(ccv->state,tsv.tg); |
164 #if DEBUG | 165 ccv->tState = tsv.current; |
165 *tsvp = tsv; | 166 } |
166 return *tsvp; | 167 goto next; |
167 #else | 168 noMatch: |
168 return tsv; | 169 tsv.current = tsv.tg->stateStart->tState; |
169 #endif | 170 tsv = tsv.current->stateSkip(tsv); |
171 } | |
172 return tsv; | |
170 } | 173 } |
171 | 174 |
172 TSValue | 175 TSValue |
173 createTSValue(TransitionGeneratorPtr tg, Buffer buff) { | 176 createTSValue(TransitionGeneratorPtr tg, Buffer buff) { |
174 TSValue tsv; | 177 TSValue tsv; |