aboutsummaryrefslogtreecommitdiff
path: root/lptree.c
diff options
context:
space:
mode:
authorSérgio Queiroz <sqmedeiros@gmail.com>2017-12-15 16:31:41 -0300
committerSérgio Queiroz <sqmedeiros@gmail.com>2017-12-15 16:31:41 -0300
commit4bdf8d40a9ca5f00e454a38d301a3ab35c9b50d5 (patch)
treee59c5041761c237f27fe51589901da5a963ee103 /lptree.c
parent0f53a65f4a32c8be2d84c4a8172b885065f7c1e5 (diff)
downloadlpeglabel-4bdf8d40a9ca5f00e454a38d301a3ab35c9b50d5.tar.gz
lpeglabel-4bdf8d40a9ca5f00e454a38d301a3ab35c9b50d5.tar.bz2
lpeglabel-4bdf8d40a9ca5f00e454a38d301a3ab35c9b50d5.zip
Removing code related to labeled choice and recovery operators and updating tests
Diffstat (limited to 'lptree.c')
-rw-r--r--lptree.c36
1 files changed, 2 insertions, 34 deletions
diff --git a/lptree.c b/lptree.c
index 90e82ef..6d6b399 100644
--- a/lptree.c
+++ b/lptree.c
@@ -28,7 +28,7 @@ const byte numsiblings[] = {
28 0, 0, 2, 1, /* call, opencall, rule, grammar */ 28 0, 0, 2, 1, /* call, opencall, rule, grammar */
29 1, /* behind */ 29 1, /* behind */
30 1, 1, /* capture, runtime capture */ 30 1, 1, /* capture, runtime capture */
31 0, 2, 2 /* labeled failure throw, recovery, labeled choice */ 31 0 /* labeled failure throw */
32}; 32};
33 33
34 34
@@ -533,21 +533,6 @@ static TTree *newthrowleaf (lua_State *L) {
533 tree->u.s.ps = 0; /* there is no recovery rule associated */ 533 tree->u.s.ps = 0; /* there is no recovery rule associated */
534 return tree; 534 return tree;
535} 535}
536
537static TTree *newrootlab2sib (lua_State *L, int tag) {
538 int s1, s2;
539 TTree *tree1 = getpatt(L, 1, &s1);
540 TTree *tree2 = getpatt(L, 2, &s2);
541 TTree *tree = newtree(L, bytes2slots(LABELSETSIZE) + 1 + s1 + s2); /* create new tree */
542 tree->tag = tag;
543 tree->u.s.ps = 1 + s1;
544 tree->u.s.plab = 1 + s1 + s2;
545 memcpy(sib1(tree), tree1, s1 * sizeof(TTree));
546 memcpy(sib2(tree), tree2, s2 * sizeof(TTree));
547 loopset(i, treelabelset(tree)[i] = 0);
548 joinktables(L, 1, sib2(tree), 2);
549 return tree;
550}
551/* labeled failure end */ 536/* labeled failure end */
552 537
553 538
@@ -736,22 +721,6 @@ static int lp_throw (lua_State *L) {
736 tree->key = addtonewktable(L, 0, 1); 721 tree->key = addtonewktable(L, 0, 1);
737 return 1; 722 return 1;
738} 723}
739
740
741/*
742** labeled choice function
743*/
744static int lp_labchoice (lua_State *L) {
745 int n = lua_gettop(L);
746 TTree *tree = newrootlab2sib(L, TLabChoice);
747 int i;
748 for (i = 3; i <= n; i++) {
749 int d = luaL_checkinteger(L, i);
750 luaL_argcheck(L, d >= 1 && d < MAXLABELS, i, "the number of a label must be between 1 and 255");
751 setlabel(treelabelset(tree), (byte)d);
752 }
753 return 1;
754}
755/* labeled failure end */ 724/* labeled failure end */
756 725
757 726
@@ -1088,7 +1057,7 @@ static int verifyrule (lua_State *L, TTree *tree, int *passed, int npassed,
1088 return nb; 1057 return nb;
1089 /* else return verifyrule(L, sib2(tree), passed, npassed, nb); */ 1058 /* else return verifyrule(L, sib2(tree), passed, npassed, nb); */
1090 tree = sib2(tree); goto tailcall; 1059 tree = sib2(tree); goto tailcall;
1091 case TChoice: case TLabChoice: /* must check both children */ /* labeled failure */ 1060 case TChoice: /* must check both children */
1092 nb = verifyrule(L, sib1(tree), passed, npassed, nb); 1061 nb = verifyrule(L, sib1(tree), passed, npassed, nb);
1093 /* return verifyrule(L, sib2(tree), passed, npassed, nb); */ 1062 /* return verifyrule(L, sib2(tree), passed, npassed, nb); */
1094 tree = sib2(tree); goto tailcall; 1063 tree = sib2(tree); goto tailcall;
@@ -1344,7 +1313,6 @@ static struct luaL_Reg pattreg[] = {
1344 {"setmaxstack", lp_setmax}, 1313 {"setmaxstack", lp_setmax},
1345 {"type", lp_type}, 1314 {"type", lp_type},
1346 {"T", lp_throw}, /* labeled failure throw */ 1315 {"T", lp_throw}, /* labeled failure throw */
1347 {"Lc", lp_labchoice}, /* labeled failure choice */
1348 {NULL, NULL} 1316 {NULL, NULL}
1349}; 1317};
1350 1318