]>
Commit | Line | Data |
---|---|---|
3ab71051 ER |
1 | To: vim-dev@vim.org |
2 | Subject: Patch 7.1.292 | |
3 | Fcc: outbox | |
4 | From: Bram Moolenaar <Bram@moolenaar.net> | |
5 | Mime-Version: 1.0 | |
6 | Content-Type: text/plain; charset=ISO-8859-1 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ------------ | |
9 | ||
10 | Patch 7.1.292 | |
11 | Problem: When using a pattern with "\@<=" the submatches can be wrong. | |
12 | (Brett Stahlman) | |
13 | Solution: Save the submatches when attempting a look-behind match. | |
14 | Files: src/regexp.c | |
15 | ||
16 | ||
17 | *** ../vim-7.1.291/src/regexp.c Sat Jan 19 15:55:51 2008 | |
18 | --- src/regexp.c Tue Apr 1 18:15:47 2008 | |
19 | *************** | |
20 | *** 3039,3044 **** | |
21 | --- 3039,3053 ---- | |
22 | } se_u; | |
23 | } save_se_T; | |
24 | ||
25 | + /* used for BEHIND and NOBEHIND matching */ | |
26 | + typedef struct regbehind_S | |
27 | + { | |
28 | + regsave_T save_after; | |
29 | + regsave_T save_behind; | |
30 | + save_se_T save_start[NSUBEXP]; | |
31 | + save_se_T save_end[NSUBEXP]; | |
32 | + } regbehind_T; | |
33 | + | |
34 | static char_u *reg_getline __ARGS((linenr_T lnum)); | |
35 | static long vim_regexec_both __ARGS((char_u *line, colnr_T col, proftime_T *tm)); | |
36 | static long regtry __ARGS((regprog_T *prog, colnr_T col)); | |
37 | *************** | |
38 | *** 3046,3051 **** | |
39 | --- 3055,3062 ---- | |
40 | #ifdef FEAT_SYN_HL | |
41 | static void cleanup_zsubexpr __ARGS((void)); | |
42 | #endif | |
43 | + static void save_subexpr __ARGS((regbehind_T *bp)); | |
44 | + static void restore_subexpr __ARGS((regbehind_T *bp)); | |
45 | static void reg_nextline __ARGS((void)); | |
46 | static void reg_save __ARGS((regsave_T *save, garray_T *gap)); | |
47 | static void reg_restore __ARGS((regsave_T *save, garray_T *gap)); | |
48 | *************** | |
49 | *** 3166,3184 **** | |
50 | save_se_T sesave; | |
51 | regsave_T regsave; | |
52 | } rs_un; /* room for saving reginput */ | |
53 | ! short rs_no; /* submatch nr */ | |
54 | } regitem_T; | |
55 | ||
56 | static regitem_T *regstack_push __ARGS((regstate_T state, char_u *scan)); | |
57 | static void regstack_pop __ARGS((char_u **scan)); | |
58 | ||
59 | - /* used for BEHIND and NOBEHIND matching */ | |
60 | - typedef struct regbehind_S | |
61 | - { | |
62 | - regsave_T save_after; | |
63 | - regsave_T save_behind; | |
64 | - } regbehind_T; | |
65 | - | |
66 | /* used for STAR, PLUS and BRACE_SIMPLE matching */ | |
67 | typedef struct regstar_S | |
68 | { | |
69 | --- 3177,3188 ---- | |
70 | save_se_T sesave; | |
71 | regsave_T regsave; | |
72 | } rs_un; /* room for saving reginput */ | |
73 | ! short rs_no; /* submatch nr or BEHIND/NOBEHIND */ | |
74 | } regitem_T; | |
75 | ||
76 | static regitem_T *regstack_push __ARGS((regstate_T state, char_u *scan)); | |
77 | static void regstack_pop __ARGS((char_u **scan)); | |
78 | ||
79 | /* used for STAR, PLUS and BRACE_SIMPLE matching */ | |
80 | typedef struct regstar_S | |
81 | { | |
82 | *************** | |
83 | *** 4888,4893 **** | |
84 | --- 4892,4901 ---- | |
85 | status = RA_FAIL; | |
86 | else | |
87 | { | |
88 | + /* Need to save the subexpr to be able to restore them | |
89 | + * when there is a match but we don't use it. */ | |
90 | + save_subexpr(((regbehind_T *)rp) - 1); | |
91 | + | |
92 | rp->rs_no = op; | |
93 | reg_save(&rp->rs_un.regsave, &backpos); | |
94 | /* First try if what follows matches. If it does then we | |
95 | *************** | |
96 | *** 5118,5132 **** | |
97 | reg_restore(&(((regbehind_T *)rp) - 1)->save_after, | |
98 | &backpos); | |
99 | else | |
100 | ! /* But we didn't want a match. */ | |
101 | status = RA_NOMATCH; | |
102 | regstack_pop(&scan); | |
103 | regstack.ga_len -= sizeof(regbehind_T); | |
104 | } | |
105 | else | |
106 | { | |
107 | ! /* No match: Go back one character. May go to previous | |
108 | ! * line once. */ | |
109 | no = OK; | |
110 | if (REG_MULTI) | |
111 | { | |
112 | --- 5126,5145 ---- | |
113 | reg_restore(&(((regbehind_T *)rp) - 1)->save_after, | |
114 | &backpos); | |
115 | else | |
116 | ! { | |
117 | ! /* But we didn't want a match. Need to restore the | |
118 | ! * subexpr, because what follows matched, so they have | |
119 | ! * been set. */ | |
120 | status = RA_NOMATCH; | |
121 | + restore_subexpr(((regbehind_T *)rp) - 1); | |
122 | + } | |
123 | regstack_pop(&scan); | |
124 | regstack.ga_len -= sizeof(regbehind_T); | |
125 | } | |
126 | else | |
127 | { | |
128 | ! /* No match or a match that doesn't end where we want it: Go | |
129 | ! * back one character. May go to previous line once. */ | |
130 | no = OK; | |
131 | if (REG_MULTI) | |
132 | { | |
133 | *************** | |
134 | *** 5160,5165 **** | |
135 | --- 5173,5185 ---- | |
136 | /* Advanced, prepare for finding match again. */ | |
137 | reg_restore(&rp->rs_un.regsave, &backpos); | |
138 | scan = OPERAND(rp->rs_scan); | |
139 | + if (status == RA_MATCH) | |
140 | + { | |
141 | + /* We did match, so subexpr may have been changed, | |
142 | + * need to restore them for the next try. */ | |
143 | + status = RA_NOMATCH; | |
144 | + restore_subexpr(((regbehind_T *)rp) - 1); | |
145 | + } | |
146 | } | |
147 | else | |
148 | { | |
149 | *************** | |
150 | *** 5172,5178 **** | |
151 | status = RA_MATCH; | |
152 | } | |
153 | else | |
154 | ! status = RA_NOMATCH; | |
155 | regstack_pop(&scan); | |
156 | regstack.ga_len -= sizeof(regbehind_T); | |
157 | } | |
158 | --- 5192,5207 ---- | |
159 | status = RA_MATCH; | |
160 | } | |
161 | else | |
162 | ! { | |
163 | ! /* We do want a proper match. Need to restore the | |
164 | ! * subexpr if we had a match, because they may have | |
165 | ! * been set. */ | |
166 | ! if (status == RA_MATCH) | |
167 | ! { | |
168 | ! status = RA_NOMATCH; | |
169 | ! restore_subexpr(((regbehind_T *)rp) - 1); | |
170 | ! } | |
171 | ! } | |
172 | regstack_pop(&scan); | |
173 | regstack.ga_len -= sizeof(regbehind_T); | |
174 | } | |
175 | *************** | |
176 | *** 5820,5825 **** | |
177 | --- 5849,5903 ---- | |
178 | #endif | |
179 | ||
180 | /* | |
181 | + * Save the current subexpr to "bp", so that they can be restored | |
182 | + * later by restore_subexpr(). | |
183 | + */ | |
184 | + static void | |
185 | + save_subexpr(bp) | |
186 | + regbehind_T *bp; | |
187 | + { | |
188 | + int i; | |
189 | + | |
190 | + for (i = 0; i < NSUBEXP; ++i) | |
191 | + { | |
192 | + if (REG_MULTI) | |
193 | + { | |
194 | + bp->save_start[i].se_u.pos = reg_startpos[i]; | |
195 | + bp->save_end[i].se_u.pos = reg_endpos[i]; | |
196 | + } | |
197 | + else | |
198 | + { | |
199 | + bp->save_start[i].se_u.ptr = reg_startp[i]; | |
200 | + bp->save_end[i].se_u.ptr = reg_endp[i]; | |
201 | + } | |
202 | + } | |
203 | + } | |
204 | + | |
205 | + /* | |
206 | + * Restore the subexpr from "bp". | |
207 | + */ | |
208 | + static void | |
209 | + restore_subexpr(bp) | |
210 | + regbehind_T *bp; | |
211 | + { | |
212 | + int i; | |
213 | + | |
214 | + for (i = 0; i < NSUBEXP; ++i) | |
215 | + { | |
216 | + if (REG_MULTI) | |
217 | + { | |
218 | + reg_startpos[i] = bp->save_start[i].se_u.pos; | |
219 | + reg_endpos[i] = bp->save_end[i].se_u.pos; | |
220 | + } | |
221 | + else | |
222 | + { | |
223 | + reg_startp[i] = bp->save_start[i].se_u.ptr; | |
224 | + reg_endp[i] = bp->save_end[i].se_u.ptr; | |
225 | + } | |
226 | + } | |
227 | + } | |
228 | + | |
229 | + /* | |
230 | * Advance reglnum, regline and reginput to the next line. | |
231 | */ | |
232 | static void | |
233 | *** ../vim-7.1.291/src/version.c Tue Apr 1 20:58:23 2008 | |
234 | --- src/version.c Wed Apr 9 12:12:33 2008 | |
235 | *************** | |
236 | *** 668,669 **** | |
237 | --- 673,676 ---- | |
238 | { /* Add new patch number below this line */ | |
239 | + /**/ | |
240 | + 292, | |
241 | /**/ | |
242 | ||
243 | -- | |
244 | hundred-and-one symptoms of being an internet addict: | |
245 | 259. When you enter your name in the AltaVista search engine, the top ten | |
246 | matches do indeed refer to you. | |
247 | ||
248 | /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ | |
249 | /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ | |
250 | \\\ download, build and distribute -- http://www.A-A-P.org /// | |
251 | \\\ help me help AIDS victims -- http://ICCF-Holland.org /// |