diff options
author | Sérgio Queiroz <sqmedeiros@gmail.com> | 2019-08-05 16:11:07 -0300 |
---|---|---|
committer | Sérgio Queiroz <sqmedeiros@gmail.com> | 2019-08-05 16:11:07 -0300 |
commit | 957d8f22310ebfbac08f6bb22ecddad23be026b4 (patch) | |
tree | f5878adc4917454886b4cae4570325e7321bbbf9 /lpprint.c | |
parent | 0671e873f50ba568074d1683e068d5dce88dd43b (diff) | |
download | lpeglabel-957d8f22310ebfbac08f6bb22ecddad23be026b4.tar.gz lpeglabel-957d8f22310ebfbac08f6bb22ecddad23be026b4.tar.bz2 lpeglabel-957d8f22310ebfbac08f6bb22ecddad23be026b4.zip |
Updating LPegLabel to the codebase of LPeg(1.1.0?) (https://github.com/roberto-ieru/LPeg/tree/c2680687d148820847607e13ed7100e60d94c79e)
Diffstat (limited to 'lpprint.c')
-rw-r--r-- | lpprint.c | 54 |
1 files changed, 34 insertions, 20 deletions
@@ -56,21 +56,26 @@ void printinst (const Instruction *op, const Instruction *p) { | |||
56 | const char *const names[] = { | 56 | const char *const names[] = { |
57 | "any", "char", "set", | 57 | "any", "char", "set", |
58 | "testany", "testchar", "testset", | 58 | "testany", "testchar", "testset", |
59 | "span", "behind", | 59 | "span", "utf-range", "behind", |
60 | "ret", "end", | 60 | "ret", "end", |
61 | "choice", "pred_choice", "jmp", "call", "open_call", /* labeled failure */ | 61 | "choice", "pred_choice", "jmp", "call", "open_call", /* labeled failure */ |
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 | "throw", "throw_rec", /* labeled failure */ | 64 | "throw", "throw_rec", /* labeled failure */ |
65 | "--" | ||
65 | }; | 66 | }; |
66 | printf("%02ld: %s ", (long)(p - op), names[p->i.code]); | 67 | printf("%02ld: %s ", (long)(p - op), names[p->i.code]); |
67 | switch ((Opcode)p->i.code) { | 68 | switch ((Opcode)p->i.code) { |
68 | case IChar: { | 69 | case IChar: { |
69 | printf("'%c'", p->i.aux); | 70 | printf("'%c' (%02x)", p->i.aux, p->i.aux); |
70 | break; | 71 | break; |
71 | } | 72 | } |
72 | case ITestChar: { | 73 | case ITestChar: { |
73 | printf("'%c'", p->i.aux); printjmp(op, p); | 74 | printf("'%c' (%02x)", p->i.aux, p->i.aux); printjmp(op, p); |
75 | break; | ||
76 | } | ||
77 | case IUTFR: { | ||
78 | printf("%d - %d", p[1].offset, utf_to(p)); | ||
74 | break; | 79 | break; |
75 | } | 80 | } |
76 | case IFullCapture: { | 81 | case IFullCapture: { |
@@ -157,11 +162,11 @@ void printcaplist (Capture *cap, Capture *limit) { | |||
157 | 162 | ||
158 | static const char *tagnames[] = { | 163 | static const char *tagnames[] = { |
159 | "char", "set", "any", | 164 | "char", "set", "any", |
160 | "true", "false", | 165 | "true", "false", "utf8.range", |
161 | "rep", | 166 | "rep", |
162 | "seq", "choice", | 167 | "seq", "choice", |
163 | "not", "and", | 168 | "not", "and", |
164 | "call", "opencall", "rule", "grammar", | 169 | "call", "opencall", "rule", "xinfo", "grammar", |
165 | "behind", | 170 | "behind", |
166 | "capture", "run-time", | 171 | "capture", "run-time", |
167 | "throw" /* labeled failure */ | 172 | "throw" /* labeled failure */ |
@@ -170,6 +175,7 @@ static const char *tagnames[] = { | |||
170 | 175 | ||
171 | void printtree (TTree *tree, int ident) { | 176 | void printtree (TTree *tree, int ident) { |
172 | int i; | 177 | int i; |
178 | int sibs = numsiblings[tree->tag]; | ||
173 | for (i = 0; i < ident; i++) printf(" "); | 179 | for (i = 0; i < ident; i++) printf(" "); |
174 | printf("%s", tagnames[tree->tag]); | 180 | printf("%s", tagnames[tree->tag]); |
175 | switch (tree->tag) { | 181 | switch (tree->tag) { |
@@ -186,25 +192,34 @@ void printtree (TTree *tree, int ident) { | |||
186 | printf("\n"); | 192 | printf("\n"); |
187 | break; | 193 | break; |
188 | } | 194 | } |
195 | case TUTFR: { | ||
196 | assert(sib1(tree)->tag == TXInfo); | ||
197 | printf(" %d (%02x %d) - %d (%02x %d) \n", | ||
198 | tree->u.n, tree->key, tree->cap, | ||
199 | sib1(tree)->u.n, sib1(tree)->key, sib1(tree)->cap); | ||
200 | break; | ||
201 | } | ||
189 | case TOpenCall: case TCall: { | 202 | case TOpenCall: case TCall: { |
190 | assert(sib2(tree)->tag == TRule); | 203 | assert(sib1(sib2(tree))->tag == TXInfo); |
191 | printf(" key: %d (rule: %d)\n", tree->key, sib2(tree)->cap); | 204 | printf(" key: %d (rule: %d)\n", tree->key, sib1(sib2(tree))->u.n); |
192 | break; | 205 | break; |
193 | } | 206 | } |
194 | case TBehind: { | 207 | case TBehind: { |
195 | printf(" %d\n", tree->u.n); | 208 | printf(" %d\n", tree->u.n); |
196 | printtree(sib1(tree), ident + 2); | ||
197 | break; | 209 | break; |
198 | } | 210 | } |
199 | case TCapture: { | 211 | case TCapture: { |
200 | printf(" kind: '%s' key: %d\n", capkind(tree->cap), tree->key); | 212 | printf(" kind: '%s' key: %d\n", capkind(tree->cap), tree->key); |
201 | printtree(sib1(tree), ident + 2); | ||
202 | break; | 213 | break; |
203 | } | 214 | } |
204 | case TRule: { | 215 | case TRule: { |
205 | printf(" n: %d key: %d\n", tree->cap, tree->key); | 216 | printf(" key: %d\n", tree->key); |
206 | printtree(sib1(tree), ident + 2); | 217 | sibs = 1; /* do not print 'sib2' (next rule) as a sibling */ |
207 | break; /* do not print next rule as a sibling */ | 218 | break; |
219 | } | ||
220 | case TXInfo: { | ||
221 | printf(" n: %d\n", tree->u.n); | ||
222 | break; | ||
208 | } | 223 | } |
209 | case TGrammar: { | 224 | case TGrammar: { |
210 | TTree *rule = sib1(tree); | 225 | TTree *rule = sib1(tree); |
@@ -214,6 +229,7 @@ void printtree (TTree *tree, int ident) { | |||
214 | rule = sib2(rule); | 229 | rule = sib2(rule); |
215 | } | 230 | } |
216 | assert(rule->tag == TTrue); /* sentinel */ | 231 | assert(rule->tag == TTrue); /* sentinel */ |
232 | sibs = 0; /* siblings already handled */ | ||
217 | break; | 233 | break; |
218 | } | 234 | } |
219 | case TThrow: { /* labeled failure */ | 235 | case TThrow: { /* labeled failure */ |
@@ -222,16 +238,14 @@ void printtree (TTree *tree, int ident) { | |||
222 | printf(" key: %d (rule: %d)\n", tree->key, sib2(tree)->cap); | 238 | printf(" key: %d (rule: %d)\n", tree->key, sib2(tree)->cap); |
223 | break; | 239 | break; |
224 | } | 240 | } |
225 | default: { | 241 | default: |
226 | int sibs = numsiblings[tree->tag]; | ||
227 | printf("\n"); | 242 | printf("\n"); |
228 | if (sibs >= 1) { | ||
229 | printtree(sib1(tree), ident + 2); | ||
230 | if (sibs >= 2) | ||
231 | printtree(sib2(tree), ident + 2); | ||
232 | } | ||
233 | break; | 243 | break; |
234 | } | 244 | } |
245 | if (sibs >= 1) { | ||
246 | printtree(sib1(tree), ident + 2); | ||
247 | if (sibs >= 2) | ||
248 | printtree(sib2(tree), ident + 2); | ||
235 | } | 249 | } |
236 | } | 250 | } |
237 | 251 | ||