diff --git a/include/tree_sitter/runtime.h b/include/tree_sitter/runtime.h index fb24d6f4..e742ace1 100644 --- a/include/tree_sitter/runtime.h +++ b/include/tree_sitter/runtime.h @@ -91,6 +91,7 @@ void ts_document_set_input(TSDocument *, TSInput); void ts_document_set_input_string(TSDocument *, const char *); TSDebugger ts_document_debugger(const TSDocument *); void ts_document_set_debugger(TSDocument *, TSDebugger); +void ts_document_print_debugging_graphs(TSDocument *, bool); void ts_document_edit(TSDocument *, TSInputEdit); int ts_document_parse(TSDocument *); void ts_document_invalidate(TSDocument *); diff --git a/src/runtime/document.c b/src/runtime/document.c index c852b816..3d0ef2a1 100644 --- a/src/runtime/document.c +++ b/src/runtime/document.c @@ -52,6 +52,10 @@ void ts_document_set_debugger(TSDocument *self, TSDebugger debugger) { ts_parser_set_debugger(&self->parser, debugger); } +void ts_document_print_debugging_graphs(TSDocument *self, bool should_print) { + self->parser.print_debugging_graphs = should_print; +} + TSInput ts_document_input(TSDocument *self) { return self->input; } diff --git a/src/runtime/parser.c b/src/runtime/parser.c index ee8109d5..0bb3cb9e 100644 --- a/src/runtime/parser.c +++ b/src/runtime/parser.c @@ -15,8 +15,6 @@ * Debugging */ -bool TS_PARSER_PRINT_STACKS = false; - #define LOG(...) \ if (self->lexer.debugger.debug_fn) { \ snprintf(self->lexer.debug_buffer, TS_DEBUG_BUFFER_SIZE, __VA_ARGS__); \ @@ -26,14 +24,14 @@ bool TS_PARSER_PRINT_STACKS = false; #define LOG_ACTION(...) \ LOG(__VA_ARGS__); \ - if (TS_PARSER_PRINT_STACKS) { \ + if (self->print_debugging_graphs) { \ fprintf(stderr, "graph {\nlabel=\""); \ fprintf(stderr, __VA_ARGS__); \ fprintf(stderr, "\"\n}\n\n"); \ } #define LOG_STACK() \ - if (TS_PARSER_PRINT_STACKS) { \ + if (self->print_debugging_graphs) { \ fputs(ts_stack_dot_graph(self->stack, self->language->symbol_names), \ stderr); \ fputs("\n\n", stderr); \ diff --git a/src/runtime/parser.h b/src/runtime/parser.h index 73223e97..d9a60f6f 100644 --- a/src/runtime/parser.h +++ b/src/runtime/parser.h @@ -18,6 +18,7 @@ typedef struct { Array(TSTree *) reduce_parents; TSTree *finished_tree; bool is_split; + bool print_debugging_graphs; } TSParser; bool ts_parser_init(TSParser *);