diff --git a/include/tree_sitter/parser.h b/include/tree_sitter/parser.h index 350fe03c..85344443 100644 --- a/include/tree_sitter/parser.h +++ b/include/tree_sitter/parser.h @@ -7,6 +7,7 @@ extern "C" { #include #include +#include #include "tree_sitter/runtime.h" typedef struct TSTree TSTree; @@ -29,7 +30,7 @@ typedef struct TSLexer { int32_t lookahead; TSTree *(*accept_fn)(struct TSLexer *, TSSymbol, int); - int (*advance_fn)(struct TSLexer *); + bool (*advance_fn)(struct TSLexer *); } TSLexer; static inline int32_t ts_lexer_lookahead_char(const TSLexer *lexer) { diff --git a/include/tree_sitter/runtime.h b/include/tree_sitter/runtime.h index ddc560c2..2ea3e67d 100644 --- a/include/tree_sitter/runtime.h +++ b/include/tree_sitter/runtime.h @@ -6,6 +6,7 @@ extern "C" { #endif #include +#include typedef struct { size_t bytes; @@ -43,7 +44,7 @@ const char *ts_node_name(const TSNode *); const char *ts_node_string(const TSNode *); void ts_node_retain(TSNode *node); void ts_node_release(TSNode *node); -int ts_node_eq(const TSNode *, const TSNode *); +bool ts_node_eq(const TSNode *, const TSNode *); typedef struct TSDocument TSDocument; TSDocument *ts_document_make(); diff --git a/spec/runtime/tree_spec.cc b/spec/runtime/tree_spec.cc index 0ba3e66d..1832e0c9 100644 --- a/spec/runtime/tree_spec.cc +++ b/spec/runtime/tree_spec.cc @@ -124,7 +124,7 @@ describe("Tree", []() { ts_length_make(2, 1), 0); - AssertThat(ts_tree_equals(tree1, tree1_copy), Equals(1)); + AssertThat(ts_tree_eq(tree1, tree1_copy), IsTrue()); TSTree *tree2_copy = ts_tree_make_leaf( cat, @@ -132,13 +132,13 @@ describe("Tree", []() { ts_length_make(1, 1), 0); - AssertThat(ts_tree_equals(tree2, tree2_copy), Equals(1)); + AssertThat(ts_tree_eq(tree2, tree2_copy), IsTrue()); TSTree *parent2 = ts_tree_make_node(dog, 2, tree_array({ tree1_copy, tree2_copy, }), 0); - AssertThat(ts_tree_equals(parent1, parent2), Equals(1)); + AssertThat(ts_tree_eq(parent1, parent2), IsTrue()); ts_tree_release(tree1_copy); ts_tree_release(tree2_copy); @@ -152,7 +152,7 @@ describe("Tree", []() { tree1->padding, 0); - AssertThat(ts_tree_equals(tree1, different_tree), Equals(0)); + AssertThat(ts_tree_eq(tree1, different_tree), IsFalse()); ts_tree_release(different_tree); }); @@ -167,8 +167,8 @@ describe("Tree", []() { different_tree, different_tree, }), 0); - AssertThat(ts_tree_equals(different_parent, parent1), Equals(0)); - AssertThat(ts_tree_equals(parent1, different_parent), Equals(0)); + AssertThat(ts_tree_eq(different_parent, parent1), IsFalse()); + AssertThat(ts_tree_eq(parent1, different_parent), IsFalse()); ts_tree_release(different_tree); ts_tree_release(different_parent); diff --git a/src/runtime/lexer.c b/src/runtime/lexer.c index 5e6650ef..f7c28a2c 100644 --- a/src/runtime/lexer.c +++ b/src/runtime/lexer.c @@ -6,13 +6,13 @@ static const char *empty_chunk = ""; -static int advance(TSLexer *lexer) { +static bool advance(TSLexer *lexer) { /* * Return false if the Lexer has already reached the end of the input. */ if (lexer->chunk == empty_chunk) - return 0; + return false; /* * Increment the Lexer's position. @@ -41,7 +41,7 @@ static int advance(TSLexer *lexer) { (const uint8_t *)lexer->chunk + position_in_chunk, lexer->chunk_size - position_in_chunk + 1, &lexer->lookahead); - return 1; + return true; } static TSTree *accept(TSLexer *lexer, TSSymbol symbol, int is_hidden) { diff --git a/src/runtime/node.c b/src/runtime/node.c index 161b9469..d45d6b1b 100644 --- a/src/runtime/node.c +++ b/src/runtime/node.c @@ -1,3 +1,4 @@ +#include #include "runtime/node.h" #include "runtime/length.h" #include "runtime/tree.h" @@ -35,8 +36,8 @@ TSLength ts_node_pos(const TSNode *node) { return node->position; } TSLength ts_node_size(const TSNode *node) { return node->content->size; } -int ts_node_eq(const TSNode *left, const TSNode *right) { - return ts_tree_equals(left->content, right->content); +bool ts_node_eq(const TSNode *left, const TSNode *right) { + return ts_tree_eq(left->content, right->content); } const char *ts_node_name(const TSNode *node) { diff --git a/src/runtime/tree.c b/src/runtime/tree.c index cbb18ca8..c72ee16a 100644 --- a/src/runtime/tree.c +++ b/src/runtime/tree.c @@ -127,19 +127,19 @@ TSLength ts_tree_total_size(const TSTree *tree) { return ts_length_add(tree->padding, tree->size); } -int ts_tree_equals(const TSTree *node1, const TSTree *node2) { +bool ts_tree_eq(const TSTree *node1, const TSTree *node2) { if (node1->symbol != node2->symbol) - return 0; + return false; if (node1->lookahead_char != node2->lookahead_char) - return 0; + return false; if (node1->child_count != node2->child_count) - return 0; + return false; if (node1->visible_child_count != node2->visible_child_count) - return 0; + return false; for (size_t i = 0; i < node1->child_count; i++) - if (!ts_tree_equals(node1->children[i], node2->children[i])) - return 0; - return 1; + if (!ts_tree_eq(node1->children[i], node2->children[i])) + return false; + return true; } TSTree **ts_tree_children(const TSTree *tree, size_t *count) { diff --git a/src/runtime/tree.h b/src/runtime/tree.h index 30a43063..0500042e 100644 --- a/src/runtime/tree.h +++ b/src/runtime/tree.h @@ -52,7 +52,7 @@ TSTree *ts_tree_make_node(TSSymbol, size_t, TSTree **, bool); TSTree *ts_tree_make_error(TSLength size, TSLength padding, char lookahead_char); void ts_tree_retain(TSTree *tree); void ts_tree_release(TSTree *tree); -int ts_tree_equals(const TSTree *tree1, const TSTree *tree2); +bool ts_tree_eq(const TSTree *tree1, const TSTree *tree2); char *ts_tree_string(const TSTree *tree, const char **names); char *ts_tree_error_string(const TSTree *tree, const char **names); TSTree **ts_tree_children(const TSTree *tree, size_t *count);