Make stack_print_dot_graph function take a language as an argument

This commit is contained in:
Max Brunsfeld 2018-04-08 13:49:20 -07:00
parent 379a2fd121
commit 33820253e8
4 changed files with 16 additions and 20 deletions

View file

@ -19,10 +19,10 @@
parser__log(self); \
}
#define LOG_STACK() \
if (self->print_debugging_graphs) { \
ts_stack_print_dot_graph(self->stack, self->language->symbol_names, stderr); \
fputs("\n\n", stderr); \
#define LOG_STACK() \
if (self->print_debugging_graphs) { \
ts_stack_print_dot_graph(self->stack, self->language, stderr); \
fputs("\n\n", stderr); \
}
#define LOG_TREE() \

View file

@ -1,4 +1,5 @@
#include "runtime/alloc.h"
#include "runtime/language.h"
#include "runtime/tree.h"
#include "runtime/array.h"
#include "runtime/stack.h"
@ -646,7 +647,7 @@ void ts_stack_clear(Stack *self) {
}));
}
bool ts_stack_print_dot_graph(Stack *self, const char **symbol_names, FILE *f) {
bool ts_stack_print_dot_graph(Stack *self, const TSLanguage *language, FILE *f) {
bool was_recording_allocations = ts_toggle_allocation_recording(false);
if (!f)
f = stderr;
@ -734,19 +735,15 @@ bool ts_stack_print_dot_graph(Stack *self, const char **symbol_names, FILE *f) {
if (!link.tree) {
fprintf(f, "color=red");
} else {
if (link.tree->symbol == ts_builtin_sym_error) {
fprintf(f, "label=\"ERROR\"");
} else {
fprintf(f, "label=\"");
if (!link.tree->named) fprintf(f, "'");
const char *name = symbol_names[link.tree->symbol];
for (const char *c = name; *c; c++) {
if (*c == '\"' || *c == '\\') fprintf(f, "\\");
fprintf(f, "%c", *c);
}
if (!link.tree->named) fprintf(f, "'");
fprintf(f, "\"");
fprintf(f, "label=\"");
if (link.tree->visible && !link.tree->named) fprintf(f, "'");
const char *name = ts_language_symbol_name(language, link.tree->symbol);
for (const char *c = name; *c; c++) {
if (*c == '\"' || *c == '\\') fprintf(f, "\\");
fprintf(f, "%c", *c);
}
if (link.tree->visible && !link.tree->named) fprintf(f, "'");
fprintf(f, "\"");
fprintf(f, "labeltooltip=\"error_cost: %u\ndynamic_precedence: %u\"",
link.tree->error_cost,
link.tree->dynamic_precedence);

View file

@ -120,7 +120,7 @@ void ts_stack_remove_version(Stack *, StackVersion);
void ts_stack_clear(Stack *);
bool ts_stack_print_dot_graph(Stack *, const char **, FILE *);
bool ts_stack_print_dot_graph(Stack *, const TSLanguage *, FILE *);
typedef void (*StackIterateCallback)(void *, TSStateId, uint32_t);

View file

@ -715,8 +715,7 @@ void ts_tree__print_dot_graph(const Tree *self, uint32_t byte_offset,
}
}
void ts_tree_print_dot_graph(const Tree *self, const TSLanguage *language,
FILE *f) {
void ts_tree_print_dot_graph(const Tree *self, const TSLanguage *language, FILE *f) {
fprintf(f, "digraph tree {\n");
fprintf(f, "edge [arrowhead=none]\n");
ts_tree__print_dot_graph(self, 0, language, f);