Mirror of the Vim source from https://github.com/vim/vim
Révision | 25bc02d83cf438d5794ce106edad2959e2f89454 (tree) |
---|---|
l'heure | 2008-04-09 19:16:02 |
Auteur | vimboss |
Commiter | vimboss |
updated for version 7.1-292
@@ -3039,6 +3039,15 @@ | ||
3039 | 3039 | } se_u; |
3040 | 3040 | } save_se_T; |
3041 | 3041 | |
3042 | +/* used for BEHIND and NOBEHIND matching */ | |
3043 | +typedef struct regbehind_S | |
3044 | +{ | |
3045 | + regsave_T save_after; | |
3046 | + regsave_T save_behind; | |
3047 | + save_se_T save_start[NSUBEXP]; | |
3048 | + save_se_T save_end[NSUBEXP]; | |
3049 | +} regbehind_T; | |
3050 | + | |
3042 | 3051 | static char_u *reg_getline __ARGS((linenr_T lnum)); |
3043 | 3052 | static long vim_regexec_both __ARGS((char_u *line, colnr_T col, proftime_T *tm)); |
3044 | 3053 | static long regtry __ARGS((regprog_T *prog, colnr_T col)); |
@@ -3046,6 +3055,8 @@ | ||
3046 | 3055 | #ifdef FEAT_SYN_HL |
3047 | 3056 | static void cleanup_zsubexpr __ARGS((void)); |
3048 | 3057 | #endif |
3058 | +static void save_subexpr __ARGS((regbehind_T *bp)); | |
3059 | +static void restore_subexpr __ARGS((regbehind_T *bp)); | |
3049 | 3060 | static void reg_nextline __ARGS((void)); |
3050 | 3061 | static void reg_save __ARGS((regsave_T *save, garray_T *gap)); |
3051 | 3062 | static void reg_restore __ARGS((regsave_T *save, garray_T *gap)); |
@@ -3166,19 +3177,12 @@ | ||
3166 | 3177 | save_se_T sesave; |
3167 | 3178 | regsave_T regsave; |
3168 | 3179 | } rs_un; /* room for saving reginput */ |
3169 | - short rs_no; /* submatch nr */ | |
3180 | + short rs_no; /* submatch nr or BEHIND/NOBEHIND */ | |
3170 | 3181 | } regitem_T; |
3171 | 3182 | |
3172 | 3183 | static regitem_T *regstack_push __ARGS((regstate_T state, char_u *scan)); |
3173 | 3184 | static void regstack_pop __ARGS((char_u **scan)); |
3174 | 3185 | |
3175 | -/* used for BEHIND and NOBEHIND matching */ | |
3176 | -typedef struct regbehind_S | |
3177 | -{ | |
3178 | - regsave_T save_after; | |
3179 | - regsave_T save_behind; | |
3180 | -} regbehind_T; | |
3181 | - | |
3182 | 3186 | /* used for STAR, PLUS and BRACE_SIMPLE matching */ |
3183 | 3187 | typedef struct regstar_S |
3184 | 3188 | { |
@@ -4888,6 +4892,10 @@ | ||
4888 | 4892 | status = RA_FAIL; |
4889 | 4893 | else |
4890 | 4894 | { |
4895 | + /* Need to save the subexpr to be able to restore them | |
4896 | + * when there is a match but we don't use it. */ | |
4897 | + save_subexpr(((regbehind_T *)rp) - 1); | |
4898 | + | |
4891 | 4899 | rp->rs_no = op; |
4892 | 4900 | reg_save(&rp->rs_un.regsave, &backpos); |
4893 | 4901 | /* First try if what follows matches. If it does then we |
@@ -5118,15 +5126,20 @@ | ||
5118 | 5126 | reg_restore(&(((regbehind_T *)rp) - 1)->save_after, |
5119 | 5127 | &backpos); |
5120 | 5128 | else |
5121 | - /* But we didn't want a match. */ | |
5129 | + { | |
5130 | + /* But we didn't want a match. Need to restore the | |
5131 | + * subexpr, because what follows matched, so they have | |
5132 | + * been set. */ | |
5122 | 5133 | status = RA_NOMATCH; |
5134 | + restore_subexpr(((regbehind_T *)rp) - 1); | |
5135 | + } | |
5123 | 5136 | regstack_pop(&scan); |
5124 | 5137 | regstack.ga_len -= sizeof(regbehind_T); |
5125 | 5138 | } |
5126 | 5139 | else |
5127 | 5140 | { |
5128 | - /* No match: Go back one character. May go to previous | |
5129 | - * line once. */ | |
5141 | + /* No match or a match that doesn't end where we want it: Go | |
5142 | + * back one character. May go to previous line once. */ | |
5130 | 5143 | no = OK; |
5131 | 5144 | if (REG_MULTI) |
5132 | 5145 | { |
@@ -5160,6 +5173,13 @@ | ||
5160 | 5173 | /* Advanced, prepare for finding match again. */ |
5161 | 5174 | reg_restore(&rp->rs_un.regsave, &backpos); |
5162 | 5175 | scan = OPERAND(rp->rs_scan); |
5176 | + if (status == RA_MATCH) | |
5177 | + { | |
5178 | + /* We did match, so subexpr may have been changed, | |
5179 | + * need to restore them for the next try. */ | |
5180 | + status = RA_NOMATCH; | |
5181 | + restore_subexpr(((regbehind_T *)rp) - 1); | |
5182 | + } | |
5163 | 5183 | } |
5164 | 5184 | else |
5165 | 5185 | { |
@@ -5172,7 +5192,16 @@ | ||
5172 | 5192 | status = RA_MATCH; |
5173 | 5193 | } |
5174 | 5194 | else |
5175 | - status = RA_NOMATCH; | |
5195 | + { | |
5196 | + /* We do want a proper match. Need to restore the | |
5197 | + * subexpr if we had a match, because they may have | |
5198 | + * been set. */ | |
5199 | + if (status == RA_MATCH) | |
5200 | + { | |
5201 | + status = RA_NOMATCH; | |
5202 | + restore_subexpr(((regbehind_T *)rp) - 1); | |
5203 | + } | |
5204 | + } | |
5176 | 5205 | regstack_pop(&scan); |
5177 | 5206 | regstack.ga_len -= sizeof(regbehind_T); |
5178 | 5207 | } |
@@ -5820,6 +5849,55 @@ | ||
5820 | 5849 | #endif |
5821 | 5850 | |
5822 | 5851 | /* |
5852 | + * Save the current subexpr to "bp", so that they can be restored | |
5853 | + * later by restore_subexpr(). | |
5854 | + */ | |
5855 | + static void | |
5856 | +save_subexpr(bp) | |
5857 | + regbehind_T *bp; | |
5858 | +{ | |
5859 | + int i; | |
5860 | + | |
5861 | + for (i = 0; i < NSUBEXP; ++i) | |
5862 | + { | |
5863 | + if (REG_MULTI) | |
5864 | + { | |
5865 | + bp->save_start[i].se_u.pos = reg_startpos[i]; | |
5866 | + bp->save_end[i].se_u.pos = reg_endpos[i]; | |
5867 | + } | |
5868 | + else | |
5869 | + { | |
5870 | + bp->save_start[i].se_u.ptr = reg_startp[i]; | |
5871 | + bp->save_end[i].se_u.ptr = reg_endp[i]; | |
5872 | + } | |
5873 | + } | |
5874 | +} | |
5875 | + | |
5876 | +/* | |
5877 | + * Restore the subexpr from "bp". | |
5878 | + */ | |
5879 | + static void | |
5880 | +restore_subexpr(bp) | |
5881 | + regbehind_T *bp; | |
5882 | +{ | |
5883 | + int i; | |
5884 | + | |
5885 | + for (i = 0; i < NSUBEXP; ++i) | |
5886 | + { | |
5887 | + if (REG_MULTI) | |
5888 | + { | |
5889 | + reg_startpos[i] = bp->save_start[i].se_u.pos; | |
5890 | + reg_endpos[i] = bp->save_end[i].se_u.pos; | |
5891 | + } | |
5892 | + else | |
5893 | + { | |
5894 | + reg_startp[i] = bp->save_start[i].se_u.ptr; | |
5895 | + reg_endp[i] = bp->save_end[i].se_u.ptr; | |
5896 | + } | |
5897 | + } | |
5898 | +} | |
5899 | + | |
5900 | +/* | |
5823 | 5901 | * Advance reglnum, regline and reginput to the next line. |
5824 | 5902 | */ |
5825 | 5903 | static void |
@@ -667,6 +667,8 @@ | ||
667 | 667 | static int included_patches[] = |
668 | 668 | { /* Add new patch number below this line */ |
669 | 669 | /**/ |
670 | + 292, | |
671 | +/**/ | |
670 | 672 | 291, |
671 | 673 | /**/ |
672 | 674 | 290, |