aboutsummaryrefslogtreecommitdiff
path: root/lptree.c
diff options
context:
space:
mode:
authorSérgio Queiroz <sqmedeiros@gmail.com>2017-12-12 11:42:14 -0300
committerSérgio Queiroz <sqmedeiros@gmail.com>2017-12-12 11:42:14 -0300
commit26c1b9aa78e10b2ed2d36d151033fe94254fa8c5 (patch)
tree743f8cca325a2788cd0aa9e98de79ab275884d01 /lptree.c
parent5ffef3da93ad53069d2510a75b11ecbb1b6e8aa7 (diff)
downloadlpeglabel-26c1b9aa78e10b2ed2d36d151033fe94254fa8c5.tar.gz
lpeglabel-26c1b9aa78e10b2ed2d36d151033fe94254fa8c5.tar.bz2
lpeglabel-26c1b9aa78e10b2ed2d36d151033fe94254fa8c5.zip
Using field 'key' to allow strings as labels (partial)
Diffstat (limited to 'lptree.c')
-rw-r--r--lptree.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/lptree.c b/lptree.c
index 810e267..fea2ecf 100644
--- a/lptree.c
+++ b/lptree.c
@@ -216,7 +216,7 @@ static void correctkeys (TTree *tree, int n) {
216 if (n == 0) return; /* no correction? */ 216 if (n == 0) return; /* no correction? */
217 tailcall: 217 tailcall:
218 switch (tree->tag) { 218 switch (tree->tag) {
219 case TOpenCall: case TCall: case TRunTime: case TRule: { 219 case TOpenCall: case TCall: case TRunTime: case TRule: case TThrow: { /* labeled failure */
220 if (tree->key > 0) 220 if (tree->key > 0)
221 tree->key += n; 221 tree->key += n;
222 break; 222 break;
@@ -721,9 +721,14 @@ static int lp_behind (lua_State *L) {
721** Throws a label 721** Throws a label
722*/ 722*/
723static int lp_throw (lua_State *L) { 723static int lp_throw (lua_State *L) {
724 int label = luaL_checkinteger(L, -1); 724 /*int label = luaL_checkinteger(L, -1);*/
725 luaL_argcheck(L, label >= 1 && label < MAXLABELS, -1, "the number of a label must be between 1 and 255"); 725 /*luaL_argcheck(L, label >= 1 && label < MAXLABELS, -1, "the number of a label must be between 1 and 255");*/
726 newthrowleaf(L, label); 726 TTree * tree;
727 luaL_checkstring(L, -1);
728 tree = newthrowleaf(L, 0);
729 tree->u.label = addtonewktable(L, 0, 1);
730 tree->key = tree->u.label;
731 /*printf("lp_throw %d %s\n", tree->key, lua_tostring(L, 1));*/
727 return 1; 732 return 1;
728} 733}
729 734
@@ -1242,7 +1247,10 @@ static int lp_match (lua_State *L) {
1242 r = match(L, s, s + i, s + l, code, capture, ptop, &labelf, &sfail); /* labeled failure */ 1247 r = match(L, s, s + i, s + l, code, capture, ptop, &labelf, &sfail); /* labeled failure */
1243 if (r == NULL) { /* labeled failure begin */ 1248 if (r == NULL) { /* labeled failure begin */
1244 lua_pushnil(L); 1249 lua_pushnil(L);
1245 lua_pushinteger(L, labelf); 1250 if (labelf)
1251 lua_rawgeti(L, ktableidx(ptop), labelf);
1252 else
1253 lua_pushstring(L, "fail");
1246 lua_pushinteger(L, sfail - (s + i) + 1); /* subject position related to the error */ 1254 lua_pushinteger(L, sfail - (s + i) + 1); /* subject position related to the error */
1247 return 3; 1255 return 3;
1248 } /* labeled failure end */ 1256 } /* labeled failure end */