Handle backslashes in token names when printing DOT debug graphs

This commit is contained in:
Max Brunsfeld 2022-06-25 17:13:11 -07:00
parent 04381dcea3
commit 3ac36b0cbe
4 changed files with 28 additions and 19 deletions

View file

@ -160,7 +160,7 @@ static void ts_parser__log(TSParser *self) {
if (self->dot_graph_file) {
fprintf(self->dot_graph_file, "graph {\nlabel=\"");
for (char *c = &self->lexer.debug_buffer[0]; *c != 0; c++) {
if (*c == '"') fputc('\\', self->dot_graph_file);
if (*c == '"' || *c == '\\') fputc('\\', self->dot_graph_file);
fputc(*c, self->dot_graph_file);
}
fprintf(self->dot_graph_file, "\"\n}\n\n");