From eb47edb446709c36145d1bcdbbc2ba08b7be7bee Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Sun, 3 Apr 2016 23:45:43 -0700 Subject: [PATCH] Add static function for stringifying nodes including hidden ones --- src/runtime/node.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/runtime/node.c b/src/runtime/node.c index 103117ab..79eeee63 100644 --- a/src/runtime/node.c +++ b/src/runtime/node.c @@ -242,14 +242,13 @@ static size_t write_lookahead_to_string(char *string, size_t limit, static size_t ts_tree__write_to_string(const TSTree *self, const TSLanguage *language, char *string, size_t limit, bool is_root, - bool include_anonymous) { + bool include_all) { if (!self) return snprintf(string, limit, "(NULL)"); char *cursor = string; char **writer = (limit > 0) ? &cursor : &string; - bool visible = - is_root || (self->visible && (include_anonymous || self->named)); + bool visible = include_all || is_root || (self->visible && self->named); if (visible && !is_root) cursor += snprintf(*writer, limit, " "); @@ -267,7 +266,7 @@ static size_t ts_tree__write_to_string(const TSTree *self, for (size_t i = 0; i < self->child_count; i++) { TSTree *child = self->children[i]; cursor += ts_tree__write_to_string(child, language, *writer, limit, false, - include_anonymous); + include_all); } if (visible) @@ -276,17 +275,21 @@ static size_t ts_tree__write_to_string(const TSTree *self, return cursor - string; } -char *ts_node_string(TSNode self, const TSDocument *document) { +static char *ts_node__string(TSNode self, const TSDocument *document, bool include_all) { static char SCRATCH[1]; const TSTree *tree = ts_node__tree(self); const TSLanguage *language = document->parser.language; size_t size = - ts_tree__write_to_string(tree, language, SCRATCH, 0, true, false) + 1; + ts_tree__write_to_string(tree, language, SCRATCH, 0, true, include_all) + 1; char *result = ts_malloc(size * sizeof(char)); - ts_tree__write_to_string(tree, language, result, size, true, false); + ts_tree__write_to_string(tree, language, result , size, true, include_all); return result; } +char *ts_node_string(TSNode self, const TSDocument *document) { + return ts_node__string(self, document, false); +} + bool ts_node_eq(TSNode self, TSNode other) { return ts_tree_eq(ts_node__tree(self), ts_node__tree(other)) && self.offset[0] == other.offset[0] &&