aboutsummaryrefslogtreecommitdiff
path: root/lptree.c
diff options
context:
space:
mode:
authorSergio Queiroz <sqmedeiros@gmail.com>2017-07-06 11:21:56 -0300
committerSergio Queiroz <sqmedeiros@gmail.com>2017-07-06 11:21:56 -0300
commit8ee42c29131e1c7de48575d6d8a9b24ea6977cbd (patch)
tree4267e0cf0609a909be1f2eaea17d11b0efc12c98 /lptree.c
parentaad9b29e755d67d6cb4e4b861111df0d173819ce (diff)
downloadlpeglabel-8ee42c29131e1c7de48575d6d8a9b24ea6977cbd.tar.gz
lpeglabel-8ee42c29131e1c7de48575d6d8a9b24ea6977cbd.tar.bz2
lpeglabel-8ee42c29131e1c7de48575d6d8a9b24ea6977cbd.zip
Updating lpeglabel to the codebase of LPeg 1.0.1
Diffstat (limited to 'lptree.c')
-rw-r--r--lptree.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/lptree.c b/lptree.c
index 6633035..fcf5ff9 100644
--- a/lptree.c
+++ b/lptree.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lptree.c,v 1.21 2015/09/28 17:01:25 roberto Exp $ 2** $Id: lptree.c,v 1.22 2016/09/13 18:10:22 roberto Exp $
3** Copyright 2013, Lua.org & PUC-Rio (see 'lpeg.html' for license) 3** Copyright 2013, Lua.org & PUC-Rio (see 'lpeg.html' for license)
4*/ 4*/
5 5
@@ -65,7 +65,7 @@ static void fixonecall (lua_State *L, int postable, TTree *g, TTree *t) {
65 t->tag = TCall; 65 t->tag = TCall;
66 t->u.s.ps = n - (t - g); /* position relative to node */ 66 t->u.s.ps = n - (t - g); /* position relative to node */
67 assert(sib2(t)->tag == TRule); 67 assert(sib2(t)->tag == TRule);
68 sib2(t)->key = t->key; 68 sib2(t)->key = t->key; /* fix rule's key */
69} 69}
70 70
71 71
@@ -542,7 +542,6 @@ static TTree *newrootlab2sib (lua_State *L, int tag) {
542/* labeled failure end */ 542/* labeled failure end */
543 543
544 544
545
546static int lp_P (lua_State *L) { 545static int lp_P (lua_State *L) {
547 luaL_checkany(L, 1); 546 luaL_checkany(L, 1);
548 getpatt(L, 1, NULL); 547 getpatt(L, 1, NULL);
@@ -728,6 +727,7 @@ static int lp_throw (lua_State *L) {
728 return 1; 727 return 1;
729} 728}
730 729
730
731/* 731/*
732** labeled recovery function 732** labeled recovery function
733*/ 733*/
@@ -747,7 +747,6 @@ static int lp_recovery (lua_State *L) {
747 } 747 }
748 return 1; 748 return 1;
749} 749}
750
751/* labeled failure end */ 750/* labeled failure end */
752 751
753 752
@@ -996,7 +995,7 @@ static void buildgrammar (lua_State *L, TTree *grammar, int frule, int n) {
996 int rulesize; 995 int rulesize;
997 TTree *rn = gettree(L, ridx, &rulesize); 996 TTree *rn = gettree(L, ridx, &rulesize);
998 nd->tag = TRule; 997 nd->tag = TRule;
999 nd->key = 0; 998 nd->key = 0; /* will be fixed when rule is used */
1000 nd->cap = i; /* rule number */ 999 nd->cap = i; /* rule number */
1001 nd->u.s.ps = rulesize + 1; /* point to next rule */ 1000 nd->u.s.ps = rulesize + 1; /* point to next rule */
1002 memcpy(sib1(nd), rn, rulesize * sizeof(TTree)); /* copy rule */ 1001 memcpy(sib1(nd), rn, rulesize * sizeof(TTree)); /* copy rule */
@@ -1030,6 +1029,11 @@ static int checkloops (TTree *tree) {
1030} 1029}
1031 1030
1032 1031
1032/*
1033** Give appropriate error message for 'verifyrule'. If a rule appears
1034** twice in 'passed', there is path from it back to itself without
1035** advancing the subject.
1036*/
1033static int verifyerror (lua_State *L, int *passed, int npassed) { 1037static int verifyerror (lua_State *L, int *passed, int npassed) {
1034 int i, j; 1038 int i, j;
1035 for (i = npassed - 1; i >= 0; i--) { /* search for a repetition */ 1039 for (i = npassed - 1; i >= 0; i--) { /* search for a repetition */
@@ -1051,6 +1055,8 @@ static int verifyerror (lua_State *L, int *passed, int npassed) {
1051** is only relevant if the first is nullable. 1055** is only relevant if the first is nullable.
1052** Parameter 'nb' works as an accumulator, to allow tail calls in 1056** Parameter 'nb' works as an accumulator, to allow tail calls in
1053** choices. ('nb' true makes function returns true.) 1057** choices. ('nb' true makes function returns true.)
1058** Parameter 'passed' is a list of already visited rules, 'npassed'
1059** counts the elements in 'passed'.
1054** Assume ktable at the top of the stack. 1060** Assume ktable at the top of the stack.
1055*/ 1061*/
1056static int verifyrule (lua_State *L, TTree *tree, int *passed, int npassed, 1062static int verifyrule (lua_State *L, TTree *tree, int *passed, int npassed,
@@ -1330,7 +1336,7 @@ static struct luaL_Reg pattreg[] = {
1330 {"setmaxstack", lp_setmax}, 1336 {"setmaxstack", lp_setmax},
1331 {"type", lp_type}, 1337 {"type", lp_type},
1332 {"T", lp_throw}, /* labeled failure throw */ 1338 {"T", lp_throw}, /* labeled failure throw */
1333 {"Rec", lp_recovery}, /* labeled failure choice */ 1339 {"Rec", lp_recovery}, /* labeled failure recovery */
1334 {NULL, NULL} 1340 {NULL, NULL}
1335}; 1341};
1336 1342
@@ -1347,7 +1353,6 @@ static struct luaL_Reg metareg[] = {
1347 {NULL, NULL} 1353 {NULL, NULL}
1348}; 1354};
1349 1355
1350
1351int luaopen_lpeglabel (lua_State *L); /* labeled failure */ 1356int luaopen_lpeglabel (lua_State *L); /* labeled failure */
1352int luaopen_lpeglabel (lua_State *L) { /* labeled failure */ 1357int luaopen_lpeglabel (lua_State *L) { /* labeled failure */
1353 luaL_newmetatable(L, PATTERN_T); 1358 luaL_newmetatable(L, PATTERN_T);