Mercurial > vim
comparison src/regexp.c @ 179:7fd70926e2e1 v7.0055
updated for version 7.0055
author | vimboss |
---|---|
date | Fri, 04 Mar 2005 23:39:37 +0000 |
parents | 84c21eb4fc40 |
children | 7e70fc748752 |
comparison
equal
deleted
inserted
replaced
178:4d53c2a2af94 | 179:7fd70926e2e1 |
---|---|
98 * +---------------------------------------------+ | 98 * +---------------------------------------------+ |
99 * | 99 * |
100 * | 100 * |
101 * +----------------------+ | 101 * +----------------------+ |
102 * V | | 102 * V | |
103 * <aa>\+ BRANCH <aa> --> BRANCH --> BACK BRANCH --> NOTHING --> END | 103 * <aa>\+ BRANCH <aa> --> BRANCH --> BACKP BRANCH --> NOTHING --> END |
104 * | | ^ ^ | 104 * | | ^ ^ |
105 * | +----------+ | | 105 * | +-----------+ | |
106 * +-------------------------------------------------+ | 106 * +--------------------------------------------------+ |
107 * | 107 * |
108 * | 108 * |
109 * +-------------------------+ | 109 * +-------------------------+ |
110 * V | | 110 * V | |
111 * <aa>\{} BRANCH BRACE_LIMITS --> BRACE_COMPLEX <aa> --> BACK END | 111 * <aa>\{} BRANCH BRACE_LIMITS --> BRACE_COMPLEX <aa> --> BACK END |
227 | 227 |
228 #define RE_LNUM 204 /* nr cmp Match line number */ | 228 #define RE_LNUM 204 /* nr cmp Match line number */ |
229 #define RE_COL 205 /* nr cmp Match column number */ | 229 #define RE_COL 205 /* nr cmp Match column number */ |
230 #define RE_VCOL 206 /* nr cmp Match virtual column number */ | 230 #define RE_VCOL 206 /* nr cmp Match virtual column number */ |
231 | 231 |
232 #define BACKP 207 /* Like BACK but for \+ */ | |
233 | |
232 /* | 234 /* |
233 * Magic characters have a special meaning, they don't match literally. | 235 * Magic characters have a special meaning, they don't match literally. |
234 * Magic characters are negative. This separates them from literal characters | 236 * Magic characters are negative. This separates them from literal characters |
235 * (possibly multi-byte). Only ASCII characters can be Magic. | 237 * (possibly multi-byte). Only ASCII characters can be Magic. |
236 */ | 238 */ |
278 * final "next" pointer of each individual branch points; each | 280 * final "next" pointer of each individual branch points; each |
279 * branch starts with the operand node of a BRANCH node. | 281 * branch starts with the operand node of a BRANCH node. |
280 * | 282 * |
281 * BACK Normal "next" pointers all implicitly point forward; BACK | 283 * BACK Normal "next" pointers all implicitly point forward; BACK |
282 * exists to make loop structures possible. | 284 * exists to make loop structures possible. |
285 * | |
286 * BACKP Like BACK, but used for \+. Doesn't check for an empty match. | |
283 * | 287 * |
284 * STAR,PLUS '=', and complex '*' and '+', are implemented as circular | 288 * STAR,PLUS '=', and complex '*' and '+', are implemented as circular |
285 * BRANCH structures using BACK. Simple cases (one character | 289 * BRANCH structures using BACK. Simple cases (one character |
286 * per match) are implemented with STAR and PLUS for speed | 290 * per match) are implemented with STAR and PLUS for speed |
287 * and to minimize recursive plunges. | 291 * and to minimize recursive plunges. |
1446 else | 1450 else |
1447 { | 1451 { |
1448 /* Emit x+ as x(&|), where & means "self". */ | 1452 /* Emit x+ as x(&|), where & means "self". */ |
1449 next = regnode(BRANCH); /* Either */ | 1453 next = regnode(BRANCH); /* Either */ |
1450 regtail(ret, next); | 1454 regtail(ret, next); |
1451 regtail(regnode(BACK), ret); /* loop back */ | 1455 regtail(regnode(BACKP), ret); /* loop back */ |
1452 regtail(next, regnode(BRANCH)); /* or */ | 1456 regtail(next, regnode(BRANCH)); /* or */ |
1453 regtail(ret, regnode(NOTHING)); /* null. */ | 1457 regtail(ret, regnode(NOTHING)); /* null. */ |
1454 } | 1458 } |
1455 *flagp = (WORST | HASWIDTH | (flags & (HASNL | HASLOOKBH))); | 1459 *flagp = (WORST | HASWIDTH | (flags & (HASNL | HASLOOKBH))); |
1456 break; | 1460 break; |
2481 if (temp == NULL) | 2485 if (temp == NULL) |
2482 break; | 2486 break; |
2483 scan = temp; | 2487 scan = temp; |
2484 } | 2488 } |
2485 | 2489 |
2486 if (OP(scan) == BACK) | 2490 if (OP(scan) == BACK || OP(scan) == BACKP) |
2487 offset = (int)(scan - val); | 2491 offset = (int)(scan - val); |
2488 else | 2492 else |
2489 offset = (int)(val - scan); | 2493 offset = (int)(val - scan); |
2490 *(scan + 1) = (char_u) (((unsigned)offset >> 8) & 0377); | 2494 *(scan + 1) = (char_u) (((unsigned)offset >> 8) & 0377); |
2491 *(scan + 2) = (char_u) (offset & 0377); | 2495 *(scan + 2) = (char_u) (offset & 0377); |
4088 case BACK: | 4092 case BACK: |
4089 /* When we run into BACK without matching something non-empty, we | 4093 /* When we run into BACK without matching something non-empty, we |
4090 * fail. */ | 4094 * fail. */ |
4091 if (startp != NULL && reg_save_equal(startp)) | 4095 if (startp != NULL && reg_save_equal(startp)) |
4092 return FALSE; | 4096 return FALSE; |
4097 break; | |
4098 | |
4099 case BACKP: | |
4093 break; | 4100 break; |
4094 | 4101 |
4095 case MOPEN + 0: /* Match start: \zs */ | 4102 case MOPEN + 0: /* Match start: \zs */ |
4096 case MOPEN + 1: /* \( */ | 4103 case MOPEN + 1: /* \( */ |
4097 case MOPEN + 2: | 4104 case MOPEN + 2: |
4354 | 4361 |
4355 case BRANCH: | 4362 case BRANCH: |
4356 { | 4363 { |
4357 if (OP(next) != BRANCH) /* No choice. */ | 4364 if (OP(next) != BRANCH) /* No choice. */ |
4358 next = OPERAND(scan); /* Avoid recursion. */ | 4365 next = OPERAND(scan); /* Avoid recursion. */ |
4366 else if (startp != NULL && OP(OPERAND(scan)) == BACKP | |
4367 && reg_save_equal(startp)) | |
4368 /* \+ with something empty before it */ | |
4369 return FALSE; | |
4359 else | 4370 else |
4360 { | 4371 { |
4361 regsave_T save; | 4372 regsave_T save; |
4362 | 4373 |
4363 do | 4374 do |
5132 | 5143 |
5133 offset = NEXT(p); | 5144 offset = NEXT(p); |
5134 if (offset == 0) | 5145 if (offset == 0) |
5135 return NULL; | 5146 return NULL; |
5136 | 5147 |
5137 if (OP(p) == BACK) | 5148 if (OP(p) == BACK || OP(p) == BACKP) |
5138 return p - offset; | 5149 return p - offset; |
5139 else | 5150 else |
5140 return p + offset; | 5151 return p + offset; |
5141 } | 5152 } |
5142 | 5153 |
5601 case NOTHING: | 5612 case NOTHING: |
5602 p = "NOTHING"; | 5613 p = "NOTHING"; |
5603 break; | 5614 break; |
5604 case BACK: | 5615 case BACK: |
5605 p = "BACK"; | 5616 p = "BACK"; |
5617 break; | |
5618 case BACKP: | |
5619 p = "BACKP"; | |
5606 break; | 5620 break; |
5607 case END: | 5621 case END: |
5608 p = "END"; | 5622 p = "END"; |
5609 break; | 5623 break; |
5610 case MOPEN + 0: | 5624 case MOPEN + 0: |