aboutsummaryrefslogtreecommitdiff
path: root/lptree.c
diff options
context:
space:
mode:
Diffstat (limited to 'lptree.c')
-rw-r--r--lptree.c24
1 files changed, 8 insertions, 16 deletions
diff --git a/lptree.c b/lptree.c
index b974bbb..6d0f78c 100644
--- a/lptree.c
+++ b/lptree.c
@@ -34,6 +34,7 @@ const byte numsiblings[] = {
34 34
35static TTree *newgrammar (lua_State *L, int arg); 35static TTree *newgrammar (lua_State *L, int arg);
36 36
37
37/* 38/*
38** returns a reasonable name for value at index 'idx' on the stack 39** returns a reasonable name for value at index 'idx' on the stack
39*/ 40*/
@@ -563,7 +564,7 @@ static int lp_seq (lua_State *L) {
563 else if (tree1->tag == TTrue) 564 else if (tree1->tag == TTrue)
564 lua_pushvalue(L, 2); /* true . x = x */ 565 lua_pushvalue(L, 2); /* true . x = x */
565 else 566 else
566 newroot2sib(L, TSeq); 567 newroot2sib(L, TSeq);
567 return 1; 568 return 1;
568} 569}
569 570
@@ -718,11 +719,11 @@ static int lp_behind (lua_State *L) {
718 719
719/* labeled failure begin */ 720/* labeled failure begin */
720/* 721/*
721** Throws a label 722** Throws a label
722*/ 723*/
723static int lp_throw (lua_State *L) { 724static int lp_throw (lua_State *L) {
724 int label = luaL_checkinteger(L, -1); 725 int label = luaL_checkinteger(L, -1);
725 luaL_argcheck(L, label >= 0 && label < MAXLABELS, -1, "max or min label index exceeded"); 726 luaL_argcheck(L, label >= 0 && label < MAXLABELS, -1, "the number of a label must be between 0 and 255");
726 newthrowleaf(L, label); 727 newthrowleaf(L, label);
727 return 1; 728 return 1;
728} 729}
@@ -736,7 +737,7 @@ static int lp_labchoice (lua_State *L) {
736 int i; 737 int i;
737 for (i = 3; i <= n; i++) { 738 for (i = 3; i <= n; i++) {
738 int d = luaL_checkinteger(L, i); 739 int d = luaL_checkinteger(L, i);
739 luaL_argcheck(L, d >= 0 && d < MAXLABELS, i, "max or min label index exceeded"); 740 luaL_argcheck(L, d >= 0 && d < MAXLABELS, i, "the number of a label must be between 0 and 255");
740 setlabel(treelabelset(tree), (byte)d); 741 setlabel(treelabelset(tree), (byte)d);
741 } 742 }
742 return 1; 743 return 1;
@@ -1209,26 +1210,17 @@ static int lp_match (lua_State *L) {
1209 const char *s = luaL_checklstring(L, SUBJIDX, &l); 1210 const char *s = luaL_checklstring(L, SUBJIDX, &l);
1210 size_t i = initposition(L, l); 1211 size_t i = initposition(L, l);
1211 int ptop = lua_gettop(L); 1212 int ptop = lua_gettop(L);
1212 Labelset labelf; /* labeled failure */ 1213 byte labelf; /* labeled failure */
1213 const char *sfail = NULL; /* labeled failure */ 1214 const char *sfail = NULL; /* labeled failure */
1214 lua_pushnil(L); /* initialize subscache */ 1215 lua_pushnil(L); /* initialize subscache */
1215 lua_pushlightuserdata(L, capture); /* initialize caplistidx */ 1216 lua_pushlightuserdata(L, capture); /* initialize caplistidx */
1216 lua_getuservalue(L, 1); /* initialize penvidx */ 1217 lua_getuservalue(L, 1); /* initialize penvidx */
1217 r = match(L, s, s + i, s + l, code, capture, ptop, &labelf, &sfail); /* labeled failure */ 1218 r = match(L, s, s + i, s + l, code, capture, ptop, &labelf, &sfail); /* labeled failure */
1218 if (r == NULL) { /* labeled failure begin */ 1219 if (r == NULL) { /* labeled failure begin */
1219 long long int j = 0;
1220 int n = 1;
1221 lua_pushnil(L); 1220 lua_pushnil(L);
1222 while (j < MAXLABELS) { 1221 lua_pushinteger(L, labelf);
1223 if (testlabel(labelf.cs, j)) {
1224 lua_pushinteger(L, j);
1225 n++;
1226 break; /* Changing the semantics: only one label */
1227 }
1228 j++;
1229 }
1230 lua_pushstring(L, sfail); /* Pushing the subject where the failure occurred */ 1222 lua_pushstring(L, sfail); /* Pushing the subject where the failure occurred */
1231 return n + 1; 1223 return 3;
1232 } /* labeled failure end */ 1224 } /* labeled failure end */
1233 return getcaptures(L, s, r, ptop); 1225 return getcaptures(L, s, r, ptop);
1234} 1226}