aboutsummaryrefslogtreecommitdiff
path: root/lpvm.c
diff options
context:
space:
mode:
authorSergio Queiroz <sqmedeiros@gmail.com>2015-09-11 15:01:10 -0300
committerSergio Queiroz <sqmedeiros@gmail.com>2015-09-11 15:01:10 -0300
commit8ac31b94b88227222b189c447aeea1b4131eed18 (patch)
tree8a913ad00c03d15cd2cb5bcedd10ddba65b01e3b /lpvm.c
parentce9f1486d1d11699e8099d13c6f65fabe372385d (diff)
downloadlpeglabel-8ac31b94b88227222b189c447aeea1b4131eed18.tar.gz
lpeglabel-8ac31b94b88227222b189c447aeea1b4131eed18.tar.bz2
lpeglabel-8ac31b94b88227222b189c447aeea1b4131eed18.zip
Result of an unsuccessful matching is label + subject
Diffstat (limited to 'lpvm.c')
-rw-r--r--lpvm.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/lpvm.c b/lpvm.c
index a9198ba..3ae22f5 100644
--- a/lpvm.c
+++ b/lpvm.c
@@ -146,7 +146,7 @@ static int removedyncap (lua_State *L, Capture *capture,
146** Opcode interpreter 146** Opcode interpreter
147*/ 147*/
148const char *match (lua_State *L, const char *o, const char *s, const char *e, 148const char *match (lua_State *L, const char *o, const char *s, const char *e,
149 Instruction *op, Capture *capture, int ptop, Labelset *labelf) { /* labeled failure */ 149 Instruction *op, Capture *capture, int ptop, Labelset *labelf, const char **sfail) { /* labeled failure */
150 Stack stackbase[INITBACK]; 150 Stack stackbase[INITBACK];
151 Stack *stacklimit = stackbase + INITBACK; 151 Stack *stacklimit = stackbase + INITBACK;
152 Stack *stack = stackbase; /* point to first empty slot in stack */ 152 Stack *stack = stackbase; /* point to first empty slot in stack */
@@ -184,6 +184,7 @@ const char *match (lua_State *L, const char *o, const char *s, const char *e,
184 if (s < e) { p++; s++; } 184 if (s < e) { p++; s++; }
185 else { 185 else {
186 *labelf = LFAIL; /* labeled failure */ 186 *labelf = LFAIL; /* labeled failure */
187 *sfail = s;
187 goto fail; 188 goto fail;
188 } 189 }
189 continue; 190 continue;
@@ -197,6 +198,7 @@ const char *match (lua_State *L, const char *o, const char *s, const char *e,
197 if ((byte)*s == p->i.aux && s < e) { p++; s++; } 198 if ((byte)*s == p->i.aux && s < e) { p++; s++; }
198 else { 199 else {
199 *labelf = LFAIL; /* labeled failure */ 200 *labelf = LFAIL; /* labeled failure */
201 *sfail = s;
200 goto fail; 202 goto fail;
201 } 203 }
202 continue; 204 continue;
@@ -212,6 +214,7 @@ const char *match (lua_State *L, const char *o, const char *s, const char *e,
212 { p += CHARSETINSTSIZE; s++; } 214 { p += CHARSETINSTSIZE; s++; }
213 else { 215 else {
214 *labelf = LFAIL; /* labeled failure */ 216 *labelf = LFAIL; /* labeled failure */
217 *sfail = s;
215 goto fail; 218 goto fail;
216 } 219 }
217 continue; 220 continue;
@@ -227,6 +230,7 @@ const char *match (lua_State *L, const char *o, const char *s, const char *e,
227 int n = p->i.aux; 230 int n = p->i.aux;
228 if (n > s - o) { 231 if (n > s - o) {
229 *labelf = LFAIL; /* labeled failure */ 232 *labelf = LFAIL; /* labeled failure */
233 *sfail = s;
230 goto fail; 234 goto fail;
231 } 235 }
232 s -= n; p++; 236 s -= n; p++;
@@ -297,6 +301,8 @@ const char *match (lua_State *L, const char *o, const char *s, const char *e,
297 } 301 }
298 case IThrow: { /* labeled failure */ 302 case IThrow: { /* labeled failure */
299 *labelf = (p+1)->labels; 303 *labelf = (p+1)->labels;
304 *sfail = s;
305 /*printf("s = %s, sfail = %s\n", s, *sfail);*/
300 goto fail; 306 goto fail;
301 } 307 }
302 case IFailTwice: 308 case IFailTwice:
@@ -305,6 +311,7 @@ const char *match (lua_State *L, const char *o, const char *s, const char *e,
305 /* go through */ 311 /* go through */
306 case IFail: 312 case IFail:
307 *labelf = LFAIL; /* labeled failure */ 313 *labelf = LFAIL; /* labeled failure */
314 *sfail = s;
308 fail: { /* pattern failed: try to backtrack */ 315 fail: { /* pattern failed: try to backtrack */
309 do { /* remove pending calls */ 316 do { /* remove pending calls */
310 assert(stack > getstackbase(L, ptop)); 317 assert(stack > getstackbase(L, ptop));
@@ -327,6 +334,7 @@ const char *match (lua_State *L, const char *o, const char *s, const char *e,
327 res = resdyncaptures(L, fr, s - o, e - o); /* get result */ 334 res = resdyncaptures(L, fr, s - o, e - o); /* get result */
328 if (res == -1) { /* fail? */ 335 if (res == -1) { /* fail? */
329 *labelf = LFAIL; /* labeled failure */ 336 *labelf = LFAIL; /* labeled failure */
337 *sfail = (const char *) s; /* TODO: ??? */
330 goto fail; 338 goto fail;
331 } 339 }
332 s = o + res; /* else update current position */ 340 s = o + res; /* else update current position */