Improve parser runtime specs

This commit is contained in:
Max Brunsfeld 2014-01-23 13:00:08 -08:00
parent 8a317f6918
commit 432e97e063
5 changed files with 119 additions and 96 deletions

View file

@ -32,9 +32,7 @@ TSTree * TSDocumentTree(const TSDocument *document) {
const char * TSDocumentToString(const TSDocument *document) {
if (document->error.type != TSParseErrorTypeNone) {
return TSParseErrorToString(&document->error, document->text, document->symbol_names);
} else if (document->tree) {
return TSTreeToString(document->tree, document->symbol_names);
} else {
return "#<null tree>";
return TSTreeToString(document->tree, document->symbol_names);
}
}

View file

@ -37,6 +37,9 @@ int TSTreeEquals(const TSTree *node1, const TSTree *node2) {
}
char * TSTreeWriteToString(const TSTree *tree, const char **symbol_names, char *string) {
if (!tree) {
sprintf(string, "#<null tree>");
}
char *result = string;
const char *name = symbol_names[tree->value];
sprintf(result, "(%s", name);
@ -52,7 +55,7 @@ char * TSTreeWriteToString(const TSTree *tree, const char **symbol_names, char *
}
char * TSTreeToString(const TSTree *tree, const char **symbol_names) {
char *string = calloc(100, sizeof(char));
char *string = calloc(200, sizeof(char));
TSTreeWriteToString(tree, symbol_names, string);
return string;
}