diff options
Diffstat (limited to 'lptree.c')
-rw-r--r-- | lptree.c | 23 |
1 files changed, 5 insertions, 18 deletions
@@ -723,37 +723,25 @@ static int lp_behind (lua_State *L) { | |||
723 | */ | 723 | */ |
724 | static int lp_throw (lua_State *L) { | 724 | static int lp_throw (lua_State *L) { |
725 | int label = luaL_checkinteger(L, -1); | 725 | int label = luaL_checkinteger(L, -1); |
726 | luaL_argcheck(L, label >= 0 && label < MAXLABELS, -1, "the number of a label must be between 0 and 255"); | 726 | luaL_argcheck(L, label >= 1 && label < MAXLABELS, -1, "the number of a label must be between 1 and 255"); |
727 | newthrowleaf(L, label); | 727 | newthrowleaf(L, label); |
728 | return 1; | 728 | return 1; |
729 | } | 729 | } |
730 | 730 | ||
731 | /* | 731 | /* |
732 | ** labeled choice function | 732 | ** labeled recovery function |
733 | */ | 733 | */ |
734 | static int lp_labchoice (lua_State *L) { | ||
735 | int n = lua_gettop(L); | ||
736 | TTree *tree = newrootlab2sib(L, TLabChoice); | ||
737 | int i; | ||
738 | for (i = 3; i <= n; i++) { | ||
739 | int d = luaL_checkinteger(L, i); | ||
740 | luaL_argcheck(L, d >= 0 && d < MAXLABELS, i, "the number of a label must be between 0 and 255"); | ||
741 | setlabel(treelabelset(tree), (byte)d); | ||
742 | } | ||
743 | return 1; | ||
744 | } | ||
745 | |||
746 | |||
747 | static int lp_recovery (lua_State *L) { | 734 | static int lp_recovery (lua_State *L) { |
748 | int n = lua_gettop(L); | 735 | int n = lua_gettop(L); |
749 | TTree *tree = newrootlab2sib(L, TRecov); | 736 | TTree *tree = newrootlab2sib(L, TRecov); |
737 | luaL_argcheck(L, n >= 3, 3, "non-nil value expected"); | ||
750 | if (n == 2) { /* catches fail as default */ | 738 | if (n == 2) { /* catches fail as default */ |
751 | /*setlabel(treelabelset(tree), LFAIL); recovery does not catch regular fail */ | 739 | /*setlabel(treelabelset(tree), LFAIL); recovery does not catch regular fail */ |
752 | } else { | 740 | } else { |
753 | int i; | 741 | int i; |
754 | for (i = 3; i <= n; i++) { | 742 | for (i = 3; i <= n; i++) { |
755 | int d = luaL_checkinteger(L, i); | 743 | int d = luaL_checkinteger(L, i); |
756 | luaL_argcheck(L, d >= 0 && d < MAXLABELS, i, "the number of a label must be between 0 and 255"); | 744 | luaL_argcheck(L, d >= 1 && d < MAXLABELS, i, "the number of a label must be between 1 and 255"); |
757 | setlabel(treelabelset(tree), (byte)d); | 745 | setlabel(treelabelset(tree), (byte)d); |
758 | } | 746 | } |
759 | } | 747 | } |
@@ -1089,7 +1077,7 @@ static int verifyrule (lua_State *L, TTree *tree, int *passed, int npassed, | |||
1089 | return nb; | 1077 | return nb; |
1090 | /* else return verifyrule(L, sib2(tree), passed, npassed, nb); */ | 1078 | /* else return verifyrule(L, sib2(tree), passed, npassed, nb); */ |
1091 | tree = sib2(tree); goto tailcall; | 1079 | tree = sib2(tree); goto tailcall; |
1092 | case TChoice: case TLabChoice: case TRecov: /* must check both children */ /* labeled failure */ | 1080 | case TChoice: case TRecov: /* must check both children */ /* labeled failure */ |
1093 | nb = verifyrule(L, sib1(tree), passed, npassed, nb); | 1081 | nb = verifyrule(L, sib1(tree), passed, npassed, nb); |
1094 | /* return verifyrule(L, sib2(tree), passed, npassed, nb); */ | 1082 | /* return verifyrule(L, sib2(tree), passed, npassed, nb); */ |
1095 | tree = sib2(tree); goto tailcall; | 1083 | tree = sib2(tree); goto tailcall; |
@@ -1342,7 +1330,6 @@ static struct luaL_Reg pattreg[] = { | |||
1342 | {"setmaxstack", lp_setmax}, | 1330 | {"setmaxstack", lp_setmax}, |
1343 | {"type", lp_type}, | 1331 | {"type", lp_type}, |
1344 | {"T", lp_throw}, /* labeled failure throw */ | 1332 | {"T", lp_throw}, /* labeled failure throw */ |
1345 | {"Lc", lp_labchoice}, /* labeled failure choice */ | ||
1346 | {"Rec", lp_recovery}, /* labeled failure choice */ | 1333 | {"Rec", lp_recovery}, /* labeled failure choice */ |
1347 | {NULL, NULL} | 1334 | {NULL, NULL} |
1348 | }; | 1335 | }; |