]> ocean-lang.org Git - ocean/commitdiff
parsergen: improve tracing.
authorNeilBrown <neilb@suse.de>
Sun, 22 Jun 2014 05:18:32 +0000 (15:18 +1000)
committerNeilBrown <neilb@suse.de>
Sun, 22 Jun 2014 05:18:32 +0000 (15:18 +1000)
1/ perform the "is null?" test on trace find in parser_trace.
   code is cleaner that way

2/ Report the action at each step in the parse.

Signed-off-by: NeilBrown <neilb@suse.de>
csrc/parsergen.mdc

index 19703bce82000b2ce642a29e9e6ad5c15bd91d3a..93065928492d0d164433fbce946e47e814f8c2d5 100644 (file)
@@ -2601,14 +2601,14 @@ since the last state which could have been at the start of a line.
                        if (!tk)
                                tk = tok_copy(token_next(tokens));
                        next.sym = tk->num;
-                       if (trace)
-                               parser_trace(trace, &p, &next, tk, states, non_term, config->known_count);
+                       parser_trace(trace, &p, &next, tk, states, non_term, config->known_count);
 
                        if (next.sym == TK_in) {
                                next.starts_indented = 1;
                                next.indents = 1;
                                free(tk);
                                tk = NULL;
+                               parser_trace_action(trace, "Record");
                                continue;
                        }
                        if (next.sym == TK_out) {
@@ -2625,6 +2625,7 @@ since the last state which could have been at the start of a line.
                                        }
                                        free(tk);
                                        tk = NULL;
+                                       parser_trace_action(trace, "Cancel");
                                        continue;
                                }
                                // fall through and force a REDUCE (as 'shift'
@@ -2634,6 +2635,7 @@ since the last state which could have been at the start of a line.
                                if (! tos->newline_permitted) {
                                        free(tk);
                                        tk = NULL;
+                                       parser_trace_action(trace, "Discard");
                                        continue;
                                }
                        }
@@ -2641,6 +2643,7 @@ since the last state which could have been at the start of a line.
                                tk = NULL;
                                next.starts_indented = 0;
                                next.indents = 0;
+                               parser_trace_action(trace, "Shift");
                                continue;
                        }
                        if (states[tos->state].reduce_prod >= 0) {
@@ -2673,6 +2676,7 @@ since the last state which could have been at the start of a line.
                                        accepted = 1;
                                        ret = res;
                                }
+                               parser_trace_action(trace, "Reduce");
                                continue;
                        }
                        if (tk->num == TK_out) {
@@ -2683,6 +2687,7 @@ since the last state which could have been at the start of a line.
                                frame.sym = states[tos->state].shift_sym;
                                shift(&p, &frame, tok_copy(*tk), states);
                                // FIXME need to report this error somehow
+                               parser_trace_action(trace, "Synthesize");
                                continue;
                        }
                        /* Error. We walk up the stack until we
@@ -2692,6 +2697,7 @@ since the last state which could have been at the start of a line.
                         * Then we discard input tokens until
                         * we find one that is acceptable.
                         */
+                       parser_trace_action(trace, "ERROR");
 
                        err_tk = tok_copy(*tk);
                        next.sym = TK_error;
@@ -2777,6 +2783,8 @@ end inside square brackets.
                          const char *non_term[], int knowns)
        {
                int i;
+               if (!trace)
+                       return;
                for (i = 0; i < p->tos; i++) {
                        struct frame *f = &p->stack[i];
                        if (i) {
@@ -2806,7 +2814,13 @@ end inside square brackets.
                if (n->indents)
                        fprintf(trace, "%c%d", n->starts_indented?':':'.',
                                n->indents);
-               fputs("]\n", trace);
+               fputs("]", trace);
+       }
+
+       void parser_trace_action(FILE *trace, char *action)
+       {
+               if (trace)
+                       fprintf(trace, " - %s\n", action);
        }
 
 # A Worked Example