diff --git a/src/runtime/parser.c b/src/runtime/parser.c index 0ce47f45..4b2cbeba 100644 --- a/src/runtime/parser.c +++ b/src/runtime/parser.c @@ -136,7 +136,7 @@ static bool ts_parser__can_reuse(TSParser *self, int head, TSTree *subtree) { TSStateId state = ts_stack_top_state(self->stack, head); - if (subtree->lex_state != TSTREE_STATE_INDEPENDENT) { + if (subtree->lex_state != TS_TREE_STATE_INDEPENDENT) { TSStateId lex_state = self->language->lex_states[state]; if (subtree->lex_state != lex_state) return false; @@ -338,7 +338,7 @@ static bool ts_parser__reduce(TSParser *self, int head, TSSymbol symbol, TSStateId state; TSStateId top_state = ts_stack_top_state(self->stack, new_head); - if (parent->parse_state != TSTREE_STATE_ERROR) + if (parent->parse_state != TS_TREE_STATE_ERROR) parent->parse_state = top_state; if (extra) { @@ -384,7 +384,7 @@ static bool ts_parser__reduce(TSParser *self, int head, TSSymbol symbol, TSTree **parent = vector_get(&self->reduce_parents, i); (*parent)->fragile_left = true; (*parent)->fragile_right = true; - (*parent)->parse_state = TSTREE_STATE_ERROR; + (*parent)->parse_state = TS_TREE_STATE_ERROR; } } diff --git a/src/runtime/tree.c b/src/runtime/tree.c index c55a6545..0f9a279c 100644 --- a/src/runtime/tree.c +++ b/src/runtime/tree.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -6,6 +7,9 @@ #include "runtime/tree.h" #include "runtime/length.h" +TSStateId TS_TREE_STATE_INDEPENDENT = USHRT_MAX; +TSStateId TS_TREE_STATE_ERROR = USHRT_MAX - 1; + TSTree *ts_tree_make_leaf(TSSymbol sym, TSLength padding, TSLength size, TSSymbolMetadata metadata) { TSTree *result = malloc(sizeof(TSTree)); @@ -20,8 +24,8 @@ TSTree *ts_tree_make_leaf(TSSymbol sym, TSLength padding, TSLength size, .padding = padding, .visible = metadata.visible, .named = metadata.named, - .lex_state = TSTREE_STATE_INDEPENDENT, - .parse_state = TSTREE_STATE_INDEPENDENT, + .lex_state = TS_TREE_STATE_INDEPENDENT, + .parse_state = TS_TREE_STATE_INDEPENDENT, }; if (sym == ts_builtin_sym_error) { @@ -88,7 +92,7 @@ void ts_tree_set_children(TSTree *self, size_t child_count, TSTree **children) { if (child->symbol == ts_builtin_sym_error) { self->fragile_left = self->fragile_right = true; - self->parse_state = TSTREE_STATE_ERROR; + self->parse_state = TS_TREE_STATE_ERROR; } } diff --git a/src/runtime/tree.h b/src/runtime/tree.h index 6ac40289..615d6f6e 100644 --- a/src/runtime/tree.h +++ b/src/runtime/tree.h @@ -9,8 +9,8 @@ extern "C" { #include "tree_sitter/parser.h" #include "runtime/length.h" -#define TSTREE_STATE_INDEPENDENT (unsigned short)(-1) -#define TSTREE_STATE_ERROR (TSTREE_STATE_INDEPENDENT - 1) +extern TSStateId TS_TREE_STATE_INDEPENDENT; +extern TSStateId TS_TREE_STATE_ERROR; struct TSTree { struct {