Start work AGAIN

This commit is contained in:
Maix0 2024-04-30 22:25:51 +02:00
parent 0eb8922770
commit 86b5025fb0
24 changed files with 13158 additions and 892 deletions

View file

@ -6,7 +6,7 @@
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ # # By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# # # Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
# Updated: 2024/04/30 17:20:27 by maiboyer ### ########.fr # # Updated: 2024/04/30 22:23:58 by maiboyer ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -22,7 +22,7 @@ CFLAGS = -Wall -Wextra -Werror -MMD -I./includes -I../includes -I../output/inc
include ./Filelist.mk include ./Filelist.mk
SRC_FILES += ./src/lib ./src/scanner SRC_FILES += ./combined
SRC = $(addsuffix .c,$(addprefix $(SRC_DIR)/,$(SRC_FILES))) SRC = $(addsuffix .c,$(addprefix $(SRC_DIR)/,$(SRC_FILES)))
OBJ = $(addsuffix .o,$(addprefix $(BUILD_DIR)/,$(SRC_FILES))) OBJ = $(addsuffix .o,$(addprefix $(BUILD_DIR)/,$(SRC_FILES)))
DEPS = $(addsuffix .d,$(addprefix $(BUILD_DIR)/,$(SRC_FILES))) DEPS = $(addsuffix .d,$(addprefix $(BUILD_DIR)/,$(SRC_FILES)))

12273
parser/combined.c Normal file

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -13,7 +13,7 @@ static void ts_range_array_add(
Length end Length end
) { ) {
if (self->size > 0) { if (self->size > 0) {
TSRange *last_range = array_back(self); t_range *last_range = array_back(self);
if (start.bytes <= last_range->end_byte) { if (start.bytes <= last_range->end_byte) {
last_range->end_byte = end.bytes; last_range->end_byte = end.bytes;
last_range->end_point = end.extent; last_range->end_point = end.extent;
@ -22,7 +22,7 @@ static void ts_range_array_add(
} }
if (start.bytes < end.bytes) { if (start.bytes < end.bytes) {
TSRange range = { start.extent, end.extent, start.bytes, end.bytes }; t_range range = { start.extent, end.extent, start.bytes, end.bytes };
array_push(self, range); array_push(self, range);
} }
} }
@ -34,7 +34,7 @@ bool ts_range_array_intersects(
uint32_t end_byte uint32_t end_byte
) { ) {
for (unsigned i = start_index; i < self->size; i++) { for (unsigned i = start_index; i < self->size; i++) {
TSRange *range = &self->contents[i]; t_range *range = &self->contents[i];
if (range->end_byte > start_byte) { if (range->end_byte > start_byte) {
if (range->start_byte >= end_byte) break; if (range->start_byte >= end_byte) break;
return true; return true;
@ -44,8 +44,8 @@ bool ts_range_array_intersects(
} }
void ts_range_array_get_changed_ranges( void ts_range_array_get_changed_ranges(
const TSRange *old_ranges, unsigned old_range_count, const t_range *old_ranges, unsigned old_range_count,
const TSRange *new_ranges, unsigned new_range_count, const t_range *new_ranges, unsigned new_range_count,
TSRangeArray *differences TSRangeArray *differences
) { ) {
unsigned new_index = 0; unsigned new_index = 0;
@ -55,8 +55,8 @@ void ts_range_array_get_changed_ranges(
bool in_new_range = false; bool in_new_range = false;
while (old_index < old_range_count || new_index < new_range_count) { while (old_index < old_range_count || new_index < new_range_count) {
const TSRange *old_range = &old_ranges[old_index]; const t_range *old_range = &old_ranges[old_index];
const TSRange *new_range = &new_ranges[new_index]; const t_range *new_range = &new_ranges[new_index];
Length next_old_position; Length next_old_position;
if (in_old_range) { if (in_old_range) {
@ -105,7 +105,7 @@ void ts_range_array_get_changed_ranges(
typedef struct { typedef struct {
TreeCursor cursor; TreeCursor cursor;
const TSLanguage *language; const t_language *language;
unsigned visible_depth; unsigned visible_depth;
bool in_padding; bool in_padding;
} Iterator; } Iterator;
@ -113,7 +113,7 @@ typedef struct {
static Iterator iterator_new( static Iterator iterator_new(
TreeCursor *cursor, TreeCursor *cursor,
const Subtree *tree, const Subtree *tree,
const TSLanguage *language const t_language *language
) { ) {
array_clear(&cursor->stack); array_clear(&cursor->stack);
array_push(&cursor->stack, ((TreeCursorEntry) { array_push(&cursor->stack, ((TreeCursorEntry) {
@ -170,7 +170,7 @@ static bool iterator_tree_is_visible(const Iterator *self) {
static void iterator_get_visible_state( static void iterator_get_visible_state(
const Iterator *self, const Iterator *self,
Subtree *tree, Subtree *tree,
TSSymbol *alias_symbol, t_symbol *alias_symbol,
uint32_t *start_byte uint32_t *start_byte
) { ) {
uint32_t i = self->cursor.stack.size - 1; uint32_t i = self->cursor.stack.size - 1;
@ -309,8 +309,8 @@ static IteratorComparison iterator_compare(
Subtree new_tree = NULL_SUBTREE; Subtree new_tree = NULL_SUBTREE;
uint32_t old_start = 0; uint32_t old_start = 0;
uint32_t new_start = 0; uint32_t new_start = 0;
TSSymbol old_alias_symbol = 0; t_symbol old_alias_symbol = 0;
TSSymbol new_alias_symbol = 0; t_symbol new_alias_symbol = 0;
iterator_get_visible_state(old_iter, &old_tree, &old_alias_symbol, &old_start); iterator_get_visible_state(old_iter, &old_tree, &old_alias_symbol, &old_start);
iterator_get_visible_state(new_iter, &new_tree, &new_alias_symbol, &new_start); iterator_get_visible_state(new_iter, &new_tree, &new_alias_symbol, &new_start);
@ -357,9 +357,9 @@ static inline void iterator_print_state(Iterator *self) {
unsigned ts_subtree_get_changed_ranges( unsigned ts_subtree_get_changed_ranges(
const Subtree *old_tree, const Subtree *new_tree, const Subtree *old_tree, const Subtree *new_tree,
TreeCursor *cursor1, TreeCursor *cursor2, TreeCursor *cursor1, TreeCursor *cursor2,
const TSLanguage *language, const t_language *language,
const TSRangeArray *included_range_differences, const TSRangeArray *included_range_differences,
TSRange **ranges t_range **ranges
) { ) {
TSRangeArray results = array_new(); TSRangeArray results = array_new();
@ -475,7 +475,7 @@ unsigned ts_subtree_get_changed_ranges(
// Keep track of the current position in the included range differences // Keep track of the current position in the included range differences
// array in order to avoid scanning the entire array on each iteration. // array in order to avoid scanning the entire array on each iteration.
while (included_range_difference_index < included_range_differences->size) { while (included_range_difference_index < included_range_differences->size) {
const TSRange *range = &included_range_differences->contents[ const t_range *range = &included_range_differences->contents[
included_range_difference_index included_range_difference_index
]; ];
if (range->end_byte <= position.bytes) { if (range->end_byte <= position.bytes) {

View file

@ -8,11 +8,11 @@ extern "C" {
#include "./tree_cursor.h" #include "./tree_cursor.h"
#include "./subtree.h" #include "./subtree.h"
typedef Array(TSRange) TSRangeArray; typedef Array(t_range) TSRangeArray;
void ts_range_array_get_changed_ranges( void ts_range_array_get_changed_ranges(
const TSRange *old_ranges, unsigned old_range_count, const t_range *old_ranges, unsigned old_range_count,
const TSRange *new_ranges, unsigned new_range_count, const t_range *new_ranges, unsigned new_range_count,
TSRangeArray *differences TSRangeArray *differences
); );
@ -24,9 +24,9 @@ bool ts_range_array_intersects(
unsigned ts_subtree_get_changed_ranges( unsigned ts_subtree_get_changed_ranges(
const Subtree *old_tree, const Subtree *new_tree, const Subtree *old_tree, const Subtree *new_tree,
TreeCursor *cursor1, TreeCursor *cursor2, TreeCursor *cursor1, TreeCursor *cursor2,
const TSLanguage *language, const t_language *language,
const TSRangeArray *included_range_differences, const TSRangeArray *included_range_differences,
TSRange **ranges t_range **ranges
); );
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -3,34 +3,34 @@
#include "./api.h" #include "./api.h"
#include <string.h> #include <string.h>
const TSLanguage *ts_language_copy(const TSLanguage *self) { const t_language *ts_language_copy(const t_language *self) {
return self; return self;
} }
void ts_language_delete(const TSLanguage *self) { void ts_language_delete(const t_language *self) {
(void)(self); (void)(self);
} }
uint32_t ts_language_symbol_count(const TSLanguage *self) { uint32_t ts_language_symbol_count(const t_language *self) {
return self->symbol_count + self->alias_count; return self->symbol_count + self->alias_count;
} }
uint32_t ts_language_state_count(const TSLanguage *self) { uint32_t ts_language_state_count(const t_language *self) {
return self->state_count; return self->state_count;
} }
uint32_t ts_language_version(const TSLanguage *self) { uint32_t ts_language_version(const t_language *self) {
return self->version; return self->version;
} }
uint32_t ts_language_field_count(const TSLanguage *self) { uint32_t ts_language_field_count(const t_language *self) {
return self->field_count; return self->field_count;
} }
void ts_language_table_entry( void ts_language_table_entry(
const TSLanguage *self, const t_language *self,
TSStateId state, t_state_id state,
TSSymbol symbol, t_symbol symbol,
TableEntry *result TableEntry *result
) { ) {
if (symbol == ts_builtin_sym_error || symbol == ts_builtin_sym_error_repeat) { if (symbol == ts_builtin_sym_error || symbol == ts_builtin_sym_error_repeat) {
@ -48,8 +48,8 @@ void ts_language_table_entry(
} }
TSSymbolMetadata ts_language_symbol_metadata( TSSymbolMetadata ts_language_symbol_metadata(
const TSLanguage *self, const t_language *self,
TSSymbol symbol t_symbol symbol
) { ) {
if (symbol == ts_builtin_sym_error) { if (symbol == ts_builtin_sym_error) {
return (TSSymbolMetadata) {.visible = true, .named = true}; return (TSSymbolMetadata) {.visible = true, .named = true};
@ -60,18 +60,18 @@ TSSymbolMetadata ts_language_symbol_metadata(
} }
} }
TSSymbol ts_language_public_symbol( t_symbol ts_language_public_symbol(
const TSLanguage *self, const t_language *self,
TSSymbol symbol t_symbol symbol
) { ) {
if (symbol == ts_builtin_sym_error) return symbol; if (symbol == ts_builtin_sym_error) return symbol;
return self->public_symbol_map[symbol]; return self->public_symbol_map[symbol];
} }
TSStateId ts_language_next_state( t_state_id ts_language_next_state(
const TSLanguage *self, const t_language *self,
TSStateId state, t_state_id state,
TSSymbol symbol t_symbol symbol
) { ) {
if (symbol == ts_builtin_sym_error || symbol == ts_builtin_sym_error_repeat) { if (symbol == ts_builtin_sym_error || symbol == ts_builtin_sym_error_repeat) {
return 0; return 0;
@ -91,8 +91,8 @@ TSStateId ts_language_next_state(
} }
const char *ts_language_symbol_name( const char *ts_language_symbol_name(
const TSLanguage *self, const t_language *self,
TSSymbol symbol t_symbol symbol
) { ) {
if (symbol == ts_builtin_sym_error) { if (symbol == ts_builtin_sym_error) {
return "ERROR"; return "ERROR";
@ -105,15 +105,15 @@ const char *ts_language_symbol_name(
} }
} }
TSSymbol ts_language_symbol_for_name( t_symbol ts_language_symbol_for_name(
const TSLanguage *self, const t_language *self,
const char *string, const char *string,
uint32_t length, uint32_t length,
bool is_named bool is_named
) { ) {
if (!strncmp(string, "ERROR", length)) return ts_builtin_sym_error; if (!strncmp(string, "ERROR", length)) return ts_builtin_sym_error;
uint16_t count = (uint16_t)ts_language_symbol_count(self); uint16_t count = (uint16_t)ts_language_symbol_count(self);
for (TSSymbol i = 0; i < count; i++) { for (t_symbol i = 0; i < count; i++) {
TSSymbolMetadata metadata = ts_language_symbol_metadata(self, i); TSSymbolMetadata metadata = ts_language_symbol_metadata(self, i);
if ((!metadata.visible && !metadata.supertype) || metadata.named != is_named) continue; if ((!metadata.visible && !metadata.supertype) || metadata.named != is_named) continue;
const char *symbol_name = self->symbol_names[i]; const char *symbol_name = self->symbol_names[i];
@ -124,9 +124,9 @@ TSSymbol ts_language_symbol_for_name(
return 0; return 0;
} }
TSSymbolType ts_language_symbol_type( t_symbol_type ts_language_symbol_type(
const TSLanguage *self, const t_language *self,
TSSymbol symbol t_symbol symbol
) { ) {
TSSymbolMetadata metadata = ts_language_symbol_metadata(self, symbol); TSSymbolMetadata metadata = ts_language_symbol_metadata(self, symbol);
if (metadata.named && metadata.visible) { if (metadata.named && metadata.visible) {
@ -139,8 +139,8 @@ TSSymbolType ts_language_symbol_type(
} }
const char *ts_language_field_name_for_id( const char *ts_language_field_name_for_id(
const TSLanguage *self, const t_language *self,
TSFieldId id t_field_id id
) { ) {
uint32_t count = ts_language_field_count(self); uint32_t count = ts_language_field_count(self);
if (count && id <= count) { if (count && id <= count) {
@ -150,13 +150,13 @@ const char *ts_language_field_name_for_id(
} }
} }
TSFieldId ts_language_field_id_for_name( t_field_id ts_language_field_id_for_name(
const TSLanguage *self, const t_language *self,
const char *name, const char *name,
uint32_t name_length uint32_t name_length
) { ) {
uint16_t count = (uint16_t)ts_language_field_count(self); uint16_t count = (uint16_t)ts_language_field_count(self);
for (TSSymbol i = 1; i < count + 1; i++) { for (t_symbol i = 1; i < count + 1; i++) {
switch (strncmp(name, self->field_names[i], name_length)) { switch (strncmp(name, self->field_names[i], name_length)) {
case 0: case 0:
if (self->field_names[i][name_length] == 0) return i; if (self->field_names[i][name_length] == 0) return i;
@ -170,47 +170,47 @@ TSFieldId ts_language_field_id_for_name(
return 0; return 0;
} }
TSLookaheadIterator *ts_lookahead_iterator_new(const TSLanguage *self, TSStateId state) { t_lookahead_iterator *ts_lookahead_iterator_new(const t_language *self, t_state_id state) {
if (state >= self->state_count) return NULL; if (state >= self->state_count) return NULL;
LookaheadIterator *iterator = ts_malloc(sizeof(LookaheadIterator)); LookaheadIterator *iterator = ts_malloc(sizeof(LookaheadIterator));
*iterator = ts_language_lookaheads(self, state); *iterator = ts_language_lookaheads(self, state);
return (TSLookaheadIterator *)iterator; return (t_lookahead_iterator *)iterator;
} }
void ts_lookahead_iterator_delete(TSLookaheadIterator *self) { void ts_lookahead_iterator_delete(t_lookahead_iterator *self) {
ts_free(self); ts_free(self);
} }
bool ts_lookahead_iterator_reset_state(TSLookaheadIterator * self, TSStateId state) { bool ts_lookahead_iterator_reset_state(t_lookahead_iterator * self, t_state_id state) {
LookaheadIterator *iterator = (LookaheadIterator *)self; LookaheadIterator *iterator = (LookaheadIterator *)self;
if (state >= iterator->language->state_count) return false; if (state >= iterator->language->state_count) return false;
*iterator = ts_language_lookaheads(iterator->language, state); *iterator = ts_language_lookaheads(iterator->language, state);
return true; return true;
} }
const TSLanguage *ts_lookahead_iterator_language(const TSLookaheadIterator *self) { const t_language *ts_lookahead_iterator_language(const t_lookahead_iterator *self) {
const LookaheadIterator *iterator = (const LookaheadIterator *)self; const LookaheadIterator *iterator = (const LookaheadIterator *)self;
return iterator->language; return iterator->language;
} }
bool ts_lookahead_iterator_reset(TSLookaheadIterator *self, const TSLanguage *language, TSStateId state) { bool ts_lookahead_iterator_reset(t_lookahead_iterator *self, const t_language *language, t_state_id state) {
if (state >= language->state_count) return false; if (state >= language->state_count) return false;
LookaheadIterator *iterator = (LookaheadIterator *)self; LookaheadIterator *iterator = (LookaheadIterator *)self;
*iterator = ts_language_lookaheads(language, state); *iterator = ts_language_lookaheads(language, state);
return true; return true;
} }
bool ts_lookahead_iterator_next(TSLookaheadIterator *self) { bool ts_lookahead_iterator_next(t_lookahead_iterator *self) {
LookaheadIterator *iterator = (LookaheadIterator *)self; LookaheadIterator *iterator = (LookaheadIterator *)self;
return ts_lookahead_iterator__next(iterator); return ts_lookahead_iterator__next(iterator);
} }
TSSymbol ts_lookahead_iterator_current_symbol(const TSLookaheadIterator *self) { t_symbol ts_lookahead_iterator_current_symbol(const t_lookahead_iterator *self) {
const LookaheadIterator *iterator = (const LookaheadIterator *)self; const LookaheadIterator *iterator = (const LookaheadIterator *)self;
return iterator->symbol; return iterator->symbol;
} }
const char *ts_lookahead_iterator_current_symbol_name(const TSLookaheadIterator *self) { const char *ts_lookahead_iterator_current_symbol_name(const t_lookahead_iterator *self) {
const LookaheadIterator *iterator = (const LookaheadIterator *)self; const LookaheadIterator *iterator = (const LookaheadIterator *)self;
return ts_language_symbol_name(iterator->language, iterator->symbol); return ts_language_symbol_name(iterator->language, iterator->symbol);
} }

View file

@ -20,37 +20,37 @@ typedef struct {
} TableEntry; } TableEntry;
typedef struct { typedef struct {
const TSLanguage *language; const t_language *language;
const uint16_t *data; const uint16_t *data;
const uint16_t *group_end; const uint16_t *group_end;
TSStateId state; t_state_id state;
uint16_t table_value; uint16_t table_value;
uint16_t section_index; uint16_t section_index;
uint16_t group_count; uint16_t group_count;
bool is_small_state; bool is_small_state;
const TSParseAction *actions; const TSParseAction *actions;
TSSymbol symbol; t_symbol symbol;
TSStateId next_state; t_state_id next_state;
uint16_t action_count; uint16_t action_count;
} LookaheadIterator; } LookaheadIterator;
void ts_language_table_entry(const TSLanguage *, TSStateId, TSSymbol, TableEntry *); void ts_language_table_entry(const t_language *, t_state_id, t_symbol, TableEntry *);
TSSymbolMetadata ts_language_symbol_metadata(const TSLanguage *, TSSymbol); TSSymbolMetadata ts_language_symbol_metadata(const t_language *, t_symbol);
TSSymbol ts_language_public_symbol(const TSLanguage *, TSSymbol); t_symbol ts_language_public_symbol(const t_language *, t_symbol);
TSStateId ts_language_next_state(const TSLanguage *self, TSStateId state, TSSymbol symbol); t_state_id ts_language_next_state(const t_language *self, t_state_id state, t_symbol symbol);
static inline bool ts_language_is_symbol_external(const TSLanguage *self, TSSymbol symbol) { static inline bool ts_language_is_symbol_external(const t_language *self, t_symbol symbol) {
return 0 < symbol && symbol < self->external_token_count + 1; return 0 < symbol && symbol < self->external_token_count + 1;
} }
static inline const TSParseAction *ts_language_actions( static inline const TSParseAction *ts_language_actions(
const TSLanguage *self, const t_language *self,
TSStateId state, t_state_id state,
TSSymbol symbol, t_symbol symbol,
uint32_t *count uint32_t *count
) { ) {
TableEntry entry; TableEntry entry;
@ -60,9 +60,9 @@ static inline const TSParseAction *ts_language_actions(
} }
static inline bool ts_language_has_reduce_action( static inline bool ts_language_has_reduce_action(
const TSLanguage *self, const t_language *self,
TSStateId state, t_state_id state,
TSSymbol symbol t_symbol symbol
) { ) {
TableEntry entry; TableEntry entry;
ts_language_table_entry(self, state, symbol, &entry); ts_language_table_entry(self, state, symbol, &entry);
@ -77,9 +77,9 @@ static inline bool ts_language_has_reduce_action(
// states, this requires searching through the symbol groups to find // states, this requires searching through the symbol groups to find
// the given symbol. // the given symbol.
static inline uint16_t ts_language_lookup( static inline uint16_t ts_language_lookup(
const TSLanguage *self, const t_language *self,
TSStateId state, t_state_id state,
TSSymbol symbol t_symbol symbol
) { ) {
if (state >= self->large_state_count) { if (state >= self->large_state_count) {
uint32_t index = self->small_parse_table_map[state - self->large_state_count]; uint32_t index = self->small_parse_table_map[state - self->large_state_count];
@ -99,9 +99,9 @@ static inline uint16_t ts_language_lookup(
} }
static inline bool ts_language_has_actions( static inline bool ts_language_has_actions(
const TSLanguage *self, const t_language *self,
TSStateId state, t_state_id state,
TSSymbol symbol t_symbol symbol
) { ) {
return ts_language_lookup(self, state, symbol) != 0; return ts_language_lookup(self, state, symbol) != 0;
} }
@ -113,8 +113,8 @@ static inline bool ts_language_has_actions(
// For 'small' parse states, this exploits the structure of the // For 'small' parse states, this exploits the structure of the
// table to only visit the valid symbols. // table to only visit the valid symbols.
static inline LookaheadIterator ts_language_lookaheads( static inline LookaheadIterator ts_language_lookaheads(
const TSLanguage *self, const t_language *self,
TSStateId state t_state_id state
) { ) {
bool is_small_state = state >= self->large_state_count; bool is_small_state = state >= self->large_state_count;
const uint16_t *data; const uint16_t *data;
@ -186,8 +186,8 @@ static inline bool ts_lookahead_iterator__next(LookaheadIterator *self) {
// Whether the state is a "primary state". If this returns false, it indicates that there exists // Whether the state is a "primary state". If this returns false, it indicates that there exists
// another state that behaves identically to this one with respect to query analysis. // another state that behaves identically to this one with respect to query analysis.
static inline bool ts_language_state_is_primary( static inline bool ts_language_state_is_primary(
const TSLanguage *self, const t_language *self,
TSStateId state t_state_id state
) { ) {
if (self->version >= LANGUAGE_VERSION_WITH_PRIMARY_STATES) { if (self->version >= LANGUAGE_VERSION_WITH_PRIMARY_STATES) {
return state == self->primary_state_ids[state]; return state == self->primary_state_ids[state];
@ -197,7 +197,7 @@ static inline bool ts_language_state_is_primary(
} }
static inline const bool *ts_language_enabled_external_tokens( static inline const bool *ts_language_enabled_external_tokens(
const TSLanguage *self, const t_language *self,
unsigned external_scanner_state unsigned external_scanner_state
) { ) {
if (external_scanner_state == 0) { if (external_scanner_state == 0) {
@ -207,8 +207,8 @@ static inline const bool *ts_language_enabled_external_tokens(
} }
} }
static inline const TSSymbol *ts_language_alias_sequence( static inline const t_symbol *ts_language_alias_sequence(
const TSLanguage *self, const t_language *self,
uint32_t production_id uint32_t production_id
) { ) {
return production_id ? return production_id ?
@ -216,8 +216,8 @@ static inline const TSSymbol *ts_language_alias_sequence(
NULL; NULL;
} }
static inline TSSymbol ts_language_alias_at( static inline t_symbol ts_language_alias_at(
const TSLanguage *self, const t_language *self,
uint32_t production_id, uint32_t production_id,
uint32_t child_index uint32_t child_index
) { ) {
@ -227,7 +227,7 @@ static inline TSSymbol ts_language_alias_at(
} }
static inline void ts_language_field_map( static inline void ts_language_field_map(
const TSLanguage *self, const t_language *self,
uint32_t production_id, uint32_t production_id,
const TSFieldMapEntry **start, const TSFieldMapEntry **start,
const TSFieldMapEntry **end const TSFieldMapEntry **end
@ -244,17 +244,17 @@ static inline void ts_language_field_map(
} }
static inline void ts_language_aliases_for_symbol( static inline void ts_language_aliases_for_symbol(
const TSLanguage *self, const t_language *self,
TSSymbol original_symbol, t_symbol original_symbol,
const TSSymbol **start, const t_symbol **start,
const TSSymbol **end const t_symbol **end
) { ) {
*start = &self->public_symbol_map[original_symbol]; *start = &self->public_symbol_map[original_symbol];
*end = *start + 1; *end = *start + 1;
unsigned idx = 0; unsigned idx = 0;
for (;;) { for (;;) {
TSSymbol symbol = self->alias_map[idx++]; t_symbol symbol = self->alias_map[idx++];
if (symbol == 0 || symbol > original_symbol) break; if (symbol == 0 || symbol > original_symbol) break;
uint16_t count = self->alias_map[idx++]; uint16_t count = self->alias_map[idx++];
if (symbol == original_symbol) { if (symbol == original_symbol) {
@ -267,9 +267,9 @@ static inline void ts_language_aliases_for_symbol(
} }
static inline void ts_language_write_symbol_as_dot_string( static inline void ts_language_write_symbol_as_dot_string(
const TSLanguage *self, const t_language *self,
FILE *f, FILE *f,
TSSymbol symbol t_symbol symbol
) { ) {
const char *name = ts_language_symbol_name(self, symbol); const char *name = ts_language_symbol_name(self, symbol);
for (const char *chr = name; *chr; chr++) { for (const char *chr = name; *chr; chr++) {

View file

@ -8,7 +8,7 @@
typedef struct { typedef struct {
uint32_t bytes; uint32_t bytes;
TSPoint extent; t_point extent;
} Length; } Length;
static const Length LENGTH_UNDEFINED = {0, {0, 1}}; static const Length LENGTH_UNDEFINED = {0, {0, 1}};

View file

@ -23,7 +23,7 @@
static const int32_t BYTE_ORDER_MARK = 0xFEFF; static const int32_t BYTE_ORDER_MARK = 0xFEFF;
static const TSRange DEFAULT_RANGE = { static const t_range DEFAULT_RANGE = {
.start_point = { .start_point = {
.row = 0, .row = 0,
.column = 0, .column = 0,
@ -127,7 +127,7 @@ static void ts_lexer_goto(Lexer *self, Length position) {
// Move to the first valid position at or after the given position. // Move to the first valid position at or after the given position.
bool found_included_range = false; bool found_included_range = false;
for (unsigned i = 0; i < self->included_range_count; i++) { for (unsigned i = 0; i < self->included_range_count; i++) {
TSRange *included_range = &self->included_ranges[i]; t_range *included_range = &self->included_ranges[i];
if ( if (
included_range->end_byte > self->current_position.bytes && included_range->end_byte > self->current_position.bytes &&
included_range->end_byte > included_range->start_byte included_range->end_byte > included_range->start_byte
@ -163,7 +163,7 @@ static void ts_lexer_goto(Lexer *self, Length position) {
// state - past the end of the included ranges. // state - past the end of the included ranges.
else { else {
self->current_included_range_index = self->included_range_count; self->current_included_range_index = self->included_range_count;
TSRange *last_included_range = &self->included_ranges[self->included_range_count - 1]; t_range *last_included_range = &self->included_ranges[self->included_range_count - 1];
self->current_position = (Length) { self->current_position = (Length) {
.bytes = last_included_range->end_byte, .bytes = last_included_range->end_byte,
.extent = last_included_range->end_point, .extent = last_included_range->end_point,
@ -186,7 +186,7 @@ static void ts_lexer__do_advance(Lexer *self, bool skip) {
} }
} }
const TSRange *current_range = &self->included_ranges[self->current_included_range_index]; const t_range *current_range = &self->included_ranges[self->current_included_range_index];
while ( while (
self->current_position.bytes >= current_range->end_byte || self->current_position.bytes >= current_range->end_byte ||
current_range->end_byte == current_range->start_byte current_range->end_byte == current_range->start_byte
@ -246,14 +246,14 @@ static void ts_lexer__mark_end(TSLexer *_self) {
// If the lexer is right at the beginning of included range, // If the lexer is right at the beginning of included range,
// then the token should be considered to end at the *end* of the // then the token should be considered to end at the *end* of the
// previous included range, rather than here. // previous included range, rather than here.
TSRange *current_included_range = &self->included_ranges[ t_range *current_included_range = &self->included_ranges[
self->current_included_range_index self->current_included_range_index
]; ];
if ( if (
self->current_included_range_index > 0 && self->current_included_range_index > 0 &&
self->current_position.bytes == current_included_range->start_byte self->current_position.bytes == current_included_range->start_byte
) { ) {
TSRange *previous_included_range = current_included_range - 1; t_range *previous_included_range = current_included_range - 1;
self->token_end_position = (Length) { self->token_end_position = (Length) {
previous_included_range->end_byte, previous_included_range->end_byte,
previous_included_range->end_point, previous_included_range->end_point,
@ -296,7 +296,7 @@ static uint32_t ts_lexer__get_column(TSLexer *_self) {
static bool ts_lexer__is_at_included_range_start(const TSLexer *_self) { static bool ts_lexer__is_at_included_range_start(const TSLexer *_self) {
const Lexer *self = (const Lexer *)_self; const Lexer *self = (const Lexer *)_self;
if (self->current_included_range_index < self->included_range_count) { if (self->current_included_range_index < self->included_range_count) {
TSRange *current_range = &self->included_ranges[self->current_included_range_index]; t_range *current_range = &self->included_ranges[self->current_included_range_index];
return self->current_position.bytes == current_range->start_byte; return self->current_position.bytes == current_range->start_byte;
} else { } else {
return false; return false;
@ -336,7 +336,7 @@ void ts_lexer_delete(Lexer *self) {
ts_free(self->included_ranges); ts_free(self->included_ranges);
} }
void ts_lexer_set_input(Lexer *self, TSInput input) { void ts_lexer_set_input(Lexer *self, t_input input) {
self->input = input; self->input = input;
ts_lexer__clear_chunk(self); ts_lexer__clear_chunk(self);
ts_lexer_goto(self, self->current_position); ts_lexer_goto(self, self->current_position);
@ -404,7 +404,7 @@ void ts_lexer_mark_end(Lexer *self) {
bool ts_lexer_set_included_ranges( bool ts_lexer_set_included_ranges(
Lexer *self, Lexer *self,
const TSRange *ranges, const t_range *ranges,
uint32_t count uint32_t count
) { ) {
if (count == 0 || !ranges) { if (count == 0 || !ranges) {
@ -413,7 +413,7 @@ bool ts_lexer_set_included_ranges(
} else { } else {
uint32_t previous_byte = 0; uint32_t previous_byte = 0;
for (unsigned i = 0; i < count; i++) { for (unsigned i = 0; i < count; i++) {
const TSRange *range = &ranges[i]; const t_range *range = &ranges[i];
if ( if (
range->start_byte < previous_byte || range->start_byte < previous_byte ||
range->end_byte < range->start_byte range->end_byte < range->start_byte
@ -422,7 +422,7 @@ bool ts_lexer_set_included_ranges(
} }
} }
size_t size = count * sizeof(TSRange); size_t size = count * sizeof(t_range);
self->included_ranges = ts_realloc(self->included_ranges, size); self->included_ranges = ts_realloc(self->included_ranges, size);
memcpy(self->included_ranges, ranges, size); memcpy(self->included_ranges, ranges, size);
self->included_range_count = count; self->included_range_count = count;
@ -430,7 +430,7 @@ bool ts_lexer_set_included_ranges(
return true; return true;
} }
TSRange *ts_lexer_included_ranges(const Lexer *self, uint32_t *count) { t_range *ts_lexer_included_ranges(const Lexer *self, uint32_t *count) {
*count = self->included_range_count; *count = self->included_range_count;
return self->included_ranges; return self->included_ranges;
} }

View file

@ -16,10 +16,10 @@ typedef struct {
Length token_start_position; Length token_start_position;
Length token_end_position; Length token_end_position;
TSRange *included_ranges; t_range *included_ranges;
const char *chunk; const char *chunk;
TSInput input; t_input input;
TSLogger logger; t_logger logger;
uint32_t included_range_count; uint32_t included_range_count;
uint32_t current_included_range_index; uint32_t current_included_range_index;
@ -33,14 +33,14 @@ typedef struct {
void ts_lexer_init(Lexer *); void ts_lexer_init(Lexer *);
void ts_lexer_delete(Lexer *); void ts_lexer_delete(Lexer *);
void ts_lexer_set_input(Lexer *, TSInput); void ts_lexer_set_input(Lexer *, t_input);
void ts_lexer_reset(Lexer *, Length); void ts_lexer_reset(Lexer *, Length);
void ts_lexer_start(Lexer *); void ts_lexer_start(Lexer *);
void ts_lexer_finish(Lexer *, uint32_t *); void ts_lexer_finish(Lexer *, uint32_t *);
void ts_lexer_advance_to_end(Lexer *); void ts_lexer_advance_to_end(Lexer *);
void ts_lexer_mark_end(Lexer *); void ts_lexer_mark_end(Lexer *);
bool ts_lexer_set_included_ranges(Lexer *self, const TSRange *ranges, uint32_t count); bool ts_lexer_set_included_ranges(Lexer *self, const t_range *ranges, uint32_t count);
TSRange *ts_lexer_included_ranges(const Lexer *self, uint32_t *count); t_range *ts_lexer_included_ranges(const Lexer *self, uint32_t *count);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -5,58 +5,58 @@
typedef struct { typedef struct {
Subtree parent; Subtree parent;
const TSTree *tree; const t_tree *tree;
Length position; Length position;
uint32_t child_index; uint32_t child_index;
uint32_t structural_child_index; uint32_t structural_child_index;
const TSSymbol *alias_sequence; const t_symbol *alias_sequence;
} NodeChildIterator; } NodeChildIterator;
// TSNode - constructors // TSNode - constructors
TSNode ts_node_new( t_parse_node ts_node_new(
const TSTree *tree, const t_tree *tree,
const Subtree *subtree, const Subtree *subtree,
Length position, Length position,
TSSymbol alias t_symbol alias
) { ) {
return (TSNode) { return (t_parse_node) {
{position.bytes, position.extent.row, position.extent.column, alias}, {position.bytes, position.extent.row, position.extent.column, alias},
subtree, subtree,
tree, tree,
}; };
} }
static inline TSNode ts_node__null(void) { static inline t_parse_node ts_node__null(void) {
return ts_node_new(NULL, NULL, length_zero(), 0); return ts_node_new(NULL, NULL, length_zero(), 0);
} }
// TSNode - accessors // TSNode - accessors
uint32_t ts_node_start_byte(TSNode self) { uint32_t ts_node_start_byte(t_parse_node self) {
return self.context[0]; return self.context[0];
} }
TSPoint ts_node_start_point(TSNode self) { t_point ts_node_start_point(t_parse_node self) {
return (TSPoint) {self.context[1], self.context[2]}; return (t_point) {self.context[1], self.context[2]};
} }
static inline uint32_t ts_node__alias(const TSNode *self) { static inline uint32_t ts_node__alias(const t_parse_node *self) {
return self->context[3]; return self->context[3];
} }
static inline Subtree ts_node__subtree(TSNode self) { static inline Subtree ts_node__subtree(t_parse_node self) {
return *(const Subtree *)self.id; return *(const Subtree *)self.id;
} }
// NodeChildIterator // NodeChildIterator
static inline NodeChildIterator ts_node_iterate_children(const TSNode *node) { static inline NodeChildIterator ts_node_iterate_children(const t_parse_node *node) {
Subtree subtree = ts_node__subtree(*node); Subtree subtree = ts_node__subtree(*node);
if (ts_subtree_child_count(subtree) == 0) { if (ts_subtree_child_count(subtree) == 0) {
return (NodeChildIterator) {NULL_SUBTREE, node->tree, length_zero(), 0, 0, NULL}; return (NodeChildIterator) {NULL_SUBTREE, node->tree, length_zero(), 0, 0, NULL};
} }
const TSSymbol *alias_sequence = ts_language_alias_sequence( const t_symbol *alias_sequence = ts_language_alias_sequence(
node->tree->language, node->tree->language,
subtree.ptr->production_id subtree.ptr->production_id
); );
@ -76,11 +76,11 @@ static inline bool ts_node_child_iterator_done(NodeChildIterator *self) {
static inline bool ts_node_child_iterator_next( static inline bool ts_node_child_iterator_next(
NodeChildIterator *self, NodeChildIterator *self,
TSNode *result t_parse_node *result
) { ) {
if (!self->parent.ptr || ts_node_child_iterator_done(self)) return false; if (!self->parent.ptr || ts_node_child_iterator_done(self)) return false;
const Subtree *child = &ts_subtree_children(self->parent)[self->child_index]; const Subtree *child = &ts_subtree_children(self->parent)[self->child_index];
TSSymbol alias_symbol = 0; t_symbol alias_symbol = 0;
if (!ts_subtree_extra(*child)) { if (!ts_subtree_extra(*child)) {
if (self->alias_sequence) { if (self->alias_sequence) {
alias_symbol = self->alias_sequence[self->structural_child_index]; alias_symbol = self->alias_sequence[self->structural_child_index];
@ -103,12 +103,12 @@ static inline bool ts_node_child_iterator_next(
// TSNode - private // TSNode - private
static inline bool ts_node__is_relevant(TSNode self, bool include_anonymous) { static inline bool ts_node__is_relevant(t_parse_node self, bool include_anonymous) {
Subtree tree = ts_node__subtree(self); Subtree tree = ts_node__subtree(self);
if (include_anonymous) { if (include_anonymous) {
return ts_subtree_visible(tree) || ts_node__alias(&self); return ts_subtree_visible(tree) || ts_node__alias(&self);
} else { } else {
TSSymbol alias = ts_node__alias(&self); t_symbol alias = ts_node__alias(&self);
if (alias) { if (alias) {
return ts_language_symbol_metadata(self.tree->language, alias).named; return ts_language_symbol_metadata(self.tree->language, alias).named;
} else { } else {
@ -118,7 +118,7 @@ static inline bool ts_node__is_relevant(TSNode self, bool include_anonymous) {
} }
static inline uint32_t ts_node__relevant_child_count( static inline uint32_t ts_node__relevant_child_count(
TSNode self, t_parse_node self,
bool include_anonymous bool include_anonymous
) { ) {
Subtree tree = ts_node__subtree(self); Subtree tree = ts_node__subtree(self);
@ -133,18 +133,18 @@ static inline uint32_t ts_node__relevant_child_count(
} }
} }
static inline TSNode ts_node__child( static inline t_parse_node ts_node__child(
TSNode self, t_parse_node self,
uint32_t child_index, uint32_t child_index,
bool include_anonymous bool include_anonymous
) { ) {
TSNode result = self; t_parse_node result = self;
bool did_descend = true; bool did_descend = true;
while (did_descend) { while (did_descend) {
did_descend = false; did_descend = false;
TSNode child; t_parse_node child;
uint32_t index = 0; uint32_t index = 0;
NodeChildIterator iterator = ts_node_iterate_children(&result); NodeChildIterator iterator = ts_node_iterate_children(&result);
while (ts_node_child_iterator_next(&iterator, &child)) { while (ts_node_child_iterator_next(&iterator, &child)) {
@ -184,21 +184,21 @@ static bool ts_subtree_has_trailing_empty_descendant(
return false; return false;
} }
static inline TSNode ts_node__prev_sibling(TSNode self, bool include_anonymous) { static inline t_parse_node ts_node__prev_sibling(t_parse_node self, bool include_anonymous) {
Subtree self_subtree = ts_node__subtree(self); Subtree self_subtree = ts_node__subtree(self);
bool self_is_empty = ts_subtree_total_bytes(self_subtree) == 0; bool self_is_empty = ts_subtree_total_bytes(self_subtree) == 0;
uint32_t target_end_byte = ts_node_end_byte(self); uint32_t target_end_byte = ts_node_end_byte(self);
TSNode node = ts_node_parent(self); t_parse_node node = ts_node_parent(self);
TSNode earlier_node = ts_node__null(); t_parse_node earlier_node = ts_node__null();
bool earlier_node_is_relevant = false; bool earlier_node_is_relevant = false;
while (!ts_node_is_null(node)) { while (!ts_node_is_null(node)) {
TSNode earlier_child = ts_node__null(); t_parse_node earlier_child = ts_node__null();
bool earlier_child_is_relevant = false; bool earlier_child_is_relevant = false;
bool found_child_containing_target = false; bool found_child_containing_target = false;
TSNode child; t_parse_node child;
NodeChildIterator iterator = ts_node_iterate_children(&node); NodeChildIterator iterator = ts_node_iterate_children(&node);
while (ts_node_child_iterator_next(&iterator, &child)) { while (ts_node_child_iterator_next(&iterator, &child)) {
if (child.id == self.id) break; if (child.id == self.id) break;
@ -245,19 +245,19 @@ static inline TSNode ts_node__prev_sibling(TSNode self, bool include_anonymous)
return ts_node__null(); return ts_node__null();
} }
static inline TSNode ts_node__next_sibling(TSNode self, bool include_anonymous) { static inline t_parse_node ts_node__next_sibling(t_parse_node self, bool include_anonymous) {
uint32_t target_end_byte = ts_node_end_byte(self); uint32_t target_end_byte = ts_node_end_byte(self);
TSNode node = ts_node_parent(self); t_parse_node node = ts_node_parent(self);
TSNode later_node = ts_node__null(); t_parse_node later_node = ts_node__null();
bool later_node_is_relevant = false; bool later_node_is_relevant = false;
while (!ts_node_is_null(node)) { while (!ts_node_is_null(node)) {
TSNode later_child = ts_node__null(); t_parse_node later_child = ts_node__null();
bool later_child_is_relevant = false; bool later_child_is_relevant = false;
TSNode child_containing_target = ts_node__null(); t_parse_node child_containing_target = ts_node__null();
TSNode child; t_parse_node child;
NodeChildIterator iterator = ts_node_iterate_children(&node); NodeChildIterator iterator = ts_node_iterate_children(&node);
while (ts_node_child_iterator_next(&iterator, &child)) { while (ts_node_child_iterator_next(&iterator, &child)) {
if (iterator.position.bytes < target_end_byte) continue; if (iterator.position.bytes < target_end_byte) continue;
@ -296,18 +296,18 @@ static inline TSNode ts_node__next_sibling(TSNode self, bool include_anonymous)
return ts_node__null(); return ts_node__null();
} }
static inline TSNode ts_node__first_child_for_byte( static inline t_parse_node ts_node__first_child_for_byte(
TSNode self, t_parse_node self,
uint32_t goal, uint32_t goal,
bool include_anonymous bool include_anonymous
) { ) {
TSNode node = self; t_parse_node node = self;
bool did_descend = true; bool did_descend = true;
while (did_descend) { while (did_descend) {
did_descend = false; did_descend = false;
TSNode child; t_parse_node child;
NodeChildIterator iterator = ts_node_iterate_children(&node); NodeChildIterator iterator = ts_node_iterate_children(&node);
while (ts_node_child_iterator_next(&iterator, &child)) { while (ts_node_child_iterator_next(&iterator, &child)) {
if (ts_node_end_byte(child) > goal) { if (ts_node_end_byte(child) > goal) {
@ -325,20 +325,20 @@ static inline TSNode ts_node__first_child_for_byte(
return ts_node__null(); return ts_node__null();
} }
static inline TSNode ts_node__descendant_for_byte_range( static inline t_parse_node ts_node__descendant_for_byte_range(
TSNode self, t_parse_node self,
uint32_t range_start, uint32_t range_start,
uint32_t range_end, uint32_t range_end,
bool include_anonymous bool include_anonymous
) { ) {
TSNode node = self; t_parse_node node = self;
TSNode last_visible_node = self; t_parse_node last_visible_node = self;
bool did_descend = true; bool did_descend = true;
while (did_descend) { while (did_descend) {
did_descend = false; did_descend = false;
TSNode child; t_parse_node child;
NodeChildIterator iterator = ts_node_iterate_children(&node); NodeChildIterator iterator = ts_node_iterate_children(&node);
while (ts_node_child_iterator_next(&iterator, &child)) { while (ts_node_child_iterator_next(&iterator, &child)) {
uint32_t node_end = iterator.position.bytes; uint32_t node_end = iterator.position.bytes;
@ -364,23 +364,23 @@ static inline TSNode ts_node__descendant_for_byte_range(
return last_visible_node; return last_visible_node;
} }
static inline TSNode ts_node__descendant_for_point_range( static inline t_parse_node ts_node__descendant_for_point_range(
TSNode self, t_parse_node self,
TSPoint range_start, t_point range_start,
TSPoint range_end, t_point range_end,
bool include_anonymous bool include_anonymous
) { ) {
TSNode node = self; t_parse_node node = self;
TSNode last_visible_node = self; t_parse_node last_visible_node = self;
bool did_descend = true; bool did_descend = true;
while (did_descend) { while (did_descend) {
did_descend = false; did_descend = false;
TSNode child; t_parse_node child;
NodeChildIterator iterator = ts_node_iterate_children(&node); NodeChildIterator iterator = ts_node_iterate_children(&node);
while (ts_node_child_iterator_next(&iterator, &child)) { while (ts_node_child_iterator_next(&iterator, &child)) {
TSPoint node_end = iterator.position.extent; t_point node_end = iterator.position.extent;
// The end of this node must extend far enough forward to touch // The end of this node must extend far enough forward to touch
// the end of the range and exceed the start of the range. // the end of the range and exceed the start of the range.
@ -405,41 +405,41 @@ static inline TSNode ts_node__descendant_for_point_range(
// TSNode - public // TSNode - public
uint32_t ts_node_end_byte(TSNode self) { uint32_t ts_node_end_byte(t_parse_node self) {
return ts_node_start_byte(self) + ts_subtree_size(ts_node__subtree(self)).bytes; return ts_node_start_byte(self) + ts_subtree_size(ts_node__subtree(self)).bytes;
} }
TSPoint ts_node_end_point(TSNode self) { t_point ts_node_end_point(t_parse_node self) {
return point_add(ts_node_start_point(self), ts_subtree_size(ts_node__subtree(self)).extent); return point_add(ts_node_start_point(self), ts_subtree_size(ts_node__subtree(self)).extent);
} }
TSSymbol ts_node_symbol(TSNode self) { t_symbol ts_node_symbol(t_parse_node self) {
TSSymbol symbol = ts_node__alias(&self); t_symbol symbol = ts_node__alias(&self);
if (!symbol) symbol = ts_subtree_symbol(ts_node__subtree(self)); if (!symbol) symbol = ts_subtree_symbol(ts_node__subtree(self));
return ts_language_public_symbol(self.tree->language, symbol); return ts_language_public_symbol(self.tree->language, symbol);
} }
const char *ts_node_type(TSNode self) { const char *ts_node_type(t_parse_node self) {
TSSymbol symbol = ts_node__alias(&self); t_symbol symbol = ts_node__alias(&self);
if (!symbol) symbol = ts_subtree_symbol(ts_node__subtree(self)); if (!symbol) symbol = ts_subtree_symbol(ts_node__subtree(self));
return ts_language_symbol_name(self.tree->language, symbol); return ts_language_symbol_name(self.tree->language, symbol);
} }
const TSLanguage *ts_node_language(TSNode self) { const t_language *ts_node_language(t_parse_node self) {
return self.tree->language; return self.tree->language;
} }
TSSymbol ts_node_grammar_symbol(TSNode self) { t_symbol ts_node_grammar_symbol(t_parse_node self) {
return ts_subtree_symbol(ts_node__subtree(self)); return ts_subtree_symbol(ts_node__subtree(self));
} }
const char *ts_node_grammar_type(TSNode self) { const char *ts_node_grammar_type(t_parse_node self) {
TSSymbol symbol = ts_subtree_symbol(ts_node__subtree(self)); t_symbol symbol = ts_subtree_symbol(ts_node__subtree(self));
return ts_language_symbol_name(self.tree->language, symbol); return ts_language_symbol_name(self.tree->language, symbol);
} }
char *ts_node_string(TSNode self) { char *ts_node_string(t_parse_node self) {
TSSymbol alias_symbol = ts_node__alias(&self); t_symbol alias_symbol = ts_node__alias(&self);
return ts_subtree_string( return ts_subtree_string(
ts_node__subtree(self), ts_node__subtree(self),
alias_symbol, alias_symbol,
@ -449,52 +449,52 @@ char *ts_node_string(TSNode self) {
); );
} }
bool ts_node_eq(TSNode self, TSNode other) { bool ts_node_eq(t_parse_node self, t_parse_node other) {
return self.tree == other.tree && self.id == other.id; return self.tree == other.tree && self.id == other.id;
} }
bool ts_node_is_null(TSNode self) { bool ts_node_is_null(t_parse_node self) {
return self.id == 0; return self.id == 0;
} }
bool ts_node_is_extra(TSNode self) { bool ts_node_is_extra(t_parse_node self) {
return ts_subtree_extra(ts_node__subtree(self)); return ts_subtree_extra(ts_node__subtree(self));
} }
bool ts_node_is_named(TSNode self) { bool ts_node_is_named(t_parse_node self) {
TSSymbol alias = ts_node__alias(&self); t_symbol alias = ts_node__alias(&self);
return alias return alias
? ts_language_symbol_metadata(self.tree->language, alias).named ? ts_language_symbol_metadata(self.tree->language, alias).named
: ts_subtree_named(ts_node__subtree(self)); : ts_subtree_named(ts_node__subtree(self));
} }
bool ts_node_is_missing(TSNode self) { bool ts_node_is_missing(t_parse_node self) {
return ts_subtree_missing(ts_node__subtree(self)); return ts_subtree_missing(ts_node__subtree(self));
} }
bool ts_node_has_changes(TSNode self) { bool ts_node_has_changes(t_parse_node self) {
return ts_subtree_has_changes(ts_node__subtree(self)); return ts_subtree_has_changes(ts_node__subtree(self));
} }
bool ts_node_has_error(TSNode self) { bool ts_node_has_error(t_parse_node self) {
return ts_subtree_error_cost(ts_node__subtree(self)) > 0; return ts_subtree_error_cost(ts_node__subtree(self)) > 0;
} }
bool ts_node_is_error(TSNode self) { bool ts_node_is_error(t_parse_node self) {
TSSymbol symbol = ts_node_symbol(self); t_symbol symbol = ts_node_symbol(self);
return symbol == ts_builtin_sym_error; return symbol == ts_builtin_sym_error;
} }
uint32_t ts_node_descendant_count(TSNode self) { uint32_t ts_node_descendant_count(t_parse_node self) {
return ts_subtree_visible_descendant_count(ts_node__subtree(self)) + 1; return ts_subtree_visible_descendant_count(ts_node__subtree(self)) + 1;
} }
TSStateId ts_node_parse_state(TSNode self) { t_state_id ts_node_parse_state(t_parse_node self) {
return ts_subtree_parse_state(ts_node__subtree(self)); return ts_subtree_parse_state(ts_node__subtree(self));
} }
TSStateId ts_node_next_parse_state(TSNode self) { t_state_id ts_node_next_parse_state(t_parse_node self) {
const TSLanguage *language = self.tree->language; const t_language *language = self.tree->language;
uint16_t state = ts_node_parse_state(self); uint16_t state = ts_node_parse_state(self);
if (state == TS_TREE_STATE_NONE) { if (state == TS_TREE_STATE_NONE) {
return TS_TREE_STATE_NONE; return TS_TREE_STATE_NONE;
@ -503,12 +503,12 @@ TSStateId ts_node_next_parse_state(TSNode self) {
return ts_language_next_state(language, state, symbol); return ts_language_next_state(language, state, symbol);
} }
TSNode ts_node_parent(TSNode self) { t_parse_node ts_node_parent(t_parse_node self) {
TSNode node = ts_tree_root_node(self.tree); t_parse_node node = ts_tree_root_node(self.tree);
if (node.id == self.id) return ts_node__null(); if (node.id == self.id) return ts_node__null();
while (true) { while (true) {
TSNode next_node = ts_node_child_containing_descendant(node, self); t_parse_node next_node = ts_node_child_containing_descendant(node, self);
if (ts_node_is_null(next_node)) break; if (ts_node_is_null(next_node)) break;
node = next_node; node = next_node;
} }
@ -516,7 +516,7 @@ TSNode ts_node_parent(TSNode self) {
return node; return node;
} }
TSNode ts_node_child_containing_descendant(TSNode self, TSNode subnode) { t_parse_node ts_node_child_containing_descendant(t_parse_node self, t_parse_node subnode) {
uint32_t start_byte = ts_node_start_byte(subnode); uint32_t start_byte = ts_node_start_byte(subnode);
uint32_t end_byte = ts_node_end_byte(subnode); uint32_t end_byte = ts_node_end_byte(subnode);
@ -536,15 +536,15 @@ TSNode ts_node_child_containing_descendant(TSNode self, TSNode subnode) {
return self; return self;
} }
TSNode ts_node_child(TSNode self, uint32_t child_index) { t_parse_node ts_node_child(t_parse_node self, uint32_t child_index) {
return ts_node__child(self, child_index, true); return ts_node__child(self, child_index, true);
} }
TSNode ts_node_named_child(TSNode self, uint32_t child_index) { t_parse_node ts_node_named_child(t_parse_node self, uint32_t child_index) {
return ts_node__child(self, child_index, false); return ts_node__child(self, child_index, false);
} }
TSNode ts_node_child_by_field_id(TSNode self, TSFieldId field_id) { t_parse_node ts_node_child_by_field_id(t_parse_node self, t_field_id field_id) {
recur: recur:
if (!field_id || ts_node_child_count(self) == 0) return ts_node__null(); if (!field_id || ts_node_child_count(self) == 0) return ts_node__null();
@ -568,7 +568,7 @@ recur:
if (field_map == field_map_end) return ts_node__null(); if (field_map == field_map_end) return ts_node__null();
} }
TSNode child; t_parse_node child;
NodeChildIterator iterator = ts_node_iterate_children(&self); NodeChildIterator iterator = ts_node_iterate_children(&self);
while (ts_node_child_iterator_next(&iterator, &child)) { while (ts_node_child_iterator_next(&iterator, &child)) {
if (!ts_subtree_extra(ts_node__subtree(child))) { if (!ts_subtree_extra(ts_node__subtree(child))) {
@ -588,7 +588,7 @@ recur:
// Otherwise, descend into this child, but if it doesn't contain // Otherwise, descend into this child, but if it doesn't contain
// the field, continue searching subsequent children. // the field, continue searching subsequent children.
else { else {
TSNode result = ts_node_child_by_field_id(child, field_id); t_parse_node result = ts_node_child_by_field_id(child, field_id);
if (result.id) return result; if (result.id) return result;
field_map++; field_map++;
if (field_map == field_map_end) return ts_node__null(); if (field_map == field_map_end) return ts_node__null();
@ -616,7 +616,7 @@ recur:
return ts_node__null(); return ts_node__null();
} }
static inline const char *ts_node__field_name_from_language(TSNode self, uint32_t structural_child_index) { static inline const char *ts_node__field_name_from_language(t_parse_node self, uint32_t structural_child_index) {
const TSFieldMapEntry *field_map, *field_map_end; const TSFieldMapEntry *field_map, *field_map_end;
ts_language_field_map( ts_language_field_map(
self.tree->language, self.tree->language,
@ -632,15 +632,15 @@ static inline const char *ts_node__field_name_from_language(TSNode self, uint32_
return NULL; return NULL;
} }
const char *ts_node_field_name_for_child(TSNode self, uint32_t child_index) { const char *ts_node_field_name_for_child(t_parse_node self, uint32_t child_index) {
TSNode result = self; t_parse_node result = self;
bool did_descend = true; bool did_descend = true;
const char *inherited_field_name = NULL; const char *inherited_field_name = NULL;
while (did_descend) { while (did_descend) {
did_descend = false; did_descend = false;
TSNode child; t_parse_node child;
uint32_t index = 0; uint32_t index = 0;
NodeChildIterator iterator = ts_node_iterate_children(&result); NodeChildIterator iterator = ts_node_iterate_children(&result);
while (ts_node_child_iterator_next(&iterator, &child)) { while (ts_node_child_iterator_next(&iterator, &child)) {
@ -671,12 +671,12 @@ const char *ts_node_field_name_for_child(TSNode self, uint32_t child_index) {
return NULL; return NULL;
} }
TSNode ts_node_child_by_field_name( t_parse_node ts_node_child_by_field_name(
TSNode self, t_parse_node self,
const char *name, const char *name,
uint32_t name_length uint32_t name_length
) { ) {
TSFieldId field_id = ts_language_field_id_for_name( t_field_id field_id = ts_language_field_id_for_name(
self.tree->language, self.tree->language,
name, name,
name_length name_length
@ -684,7 +684,7 @@ TSNode ts_node_child_by_field_name(
return ts_node_child_by_field_id(self, field_id); return ts_node_child_by_field_id(self, field_id);
} }
uint32_t ts_node_child_count(TSNode self) { uint32_t ts_node_child_count(t_parse_node self) {
Subtree tree = ts_node__subtree(self); Subtree tree = ts_node__subtree(self);
if (ts_subtree_child_count(tree) > 0) { if (ts_subtree_child_count(tree) > 0) {
return tree.ptr->visible_child_count; return tree.ptr->visible_child_count;
@ -693,7 +693,7 @@ uint32_t ts_node_child_count(TSNode self) {
} }
} }
uint32_t ts_node_named_child_count(TSNode self) { uint32_t ts_node_named_child_count(t_parse_node self) {
Subtree tree = ts_node__subtree(self); Subtree tree = ts_node__subtree(self);
if (ts_subtree_child_count(tree) > 0) { if (ts_subtree_child_count(tree) > 0) {
return tree.ptr->named_child_count; return tree.ptr->named_child_count;
@ -702,65 +702,65 @@ uint32_t ts_node_named_child_count(TSNode self) {
} }
} }
TSNode ts_node_next_sibling(TSNode self) { t_parse_node ts_node_next_sibling(t_parse_node self) {
return ts_node__next_sibling(self, true); return ts_node__next_sibling(self, true);
} }
TSNode ts_node_next_named_sibling(TSNode self) { t_parse_node ts_node_next_named_sibling(t_parse_node self) {
return ts_node__next_sibling(self, false); return ts_node__next_sibling(self, false);
} }
TSNode ts_node_prev_sibling(TSNode self) { t_parse_node ts_node_prev_sibling(t_parse_node self) {
return ts_node__prev_sibling(self, true); return ts_node__prev_sibling(self, true);
} }
TSNode ts_node_prev_named_sibling(TSNode self) { t_parse_node ts_node_prev_named_sibling(t_parse_node self) {
return ts_node__prev_sibling(self, false); return ts_node__prev_sibling(self, false);
} }
TSNode ts_node_first_child_for_byte(TSNode self, uint32_t byte) { t_parse_node ts_node_first_child_for_byte(t_parse_node self, uint32_t byte) {
return ts_node__first_child_for_byte(self, byte, true); return ts_node__first_child_for_byte(self, byte, true);
} }
TSNode ts_node_first_named_child_for_byte(TSNode self, uint32_t byte) { t_parse_node ts_node_first_named_child_for_byte(t_parse_node self, uint32_t byte) {
return ts_node__first_child_for_byte(self, byte, false); return ts_node__first_child_for_byte(self, byte, false);
} }
TSNode ts_node_descendant_for_byte_range( t_parse_node ts_node_descendant_for_byte_range(
TSNode self, t_parse_node self,
uint32_t start, uint32_t start,
uint32_t end uint32_t end
) { ) {
return ts_node__descendant_for_byte_range(self, start, end, true); return ts_node__descendant_for_byte_range(self, start, end, true);
} }
TSNode ts_node_named_descendant_for_byte_range( t_parse_node ts_node_named_descendant_for_byte_range(
TSNode self, t_parse_node self,
uint32_t start, uint32_t start,
uint32_t end uint32_t end
) { ) {
return ts_node__descendant_for_byte_range(self, start, end, false); return ts_node__descendant_for_byte_range(self, start, end, false);
} }
TSNode ts_node_descendant_for_point_range( t_parse_node ts_node_descendant_for_point_range(
TSNode self, t_parse_node self,
TSPoint start, t_point start,
TSPoint end t_point end
) { ) {
return ts_node__descendant_for_point_range(self, start, end, true); return ts_node__descendant_for_point_range(self, start, end, true);
} }
TSNode ts_node_named_descendant_for_point_range( t_parse_node ts_node_named_descendant_for_point_range(
TSNode self, t_parse_node self,
TSPoint start, t_point start,
TSPoint end t_point end
) { ) {
return ts_node__descendant_for_point_range(self, start, end, false); return ts_node__descendant_for_point_range(self, start, end, false);
} }
void ts_node_edit(TSNode *self, const TSInputEdit *edit) { void ts_node_edit(t_parse_node *self, const t_input_edit *edit) {
uint32_t start_byte = ts_node_start_byte(*self); uint32_t start_byte = ts_node_start_byte(*self);
TSPoint start_point = ts_node_start_point(*self); t_point start_point = ts_node_start_point(*self);
if (start_byte >= edit->old_end_byte) { if (start_byte >= edit->old_end_byte) {
start_byte = edit->new_end_byte + (start_byte - edit->old_end_byte); start_byte = edit->new_end_byte + (start_byte - edit->old_end_byte);

View file

@ -87,11 +87,11 @@ typedef struct {
uint32_t byte_index; uint32_t byte_index;
} TokenCache; } TokenCache;
struct TSParser { struct t_parser {
Lexer lexer; Lexer lexer;
Stack *stack; Stack *stack;
SubtreePool tree_pool; SubtreePool tree_pool;
const TSLanguage *language; const t_language *language;
ReduceActionSet reduce_actions; ReduceActionSet reduce_actions;
Subtree finished_tree; Subtree finished_tree;
SubtreeArray trailing_extras; SubtreeArray trailing_extras;
@ -137,7 +137,7 @@ typedef struct {
static const char *ts_string_input_read( static const char *ts_string_input_read(
void *_self, void *_self,
uint32_t byte, uint32_t byte,
TSPoint point, t_point point,
uint32_t *length uint32_t *length
) { ) {
(void)point; (void)point;
@ -153,7 +153,7 @@ static const char *ts_string_input_read(
// Parser - Private // Parser - Private
static void ts_parser__log(TSParser *self) { static void ts_parser__log(t_parser *self) {
if (self->lexer.logger.log) { if (self->lexer.logger.log) {
self->lexer.logger.log( self->lexer.logger.log(
self->lexer.logger.payload, self->lexer.logger.payload,
@ -173,7 +173,7 @@ static void ts_parser__log(TSParser *self) {
} }
static bool ts_parser__breakdown_top_of_stack( static bool ts_parser__breakdown_top_of_stack(
TSParser *self, t_parser *self,
StackVersion version StackVersion version
) { ) {
bool did_break_down = false; bool did_break_down = false;
@ -187,7 +187,7 @@ static bool ts_parser__breakdown_top_of_stack(
pending = false; pending = false;
for (uint32_t i = 0; i < pop.size; i++) { for (uint32_t i = 0; i < pop.size; i++) {
StackSlice slice = pop.contents[i]; StackSlice slice = pop.contents[i];
TSStateId state = ts_stack_state(self->stack, slice.version); t_state_id state = ts_stack_state(self->stack, slice.version);
Subtree parent = *array_front(&slice.subtrees); Subtree parent = *array_front(&slice.subtrees);
for (uint32_t j = 0, n = ts_subtree_child_count(parent); j < n; j++) { for (uint32_t j = 0, n = ts_subtree_child_count(parent); j < n; j++) {
@ -221,9 +221,9 @@ static bool ts_parser__breakdown_top_of_stack(
} }
static void ts_parser__breakdown_lookahead( static void ts_parser__breakdown_lookahead(
TSParser *self, t_parser *self,
Subtree *lookahead, Subtree *lookahead,
TSStateId state, t_state_id state,
ReusableNode *reusable_node ReusableNode *reusable_node
) { ) {
bool did_descend = false; bool did_descend = false;
@ -243,7 +243,7 @@ static void ts_parser__breakdown_lookahead(
} }
static ErrorComparison ts_parser__compare_versions( static ErrorComparison ts_parser__compare_versions(
TSParser *self, t_parser *self,
ErrorStatus a, ErrorStatus a,
ErrorStatus b ErrorStatus b
) { ) {
@ -286,7 +286,7 @@ static ErrorComparison ts_parser__compare_versions(
} }
static ErrorStatus ts_parser__version_status( static ErrorStatus ts_parser__version_status(
TSParser *self, t_parser *self,
StackVersion version StackVersion version
) { ) {
unsigned cost = ts_stack_error_cost(self->stack, version); unsigned cost = ts_stack_error_cost(self->stack, version);
@ -301,7 +301,7 @@ static ErrorStatus ts_parser__version_status(
} }
static bool ts_parser__better_version_exists( static bool ts_parser__better_version_exists(
TSParser *self, t_parser *self,
StackVersion version, StackVersion version,
bool is_in_error, bool is_in_error,
unsigned cost unsigned cost
@ -337,13 +337,13 @@ static bool ts_parser__better_version_exists(
return false; return false;
} }
static bool ts_parser__call_main_lex_fn(TSParser *self, TSLexMode lex_mode) { static bool ts_parser__call_main_lex_fn(t_parser *self, TSLexMode lex_mode) {
return self->language->lex_fn(&self->lexer.data, lex_mode.lex_state); return self->language->lex_fn(&self->lexer.data, lex_mode.lex_state);
} }
static bool ts_parser__call_keyword_lex_fn(TSParser *self, TSLexMode lex_mode) { static bool ts_parser__call_keyword_lex_fn(t_parser *self, TSLexMode lex_mode) {
(void)(lex_mode); (void)(lex_mode);
return self->language->keyword_lex_fn(&self->lexer.data, 0); return self->language->keyword_lex_fn(&self->lexer.data, 0);
@ -351,7 +351,7 @@ static bool ts_parser__call_keyword_lex_fn(TSParser *self, TSLexMode lex_mode) {
} }
static void ts_parser__external_scanner_create( static void ts_parser__external_scanner_create(
TSParser *self t_parser *self
) { ) {
if (self->language && self->language->external_scanner.states) { if (self->language && self->language->external_scanner.states) {
if (self->language->external_scanner.create) { if (self->language->external_scanner.create) {
@ -361,7 +361,7 @@ if (self->language->external_scanner.create) {
}} }}
static void ts_parser__external_scanner_destroy( static void ts_parser__external_scanner_destroy(
TSParser *self t_parser *self
) { ) {
if ( if (
self->language && self->language &&
@ -376,7 +376,7 @@ static void ts_parser__external_scanner_destroy(
} }
static unsigned ts_parser__external_scanner_serialize( static unsigned ts_parser__external_scanner_serialize(
TSParser *self t_parser *self
) { ) {
uint32_t length = self->language->external_scanner.serialize( uint32_t length = self->language->external_scanner.serialize(
self->external_scanner_payload, self->external_scanner_payload,
@ -388,7 +388,7 @@ static unsigned ts_parser__external_scanner_serialize(
} }
static void ts_parser__external_scanner_deserialize( static void ts_parser__external_scanner_deserialize(
TSParser *self, t_parser *self,
Subtree external_token Subtree external_token
) { ) {
const char *data = NULL; const char *data = NULL;
@ -408,8 +408,8 @@ static void ts_parser__external_scanner_deserialize(
} }
static bool ts_parser__external_scanner_scan( static bool ts_parser__external_scanner_scan(
TSParser *self, t_parser *self,
TSStateId external_lex_state t_state_id external_lex_state
) { ) {
const bool *valid_external_tokens = ts_language_enabled_external_tokens( const bool *valid_external_tokens = ts_language_enabled_external_tokens(
@ -425,14 +425,14 @@ static bool ts_parser__external_scanner_scan(
} }
static bool ts_parser__can_reuse_first_leaf( static bool ts_parser__can_reuse_first_leaf(
TSParser *self, t_parser *self,
TSStateId state, t_state_id state,
Subtree tree, Subtree tree,
TableEntry *table_entry TableEntry *table_entry
) { ) {
TSLexMode current_lex_mode = self->language->lex_modes[state]; TSLexMode current_lex_mode = self->language->lex_modes[state];
TSSymbol leaf_symbol = ts_subtree_leaf_symbol(tree); t_symbol leaf_symbol = ts_subtree_leaf_symbol(tree);
TSStateId leaf_state = ts_subtree_leaf_parse_state(tree); t_state_id leaf_state = ts_subtree_leaf_parse_state(tree);
TSLexMode leaf_lex_mode = self->language->lex_modes[leaf_state]; TSLexMode leaf_lex_mode = self->language->lex_modes[leaf_state];
// At the end of a non-terminal extra node, the lexer normally returns // At the end of a non-terminal extra node, the lexer normally returns
@ -460,9 +460,9 @@ static bool ts_parser__can_reuse_first_leaf(
} }
static Subtree ts_parser__lex( static Subtree ts_parser__lex(
TSParser *self, t_parser *self,
StackVersion version, StackVersion version,
TSStateId parse_state t_state_id parse_state
) { ) {
TSLexMode lex_mode = self->language->lex_modes[parse_state]; TSLexMode lex_mode = self->language->lex_modes[parse_state];
if (lex_mode.lex_state == (uint16_t)-1) { if (lex_mode.lex_state == (uint16_t)-1) {
@ -596,7 +596,7 @@ static Subtree ts_parser__lex(
); );
} else { } else {
bool is_keyword = false; bool is_keyword = false;
TSSymbol symbol = self->lexer.data.result_symbol; t_symbol symbol = self->lexer.data.result_symbol;
Length padding = length_sub(self->lexer.token_start_position, start_position); Length padding = length_sub(self->lexer.token_start_position, start_position);
Length size = length_sub(self->lexer.token_end_position, self->lexer.token_start_position); Length size = length_sub(self->lexer.token_end_position, self->lexer.token_start_position);
uint32_t lookahead_bytes = lookahead_end_byte - self->lexer.token_end_position.bytes; uint32_t lookahead_bytes = lookahead_end_byte - self->lexer.token_end_position.bytes;
@ -651,8 +651,8 @@ static Subtree ts_parser__lex(
} }
static Subtree ts_parser__get_cached_token( static Subtree ts_parser__get_cached_token(
TSParser *self, t_parser *self,
TSStateId state, t_state_id state,
size_t position, size_t position,
Subtree last_external_token, Subtree last_external_token,
TableEntry *table_entry TableEntry *table_entry
@ -672,7 +672,7 @@ static Subtree ts_parser__get_cached_token(
} }
static void ts_parser__set_cached_token( static void ts_parser__set_cached_token(
TSParser *self, t_parser *self,
uint32_t byte_index, uint32_t byte_index,
Subtree last_external_token, Subtree last_external_token,
Subtree token Subtree token
@ -688,7 +688,7 @@ static void ts_parser__set_cached_token(
} }
static bool ts_parser__has_included_range_difference( static bool ts_parser__has_included_range_difference(
const TSParser *self, const t_parser *self,
uint32_t start_position, uint32_t start_position,
uint32_t end_position uint32_t end_position
) { ) {
@ -701,9 +701,9 @@ static bool ts_parser__has_included_range_difference(
} }
static Subtree ts_parser__reuse_node( static Subtree ts_parser__reuse_node(
TSParser *self, t_parser *self,
StackVersion version, StackVersion version,
TSStateId *state, t_state_id *state,
uint32_t position, uint32_t position,
Subtree last_external_token, Subtree last_external_token,
TableEntry *table_entry TableEntry *table_entry
@ -759,7 +759,7 @@ static Subtree ts_parser__reuse_node(
continue; continue;
} }
TSSymbol leaf_symbol = ts_subtree_leaf_symbol(result); t_symbol leaf_symbol = ts_subtree_leaf_symbol(result);
ts_language_table_entry(self->language, *state, leaf_symbol, table_entry); ts_language_table_entry(self->language, *state, leaf_symbol, table_entry);
if (!ts_parser__can_reuse_first_leaf(self, *state, result, table_entry)) { if (!ts_parser__can_reuse_first_leaf(self, *state, result, table_entry)) {
LOG( LOG(
@ -783,7 +783,7 @@ static Subtree ts_parser__reuse_node(
// //
// The decision is based on the trees' error costs (if any), their dynamic precedence, // The decision is based on the trees' error costs (if any), their dynamic precedence,
// and finally, as a default, by a recursive comparison of the trees' symbols. // and finally, as a default, by a recursive comparison of the trees' symbols.
static bool ts_parser__select_tree(TSParser *self, Subtree left, Subtree right) { static bool ts_parser__select_tree(t_parser *self, Subtree left, Subtree right) {
if (!left.ptr) return true; if (!left.ptr) return true;
if (!right.ptr) return false; if (!right.ptr) return false;
@ -831,7 +831,7 @@ static bool ts_parser__select_tree(TSParser *self, Subtree left, Subtree right)
// Determine if a given tree's children should be replaced by an alternative // Determine if a given tree's children should be replaced by an alternative
// array of children. // array of children.
static bool ts_parser__select_children( static bool ts_parser__select_children(
TSParser *self, t_parser *self,
Subtree left, Subtree left,
const SubtreeArray *children const SubtreeArray *children
) { ) {
@ -856,9 +856,9 @@ static bool ts_parser__select_children(
} }
static void ts_parser__shift( static void ts_parser__shift(
TSParser *self, t_parser *self,
StackVersion version, StackVersion version,
TSStateId state, t_state_id state,
Subtree lookahead, Subtree lookahead,
bool extra bool extra
) { ) {
@ -879,9 +879,9 @@ static void ts_parser__shift(
} }
static StackVersion ts_parser__reduce( static StackVersion ts_parser__reduce(
TSParser *self, t_parser *self,
StackVersion version, StackVersion version,
TSSymbol symbol, t_symbol symbol,
uint32_t count, uint32_t count,
int dynamic_precedence, int dynamic_precedence,
uint16_t production_id, uint16_t production_id,
@ -957,8 +957,8 @@ static StackVersion ts_parser__reduce(
} }
} }
TSStateId state = ts_stack_state(self->stack, slice_version); t_state_id state = ts_stack_state(self->stack, slice_version);
TSStateId next_state = ts_language_next_state(self->language, state, symbol); t_state_id next_state = ts_language_next_state(self->language, state, symbol);
if (end_of_non_terminal_extra && next_state == state) { if (end_of_non_terminal_extra && next_state == state) {
parent.ptr->extra = true; parent.ptr->extra = true;
} }
@ -994,7 +994,7 @@ static StackVersion ts_parser__reduce(
} }
static void ts_parser__accept( static void ts_parser__accept(
TSParser *self, t_parser *self,
StackVersion version, StackVersion version,
Subtree lookahead Subtree lookahead
) { ) {
@ -1047,9 +1047,9 @@ static void ts_parser__accept(
} }
static bool ts_parser__do_all_potential_reductions( static bool ts_parser__do_all_potential_reductions(
TSParser *self, t_parser *self,
StackVersion starting_version, StackVersion starting_version,
TSSymbol lookahead_symbol t_symbol lookahead_symbol
) { ) {
uint32_t initial_version_count = ts_stack_version_count(self->stack); uint32_t initial_version_count = ts_stack_version_count(self->stack);
@ -1068,11 +1068,11 @@ static bool ts_parser__do_all_potential_reductions(
} }
if (merged) continue; if (merged) continue;
TSStateId state = ts_stack_state(self->stack, version); t_state_id state = ts_stack_state(self->stack, version);
bool has_shift_action = false; bool has_shift_action = false;
array_clear(&self->reduce_actions); array_clear(&self->reduce_actions);
TSSymbol first_symbol, end_symbol; t_symbol first_symbol, end_symbol;
if (lookahead_symbol != 0) { if (lookahead_symbol != 0) {
first_symbol = lookahead_symbol; first_symbol = lookahead_symbol;
end_symbol = lookahead_symbol + 1; end_symbol = lookahead_symbol + 1;
@ -1081,7 +1081,7 @@ static bool ts_parser__do_all_potential_reductions(
end_symbol = self->language->token_count; end_symbol = self->language->token_count;
} }
for (TSSymbol symbol = first_symbol; symbol < end_symbol; symbol++) { for (t_symbol symbol = first_symbol; symbol < end_symbol; symbol++) {
TableEntry entry; TableEntry entry;
ts_language_table_entry(self->language, state, symbol, &entry); ts_language_table_entry(self->language, state, symbol, &entry);
for (uint32_t j = 0; j < entry.action_count; j++) { for (uint32_t j = 0; j < entry.action_count; j++) {
@ -1137,10 +1137,10 @@ static bool ts_parser__do_all_potential_reductions(
} }
static bool ts_parser__recover_to_state( static bool ts_parser__recover_to_state(
TSParser *self, t_parser *self,
StackVersion version, StackVersion version,
unsigned depth, unsigned depth,
TSStateId goal_state t_state_id goal_state
) { ) {
StackSliceArray pop = ts_stack_pop_count(self->stack, version, depth); StackSliceArray pop = ts_stack_pop_count(self->stack, version, depth);
StackVersion previous_version = STACK_VERSION_NONE; StackVersion previous_version = STACK_VERSION_NONE;
@ -1196,7 +1196,7 @@ static bool ts_parser__recover_to_state(
} }
static void ts_parser__recover( static void ts_parser__recover(
TSParser *self, t_parser *self,
StackVersion version, StackVersion version,
Subtree lookahead Subtree lookahead
) { ) {
@ -1373,7 +1373,7 @@ static void ts_parser__recover(
} }
static void ts_parser__handle_error( static void ts_parser__handle_error(
TSParser *self, t_parser *self,
StackVersion version, StackVersion version,
Subtree lookahead Subtree lookahead
) { ) {
@ -1391,13 +1391,13 @@ static void ts_parser__handle_error(
bool did_insert_missing_token = false; bool did_insert_missing_token = false;
for (StackVersion v = version; v < version_count;) { for (StackVersion v = version; v < version_count;) {
if (!did_insert_missing_token) { if (!did_insert_missing_token) {
TSStateId state = ts_stack_state(self->stack, v); t_state_id state = ts_stack_state(self->stack, v);
for ( for (
TSSymbol missing_symbol = 1; t_symbol missing_symbol = 1;
missing_symbol < (uint16_t)self->language->token_count; missing_symbol < (uint16_t)self->language->token_count;
missing_symbol++ missing_symbol++
) { ) {
TSStateId state_after_missing_symbol = ts_language_next_state( t_state_id state_after_missing_symbol = ts_language_next_state(
self->language, state, missing_symbol self->language, state, missing_symbol
); );
if (state_after_missing_symbol == 0 || state_after_missing_symbol == state) { if (state_after_missing_symbol == 0 || state_after_missing_symbol == state) {
@ -1471,11 +1471,11 @@ static void ts_parser__handle_error(
} }
static bool ts_parser__advance( static bool ts_parser__advance(
TSParser *self, t_parser *self,
StackVersion version, StackVersion version,
bool allow_node_reuse bool allow_node_reuse
) { ) {
TSStateId state = ts_stack_state(self->stack, version); t_state_id state = ts_stack_state(self->stack, version);
uint32_t position = ts_stack_position(self->stack, version).bytes; uint32_t position = ts_stack_position(self->stack, version).bytes;
Subtree last_external_token = ts_stack_last_external_token(self->stack, version); Subtree last_external_token = ts_stack_last_external_token(self->stack, version);
@ -1548,7 +1548,7 @@ static bool ts_parser__advance(
switch (action.type) { switch (action.type) {
case TSParseActionTypeShift: { case TSParseActionTypeShift: {
if (action.shift.repetition) break; if (action.shift.repetition) break;
TSStateId next_state; t_state_id next_state;
if (action.shift.extra) { if (action.shift.extra) {
next_state = state; next_state = state;
LOG("shift_extra"); LOG("shift_extra");
@ -1688,7 +1688,7 @@ static bool ts_parser__advance(
} }
} }
static unsigned ts_parser__condense_stack(TSParser *self) { static unsigned ts_parser__condense_stack(t_parser *self) {
bool made_changes = false; bool made_changes = false;
unsigned min_error_cost = UINT_MAX; unsigned min_error_cost = UINT_MAX;
for (StackVersion i = 0; i < ts_stack_version_count(self->stack); i++) { for (StackVersion i = 0; i < ts_stack_version_count(self->stack); i++) {
@ -1788,7 +1788,7 @@ static unsigned ts_parser__condense_stack(TSParser *self) {
return min_error_cost; return min_error_cost;
} }
static bool ts_parser_has_outstanding_parse(TSParser *self) { static bool ts_parser_has_outstanding_parse(t_parser *self) {
return ( return (
self->external_scanner_payload || self->external_scanner_payload ||
ts_stack_state(self->stack, 0) != 1 || ts_stack_state(self->stack, 0) != 1 ||
@ -1798,8 +1798,8 @@ static bool ts_parser_has_outstanding_parse(TSParser *self) {
// Parser - Public // Parser - Public
TSParser *ts_parser_new(void) { t_parser *ts_parser_new(void) {
TSParser *self = ts_calloc(1, sizeof(TSParser)); t_parser *self = ts_calloc(1, sizeof(t_parser));
ts_lexer_init(&self->lexer); ts_lexer_init(&self->lexer);
array_init(&self->reduce_actions); array_init(&self->reduce_actions);
array_reserve(&self->reduce_actions, 4); array_reserve(&self->reduce_actions, 4);
@ -1822,7 +1822,7 @@ TSParser *ts_parser_new(void) {
return self; return self;
} }
void ts_parser_delete(TSParser *self) { void ts_parser_delete(t_parser *self) {
if (!self) return; if (!self) return;
ts_parser_set_language(self, NULL); ts_parser_set_language(self, NULL);
@ -1847,11 +1847,11 @@ void ts_parser_delete(TSParser *self) {
ts_free(self); ts_free(self);
} }
const TSLanguage *ts_parser_language(const TSParser *self) { const t_language *ts_parser_language(const t_parser *self) {
return self->language; return self->language;
} }
bool ts_parser_set_language(TSParser *self, const TSLanguage *language) { bool ts_parser_set_language(t_parser *self, const t_language *language) {
ts_parser_reset(self); ts_parser_reset(self);
ts_language_delete(self->language); ts_language_delete(self->language);
self->language = NULL; self->language = NULL;
@ -1869,15 +1869,15 @@ bool ts_parser_set_language(TSParser *self, const TSLanguage *language) {
return true; return true;
} }
TSLogger ts_parser_logger(const TSParser *self) { t_logger ts_parser_logger(const t_parser *self) {
return self->lexer.logger; return self->lexer.logger;
} }
void ts_parser_set_logger(TSParser *self, TSLogger logger) { void ts_parser_set_logger(t_parser *self, t_logger logger) {
self->lexer.logger = logger; self->lexer.logger = logger;
} }
void ts_parser_print_dot_graphs(TSParser *self, int fd) { void ts_parser_print_dot_graphs(t_parser *self, int fd) {
if (self->dot_graph_file) { if (self->dot_graph_file) {
fclose(self->dot_graph_file); fclose(self->dot_graph_file);
} }
@ -1893,35 +1893,35 @@ void ts_parser_print_dot_graphs(TSParser *self, int fd) {
} }
} }
const size_t *ts_parser_cancellation_flag(const TSParser *self) { const size_t *ts_parser_cancellation_flag(const t_parser *self) {
return (const size_t *)self->cancellation_flag; return (const size_t *)self->cancellation_flag;
} }
void ts_parser_set_cancellation_flag(TSParser *self, const size_t *flag) { void ts_parser_set_cancellation_flag(t_parser *self, const size_t *flag) {
self->cancellation_flag = (const volatile size_t *)flag; self->cancellation_flag = (const volatile size_t *)flag;
} }
uint64_t ts_parser_timeout_micros(const TSParser *self) { uint64_t ts_parser_timeout_micros(const t_parser *self) {
return duration_to_micros(self->timeout_duration); return duration_to_micros(self->timeout_duration);
} }
void ts_parser_set_timeout_micros(TSParser *self, uint64_t timeout_micros) { void ts_parser_set_timeout_micros(t_parser *self, uint64_t timeout_micros) {
self->timeout_duration = duration_from_micros(timeout_micros); self->timeout_duration = duration_from_micros(timeout_micros);
} }
bool ts_parser_set_included_ranges( bool ts_parser_set_included_ranges(
TSParser *self, t_parser *self,
const TSRange *ranges, const t_range *ranges,
uint32_t count uint32_t count
) { ) {
return ts_lexer_set_included_ranges(&self->lexer, ranges, count); return ts_lexer_set_included_ranges(&self->lexer, ranges, count);
} }
const TSRange *ts_parser_included_ranges(const TSParser *self, uint32_t *count) { const t_range *ts_parser_included_ranges(const t_parser *self, uint32_t *count) {
return ts_lexer_included_ranges(&self->lexer, count); return ts_lexer_included_ranges(&self->lexer, count);
} }
void ts_parser_reset(TSParser *self) { void ts_parser_reset(t_parser *self) {
ts_parser__external_scanner_destroy(self); ts_parser__external_scanner_destroy(self);
if (self->old_tree.ptr) { if (self->old_tree.ptr) {
@ -1941,12 +1941,12 @@ void ts_parser_reset(TSParser *self) {
self->has_scanner_error = false; self->has_scanner_error = false;
} }
TSTree *ts_parser_parse( t_tree *ts_parser_parse(
TSParser *self, t_parser *self,
const TSTree *old_tree, const t_tree *old_tree,
TSInput input t_input input
) { ) {
TSTree *result = NULL; t_tree *result = NULL;
if (!self->language || !input.read) return NULL; if (!self->language || !input.read) return NULL;
@ -1973,7 +1973,7 @@ TSTree *ts_parser_parse(
LOG("parse_after_edit"); LOG("parse_after_edit");
LOG_TREE(self->old_tree); LOG_TREE(self->old_tree);
for (unsigned i = 0; i < self->included_range_differences.size; i++) { for (unsigned i = 0; i < self->included_range_differences.size; i++) {
TSRange *range = &self->included_range_differences.contents[i]; t_range *range = &self->included_range_differences.contents[i];
LOG("different_included_range %u - %u", range->start_byte, range->end_byte); LOG("different_included_range %u - %u", range->start_byte, range->end_byte);
} }
} else { } else {
@ -2037,7 +2037,7 @@ TSTree *ts_parser_parse(
} }
while (self->included_range_difference_index < self->included_range_differences.size) { while (self->included_range_difference_index < self->included_range_differences.size) {
TSRange *range = &self->included_range_differences.contents[self->included_range_difference_index]; t_range *range = &self->included_range_differences.contents[self->included_range_difference_index];
if (range->end_byte <= position) { if (range->end_byte <= position) {
self->included_range_difference_index++; self->included_range_difference_index++;
} else { } else {
@ -2064,24 +2064,24 @@ exit:
return result; return result;
} }
TSTree *ts_parser_parse_string( t_tree *ts_parser_parse_string(
TSParser *self, t_parser *self,
const TSTree *old_tree, const t_tree *old_tree,
const char *string, const char *string,
uint32_t length uint32_t length
) { ) {
return ts_parser_parse_string_encoding(self, old_tree, string, length, TSInputEncodingUTF8); return ts_parser_parse_string_encoding(self, old_tree, string, length, TSInputEncodingUTF8);
} }
TSTree *ts_parser_parse_string_encoding( t_tree *ts_parser_parse_string_encoding(
TSParser *self, t_parser *self,
const TSTree *old_tree, const t_tree *old_tree,
const char *string, const char *string,
uint32_t length, uint32_t length,
TSInputEncoding encoding t_input_encoding encoding
) { ) {
TSStringInput input = {string, length}; TSStringInput input = {string, length};
return ts_parser_parse(self, old_tree, (TSInput) { return ts_parser_parse(self, old_tree, (t_input) {
&input, &input,
ts_string_input_read, ts_string_input_read,
encoding, encoding,

View file

@ -9,7 +9,7 @@ extern "C" {
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#define ts_builtin_sym_error ((TSSymbol)-1) #define ts_builtin_sym_error ((t_symbol)-1)
#define ts_builtin_sym_end 0 #define ts_builtin_sym_end 0
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024 #define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
@ -21,7 +21,7 @@ typedef struct TSLanguage TSLanguage;
#endif #endif
typedef struct { typedef struct {
TSFieldId field_id; t_field_id field_id;
uint8_t child_index; uint8_t child_index;
bool inherited; bool inherited;
} TSFieldMapEntry; } TSFieldMapEntry;
@ -41,7 +41,7 @@ typedef struct TSLexer TSLexer;
struct TSLexer { struct TSLexer {
int32_t lookahead; int32_t lookahead;
TSSymbol result_symbol; t_symbol result_symbol;
void (*advance)(TSLexer *, bool); void (*advance)(TSLexer *, bool);
void (*mark_end)(TSLexer *); void (*mark_end)(TSLexer *);
uint32_t (*get_column)(TSLexer *); uint32_t (*get_column)(TSLexer *);
@ -59,14 +59,14 @@ typedef enum {
typedef union { typedef union {
struct { struct {
uint8_t type; uint8_t type;
TSStateId state; t_state_id state;
bool extra; bool extra;
bool repetition; bool repetition;
} shift; } shift;
struct { struct {
uint8_t type; uint8_t type;
uint8_t child_count; uint8_t child_count;
TSSymbol symbol; t_symbol symbol;
int16_t dynamic_precedence; int16_t dynamic_precedence;
uint16_t production_id; uint16_t production_id;
} reduce; } reduce;
@ -91,7 +91,7 @@ typedef struct {
int32_t end; int32_t end;
} TSCharacterRange; } TSCharacterRange;
struct TSLanguage { struct t_language {
uint32_t version; uint32_t version;
uint32_t symbol_count; uint32_t symbol_count;
uint32_t alias_count; uint32_t alias_count;
@ -111,23 +111,23 @@ struct TSLanguage {
const TSFieldMapSlice *field_map_slices; const TSFieldMapSlice *field_map_slices;
const TSFieldMapEntry *field_map_entries; const TSFieldMapEntry *field_map_entries;
const TSSymbolMetadata *symbol_metadata; const TSSymbolMetadata *symbol_metadata;
const TSSymbol *public_symbol_map; const t_symbol *public_symbol_map;
const uint16_t *alias_map; const uint16_t *alias_map;
const TSSymbol *alias_sequences; const t_symbol *alias_sequences;
const TSLexMode *lex_modes; const TSLexMode *lex_modes;
bool (*lex_fn)(TSLexer *, TSStateId); bool (*lex_fn)(TSLexer *, t_state_id);
bool (*keyword_lex_fn)(TSLexer *, TSStateId); bool (*keyword_lex_fn)(TSLexer *, t_state_id);
TSSymbol keyword_capture_token; t_symbol keyword_capture_token;
struct { struct {
const bool *states; const bool *states;
const TSSymbol *symbol_map; const t_symbol *symbol_map;
void *(*create)(void); void *(*create)(void);
void (*destroy)(void *); void (*destroy)(void *);
bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist); bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist);
unsigned (*serialize)(void *, char *); unsigned (*serialize)(void *, char *);
void (*deserialize)(void *, const char *, unsigned); void (*deserialize)(void *, const char *, unsigned);
} external_scanner; } external_scanner;
const TSStateId *primary_state_ids; const t_state_id *primary_state_ids;
}; };
static inline bool set_contains(TSCharacterRange *ranges, uint32_t len, int32_t lookahead) { static inline bool set_contains(TSCharacterRange *ranges, uint32_t len, int32_t lookahead) {

View file

@ -3,56 +3,56 @@
#include "./api.h" #include "./api.h"
#define POINT_ZERO ((TSPoint) {0, 0}) #define POINT_ZERO ((t_point) {0, 0})
#define POINT_MAX ((TSPoint) {UINT32_MAX, UINT32_MAX}) #define POINT_MAX ((t_point) {UINT32_MAX, UINT32_MAX})
static inline TSPoint point__new(unsigned row, unsigned column) { static inline t_point point__new(unsigned row, unsigned column) {
TSPoint result = {row, column}; t_point result = {row, column};
return result; return result;
} }
static inline TSPoint point_add(TSPoint a, TSPoint b) { static inline t_point point_add(t_point a, t_point b) {
if (b.row > 0) if (b.row > 0)
return point__new(a.row + b.row, b.column); return point__new(a.row + b.row, b.column);
else else
return point__new(a.row, a.column + b.column); return point__new(a.row, a.column + b.column);
} }
static inline TSPoint point_sub(TSPoint a, TSPoint b) { static inline t_point point_sub(t_point a, t_point b) {
if (a.row > b.row) if (a.row > b.row)
return point__new(a.row - b.row, a.column); return point__new(a.row - b.row, a.column);
else else
return point__new(0, a.column - b.column); return point__new(0, a.column - b.column);
} }
static inline bool point_lte(TSPoint a, TSPoint b) { static inline bool point_lte(t_point a, t_point b) {
return (a.row < b.row) || (a.row == b.row && a.column <= b.column); return (a.row < b.row) || (a.row == b.row && a.column <= b.column);
} }
static inline bool point_lt(TSPoint a, TSPoint b) { static inline bool point_lt(t_point a, t_point b) {
return (a.row < b.row) || (a.row == b.row && a.column < b.column); return (a.row < b.row) || (a.row == b.row && a.column < b.column);
} }
static inline bool point_gt(TSPoint a, TSPoint b) { static inline bool point_gt(t_point a, t_point b) {
return (a.row > b.row) || (a.row == b.row && a.column > b.column); return (a.row > b.row) || (a.row == b.row && a.column > b.column);
} }
static inline bool point_gte(TSPoint a, TSPoint b) { static inline bool point_gte(t_point a, t_point b) {
return (a.row > b.row) || (a.row == b.row && a.column >= b.column); return (a.row > b.row) || (a.row == b.row && a.column >= b.column);
} }
static inline bool point_eq(TSPoint a, TSPoint b) { static inline bool point_eq(t_point a, t_point b) {
return a.row == b.row && a.column == b.column; return a.row == b.row && a.column == b.column;
} }
static inline TSPoint point_min(TSPoint a, TSPoint b) { static inline t_point point_min(t_point a, t_point b) {
if (a.row < b.row || (a.row == b.row && a.column < b.column)) if (a.row < b.row || (a.row == b.row && a.column < b.column))
return a; return a;
else else
return b; return b;
} }
static inline TSPoint point_max(TSPoint a, TSPoint b) { static inline t_point point_max(t_point a, t_point b) {
if (a.row > b.row || (a.row == b.row && a.column > b.column)) if (a.row > b.row || (a.row == b.row && a.column > b.column))
return a; return a;
else else

File diff suppressed because it is too large Load diff

View file

@ -10,7 +10,7 @@ extern "C" {
typedef struct { typedef struct {
uint32_t count; uint32_t count;
TSSymbol symbol; t_symbol symbol;
int dynamic_precedence; int dynamic_precedence;
unsigned short production_id; unsigned short production_id;
} ReduceAction; } ReduceAction;

View file

@ -27,7 +27,7 @@ typedef struct {
} StackLink; } StackLink;
struct StackNode { struct StackNode {
TSStateId state; t_state_id state;
Length position; Length position;
StackLink links[MAX_LINK_COUNT]; StackLink links[MAX_LINK_COUNT];
short unsigned int link_count; short unsigned int link_count;
@ -139,7 +139,7 @@ static StackNode *stack_node_new(
StackNode *previous_node, StackNode *previous_node,
Subtree subtree, Subtree subtree,
bool is_pending, bool is_pending,
TSStateId state, t_state_id state,
StackNodeArray *pool StackNodeArray *pool
) { ) {
StackNode *node = pool->size > 0 StackNode *node = pool->size > 0
@ -460,7 +460,7 @@ uint32_t ts_stack_version_count(const Stack *self) {
return self->heads.size; return self->heads.size;
} }
TSStateId ts_stack_state(const Stack *self, StackVersion version) { t_state_id ts_stack_state(const Stack *self, StackVersion version) {
return array_get(&self->heads, version)->node->state; return array_get(&self->heads, version)->node->state;
} }
@ -503,7 +503,7 @@ void ts_stack_push(
StackVersion version, StackVersion version,
Subtree subtree, Subtree subtree,
bool pending, bool pending,
TSStateId state t_state_id state
) { ) {
StackHead *head = array_get(&self->heads, version); StackHead *head = array_get(&self->heads, version);
StackNode *new_node = stack_node_new(head->node, subtree, pending, state, &self->node_pool); StackNode *new_node = stack_node_new(head->node, subtree, pending, state, &self->node_pool);
@ -593,7 +593,7 @@ typedef struct {
forceinline StackAction summarize_stack_callback(void *payload, const StackIterator *iterator) { forceinline StackAction summarize_stack_callback(void *payload, const StackIterator *iterator) {
SummarizeStackSession *session = payload; SummarizeStackSession *session = payload;
TSStateId state = iterator->node->state; t_state_id state = iterator->node->state;
unsigned depth = iterator->subtree_count; unsigned depth = iterator->subtree_count;
if (depth > session->max_depth) return StackActionStop; if (depth > session->max_depth) return StackActionStop;
for (unsigned i = session->summary->size - 1; i + 1 > 0; i--) { for (unsigned i = session->summary->size - 1; i + 1 > 0; i--) {
@ -764,7 +764,7 @@ void ts_stack_clear(Stack *self) {
})); }));
} }
bool ts_stack_print_dot_graph(Stack *self, const TSLanguage *language, FILE *f) { bool ts_stack_print_dot_graph(Stack *self, const t_language *language, FILE *f) {
array_reserve(&self->iterators, 32); array_reserve(&self->iterators, 32);
if (!f) f = stderr; if (!f) f = stderr;

View file

@ -24,7 +24,7 @@ typedef Array(StackSlice) StackSliceArray;
typedef struct { typedef struct {
Length position; Length position;
unsigned depth; unsigned depth;
TSStateId state; t_state_id state;
} StackSummaryEntry; } StackSummaryEntry;
typedef Array(StackSummaryEntry) StackSummary; typedef Array(StackSummaryEntry) StackSummary;
@ -39,7 +39,7 @@ uint32_t ts_stack_version_count(const Stack *);
// Get the state at the top of the given version of the stack. If the stack is // Get the state at the top of the given version of the stack. If the stack is
// empty, this returns the initial state, 0. // empty, this returns the initial state, 0.
TSStateId ts_stack_state(const Stack *, StackVersion); t_state_id ts_stack_state(const Stack *, StackVersion);
// Get the last external token associated with a given version of the stack. // Get the last external token associated with a given version of the stack.
Subtree ts_stack_last_external_token(const Stack *, StackVersion); Subtree ts_stack_last_external_token(const Stack *, StackVersion);
@ -55,7 +55,7 @@ Length ts_stack_position(const Stack *, StackVersion);
// This transfers ownership of the tree to the Stack. Callers that // This transfers ownership of the tree to the Stack. Callers that
// need to retain ownership of the tree for their own purposes should // need to retain ownership of the tree for their own purposes should
// first retain the tree. // first retain the tree.
void ts_stack_push(Stack *, StackVersion, Subtree , bool, TSStateId); void ts_stack_push(Stack *, StackVersion, Subtree , bool, t_state_id);
// Pop the given number of entries from the given version of the stack. This // Pop the given number of entries from the given version of the stack. This
// operation can increase the number of stack versions by revealing multiple // operation can increase the number of stack versions by revealing multiple
@ -122,9 +122,9 @@ void ts_stack_remove_version(Stack *, StackVersion);
void ts_stack_clear(Stack *); void ts_stack_clear(Stack *);
bool ts_stack_print_dot_graph(Stack *, const TSLanguage *, FILE *); bool ts_stack_print_dot_graph(Stack *, const t_language *, FILE *);
typedef void (*StackIterateCallback)(void *, TSStateId, uint32_t); typedef void (*StackIterateCallback)(void *, t_state_id, uint32_t);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -163,10 +163,10 @@ static inline bool ts_subtree_can_inline(Length padding, Length size, uint32_t l
} }
Subtree ts_subtree_new_leaf( Subtree ts_subtree_new_leaf(
SubtreePool *pool, TSSymbol symbol, Length padding, Length size, SubtreePool *pool, t_symbol symbol, Length padding, Length size,
uint32_t lookahead_bytes, TSStateId parse_state, uint32_t lookahead_bytes, t_state_id parse_state,
bool has_external_tokens, bool depends_on_column, bool has_external_tokens, bool depends_on_column,
bool is_keyword, const TSLanguage *language bool is_keyword, const t_language *language
) { ) {
TSSymbolMetadata metadata = ts_language_symbol_metadata(language, symbol); TSSymbolMetadata metadata = ts_language_symbol_metadata(language, symbol);
bool extra = symbol == ts_builtin_sym_end; bool extra = symbol == ts_builtin_sym_end;
@ -224,8 +224,8 @@ Subtree ts_subtree_new_leaf(
void ts_subtree_set_symbol( void ts_subtree_set_symbol(
MutableSubtree *self, MutableSubtree *self,
TSSymbol symbol, t_symbol symbol,
const TSLanguage *language const t_language *language
) { ) {
TSSymbolMetadata metadata = ts_language_symbol_metadata(language, symbol); TSSymbolMetadata metadata = ts_language_symbol_metadata(language, symbol);
if (self->data.is_inline) { if (self->data.is_inline) {
@ -242,7 +242,7 @@ void ts_subtree_set_symbol(
Subtree ts_subtree_new_error( Subtree ts_subtree_new_error(
SubtreePool *pool, int32_t lookahead_char, Length padding, Length size, SubtreePool *pool, int32_t lookahead_char, Length padding, Length size,
uint32_t bytes_scanned, TSStateId parse_state, const TSLanguage *language uint32_t bytes_scanned, t_state_id parse_state, const t_language *language
) { ) {
Subtree result = ts_subtree_new_leaf( Subtree result = ts_subtree_new_leaf(
pool, ts_builtin_sym_error, padding, size, bytes_scanned, pool, ts_builtin_sym_error, padding, size, bytes_scanned,
@ -291,13 +291,13 @@ MutableSubtree ts_subtree_make_mut(SubtreePool *pool, Subtree self) {
static void ts_subtree__compress( static void ts_subtree__compress(
MutableSubtree self, MutableSubtree self,
unsigned count, unsigned count,
const TSLanguage *language, const t_language *language,
MutableSubtreeArray *stack MutableSubtreeArray *stack
) { ) {
unsigned initial_stack_size = stack->size; unsigned initial_stack_size = stack->size;
MutableSubtree tree = self; MutableSubtree tree = self;
TSSymbol symbol = tree.ptr->symbol; t_symbol symbol = tree.ptr->symbol;
for (unsigned i = 0; i < count; i++) { for (unsigned i = 0; i < count; i++) {
if (tree.ptr->ref_count > 1 || tree.ptr->child_count < 2) break; if (tree.ptr->ref_count > 1 || tree.ptr->child_count < 2) break;
@ -334,7 +334,7 @@ static void ts_subtree__compress(
} }
} }
void ts_subtree_balance(Subtree self, SubtreePool *pool, const TSLanguage *language) { void ts_subtree_balance(Subtree self, SubtreePool *pool, const t_language *language) {
array_clear(&pool->tree_stack); array_clear(&pool->tree_stack);
if (ts_subtree_child_count(self) > 0 && self.ptr->ref_count == 1) { if (ts_subtree_child_count(self) > 0 && self.ptr->ref_count == 1) {
@ -369,7 +369,7 @@ void ts_subtree_balance(Subtree self, SubtreePool *pool, const TSLanguage *langu
// Assign all of the node's properties that depend on its children. // Assign all of the node's properties that depend on its children.
void ts_subtree_summarize_children( void ts_subtree_summarize_children(
MutableSubtree self, MutableSubtree self,
const TSLanguage *language const t_language *language
) { ) {
assert(!self.data.is_inline); assert(!self.data.is_inline);
@ -384,7 +384,7 @@ void ts_subtree_summarize_children(
self.ptr->dynamic_precedence = 0; self.ptr->dynamic_precedence = 0;
uint32_t structural_index = 0; uint32_t structural_index = 0;
const TSSymbol *alias_sequence = ts_language_alias_sequence(language, self.ptr->production_id); const t_symbol *alias_sequence = ts_language_alias_sequence(language, self.ptr->production_id);
uint32_t lookahead_end_byte = 0; uint32_t lookahead_end_byte = 0;
const Subtree *children = ts_subtree_children(self); const Subtree *children = ts_subtree_children(self);
@ -504,10 +504,10 @@ void ts_subtree_summarize_children(
// //
// This takes ownership of the children array. // This takes ownership of the children array.
MutableSubtree ts_subtree_new_node( MutableSubtree ts_subtree_new_node(
TSSymbol symbol, t_symbol symbol,
SubtreeArray *children, SubtreeArray *children,
unsigned production_id, unsigned production_id,
const TSLanguage *language const t_language *language
) { ) {
TSSymbolMetadata metadata = ts_language_symbol_metadata(language, symbol); TSSymbolMetadata metadata = ts_language_symbol_metadata(language, symbol);
bool fragile = symbol == ts_builtin_sym_error || symbol == ts_builtin_sym_error_repeat; bool fragile = symbol == ts_builtin_sym_error || symbol == ts_builtin_sym_error_repeat;
@ -549,7 +549,7 @@ MutableSubtree ts_subtree_new_node(
Subtree ts_subtree_new_error_node( Subtree ts_subtree_new_error_node(
SubtreeArray *children, SubtreeArray *children,
bool extra, bool extra,
const TSLanguage *language const t_language *language
) { ) {
MutableSubtree result = ts_subtree_new_node( MutableSubtree result = ts_subtree_new_node(
ts_builtin_sym_error, children, 0, language ts_builtin_sym_error, children, 0, language
@ -564,10 +564,10 @@ Subtree ts_subtree_new_error_node(
// having any effect on the parse state. // having any effect on the parse state.
Subtree ts_subtree_new_missing_leaf( Subtree ts_subtree_new_missing_leaf(
SubtreePool *pool, SubtreePool *pool,
TSSymbol symbol, t_symbol symbol,
Length padding, Length padding,
uint32_t lookahead_bytes, uint32_t lookahead_bytes,
const TSLanguage *language const t_language *language
) { ) {
Subtree result = ts_subtree_new_leaf( Subtree result = ts_subtree_new_leaf(
pool, symbol, padding, length_zero(), lookahead_bytes, pool, symbol, padding, length_zero(), lookahead_bytes,
@ -656,7 +656,7 @@ static inline void ts_subtree_set_has_changes(MutableSubtree *self) {
} }
} }
Subtree ts_subtree_edit(Subtree self, const TSInputEdit *input_edit, SubtreePool *pool) { Subtree ts_subtree_edit(Subtree self, const t_input_edit *input_edit, SubtreePool *pool) {
typedef struct { typedef struct {
Subtree *tree; Subtree *tree;
Edit edit; Edit edit;
@ -847,8 +847,8 @@ static const char *const ROOT_FIELD = "__ROOT__";
static size_t ts_subtree__write_to_string( static size_t ts_subtree__write_to_string(
Subtree self, char *string, size_t limit, Subtree self, char *string, size_t limit,
const TSLanguage *language, bool include_all, const t_language *language, bool include_all,
TSSymbol alias_symbol, bool alias_is_named, const char *field_name t_symbol alias_symbol, bool alias_is_named, const char *field_name
) { ) {
if (!self.ptr) return snprintf(string, limit, "(NULL)"); if (!self.ptr) return snprintf(string, limit, "(NULL)");
@ -876,7 +876,7 @@ static size_t ts_subtree__write_to_string(
cursor += snprintf(*writer, limit, "(UNEXPECTED "); cursor += snprintf(*writer, limit, "(UNEXPECTED ");
cursor += ts_subtree__write_char_to_string(*writer, limit, self.ptr->lookahead_char); cursor += ts_subtree__write_char_to_string(*writer, limit, self.ptr->lookahead_char);
} else { } else {
TSSymbol symbol = alias_symbol ? alias_symbol : ts_subtree_symbol(self); t_symbol symbol = alias_symbol ? alias_symbol : ts_subtree_symbol(self);
const char *symbol_name = ts_language_symbol_name(language, symbol); const char *symbol_name = ts_language_symbol_name(language, symbol);
if (ts_subtree_missing(self)) { if (ts_subtree_missing(self)) {
cursor += snprintf(*writer, limit, "(MISSING "); cursor += snprintf(*writer, limit, "(MISSING ");
@ -890,7 +890,7 @@ static size_t ts_subtree__write_to_string(
} }
} }
} else if (is_root) { } else if (is_root) {
TSSymbol symbol = alias_symbol ? alias_symbol : ts_subtree_symbol(self); t_symbol symbol = alias_symbol ? alias_symbol : ts_subtree_symbol(self);
const char *symbol_name = ts_language_symbol_name(language, symbol); const char *symbol_name = ts_language_symbol_name(language, symbol);
if (ts_subtree_child_count(self) > 0) { if (ts_subtree_child_count(self) > 0) {
cursor += snprintf(*writer, limit, "(%s", symbol_name); cursor += snprintf(*writer, limit, "(%s", symbol_name);
@ -902,7 +902,7 @@ static size_t ts_subtree__write_to_string(
} }
if (ts_subtree_child_count(self)) { if (ts_subtree_child_count(self)) {
const TSSymbol *alias_sequence = ts_language_alias_sequence(language, self.ptr->production_id); const t_symbol *alias_sequence = ts_language_alias_sequence(language, self.ptr->production_id);
const TSFieldMapEntry *field_map, *field_map_end; const TSFieldMapEntry *field_map, *field_map_end;
ts_language_field_map( ts_language_field_map(
language, language,
@ -921,7 +921,7 @@ static size_t ts_subtree__write_to_string(
0, false, NULL 0, false, NULL
); );
} else { } else {
TSSymbol subtree_alias_symbol = alias_sequence t_symbol subtree_alias_symbol = alias_sequence
? alias_sequence[structural_child_index] ? alias_sequence[structural_child_index]
: 0; : 0;
bool subtree_alias_is_named = subtree_alias_symbol bool subtree_alias_is_named = subtree_alias_symbol
@ -953,9 +953,9 @@ static size_t ts_subtree__write_to_string(
char *ts_subtree_string( char *ts_subtree_string(
Subtree self, Subtree self,
TSSymbol alias_symbol, t_symbol alias_symbol,
bool alias_is_named, bool alias_is_named,
const TSLanguage *language, const t_language *language,
bool include_all bool include_all
) { ) {
char scratch_string[1]; char scratch_string[1];
@ -974,10 +974,10 @@ char *ts_subtree_string(
} }
void ts_subtree__print_dot_graph(const Subtree *self, uint32_t start_offset, void ts_subtree__print_dot_graph(const Subtree *self, uint32_t start_offset,
const TSLanguage *language, TSSymbol alias_symbol, const t_language *language, t_symbol alias_symbol,
FILE *f) { FILE *f) {
TSSymbol subtree_symbol = ts_subtree_symbol(*self); t_symbol subtree_symbol = ts_subtree_symbol(*self);
TSSymbol symbol = alias_symbol ? alias_symbol : subtree_symbol; t_symbol symbol = alias_symbol ? alias_symbol : subtree_symbol;
uint32_t end_offset = start_offset + ts_subtree_total_bytes(*self); uint32_t end_offset = start_offset + ts_subtree_total_bytes(*self);
fprintf(f, "tree_%p [label=\"", (void *)self); fprintf(f, "tree_%p [label=\"", (void *)self);
ts_language_write_symbol_as_dot_string(language, f, symbol); ts_language_write_symbol_as_dot_string(language, f, symbol);
@ -1017,7 +1017,7 @@ void ts_subtree__print_dot_graph(const Subtree *self, uint32_t start_offset,
ts_subtree_production_id(*self); ts_subtree_production_id(*self);
for (uint32_t i = 0, n = ts_subtree_child_count(*self); i < n; i++) { for (uint32_t i = 0, n = ts_subtree_child_count(*self); i < n; i++) {
const Subtree *child = &ts_subtree_children(*self)[i]; const Subtree *child = &ts_subtree_children(*self)[i];
TSSymbol subtree_alias_symbol = 0; t_symbol subtree_alias_symbol = 0;
if (!ts_subtree_extra(*child) && child_info_offset) { if (!ts_subtree_extra(*child) && child_info_offset) {
subtree_alias_symbol = language->alias_sequences[child_info_offset]; subtree_alias_symbol = language->alias_sequences[child_info_offset];
child_info_offset++; child_info_offset++;
@ -1028,7 +1028,7 @@ void ts_subtree__print_dot_graph(const Subtree *self, uint32_t start_offset,
} }
} }
void ts_subtree_print_dot_graph(Subtree self, const TSLanguage *language, FILE *f) { void ts_subtree_print_dot_graph(Subtree self, const t_language *language, FILE *f) {
fprintf(f, "digraph tree {\n"); fprintf(f, "digraph tree {\n");
fprintf(f, "edge [arrowhead=none]\n"); fprintf(f, "edge [arrowhead=none]\n");
ts_subtree__print_dot_graph(&self, 0, language, 0, f); ts_subtree__print_dot_graph(&self, 0, language, 0, f);

View file

@ -115,8 +115,8 @@ typedef struct {
uint32_t lookahead_bytes; uint32_t lookahead_bytes;
uint32_t error_cost; uint32_t error_cost;
uint32_t child_count; uint32_t child_count;
TSSymbol symbol; t_symbol symbol;
TSStateId parse_state; t_state_id parse_state;
bool visible : 1; bool visible : 1;
bool named : 1; bool named : 1;
@ -140,8 +140,8 @@ typedef struct {
uint16_t repeat_depth; uint16_t repeat_depth;
uint16_t production_id; uint16_t production_id;
struct { struct {
TSSymbol symbol; t_symbol symbol;
TSStateId parse_state; t_state_id parse_state;
} first_leaf; } first_leaf;
}; };
@ -188,40 +188,40 @@ SubtreePool ts_subtree_pool_new(uint32_t capacity);
void ts_subtree_pool_delete(SubtreePool *); void ts_subtree_pool_delete(SubtreePool *);
Subtree ts_subtree_new_leaf( Subtree ts_subtree_new_leaf(
SubtreePool *, TSSymbol, Length, Length, uint32_t, SubtreePool *, t_symbol, Length, Length, uint32_t,
TSStateId, bool, bool, bool, const TSLanguage * t_state_id, bool, bool, bool, const t_language *
); );
Subtree ts_subtree_new_error( Subtree ts_subtree_new_error(
SubtreePool *, int32_t, Length, Length, uint32_t, TSStateId, const TSLanguage * SubtreePool *, int32_t, Length, Length, uint32_t, t_state_id, const t_language *
); );
MutableSubtree ts_subtree_new_node(TSSymbol, SubtreeArray *, unsigned, const TSLanguage *); MutableSubtree ts_subtree_new_node(t_symbol, SubtreeArray *, unsigned, const t_language *);
Subtree ts_subtree_new_error_node(SubtreeArray *, bool, const TSLanguage *); Subtree ts_subtree_new_error_node(SubtreeArray *, bool, const t_language *);
Subtree ts_subtree_new_missing_leaf(SubtreePool *, TSSymbol, Length, uint32_t, const TSLanguage *); Subtree ts_subtree_new_missing_leaf(SubtreePool *, t_symbol, Length, uint32_t, const t_language *);
MutableSubtree ts_subtree_make_mut(SubtreePool *, Subtree); MutableSubtree ts_subtree_make_mut(SubtreePool *, Subtree);
void ts_subtree_retain(Subtree); void ts_subtree_retain(Subtree);
void ts_subtree_release(SubtreePool *, Subtree); void ts_subtree_release(SubtreePool *, Subtree);
int ts_subtree_compare(Subtree, Subtree, SubtreePool *); int ts_subtree_compare(Subtree, Subtree, SubtreePool *);
void ts_subtree_set_symbol(MutableSubtree *, TSSymbol, const TSLanguage *); void ts_subtree_set_symbol(MutableSubtree *, t_symbol, const t_language *);
void ts_subtree_summarize(MutableSubtree, const Subtree *, uint32_t, const TSLanguage *); void ts_subtree_summarize(MutableSubtree, const Subtree *, uint32_t, const t_language *);
void ts_subtree_summarize_children(MutableSubtree, const TSLanguage *); void ts_subtree_summarize_children(MutableSubtree, const t_language *);
void ts_subtree_balance(Subtree, SubtreePool *, const TSLanguage *); void ts_subtree_balance(Subtree, SubtreePool *, const t_language *);
Subtree ts_subtree_edit(Subtree, const TSInputEdit *edit, SubtreePool *); Subtree ts_subtree_edit(Subtree, const t_input_edit *edit, SubtreePool *);
char *ts_subtree_string(Subtree, TSSymbol, bool, const TSLanguage *, bool include_all); char *ts_subtree_string(Subtree, t_symbol, bool, const t_language *, bool include_all);
void ts_subtree_print_dot_graph(Subtree, const TSLanguage *, FILE *); void ts_subtree_print_dot_graph(Subtree, const t_language *, FILE *);
Subtree ts_subtree_last_external_token(Subtree); Subtree ts_subtree_last_external_token(Subtree);
const ExternalScannerState *ts_subtree_external_scanner_state(Subtree self); const ExternalScannerState *ts_subtree_external_scanner_state(Subtree self);
bool ts_subtree_external_scanner_state_eq(Subtree, Subtree); bool ts_subtree_external_scanner_state_eq(Subtree, Subtree);
#define SUBTREE_GET(self, name) ((self).data.is_inline ? (self).data.name : (self).ptr->name) #define SUBTREE_GET(self, name) ((self).data.is_inline ? (self).data.name : (self).ptr->name)
static inline TSSymbol ts_subtree_symbol(Subtree self) { return SUBTREE_GET(self, symbol); } static inline t_symbol ts_subtree_symbol(Subtree self) { return SUBTREE_GET(self, symbol); }
static inline bool ts_subtree_visible(Subtree self) { return SUBTREE_GET(self, visible); } static inline bool ts_subtree_visible(Subtree self) { return SUBTREE_GET(self, visible); }
static inline bool ts_subtree_named(Subtree self) { return SUBTREE_GET(self, named); } static inline bool ts_subtree_named(Subtree self) { return SUBTREE_GET(self, named); }
static inline bool ts_subtree_extra(Subtree self) { return SUBTREE_GET(self, extra); } static inline bool ts_subtree_extra(Subtree self) { return SUBTREE_GET(self, extra); }
static inline bool ts_subtree_has_changes(Subtree self) { return SUBTREE_GET(self, has_changes); } static inline bool ts_subtree_has_changes(Subtree self) { return SUBTREE_GET(self, has_changes); }
static inline bool ts_subtree_missing(Subtree self) { return SUBTREE_GET(self, is_missing); } static inline bool ts_subtree_missing(Subtree self) { return SUBTREE_GET(self, is_missing); }
static inline bool ts_subtree_is_keyword(Subtree self) { return SUBTREE_GET(self, is_keyword); } static inline bool ts_subtree_is_keyword(Subtree self) { return SUBTREE_GET(self, is_keyword); }
static inline TSStateId ts_subtree_parse_state(Subtree self) { return SUBTREE_GET(self, parse_state); } static inline t_state_id ts_subtree_parse_state(Subtree self) { return SUBTREE_GET(self, parse_state); }
static inline uint32_t ts_subtree_lookahead_bytes(Subtree self) { return SUBTREE_GET(self, lookahead_bytes); } static inline uint32_t ts_subtree_lookahead_bytes(Subtree self) { return SUBTREE_GET(self, lookahead_bytes); }
#undef SUBTREE_GET #undef SUBTREE_GET
@ -245,13 +245,13 @@ static inline void ts_subtree_set_extra(MutableSubtree *self, bool is_extra) {
} }
} }
static inline TSSymbol ts_subtree_leaf_symbol(Subtree self) { static inline t_symbol ts_subtree_leaf_symbol(Subtree self) {
if (self.data.is_inline) return self.data.symbol; if (self.data.is_inline) return self.data.symbol;
if (self.ptr->child_count == 0) return self.ptr->symbol; if (self.ptr->child_count == 0) return self.ptr->symbol;
return self.ptr->first_leaf.symbol; return self.ptr->first_leaf.symbol;
} }
static inline TSStateId ts_subtree_leaf_parse_state(Subtree self) { static inline t_state_id ts_subtree_leaf_parse_state(Subtree self) {
if (self.data.is_inline) return self.data.parse_state; if (self.data.is_inline) return self.data.parse_state;
if (self.ptr->child_count == 0) return self.ptr->parse_state; if (self.ptr->child_count == 0) return self.ptr->parse_state;
return self.ptr->first_leaf.parse_state; return self.ptr->first_leaf.parse_state;

View file

@ -8,25 +8,25 @@
#include "./tree_cursor.h" #include "./tree_cursor.h"
#include "./tree.h" #include "./tree.h"
TSTree *ts_tree_new( t_tree *ts_tree_new(
Subtree root, const TSLanguage *language, Subtree root, const t_language *language,
const TSRange *included_ranges, unsigned included_range_count const t_range *included_ranges, unsigned included_range_count
) { ) {
TSTree *result = ts_malloc(sizeof(TSTree)); t_tree *result = ts_malloc(sizeof(t_tree));
result->root = root; result->root = root;
result->language = ts_language_copy(language); result->language = ts_language_copy(language);
result->included_ranges = ts_calloc(included_range_count, sizeof(TSRange)); result->included_ranges = ts_calloc(included_range_count, sizeof(t_range));
memcpy(result->included_ranges, included_ranges, included_range_count * sizeof(TSRange)); memcpy(result->included_ranges, included_ranges, included_range_count * sizeof(t_range));
result->included_range_count = included_range_count; result->included_range_count = included_range_count;
return result; return result;
} }
TSTree *ts_tree_copy(const TSTree *self) { t_tree *ts_tree_copy(const t_tree *self) {
ts_subtree_retain(self->root); ts_subtree_retain(self->root);
return ts_tree_new(self->root, self->language, self->included_ranges, self->included_range_count); return ts_tree_new(self->root, self->language, self->included_ranges, self->included_range_count);
} }
void ts_tree_delete(TSTree *self) { void ts_tree_delete(t_tree *self) {
if (!self) return; if (!self) return;
SubtreePool pool = ts_subtree_pool_new(0); SubtreePool pool = ts_subtree_pool_new(0);
@ -37,26 +37,26 @@ void ts_tree_delete(TSTree *self) {
ts_free(self); ts_free(self);
} }
TSNode ts_tree_root_node(const TSTree *self) { t_parse_node ts_tree_root_node(const t_tree *self) {
return ts_node_new(self, &self->root, ts_subtree_padding(self->root), 0); return ts_node_new(self, &self->root, ts_subtree_padding(self->root), 0);
} }
TSNode ts_tree_root_node_with_offset( t_parse_node ts_tree_root_node_with_offset(
const TSTree *self, const t_tree *self,
uint32_t offset_bytes, uint32_t offset_bytes,
TSPoint offset_extent t_point offset_extent
) { ) {
Length offset = {offset_bytes, offset_extent}; Length offset = {offset_bytes, offset_extent};
return ts_node_new(self, &self->root, length_add(offset, ts_subtree_padding(self->root)), 0); return ts_node_new(self, &self->root, length_add(offset, ts_subtree_padding(self->root)), 0);
} }
const TSLanguage *ts_tree_language(const TSTree *self) { const t_language *ts_tree_language(const t_tree *self) {
return self->language; return self->language;
} }
void ts_tree_edit(TSTree *self, const TSInputEdit *edit) { void ts_tree_edit(t_tree *self, const t_input_edit *edit) {
for (unsigned i = 0; i < self->included_range_count; i++) { for (unsigned i = 0; i < self->included_range_count; i++) {
TSRange *range = &self->included_ranges[i]; t_range *range = &self->included_ranges[i];
if (range->end_byte >= edit->old_end_byte) { if (range->end_byte >= edit->old_end_byte) {
if (range->end_byte != UINT32_MAX) { if (range->end_byte != UINT32_MAX) {
range->end_byte = edit->new_end_byte + (range->end_byte - edit->old_end_byte); range->end_byte = edit->new_end_byte + (range->end_byte - edit->old_end_byte);
@ -94,14 +94,14 @@ void ts_tree_edit(TSTree *self, const TSInputEdit *edit) {
ts_subtree_pool_delete(&pool); ts_subtree_pool_delete(&pool);
} }
TSRange *ts_tree_included_ranges(const TSTree *self, uint32_t *length) { t_range *ts_tree_included_ranges(const t_tree *self, uint32_t *length) {
*length = self->included_range_count; *length = self->included_range_count;
TSRange *ranges = ts_calloc(self->included_range_count, sizeof(TSRange)); t_range *ranges = ts_calloc(self->included_range_count, sizeof(t_range));
memcpy(ranges, self->included_ranges, self->included_range_count * sizeof(TSRange)); memcpy(ranges, self->included_ranges, self->included_range_count * sizeof(t_range));
return ranges; return ranges;
} }
TSRange *ts_tree_get_changed_ranges(const TSTree *old_tree, const TSTree *new_tree, uint32_t *length) { t_range *ts_tree_get_changed_ranges(const t_tree *old_tree, const t_tree *new_tree, uint32_t *length) {
TreeCursor cursor1 = {NULL, array_new(), 0}; TreeCursor cursor1 = {NULL, array_new(), 0};
TreeCursor cursor2 = {NULL, array_new(), 0}; TreeCursor cursor2 = {NULL, array_new(), 0};
ts_tree_cursor_init(&cursor1, ts_tree_root_node(old_tree)); ts_tree_cursor_init(&cursor1, ts_tree_root_node(old_tree));
@ -114,7 +114,7 @@ TSRange *ts_tree_get_changed_ranges(const TSTree *old_tree, const TSTree *new_tr
&included_range_differences &included_range_differences
); );
TSRange *result; t_range *result;
*length = ts_subtree_get_changed_ranges( *length = ts_subtree_get_changed_ranges(
&old_tree->root, &new_tree->root, &cursor1, &cursor2, &old_tree->root, &new_tree->root, &cursor1, &cursor2,
old_tree->language, &included_range_differences, &result old_tree->language, &included_range_differences, &result
@ -156,7 +156,7 @@ int _ts_dup(int file_descriptor) {
return dup(file_descriptor); return dup(file_descriptor);
} }
void ts_tree_print_dot_graph(const TSTree *self, int file_descriptor) { void ts_tree_print_dot_graph(const t_tree *self, int file_descriptor) {
FILE *file = fdopen(_ts_dup(file_descriptor), "a"); FILE *file = fdopen(_ts_dup(file_descriptor), "a");
ts_subtree_print_dot_graph(self->root, self->language, file); ts_subtree_print_dot_graph(self->root, self->language, file);
fclose(file); fclose(file);

View file

@ -11,18 +11,18 @@ typedef struct {
const Subtree *child; const Subtree *child;
const Subtree *parent; const Subtree *parent;
Length position; Length position;
TSSymbol alias_symbol; t_symbol alias_symbol;
} ParentCacheEntry; } ParentCacheEntry;
struct TSTree { struct t_tree {
Subtree root; Subtree root;
const TSLanguage *language; const t_language *language;
TSRange *included_ranges; t_range *included_ranges;
unsigned included_range_count; unsigned included_range_count;
}; };
TSTree *ts_tree_new(Subtree root, const TSLanguage *language, const TSRange *, unsigned); t_tree *ts_tree_new(Subtree root, const t_language *language, const t_range *, unsigned);
TSNode ts_node_new(const TSTree *, const Subtree *, Length, TSSymbol); t_parse_node ts_node_new(const t_tree *, const Subtree *, Length, t_symbol);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -6,12 +6,12 @@
typedef struct { typedef struct {
Subtree parent; Subtree parent;
const TSTree *tree; const t_tree *tree;
Length position; Length position;
uint32_t child_index; uint32_t child_index;
uint32_t structural_child_index; uint32_t structural_child_index;
uint32_t descendant_index; uint32_t descendant_index;
const TSSymbol *alias_sequence; const t_symbol *alias_sequence;
} CursorChildIterator; } CursorChildIterator;
// CursorChildIterator // CursorChildIterator
@ -37,7 +37,7 @@ static inline CursorChildIterator ts_tree_cursor_iterate_children(const TreeCurs
if (ts_subtree_child_count(*last_entry->subtree) == 0) { if (ts_subtree_child_count(*last_entry->subtree) == 0) {
return (CursorChildIterator) {NULL_SUBTREE, self->tree, length_zero(), 0, 0, 0, NULL}; return (CursorChildIterator) {NULL_SUBTREE, self->tree, length_zero(), 0, 0, 0, NULL};
} }
const TSSymbol *alias_sequence = ts_language_alias_sequence( const t_symbol *alias_sequence = ts_language_alias_sequence(
self->tree->language, self->tree->language,
last_entry->subtree->ptr->production_id last_entry->subtree->ptr->production_id
); );
@ -150,17 +150,17 @@ static inline bool ts_tree_cursor_child_iterator_previous(
// TSTreeCursor - lifecycle // TSTreeCursor - lifecycle
TSTreeCursor ts_tree_cursor_new(TSNode node) { t_tree_cursor ts_tree_cursor_new(t_parse_node node) {
TSTreeCursor self = {NULL, NULL, {0, 0, 0}}; t_tree_cursor self = {NULL, NULL, {0, 0, 0}};
ts_tree_cursor_init((TreeCursor *)&self, node); ts_tree_cursor_init((TreeCursor *)&self, node);
return self; return self;
} }
void ts_tree_cursor_reset(TSTreeCursor *_self, TSNode node) { void ts_tree_cursor_reset(t_tree_cursor *_self, t_parse_node node) {
ts_tree_cursor_init((TreeCursor *)_self, node); ts_tree_cursor_init((TreeCursor *)_self, node);
} }
void ts_tree_cursor_init(TreeCursor *self, TSNode node) { void ts_tree_cursor_init(TreeCursor *self, t_parse_node node) {
self->tree = node.tree; self->tree = node.tree;
self->root_alias_symbol = node.context[3]; self->root_alias_symbol = node.context[3];
array_clear(&self->stack); array_clear(&self->stack);
@ -176,14 +176,14 @@ void ts_tree_cursor_init(TreeCursor *self, TSNode node) {
})); }));
} }
void ts_tree_cursor_delete(TSTreeCursor *_self) { void ts_tree_cursor_delete(t_tree_cursor *_self) {
TreeCursor *self = (TreeCursor *)_self; TreeCursor *self = (TreeCursor *)_self;
array_delete(&self->stack); array_delete(&self->stack);
} }
// TSTreeCursor - walking the tree // TSTreeCursor - walking the tree
TreeCursorStep ts_tree_cursor_goto_first_child_internal(TSTreeCursor *_self) { TreeCursorStep ts_tree_cursor_goto_first_child_internal(t_tree_cursor *_self) {
TreeCursor *self = (TreeCursor *)_self; TreeCursor *self = (TreeCursor *)_self;
bool visible; bool visible;
TreeCursorEntry entry; TreeCursorEntry entry;
@ -201,7 +201,7 @@ TreeCursorStep ts_tree_cursor_goto_first_child_internal(TSTreeCursor *_self) {
return TreeCursorStepNone; return TreeCursorStepNone;
} }
bool ts_tree_cursor_goto_first_child(TSTreeCursor *self) { bool ts_tree_cursor_goto_first_child(t_tree_cursor *self) {
for (;;) { for (;;) {
switch (ts_tree_cursor_goto_first_child_internal(self)) { switch (ts_tree_cursor_goto_first_child_internal(self)) {
case TreeCursorStepHidden: case TreeCursorStepHidden:
@ -215,7 +215,7 @@ bool ts_tree_cursor_goto_first_child(TSTreeCursor *self) {
return false; return false;
} }
TreeCursorStep ts_tree_cursor_goto_last_child_internal(TSTreeCursor *_self) { TreeCursorStep ts_tree_cursor_goto_last_child_internal(t_tree_cursor *_self) {
TreeCursor *self = (TreeCursor *)_self; TreeCursor *self = (TreeCursor *)_self;
bool visible; bool visible;
TreeCursorEntry entry; TreeCursorEntry entry;
@ -242,7 +242,7 @@ TreeCursorStep ts_tree_cursor_goto_last_child_internal(TSTreeCursor *_self) {
return TreeCursorStepNone; return TreeCursorStepNone;
} }
bool ts_tree_cursor_goto_last_child(TSTreeCursor *self) { bool ts_tree_cursor_goto_last_child(t_tree_cursor *self) {
for (;;) { for (;;) {
switch (ts_tree_cursor_goto_last_child_internal(self)) { switch (ts_tree_cursor_goto_last_child_internal(self)) {
case TreeCursorStepHidden: case TreeCursorStepHidden:
@ -257,9 +257,9 @@ bool ts_tree_cursor_goto_last_child(TSTreeCursor *self) {
} }
static inline int64_t ts_tree_cursor_goto_first_child_for_byte_and_point( static inline int64_t ts_tree_cursor_goto_first_child_for_byte_and_point(
TSTreeCursor *_self, t_tree_cursor *_self,
uint32_t goal_byte, uint32_t goal_byte,
TSPoint goal_point t_point goal_point
) { ) {
TreeCursor *self = (TreeCursor *)_self; TreeCursor *self = (TreeCursor *)_self;
uint32_t initial_size = self->stack.size; uint32_t initial_size = self->stack.size;
@ -298,16 +298,16 @@ static inline int64_t ts_tree_cursor_goto_first_child_for_byte_and_point(
return -1; return -1;
} }
int64_t ts_tree_cursor_goto_first_child_for_byte(TSTreeCursor *self, uint32_t goal_byte) { int64_t ts_tree_cursor_goto_first_child_for_byte(t_tree_cursor *self, uint32_t goal_byte) {
return ts_tree_cursor_goto_first_child_for_byte_and_point(self, goal_byte, POINT_ZERO); return ts_tree_cursor_goto_first_child_for_byte_and_point(self, goal_byte, POINT_ZERO);
} }
int64_t ts_tree_cursor_goto_first_child_for_point(TSTreeCursor *self, TSPoint goal_point) { int64_t ts_tree_cursor_goto_first_child_for_point(t_tree_cursor *self, t_point goal_point) {
return ts_tree_cursor_goto_first_child_for_byte_and_point(self, 0, goal_point); return ts_tree_cursor_goto_first_child_for_byte_and_point(self, 0, goal_point);
} }
TreeCursorStep ts_tree_cursor_goto_sibling_internal( TreeCursorStep ts_tree_cursor_goto_sibling_internal(
TSTreeCursor *_self, t_tree_cursor *_self,
bool (*advance)(CursorChildIterator *, TreeCursorEntry *, bool *)) { bool (*advance)(CursorChildIterator *, TreeCursorEntry *, bool *)) {
TreeCursor *self = (TreeCursor *)_self; TreeCursor *self = (TreeCursor *)_self;
uint32_t initial_size = self->stack.size; uint32_t initial_size = self->stack.size;
@ -341,11 +341,11 @@ TreeCursorStep ts_tree_cursor_goto_sibling_internal(
return TreeCursorStepNone; return TreeCursorStepNone;
} }
TreeCursorStep ts_tree_cursor_goto_next_sibling_internal(TSTreeCursor *_self) { TreeCursorStep ts_tree_cursor_goto_next_sibling_internal(t_tree_cursor *_self) {
return ts_tree_cursor_goto_sibling_internal(_self, ts_tree_cursor_child_iterator_next); return ts_tree_cursor_goto_sibling_internal(_self, ts_tree_cursor_child_iterator_next);
} }
bool ts_tree_cursor_goto_next_sibling(TSTreeCursor *self) { bool ts_tree_cursor_goto_next_sibling(t_tree_cursor *self) {
switch (ts_tree_cursor_goto_next_sibling_internal(self)) { switch (ts_tree_cursor_goto_next_sibling_internal(self)) {
case TreeCursorStepHidden: case TreeCursorStepHidden:
ts_tree_cursor_goto_first_child(self); ts_tree_cursor_goto_first_child(self);
@ -357,7 +357,7 @@ bool ts_tree_cursor_goto_next_sibling(TSTreeCursor *self) {
} }
} }
TreeCursorStep ts_tree_cursor_goto_previous_sibling_internal(TSTreeCursor *_self) { TreeCursorStep ts_tree_cursor_goto_previous_sibling_internal(t_tree_cursor *_self) {
// since subtracting across row loses column information, we may have to // since subtracting across row loses column information, we may have to
// restore it // restore it
TreeCursor *self = (TreeCursor *)_self; TreeCursor *self = (TreeCursor *)_self;
@ -392,7 +392,7 @@ TreeCursorStep ts_tree_cursor_goto_previous_sibling_internal(TSTreeCursor *_self
return step; return step;
} }
bool ts_tree_cursor_goto_previous_sibling(TSTreeCursor *self) { bool ts_tree_cursor_goto_previous_sibling(t_tree_cursor *self) {
switch (ts_tree_cursor_goto_previous_sibling_internal(self)) { switch (ts_tree_cursor_goto_previous_sibling_internal(self)) {
case TreeCursorStepHidden: case TreeCursorStepHidden:
ts_tree_cursor_goto_last_child(self); ts_tree_cursor_goto_last_child(self);
@ -404,7 +404,7 @@ bool ts_tree_cursor_goto_previous_sibling(TSTreeCursor *self) {
} }
} }
bool ts_tree_cursor_goto_parent(TSTreeCursor *_self) { bool ts_tree_cursor_goto_parent(t_tree_cursor *_self) {
TreeCursor *self = (TreeCursor *)_self; TreeCursor *self = (TreeCursor *)_self;
for (unsigned i = self->stack.size - 2; i + 1 > 0; i--) { for (unsigned i = self->stack.size - 2; i + 1 > 0; i--) {
if (ts_tree_cursor_is_entry_visible(self, i)) { if (ts_tree_cursor_is_entry_visible(self, i)) {
@ -416,7 +416,7 @@ bool ts_tree_cursor_goto_parent(TSTreeCursor *_self) {
} }
void ts_tree_cursor_goto_descendant( void ts_tree_cursor_goto_descendant(
TSTreeCursor *_self, t_tree_cursor *_self,
uint32_t goal_descendant_index uint32_t goal_descendant_index
) { ) {
TreeCursor *self = (TreeCursor *)_self; TreeCursor *self = (TreeCursor *)_self;
@ -466,16 +466,16 @@ void ts_tree_cursor_goto_descendant(
} while (did_descend); } while (did_descend);
} }
uint32_t ts_tree_cursor_current_descendant_index(const TSTreeCursor *_self) { uint32_t ts_tree_cursor_current_descendant_index(const t_tree_cursor *_self) {
const TreeCursor *self = (const TreeCursor *)_self; const TreeCursor *self = (const TreeCursor *)_self;
TreeCursorEntry *last_entry = array_back(&self->stack); TreeCursorEntry *last_entry = array_back(&self->stack);
return last_entry->descendant_index; return last_entry->descendant_index;
} }
TSNode ts_tree_cursor_current_node(const TSTreeCursor *_self) { t_parse_node ts_tree_cursor_current_node(const t_tree_cursor *_self) {
const TreeCursor *self = (const TreeCursor *)_self; const TreeCursor *self = (const TreeCursor *)_self;
TreeCursorEntry *last_entry = array_back(&self->stack); TreeCursorEntry *last_entry = array_back(&self->stack);
TSSymbol alias_symbol = self->root_alias_symbol; t_symbol alias_symbol = self->root_alias_symbol;
if (self->stack.size > 1 && !ts_subtree_extra(*last_entry->subtree)) { if (self->stack.size > 1 && !ts_subtree_extra(*last_entry->subtree)) {
TreeCursorEntry *parent_entry = &self->stack.contents[self->stack.size - 2]; TreeCursorEntry *parent_entry = &self->stack.contents[self->stack.size - 2];
alias_symbol = ts_language_alias_at( alias_symbol = ts_language_alias_at(
@ -495,12 +495,12 @@ TSNode ts_tree_cursor_current_node(const TSTreeCursor *_self) {
// Private - Get various facts about the current node that are needed // Private - Get various facts about the current node that are needed
// when executing tree queries. // when executing tree queries.
void ts_tree_cursor_current_status( void ts_tree_cursor_current_status(
const TSTreeCursor *_self, const t_tree_cursor *_self,
TSFieldId *field_id, t_field_id *field_id,
bool *has_later_siblings, bool *has_later_siblings,
bool *has_later_named_siblings, bool *has_later_named_siblings,
bool *can_have_later_siblings_with_this_field, bool *can_have_later_siblings_with_this_field,
TSSymbol *supertypes, t_symbol *supertypes,
unsigned *supertype_count unsigned *supertype_count
) { ) {
const TreeCursor *self = (const TreeCursor *)_self; const TreeCursor *self = (const TreeCursor *)_self;
@ -517,7 +517,7 @@ void ts_tree_cursor_current_status(
TreeCursorEntry *entry = &self->stack.contents[i]; TreeCursorEntry *entry = &self->stack.contents[i];
TreeCursorEntry *parent_entry = &self->stack.contents[i - 1]; TreeCursorEntry *parent_entry = &self->stack.contents[i - 1];
const TSSymbol *alias_sequence = ts_language_alias_sequence( const t_symbol *alias_sequence = ts_language_alias_sequence(
self->tree->language, self->tree->language,
parent_entry->subtree->ptr->production_id parent_entry->subtree->ptr->production_id
); );
@ -532,7 +532,7 @@ void ts_tree_cursor_current_status(
ts_subtree_symbol(subtree)) ts_subtree_symbol(subtree))
// Stop walking up when a visible ancestor is found. // Stop walking up when a visible ancestor is found.
TSSymbol entry_symbol = subtree_symbol( t_symbol entry_symbol = subtree_symbol(
*entry->subtree, *entry->subtree,
entry->structural_child_index entry->structural_child_index
); );
@ -614,7 +614,7 @@ void ts_tree_cursor_current_status(
} }
} }
uint32_t ts_tree_cursor_current_depth(const TSTreeCursor *_self) { uint32_t ts_tree_cursor_current_depth(const t_tree_cursor *_self) {
const TreeCursor *self = (const TreeCursor *)_self; const TreeCursor *self = (const TreeCursor *)_self;
uint32_t depth = 0; uint32_t depth = 0;
for (unsigned i = 1; i < self->stack.size; i++) { for (unsigned i = 1; i < self->stack.size; i++) {
@ -625,12 +625,12 @@ uint32_t ts_tree_cursor_current_depth(const TSTreeCursor *_self) {
return depth; return depth;
} }
TSNode ts_tree_cursor_parent_node(const TSTreeCursor *_self) { t_parse_node ts_tree_cursor_parent_node(const t_tree_cursor *_self) {
const TreeCursor *self = (const TreeCursor *)_self; const TreeCursor *self = (const TreeCursor *)_self;
for (int i = (int)self->stack.size - 2; i >= 0; i--) { for (int i = (int)self->stack.size - 2; i >= 0; i--) {
TreeCursorEntry *entry = &self->stack.contents[i]; TreeCursorEntry *entry = &self->stack.contents[i];
bool is_visible = true; bool is_visible = true;
TSSymbol alias_symbol = 0; t_symbol alias_symbol = 0;
if (i > 0) { if (i > 0) {
TreeCursorEntry *parent_entry = &self->stack.contents[i - 1]; TreeCursorEntry *parent_entry = &self->stack.contents[i - 1];
alias_symbol = ts_language_alias_at( alias_symbol = ts_language_alias_at(
@ -652,7 +652,7 @@ TSNode ts_tree_cursor_parent_node(const TSTreeCursor *_self) {
return ts_node_new(NULL, NULL, length_zero(), 0); return ts_node_new(NULL, NULL, length_zero(), 0);
} }
TSFieldId ts_tree_cursor_current_field_id(const TSTreeCursor *_self) { t_field_id ts_tree_cursor_current_field_id(const t_tree_cursor *_self) {
const TreeCursor *self = (const TreeCursor *)_self; const TreeCursor *self = (const TreeCursor *)_self;
// Walk up the tree, visiting the current node and its invisible ancestors. // Walk up the tree, visiting the current node and its invisible ancestors.
@ -683,8 +683,8 @@ TSFieldId ts_tree_cursor_current_field_id(const TSTreeCursor *_self) {
return 0; return 0;
} }
const char *ts_tree_cursor_current_field_name(const TSTreeCursor *_self) { const char *ts_tree_cursor_current_field_name(const t_tree_cursor *_self) {
TSFieldId id = ts_tree_cursor_current_field_id(_self); t_field_id id = ts_tree_cursor_current_field_id(_self);
if (id) { if (id) {
const TreeCursor *self = (const TreeCursor *)_self; const TreeCursor *self = (const TreeCursor *)_self;
return self->tree->language->field_names[id]; return self->tree->language->field_names[id];
@ -693,9 +693,9 @@ const char *ts_tree_cursor_current_field_name(const TSTreeCursor *_self) {
} }
} }
TSTreeCursor ts_tree_cursor_copy(const TSTreeCursor *_cursor) { t_tree_cursor ts_tree_cursor_copy(const t_tree_cursor *_cursor) {
const TreeCursor *cursor = (const TreeCursor *)_cursor; const TreeCursor *cursor = (const TreeCursor *)_cursor;
TSTreeCursor res = {NULL, NULL, {0, 0}}; t_tree_cursor res = {NULL, NULL, {0, 0}};
TreeCursor *copy = (TreeCursor *)&res; TreeCursor *copy = (TreeCursor *)&res;
copy->tree = cursor->tree; copy->tree = cursor->tree;
copy->root_alias_symbol = cursor->root_alias_symbol; copy->root_alias_symbol = cursor->root_alias_symbol;
@ -704,7 +704,7 @@ TSTreeCursor ts_tree_cursor_copy(const TSTreeCursor *_cursor) {
return res; return res;
} }
void ts_tree_cursor_reset_to(TSTreeCursor *_dst, const TSTreeCursor *_src) { void ts_tree_cursor_reset_to(t_tree_cursor *_dst, const t_tree_cursor *_src) {
const TreeCursor *cursor = (const TreeCursor *)_src; const TreeCursor *cursor = (const TreeCursor *)_src;
TreeCursor *copy = (TreeCursor *)_dst; TreeCursor *copy = (TreeCursor *)_dst;
copy->tree = cursor->tree; copy->tree = cursor->tree;

View file

@ -12,9 +12,9 @@ typedef struct {
} TreeCursorEntry; } TreeCursorEntry;
typedef struct { typedef struct {
const TSTree *tree; const t_tree *tree;
Array(TreeCursorEntry) stack; Array(TreeCursorEntry) stack;
TSSymbol root_alias_symbol; t_symbol root_alias_symbol;
} TreeCursor; } TreeCursor;
typedef enum { typedef enum {
@ -23,26 +23,26 @@ typedef enum {
TreeCursorStepVisible, TreeCursorStepVisible,
} TreeCursorStep; } TreeCursorStep;
void ts_tree_cursor_init(TreeCursor *, TSNode); void ts_tree_cursor_init(TreeCursor *, t_parse_node);
void ts_tree_cursor_current_status( void ts_tree_cursor_current_status(
const TSTreeCursor *, const t_tree_cursor *,
TSFieldId *, t_field_id *,
bool *, bool *,
bool *, bool *,
bool *, bool *,
TSSymbol *, t_symbol *,
unsigned * unsigned *
); );
TreeCursorStep ts_tree_cursor_goto_first_child_internal(TSTreeCursor *); TreeCursorStep ts_tree_cursor_goto_first_child_internal(t_tree_cursor *);
TreeCursorStep ts_tree_cursor_goto_next_sibling_internal(TSTreeCursor *); TreeCursorStep ts_tree_cursor_goto_next_sibling_internal(t_tree_cursor *);
static inline Subtree ts_tree_cursor_current_subtree(const TSTreeCursor *_self) { static inline Subtree ts_tree_cursor_current_subtree(const t_tree_cursor *_self) {
const TreeCursor *self = (const TreeCursor *)_self; const TreeCursor *self = (const TreeCursor *)_self;
TreeCursorEntry *last_entry = array_back(&self->stack); TreeCursorEntry *last_entry = array_back(&self->stack);
return *last_entry->subtree; return *last_entry->subtree;
} }
TSNode ts_tree_cursor_parent_node(const TSTreeCursor *); t_parse_node ts_tree_cursor_parent_node(const t_tree_cursor *);
#endif // TREE_SITTER_TREE_CURSOR_H_ #endif // TREE_SITTER_TREE_CURSOR_H_