diff options
author | Sergio Queiroz <sqmedeiros@gmail.com> | 2017-01-03 10:02:52 -0300 |
---|---|---|
committer | Sergio Queiroz <sqmedeiros@gmail.com> | 2017-01-03 10:02:52 -0300 |
commit | c6277dabce8428b49ff5df63b515c68a0386d9da (patch) | |
tree | 36c6ae8ace4f1da3c8342324b415cfef2a50b750 /lpvm.c | |
parent | 2e5820c37e4e6cb2a2c01863619abd19eb5a8199 (diff) | |
download | lpeglabel-c6277dabce8428b49ff5df63b515c68a0386d9da.tar.gz lpeglabel-c6277dabce8428b49ff5df63b515c68a0386d9da.tar.bz2 lpeglabel-c6277dabce8428b49ff5df63b515c68a0386d9da.zip |
Tracking the farthest failure position in case of a regular fail
Diffstat (limited to 'lpvm.c')
-rw-r--r-- | lpvm.c | 13 |
1 files changed, 7 insertions, 6 deletions
@@ -166,6 +166,7 @@ const char *match (lua_State *L, const char *o, const char *s, const char *e, | |||
166 | Labelset lsfail; | 166 | Labelset lsfail; |
167 | setlabelfail(&lsfail); | 167 | setlabelfail(&lsfail); |
168 | stack->p = &giveup; stack->s = s; stack->ls = &lsfail; stack->caplevel = 0; stack++; /* labeled failure */ | 168 | stack->p = &giveup; stack->s = s; stack->ls = &lsfail; stack->caplevel = 0; stack++; /* labeled failure */ |
169 | *sfail = s; /* labeled failure */ | ||
169 | lua_pushlightuserdata(L, stackbase); | 170 | lua_pushlightuserdata(L, stackbase); |
170 | for (;;) { | 171 | for (;;) { |
171 | #if defined(DEBUG) | 172 | #if defined(DEBUG) |
@@ -196,7 +197,7 @@ const char *match (lua_State *L, const char *o, const char *s, const char *e, | |||
196 | else { | 197 | else { |
197 | *labelf = LFAIL; /* labeled failure */ | 198 | *labelf = LFAIL; /* labeled failure */ |
198 | pk = p + 1; | 199 | pk = p + 1; |
199 | *sfail = s; | 200 | updatefarthest(*sfail, s); /*labeled failure */ |
200 | goto fail; | 201 | goto fail; |
201 | } | 202 | } |
202 | continue; | 203 | continue; |
@@ -211,7 +212,7 @@ const char *match (lua_State *L, const char *o, const char *s, const char *e, | |||
211 | else { | 212 | else { |
212 | *labelf = LFAIL; /* labeled failure */ | 213 | *labelf = LFAIL; /* labeled failure */ |
213 | pk = p + 1; | 214 | pk = p + 1; |
214 | *sfail = s; | 215 | updatefarthest(*sfail, s); /*labeled failure */ |
215 | goto fail; | 216 | goto fail; |
216 | } | 217 | } |
217 | continue; | 218 | continue; |
@@ -228,7 +229,7 @@ const char *match (lua_State *L, const char *o, const char *s, const char *e, | |||
228 | else { | 229 | else { |
229 | *labelf = LFAIL; /* labeled failure */ | 230 | *labelf = LFAIL; /* labeled failure */ |
230 | pk = p + CHARSETINSTSIZE; | 231 | pk = p + CHARSETINSTSIZE; |
231 | *sfail = s; | 232 | updatefarthest(*sfail, s); /*labeled failure */ |
232 | goto fail; | 233 | goto fail; |
233 | } | 234 | } |
234 | continue; | 235 | continue; |
@@ -245,7 +246,7 @@ const char *match (lua_State *L, const char *o, const char *s, const char *e, | |||
245 | if (n > s - o) { | 246 | if (n > s - o) { |
246 | *labelf = LFAIL; /* labeled failure */ | 247 | *labelf = LFAIL; /* labeled failure */ |
247 | pk = p + 1; | 248 | pk = p + 1; |
248 | *sfail = s; | 249 | updatefarthest(*sfail, s); /*labeled failure */ |
249 | goto fail; | 250 | goto fail; |
250 | } | 251 | } |
251 | s -= n; p++; | 252 | s -= n; p++; |
@@ -329,7 +330,7 @@ const char *match (lua_State *L, const char *o, const char *s, const char *e, | |||
329 | case IFail: | 330 | case IFail: |
330 | *labelf = LFAIL; /* labeled failure */ | 331 | *labelf = LFAIL; /* labeled failure */ |
331 | pk = NULL; | 332 | pk = NULL; |
332 | *sfail = s; | 333 | updatefarthest(*sfail, s); /*labeled failure */ |
333 | fail: { /* pattern failed: try to backtrack */ | 334 | fail: { /* pattern failed: try to backtrack */ |
334 | const Labelset *auxlab = NULL; | 335 | const Labelset *auxlab = NULL; |
335 | Stack *pstack = stack; | 336 | Stack *pstack = stack; |
@@ -366,8 +367,8 @@ const char *match (lua_State *L, const char *o, const char *s, const char *e, | |||
366 | res = resdyncaptures(L, fr, s - o, e - o); /* get result */ | 367 | res = resdyncaptures(L, fr, s - o, e - o); /* get result */ |
367 | if (res == -1) { /* fail? */ | 368 | if (res == -1) { /* fail? */ |
368 | *labelf = LFAIL; /* labeled failure */ | 369 | *labelf = LFAIL; /* labeled failure */ |
369 | *sfail = (const char *) s; | ||
370 | pk = NULL; | 370 | pk = NULL; |
371 | updatefarthest(*sfail, s); /*labeled failure */ | ||
371 | goto fail; | 372 | goto fail; |
372 | } | 373 | } |
373 | s = o + res; /* else update current position */ | 374 | s = o + res; /* else update current position */ |