diff options
author | Sérgio Queiroz <sqmedeiros@gmail.com> | 2017-12-15 14:17:20 -0300 |
---|---|---|
committer | Sérgio Queiroz <sqmedeiros@gmail.com> | 2017-12-15 14:17:20 -0300 |
commit | 0f53a65f4a32c8be2d84c4a8172b885065f7c1e5 (patch) | |
tree | 5d9f4535723c43f82451ad2e1e65da7810d4d082 /lpcode.c | |
parent | bc071e9fe431347832fd424eb327357f38e60bfd (diff) | |
download | lpeglabel-0f53a65f4a32c8be2d84c4a8172b885065f7c1e5.tar.gz lpeglabel-0f53a65f4a32c8be2d84c4a8172b885065f7c1e5.tar.bz2 lpeglabel-0f53a65f4a32c8be2d84c4a8172b885065f7c1e5.zip |
Removing code related to previous recovery operator //{}
Diffstat (limited to 'lpcode.c')
-rw-r--r-- | lpcode.c | 43 |
1 files changed, 7 insertions, 36 deletions
@@ -220,7 +220,7 @@ int checkaux (TTree *tree, int pred) { | |||
220 | if (checkaux(sib2(tree), pred)) return 1; | 220 | if (checkaux(sib2(tree), pred)) return 1; |
221 | /* else return checkaux(sib1(tree), pred); */ | 221 | /* else return checkaux(sib1(tree), pred); */ |
222 | tree = sib1(tree); goto tailcall; | 222 | tree = sib1(tree); goto tailcall; |
223 | case TRecov: case TLabChoice: /* labeled failure */ | 223 | case TLabChoice: /* labeled failure */ |
224 | /* we do not know whether sib2 will be evaluated */ | 224 | /* we do not know whether sib2 will be evaluated */ |
225 | tree = sib1(tree); goto tailcall; | 225 | tree = sib1(tree); goto tailcall; |
226 | case TCapture: case TGrammar: case TRule: | 226 | case TCapture: case TGrammar: case TRule: |
@@ -257,7 +257,7 @@ int fixedlen (TTree *tree) { | |||
257 | else | 257 | else |
258 | return len + n1; | 258 | return len + n1; |
259 | } | 259 | } |
260 | case TSeq: case TRecov: { /* labeled failure */ | 260 | case TSeq: { |
261 | int n1 = fixedlen(sib1(tree)); | 261 | int n1 = fixedlen(sib1(tree)); |
262 | if (n1 < 0) | 262 | if (n1 < 0) |
263 | return -1; | 263 | return -1; |
@@ -321,12 +321,6 @@ static int getfirst (TTree *tree, const Charset *follow, Charset *firstset) { | |||
321 | loopset(i, firstset->cs[i] |= csaux.cs[i]); | 321 | loopset(i, firstset->cs[i] |= csaux.cs[i]); |
322 | return e1 | e2; | 322 | return e1 | e2; |
323 | } | 323 | } |
324 | case TRecov: { /* labeled failure */ | ||
325 | /* when p1 is not nullable, p2 has nothing to contribute; | ||
326 | and when p1 is nullable, then p2 will not match | ||
327 | return getfirst(sib1(tree), fullset, firstset); */ | ||
328 | tree = sib1(tree); follow = fullset; goto tailcall; | ||
329 | } | ||
330 | case TSeq: { | 324 | case TSeq: { |
331 | if (!nullable(sib1(tree))) { | 325 | if (!nullable(sib1(tree))) { |
332 | /* when p1 is not nullable, p2 has nothing to contribute; | 326 | /* when p1 is not nullable, p2 has nothing to contribute; |
@@ -405,7 +399,7 @@ static int headfail (TTree *tree) { | |||
405 | if (!nofail(sib2(tree))) return 0; | 399 | if (!nofail(sib2(tree))) return 0; |
406 | /* else return headfail(sib1(tree)); */ | 400 | /* else return headfail(sib1(tree)); */ |
407 | tree = sib1(tree); goto tailcall; | 401 | tree = sib1(tree); goto tailcall; |
408 | case TChoice: case TRecov: case TLabChoice: /* labeled failure */ | 402 | case TChoice: case TLabChoice: /* labeled failure */ |
409 | if (!headfail(sib1(tree))) return 0; | 403 | if (!headfail(sib1(tree))) return 0; |
410 | /* else return headfail(sib2(tree)); */ | 404 | /* else return headfail(sib2(tree)); */ |
411 | tree = sib2(tree); goto tailcall; | 405 | tree = sib2(tree); goto tailcall; |
@@ -425,7 +419,7 @@ static int needfollow (TTree *tree) { | |||
425 | case TChar: case TSet: case TAny: | 419 | case TChar: case TSet: case TAny: |
426 | case TFalse: case TTrue: case TAnd: case TNot: | 420 | case TFalse: case TTrue: case TAnd: case TNot: |
427 | case TRunTime: case TGrammar: case TCall: case TBehind: | 421 | case TRunTime: case TGrammar: case TCall: case TBehind: |
428 | case TThrow: case TRecov: case TLabChoice: /* (?)labeled failure */ | 422 | case TThrow: case TLabChoice: /* (?)labeled failure */ |
429 | return 0; | 423 | return 0; |
430 | case TChoice: case TRep: | 424 | case TChoice: case TRep: |
431 | return 1; | 425 | return 1; |
@@ -462,7 +456,7 @@ int sizei (const Instruction *i) { | |||
462 | return 2; | 456 | return 2; |
463 | case IThrowRec: /* labeled failure */ | 457 | case IThrowRec: /* labeled failure */ |
464 | return 3; | 458 | return 3; |
465 | case IRecov: case ILabChoice: | 459 | case ILabChoice: |
466 | return (CHARSETINSTSIZE - 1) + 2; /* labeled failure */ | 460 | return (CHARSETINSTSIZE - 1) + 2; /* labeled failure */ |
467 | 461 | ||
468 | default: return 1; | 462 | default: return 1; |
@@ -529,7 +523,7 @@ static int addoffsetinst (CompileState *compst, Opcode op) { | |||
529 | int i = addinstruction(compst, op, 0); /* instruction */ | 523 | int i = addinstruction(compst, op, 0); /* instruction */ |
530 | addinstruction(compst, (Opcode)0, 0); /* open space for offset */ | 524 | addinstruction(compst, (Opcode)0, 0); /* open space for offset */ |
531 | assert(op == ITestSet || sizei(&getinstr(compst, i)) == 2 || | 525 | assert(op == ITestSet || sizei(&getinstr(compst, i)) == 2 || |
532 | op == IRecov || op == ILabChoice); /* labeled failure */ | 526 | op == ILabChoice); /* labeled failure */ |
533 | return i; | 527 | return i; |
534 | } | 528 | } |
535 | 529 | ||
@@ -753,22 +747,6 @@ static void codechoice (CompileState *compst, TTree *p1, TTree *p2, int opt, | |||
753 | 747 | ||
754 | 748 | ||
755 | /* labeled failure begin */ | 749 | /* labeled failure begin */ |
756 | static void coderecovery (CompileState *compst, TTree *p1, TTree *p2, int opt, | ||
757 | const Charset *fl, const byte *cs) { | ||
758 | int emptyp2 = (p2->tag == TTrue); | ||
759 | int pcommit; | ||
760 | int test = NOINST; | ||
761 | int precovery = addoffsetinst(compst, IRecov); | ||
762 | addcharset(compst, cs); | ||
763 | codegen(compst, p1, emptyp2, test, fullset); | ||
764 | pcommit = addoffsetinst(compst, ICommit); | ||
765 | jumptohere(compst, precovery); | ||
766 | jumptohere(compst, test); | ||
767 | codegen(compst, p2, opt, NOINST, fl); | ||
768 | addinstruction(compst, IRet, 0); | ||
769 | jumptohere(compst, pcommit); | ||
770 | } | ||
771 | |||
772 | static void codelabchoice (CompileState *compst, TTree *p1, TTree *p2, int opt, | 750 | static void codelabchoice (CompileState *compst, TTree *p1, TTree *p2, int opt, |
773 | const Charset *fl, const byte *cs) { | 751 | const Charset *fl, const byte *cs) { |
774 | int emptyp2 = (p2->tag == TTrue); | 752 | int emptyp2 = (p2->tag == TTrue); |
@@ -1020,16 +998,9 @@ static void codegen (CompileState *compst, TTree *tree, int opt, int tt, | |||
1020 | tree = sib2(tree); goto tailcall; | 998 | tree = sib2(tree); goto tailcall; |
1021 | } | 999 | } |
1022 | case TThrow: { /* labeled failure */ | 1000 | case TThrow: { /* labeled failure */ |
1023 | /*printf("TThrow %s top %d\n", lua_typename(compst->L, -1), lua_gettop(compst->L));*/ | ||
1024 | /*lua_rawgeti(compst->L, -1, tree->key);*/ | ||
1025 | /*printf("Throw2 lab = %s\n", lua_tostring(compst->L, -1));*/ | ||
1026 | codethrow(compst, tree); | 1001 | codethrow(compst, tree); |
1027 | break; | 1002 | break; |
1028 | } | 1003 | } |
1029 | case TRecov: { /* labeled failure */ | ||
1030 | coderecovery(compst, sib1(tree), sib2(tree), opt, fl, treelabelset(tree)); | ||
1031 | break; | ||
1032 | } | ||
1033 | case TLabChoice: { /* labeled failure */ | 1004 | case TLabChoice: { /* labeled failure */ |
1034 | codelabchoice(compst, sib1(tree), sib2(tree), opt, fl, treelabelset(tree)); | 1005 | codelabchoice(compst, sib1(tree), sib2(tree), opt, fl, treelabelset(tree)); |
1035 | break; | 1006 | break; |
@@ -1056,7 +1027,7 @@ static void peephole (CompileState *compst) { | |||
1056 | switch (code[i].i.code) { | 1027 | switch (code[i].i.code) { |
1057 | case IChoice: case ICall: case ICommit: case IPartialCommit: | 1028 | case IChoice: case ICall: case ICommit: case IPartialCommit: |
1058 | case IBackCommit: case ITestChar: case ITestSet: | 1029 | case IBackCommit: case ITestChar: case ITestSet: |
1059 | case IRecov: case ILabChoice: /* labeled failure */ | 1030 | case ILabChoice: /* labeled failure */ |
1060 | case ITestAny: { /* instructions with labels */ | 1031 | case ITestAny: { /* instructions with labels */ |
1061 | jumptothere(compst, i, finallabel(code, i)); /* optimize label */ | 1032 | jumptothere(compst, i, finallabel(code, i)); /* optimize label */ |
1062 | break; | 1033 | break; |