Use stdbool.h

This commit is contained in:
Max Brunsfeld 2014-10-03 16:06:08 -07:00
parent 808b003f1a
commit e5ea4efb0b
7 changed files with 25 additions and 22 deletions

View file

@ -7,6 +7,7 @@ extern "C" {
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#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) {

View file

@ -6,6 +6,7 @@ extern "C" {
#endif
#include <stdlib.h>
#include <stdbool.h>
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();

View file

@ -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);

View file

@ -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) {

View file

@ -1,3 +1,4 @@
#include <stdbool.h>
#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) {

View file

@ -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) {

View file

@ -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);