aboutsummaryrefslogtreecommitdiff
path: root/lpprint.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-04-14 12:04:23 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-04-14 12:04:23 -0300
commit3f7797419e4d7493e1364290a5b127d1cb45e3bf (patch)
tree8dd91b0d008d5ea9f9c96eada86510495c97d1e3 /lpprint.c
parentd9f83dded93a35fb333c4e1bd371c401f7129fd1 (diff)
downloadlpeg-3f7797419e4d7493e1364290a5b127d1cb45e3bf.tar.gz
lpeg-3f7797419e4d7493e1364290a5b127d1cb45e3bf.tar.bz2
lpeg-3f7797419e4d7493e1364290a5b127d1cb45e3bf.zip
Removed 'unsigned char' limit on number of rules in grammars
Added a new tree-type node 'TXInfo', which follows 'TRule' nodes, to store extra information about a node. (In this case, the rule number, with an 'unsigned short' field.)
Diffstat (limited to 'lpprint.c')
-rw-r--r--lpprint.c37
1 files changed, 20 insertions, 17 deletions
diff --git a/lpprint.c b/lpprint.c
index df62cbe..397785e 100644
--- a/lpprint.c
+++ b/lpprint.c
@@ -60,7 +60,8 @@ void printinst (const Instruction *op, const Instruction *p) {
60 "ret", "end", 60 "ret", "end",
61 "choice", "jmp", "call", "open_call", 61 "choice", "jmp", "call", "open_call",
62 "commit", "partial_commit", "back_commit", "failtwice", "fail", "giveup", 62 "commit", "partial_commit", "back_commit", "failtwice", "fail", "giveup",
63 "fullcapture", "opencapture", "closecapture", "closeruntime" 63 "fullcapture", "opencapture", "closecapture", "closeruntime",
64 "--"
64 }; 65 };
65 printf("%02ld: %s ", (long)(p - op), names[p->i.code]); 66 printf("%02ld: %s ", (long)(p - op), names[p->i.code]);
66 switch ((Opcode)p->i.code) { 67 switch ((Opcode)p->i.code) {
@@ -151,7 +152,7 @@ static const char *tagnames[] = {
151 "rep", 152 "rep",
152 "seq", "choice", 153 "seq", "choice",
153 "not", "and", 154 "not", "and",
154 "call", "opencall", "rule", "grammar", 155 "call", "opencall", "rule", "xinfo", "grammar",
155 "behind", 156 "behind",
156 "capture", "run-time" 157 "capture", "run-time"
157}; 158};
@@ -159,6 +160,7 @@ static const char *tagnames[] = {
159 160
160void printtree (TTree *tree, int ident) { 161void printtree (TTree *tree, int ident) {
161 int i; 162 int i;
163 int sibs = numsiblings[tree->tag];
162 for (i = 0; i < ident; i++) printf(" "); 164 for (i = 0; i < ident; i++) printf(" ");
163 printf("%s", tagnames[tree->tag]); 165 printf("%s", tagnames[tree->tag]);
164 switch (tree->tag) { 166 switch (tree->tag) {
@@ -176,24 +178,26 @@ void printtree (TTree *tree, int ident) {
176 break; 178 break;
177 } 179 }
178 case TOpenCall: case TCall: { 180 case TOpenCall: case TCall: {
179 assert(sib2(tree)->tag == TRule); 181 assert(sib1(sib2(tree))->tag == TXInfo);
180 printf(" key: %d (rule: %d)\n", tree->key, sib2(tree)->cap); 182 printf(" key: %d (rule: %d)\n", tree->key, sib1(sib2(tree))->u.n);
181 break; 183 break;
182 } 184 }
183 case TBehind: { 185 case TBehind: {
184 printf(" %d\n", tree->u.n); 186 printf(" %d\n", tree->u.n);
185 printtree(sib1(tree), ident + 2);
186 break; 187 break;
187 } 188 }
188 case TCapture: { 189 case TCapture: {
189 printf(" kind: '%s' key: %d\n", capkind(tree->cap), tree->key); 190 printf(" kind: '%s' key: %d\n", capkind(tree->cap), tree->key);
190 printtree(sib1(tree), ident + 2);
191 break; 191 break;
192 } 192 }
193 case TRule: { 193 case TRule: {
194 printf(" n: %d key: %d\n", tree->cap, tree->key); 194 printf(" key: %d\n", tree->key);
195 printtree(sib1(tree), ident + 2); 195 sibs = 1; /* do not print 'sib2' (next rule) as a sibling */
196 break; /* do not print next rule as a sibling */ 196 break;
197 }
198 case TXInfo: {
199 printf(" n: %d\n", tree->u.n);
200 break;
197 } 201 }
198 case TGrammar: { 202 case TGrammar: {
199 TTree *rule = sib1(tree); 203 TTree *rule = sib1(tree);
@@ -203,18 +207,17 @@ void printtree (TTree *tree, int ident) {
203 rule = sib2(rule); 207 rule = sib2(rule);
204 } 208 }
205 assert(rule->tag == TTrue); /* sentinel */ 209 assert(rule->tag == TTrue); /* sentinel */
210 sibs = 0; /* siblings already handled */
206 break; 211 break;
207 } 212 }
208 default: { 213 default:
209 int sibs = numsiblings[tree->tag];
210 printf("\n"); 214 printf("\n");
211 if (sibs >= 1) {
212 printtree(sib1(tree), ident + 2);
213 if (sibs >= 2)
214 printtree(sib2(tree), ident + 2);
215 }
216 break; 215 break;
217 } 216 }
217 if (sibs >= 1) {
218 printtree(sib1(tree), ident + 2);
219 if (sibs >= 2)
220 printtree(sib2(tree), ident + 2);
218 } 221 }
219} 222}
220 223