Updated Makefile and parser/src

This commit is contained in:
Maix0 2024-08-17 23:40:16 +02:00
parent 6909456ce5
commit e47243c22c
11 changed files with 126 additions and 444 deletions

View file

@ -54,7 +54,7 @@ static struct ExternalScannerDefinition init_scanner(void)
});
}
static void init_language(TSLanguage *language)
/*R static R*/ void init_language(TSLanguage *language)
{
static uint32_t empty_map[] = {0, 0 ,0};
@ -80,7 +80,7 @@ static void init_language(TSLanguage *language)
const TSLanguage *tree_sitter_sh(void)
{
static bool init = false;
/*R static R*/ bool init = false;
static TSLanguage language = {
.version = LANGUAGE_VERSION,
.symbol_count = SYMBOL_COUNT,

View file

@ -1,7 +1,7 @@
#include "parser/language.h"
#include "me/types.h"
#include "parser/api.h"
#include "parser/parser.h"
#include "me/types.h"
#include <assert.h>
#include <string.h>
@ -308,4 +308,4 @@ void ts_language_aliases_for_symbol(const TSLanguage *self, TSSymbol original_sy
}
idx += count;
}
}
}

View file

@ -1,12 +1,10 @@
#include "parser/lexer.h"
#include "parser/length.h"
#include "parser/input.h"
#include "me/mem/mem.h"
#include "me/types.h"
#include "parser/input.h"
#include "parser/length.h"
#include <string.h>
#define LOG(...)
static const t_i32 BYTE_ORDER_MARK = 0xFEFF;
static const TSRange DEFAULT_RANGE = {.start_point =
@ -25,7 +23,7 @@ static const TSRange DEFAULT_RANGE = {.start_point =
// Check if the lexer has reached EOF. This state is stored
// by setting the lexer's `current_included_range_index` such that
// it has consumed all of its available ranges.
static bool ts_lexer__eof(const TSLexer *_self)
/*R static R*/ bool ts_lexer__eof(const TSLexer *_self)
{
Lexer *self = (Lexer *)_self;
return self->current_included_range_index == self->included_range_count;
@ -33,7 +31,7 @@ static bool ts_lexer__eof(const TSLexer *_self)
// Clear the currently stored chunk of source code, because the lexer's
// position has changed.
static void ts_lexer__clear_chunk(Lexer *self)
/*R static R*/ void ts_lexer__clear_chunk(Lexer *self)
{
self->chunk = NULL;
self->chunk_size = 0;
@ -42,7 +40,7 @@ static void ts_lexer__clear_chunk(Lexer *self)
// Call the lexer's input callback to obtain a new chunk of source code
// for the current position.
static void ts_lexer__get_chunk(Lexer *self)
/*R static R*/ void ts_lexer__get_chunk(Lexer *self)
{
self->chunk_start = self->current_position.bytes;
self->chunk = self->input.read(self->input.payload, self->current_position.bytes, self->current_position.extent, &self->chunk_size);
@ -56,7 +54,7 @@ static void ts_lexer__get_chunk(Lexer *self)
// Decode the next unicode character in the current chunk of source code.
// This assumes that the lexer has already retrieved a chunk of source
// code that spans the current position.
static void ts_lexer__get_lookahead(Lexer *self)
/*R static R*/ void ts_lexer__get_lookahead(Lexer *self)
{
t_u32 position_in_chunk = self->current_position.bytes - self->chunk_start;
t_u32 size = self->chunk_size - position_in_chunk;
@ -89,7 +87,7 @@ static void ts_lexer__get_lookahead(Lexer *self)
}
}
static void ts_lexer_goto(Lexer *self, Length position)
/*R static R*/ void ts_lexer_goto(Lexer *self, Length position)
{
self->current_position = position;
@ -145,7 +143,7 @@ static void ts_lexer_goto(Lexer *self, Length position)
}
// Intended to be called only from functions that control logging.
static void ts_lexer__do_advance(Lexer *self, bool skip)
/*R static R*/ void ts_lexer__do_advance(Lexer *self, bool skip)
{
if (self->lookahead_size)
{
@ -204,27 +202,17 @@ static void ts_lexer__do_advance(Lexer *self, bool skip)
// Advance to the next character in the source code, retrieving a new
// chunk of source code if needed.
static void ts_lexer__advance(TSLexer *_self, bool skip)
/*R static R*/ void ts_lexer__advance(TSLexer *_self, bool skip)
{
Lexer *self = (Lexer *)_self;
if (!self->chunk)
return;
if (skip)
{
LOG("skip", self->data.lookahead)
}
else
{
LOG("consume", self->data.lookahead)
}
ts_lexer__do_advance(self, skip);
}
// Mark that a token match has completed. This can be called multiple
// times if a longer match is found later.
static void ts_lexer__mark_end(TSLexer *_self)
/*R static R*/ void ts_lexer__mark_end(TSLexer *_self)
{
Lexer *self = (Lexer *)_self;
if (!ts_lexer__eof(&self->data))
@ -246,7 +234,7 @@ static void ts_lexer__mark_end(TSLexer *_self)
self->token_end_position = self->current_position;
}
static t_u32 ts_lexer__get_column(TSLexer *_self)
/*R static R*/ t_u32 ts_lexer__get_column(TSLexer *_self)
{
Lexer *self = (Lexer *)_self;
@ -280,7 +268,7 @@ static t_u32 ts_lexer__get_column(TSLexer *_self)
// Is the lexer at a boundary between two disjoint included ranges of
// source code? This is exposed as an API because some languages' external
// scanners need to perform custom actions at these boundaries.
static bool ts_lexer__is_at_included_range_start(const TSLexer *_self)
/*R static R*/ bool ts_lexer__is_at_included_range_start(const TSLexer *_self)
{
const Lexer *self = (const Lexer *)_self;
if (self->current_included_range_index < self->included_range_count)
@ -438,5 +426,3 @@ TSRange *ts_lexer_included_ranges(const Lexer *self, t_u32 *count)
*count = self->included_range_count;
return self->included_ranges;
}
#undef LOG

View file

@ -1,9 +1,9 @@
#include "me/types.h"
#include "parser/api.h"
#include "parser/language.h"
#include "parser/point.h"
#include "parser/subtree.h"
#include "parser/tree.h"
#include "parser/point.h"
#include "me/types.h"
typedef struct NodeChildIterator
{
@ -26,7 +26,7 @@ TSNode ts_node_new(const TSTree *tree, const Subtree *subtree, Length position,
};
}
static inline TSNode ts_node__null(void)
/*R static inline R*/ TSNode ts_node__null(void)
{
return ts_node_new(NULL, NULL, length_zero(), 0);
}
@ -43,19 +43,19 @@ TSPoint ts_node_start_point(TSNode self)
return (TSPoint){self.context[1], self.context[2]};
}
static inline t_u32 ts_node__alias(const TSNode *self)
/*R static inline R*/ t_u32 ts_node__alias(const TSNode *self)
{
return self->context[3];
}
static inline Subtree ts_node__subtree(TSNode self)
/*R static inline R*/ Subtree ts_node__subtree(TSNode self)
{
return *(const Subtree *)self.id;
}
// NodeChildIterator
static inline NodeChildIterator ts_node_iterate_children(const TSNode *node)
/*R static inline R*/ NodeChildIterator ts_node_iterate_children(const TSNode *node)
{
Subtree subtree = ts_node__subtree(*node);
if (ts_subtree_child_count(subtree) == 0)
@ -73,12 +73,12 @@ static inline NodeChildIterator ts_node_iterate_children(const TSNode *node)
};
}
static inline bool ts_node_child_iterator_done(NodeChildIterator *self)
/*R static inline R*/ bool ts_node_child_iterator_done(NodeChildIterator *self)
{
return self->child_index == self->parent.ptr->child_count;
}
static inline bool ts_node_child_iterator_next(NodeChildIterator *self, TSNode *result)
/*R static inline R*/ bool ts_node_child_iterator_next(NodeChildIterator *self, TSNode *result)
{
if (!self->parent.ptr || ts_node_child_iterator_done(self))
return false;
@ -106,7 +106,7 @@ static inline bool ts_node_child_iterator_next(NodeChildIterator *self, TSNode *
// TSNode - private
static inline bool ts_node__is_relevant(TSNode self, bool include_anonymous)
/*R static inline R*/ bool ts_node__is_relevant(TSNode self, bool include_anonymous)
{
Subtree tree = ts_node__subtree(self);
if (include_anonymous)
@ -127,7 +127,7 @@ static inline bool ts_node__is_relevant(TSNode self, bool include_anonymous)
}
}
static inline t_u32 ts_node__relevant_child_count(TSNode self, bool include_anonymous)
/*R static inline R*/ t_u32 ts_node__relevant_child_count(TSNode self, bool include_anonymous)
{
Subtree tree = ts_node__subtree(self);
if (ts_subtree_child_count(tree) > 0)
@ -147,7 +147,7 @@ static inline t_u32 ts_node__relevant_child_count(TSNode self, bool include_anon
}
}
static inline TSNode ts_node__child(TSNode self, t_u32 child_index, bool include_anonymous)
/*R static inline R*/ TSNode ts_node__child(TSNode self, t_u32 child_index, bool include_anonymous)
{
TSNode result = self;
bool did_descend = true;
@ -188,7 +188,7 @@ static inline TSNode ts_node__child(TSNode self, t_u32 child_index, bool include
return ts_node__null();
}
static bool ts_subtree_has_trailing_empty_descendant(Subtree self, Subtree other)
/*R static R*/ bool ts_subtree_has_trailing_empty_descendant(Subtree self, Subtree other)
{
for (t_u32 i = ts_subtree_child_count(self) - 1; i + 1 > 0; i--)
{
@ -203,7 +203,7 @@ static bool ts_subtree_has_trailing_empty_descendant(Subtree self, Subtree other
return false;
}
static inline TSNode ts_node__prev_sibling(TSNode self, bool include_anonymous)
/*R static inline R*/ TSNode ts_node__prev_sibling(TSNode self, bool include_anonymous)
{
Subtree self_subtree = ts_node__subtree(self);
bool self_is_empty = ts_subtree_total_bytes(self_subtree) == 0;
@ -282,7 +282,7 @@ static inline TSNode ts_node__prev_sibling(TSNode self, bool include_anonymous)
return ts_node__null();
}
static inline TSNode ts_node__next_sibling(TSNode self, bool include_anonymous)
/*R static inline R*/ TSNode ts_node__next_sibling(TSNode self, bool include_anonymous)
{
t_u32 target_end_byte = ts_node_end_byte(self);
@ -353,7 +353,7 @@ static inline TSNode ts_node__next_sibling(TSNode self, bool include_anonymous)
return ts_node__null();
}
static inline TSNode ts_node__first_child_for_byte(TSNode self, t_u32 goal, bool include_anonymous)
/*R static inline R*/ TSNode ts_node__first_child_for_byte(TSNode self, t_u32 goal, bool include_anonymous)
{
TSNode node = self;
bool did_descend = true;
@ -385,7 +385,7 @@ static inline TSNode ts_node__first_child_for_byte(TSNode self, t_u32 goal, bool
return ts_node__null();
}
static inline TSNode ts_node__descendant_for_byte_range(TSNode self, t_u32 range_start, t_u32 range_end, bool include_anonymous)
/*R static inline R*/ TSNode ts_node__descendant_for_byte_range(TSNode self, t_u32 range_start, t_u32 range_end, bool include_anonymous)
{
TSNode node = self;
TSNode last_visible_node = self;
@ -426,7 +426,7 @@ static inline TSNode ts_node__descendant_for_byte_range(TSNode self, t_u32 range
return last_visible_node;
}
static inline TSNode ts_node__descendant_for_point_range(TSNode self, TSPoint range_start, TSPoint range_end, bool include_anonymous)
/*R static inline R*/ TSNode ts_node__descendant_for_point_range(TSNode self, TSPoint range_start, TSPoint range_end, bool include_anonymous)
{
TSNode node = self;
TSNode last_visible_node = self;
@ -717,7 +717,7 @@ recur:
return ts_node__null();
}
static inline t_const_str ts_node__field_name_from_language(TSNode self, t_u32 structural_child_index)
/*R static inline R*/ t_const_str ts_node__field_name_from_language(TSNode self, t_u32 structural_child_index)
{
const TSFieldMapEntry *field_map, *field_map_end;
ts_language_field_map(self.tree->language, ts_node__subtree(self).ptr->production_id, &field_map, &field_map_end);
@ -807,84 +807,9 @@ t_u32 ts_node_named_child_count(TSNode self)
{
Subtree tree = ts_node__subtree(self);
if (ts_subtree_child_count(tree) > 0)
{
return tree.ptr->named_child_count;
}
else
{
return 0;
}
}
TSNode ts_node_next_sibling(TSNode self)
{
return ts_node__next_sibling(self, true);
}
TSNode ts_node_next_named_sibling(TSNode self)
{
return ts_node__next_sibling(self, false);
}
TSNode ts_node_prev_sibling(TSNode self)
{
return ts_node__prev_sibling(self, true);
}
TSNode ts_node_prev_named_sibling(TSNode self)
{
return ts_node__prev_sibling(self, false);
}
TSNode ts_node_first_child_for_byte(TSNode self, t_u32 byte)
{
return ts_node__first_child_for_byte(self, byte, true);
}
TSNode ts_node_first_named_child_for_byte(TSNode self, t_u32 byte)
{
return ts_node__first_child_for_byte(self, byte, false);
}
TSNode ts_node_descendant_for_byte_range(TSNode self, t_u32 start, t_u32 end)
{
return ts_node__descendant_for_byte_range(self, start, end, true);
}
TSNode ts_node_named_descendant_for_byte_range(TSNode self, t_u32 start, t_u32 end)
{
return ts_node__descendant_for_byte_range(self, start, end, false);
}
TSNode ts_node_descendant_for_point_range(TSNode self, TSPoint start, TSPoint end)
{
return ts_node__descendant_for_point_range(self, start, end, true);
}
TSNode ts_node_named_descendant_for_point_range(TSNode self, TSPoint start, TSPoint end)
{
return ts_node__descendant_for_point_range(self, start, end, false);
}
void ts_node_edit(TSNode *self, const TSInputEdit *edit)
{
t_u32 start_byte = ts_node_start_byte(*self);
TSPoint start_point = ts_node_start_point(*self);
if (start_byte >= edit->old_end_byte)
{
start_byte = edit->new_end_byte + (start_byte - edit->old_end_byte);
start_point = point_add(edit->new_end_point, point_sub(start_point, edit->old_end_point));
}
else if (start_byte > edit->start_byte)
{
start_byte = edit->new_end_byte;
start_point = edit->new_end_point;
}
self->context[0] = start_byte;
self->context[1] = start_point.row;
self->context[2] = start_point.column;
}
TSSymbol ts_node_field_id_for_child(TSNode self, t_u32 child_index)

View file

@ -81,7 +81,7 @@ typedef struct TSStringInput
// StringInput
static const t_u8 *ts_string_input_read(void *_self, t_u32 byte, TSPoint point, t_u32 *length)
/*R static R*/ const t_u8 *ts_string_input_read(void *_self, t_u32 byte, TSPoint point, t_u32 *length)
{
(void)point;
TSStringInput *self = (TSStringInput *)_self;
@ -98,28 +98,8 @@ static const t_u8 *ts_string_input_read(void *_self, t_u32 byte, TSPoint point,
}
// Parser - Private
/*
static void ts_parser__log(TSParser *self)
{
if (self->lexer.logger.log)
{
self->lexer.logger.log(self->lexer.logger.payload, TSLogTypeParse, self->lexer.debug_buffer);
}
if (self->dot_graph_file)
{
fprintf(self->dot_graph_file, "graph {\nlabel=\"");
for (char *chr = &self->lexer.debug_buffer[0]; *chr != 0; chr++)
{
if (*chr == '"' || *chr == '\\')
fputc('\\', self->dot_graph_file);
fputc(*chr, self->dot_graph_file);
}
fprintf(self->dot_graph_file, "\"\n}\n\n");
}
}
*/
static bool ts_parser__breakdown_top_of_stack(TSParser *self, StackVersion version)
/*R static R*/ bool ts_parser__breakdown_top_of_stack(TSParser *self, StackVersion version)
{
bool did_break_down = false;
bool pending = false;
@ -173,7 +153,7 @@ static bool ts_parser__breakdown_top_of_stack(TSParser *self, StackVersion versi
return did_break_down;
}
static ErrorComparison ts_parser__compare_versions(TSParser *self, ErrorStatus a, ErrorStatus b)
/*R static R*/ ErrorComparison ts_parser__compare_versions(TSParser *self, ErrorStatus a, ErrorStatus b)
{
(void)self;
if (!a.is_in_error && b.is_in_error)
@ -231,7 +211,7 @@ static ErrorComparison ts_parser__compare_versions(TSParser *self, ErrorStatus a
return ErrorComparisonNone;
}
static ErrorStatus ts_parser__version_status(TSParser *self, StackVersion version)
/*R static R*/ ErrorStatus ts_parser__version_status(TSParser *self, StackVersion version)
{
t_u32 cost = ts_stack_error_cost(self->stack, version);
bool is_paused = ts_stack_is_paused(self->stack, version);
@ -243,7 +223,7 @@ static ErrorStatus ts_parser__version_status(TSParser *self, StackVersion versio
.is_in_error = is_paused || ts_stack_state(self->stack, version) == ERROR_STATE};
}
static bool ts_parser__better_version_exists(TSParser *self, StackVersion version, bool is_in_error, t_u32 cost)
/*R static R*/ bool ts_parser__better_version_exists(TSParser *self, StackVersion version, bool is_in_error, t_u32 cost)
{
if (self->finished_tree.ptr && ts_subtree_error_cost(self->finished_tree) <= cost)
{
@ -279,19 +259,19 @@ static bool ts_parser__better_version_exists(TSParser *self, StackVersion versio
return false;
}
static bool ts_parser__call_main_lex_fn(TSParser *self, TSLexMode lex_mode)
/*R static R*/ bool ts_parser__call_main_lex_fn(TSParser *self, TSLexMode lex_mode)
{
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)
/*R static R*/ bool ts_parser__call_keyword_lex_fn(TSParser *self, TSLexMode lex_mode)
{
(void)(lex_mode);
return self->language->keyword_lex_fn(&self->lexer.data, 0);
}
static void ts_parser__external_scanner_create(TSParser *self)
/*R static R*/ void ts_parser__external_scanner_create(TSParser *self)
{
if (self->language && self->language->external_scanner.states)
{
@ -303,7 +283,7 @@ static void ts_parser__external_scanner_create(TSParser *self)
}
}
static void ts_parser__external_scanner_destroy(TSParser *self)
/*R static R*/ void ts_parser__external_scanner_destroy(TSParser *self)
{
if (self->language && self->external_scanner_payload && self->language->external_scanner.destroy)
{
@ -312,7 +292,7 @@ static void ts_parser__external_scanner_destroy(TSParser *self)
self->external_scanner_payload = NULL;
}
static t_u32 ts_parser__external_scanner_serialize(TSParser *self)
/*R static R*/ t_u32 ts_parser__external_scanner_serialize(TSParser *self)
{
t_u32 length = self->language->external_scanner.serialize(self->external_scanner_payload, self->lexer.debug_buffer);
@ -320,7 +300,7 @@ static t_u32 ts_parser__external_scanner_serialize(TSParser *self)
return length;
}
static void ts_parser__external_scanner_deserialize(TSParser *self, Subtree external_token)
/*R static R*/ void ts_parser__external_scanner_deserialize(TSParser *self, Subtree external_token)
{
const t_u8 *data = NULL;
t_u32 length = 0;
@ -333,13 +313,13 @@ static void ts_parser__external_scanner_deserialize(TSParser *self, Subtree exte
self->language->external_scanner.deserialize(self->external_scanner_payload, data, length);
}
static bool ts_parser__external_scanner_scan(TSParser *self, TSStateId external_lex_state)
/*R static R*/ bool ts_parser__external_scanner_scan(TSParser *self, TSStateId external_lex_state)
{
const bool *valid_external_tokens = ts_language_enabled_external_tokens(self->language, external_lex_state);
return self->language->external_scanner.scan(self->external_scanner_payload, &self->lexer.data, valid_external_tokens);
}
static bool ts_parser__can_reuse_first_leaf(TSParser *self, TSStateId state, Subtree tree, TableEntry *table_entry)
/*R static R*/ bool ts_parser__can_reuse_first_leaf(TSParser *self, TSStateId state, Subtree tree, TableEntry *table_entry)
{
TSLexMode current_lex_mode = self->language->lex_modes[state];
TSSymbol leaf_symbol = ts_subtree_leaf_symbol(tree);
@ -367,7 +347,7 @@ static bool ts_parser__can_reuse_first_leaf(TSParser *self, TSStateId state, Sub
return current_lex_mode.external_lex_state == 0 && table_entry->is_reusable;
}
static Subtree ts_parser__lex(TSParser *self, StackVersion version, TSStateId parse_state)
/*R static R*/ Subtree ts_parser__lex(TSParser *self, StackVersion version, TSStateId parse_state)
{
TSLexMode lex_mode = self->language->lex_modes[parse_state];
if (lex_mode.lex_state == (t_u16)-1)
@ -530,8 +510,8 @@ static Subtree ts_parser__lex(TSParser *self, StackVersion version, TSStateId pa
return result;
}
static Subtree ts_parser__get_cached_token(TSParser *self, TSStateId state, size_t position, Subtree last_external_token,
TableEntry *table_entry)
/*R static R*/ Subtree ts_parser__get_cached_token(TSParser *self, TSStateId state, size_t position, Subtree last_external_token,
TableEntry *table_entry)
{
TokenCache *cache = &self->token_cache;
if (cache->token.ptr && cache->byte_index == position &&
@ -547,7 +527,7 @@ static Subtree ts_parser__get_cached_token(TSParser *self, TSStateId state, size
return NULL_SUBTREE;
}
static void ts_parser__set_cached_token(TSParser *self, t_u32 byte_index, Subtree last_external_token, Subtree token)
/*R static R*/ void ts_parser__set_cached_token(TSParser *self, t_u32 byte_index, Subtree last_external_token, Subtree token)
{
TokenCache *cache = &self->token_cache;
if (token.ptr)
@ -567,7 +547,7 @@ static void ts_parser__set_cached_token(TSParser *self, t_u32 byte_index, Subtre
//
// 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.
static bool ts_parser__select_tree(TSParser *self, Subtree left, Subtree right)
/*R static R*/ bool ts_parser__select_tree(TSParser *self, Subtree left, Subtree right)
{
(void)(self);
if (!left.ptr)
@ -622,7 +602,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
// array of children.
static bool ts_parser__select_children(TSParser *self, Subtree left, const SubtreeArray *children)
/*R static R*/ bool ts_parser__select_children(TSParser *self, Subtree left, const SubtreeArray *children)
{
array_assign(&self->scratch_trees, children);
@ -635,7 +615,7 @@ static bool ts_parser__select_children(TSParser *self, Subtree left, const Subtr
return ts_parser__select_tree(self, left, ts_subtree_from_mut(scratch_tree));
}
static void ts_parser__shift(TSParser *self, StackVersion version, TSStateId state, Subtree lookahead, bool extra)
/*R static R*/ void ts_parser__shift(TSParser *self, StackVersion version, TSStateId state, Subtree lookahead, bool extra)
{
bool is_leaf = ts_subtree_child_count(lookahead) == 0;
Subtree subtree_to_push = lookahead;
@ -653,8 +633,8 @@ static void ts_parser__shift(TSParser *self, StackVersion version, TSStateId sta
}
}
static StackVersion ts_parser__reduce(TSParser *self, StackVersion version, TSSymbol symbol, t_u32 count, int dynamic_precedence,
t_u16 production_id, bool is_fragile, bool end_of_non_terminal_extra)
/*R static R*/ StackVersion ts_parser__reduce(TSParser *self, StackVersion version, TSSymbol symbol, t_u32 count, int dynamic_precedence,
t_u16 production_id, bool is_fragile, bool end_of_non_terminal_extra)
{
t_u32 initial_version_count = ts_stack_version_count(self->stack);
@ -768,7 +748,7 @@ static StackVersion ts_parser__reduce(TSParser *self, StackVersion version, TSSy
return ts_stack_version_count(self->stack) > initial_version_count ? initial_version_count : STACK_VERSION_NONE;
}
static void ts_parser__accept(TSParser *self, StackVersion version, Subtree lookahead)
/*R static R*/ void ts_parser__accept(TSParser *self, StackVersion version, Subtree lookahead)
{
assert(ts_subtree_is_eof(lookahead));
ts_stack_push(self->stack, version, lookahead, false, 1);
@ -822,7 +802,7 @@ static void ts_parser__accept(TSParser *self, StackVersion version, Subtree look
ts_stack_halt(self->stack, version);
}
static bool ts_parser__do_all_potential_reductions(TSParser *self, StackVersion starting_version, TSSymbol lookahead_symbol)
/*R static R*/ bool ts_parser__do_all_potential_reductions(TSParser *self, StackVersion starting_version, TSSymbol lookahead_symbol)
{
t_u32 initial_version_count = ts_stack_version_count(self->stack);
@ -927,7 +907,7 @@ static bool ts_parser__do_all_potential_reductions(TSParser *self, StackVersion
return can_shift_lookahead_symbol;
}
static bool ts_parser__recover_to_state(TSParser *self, StackVersion version, t_u32 depth, TSStateId goal_state)
/*R static R*/ bool ts_parser__recover_to_state(TSParser *self, StackVersion version, t_u32 depth, TSStateId goal_state)
{
StackSliceArray pop = ts_stack_pop_count(self->stack, version, depth);
StackVersion previous_version = STACK_VERSION_NONE;
@ -992,7 +972,7 @@ static bool ts_parser__recover_to_state(TSParser *self, StackVersion version, t_
return previous_version != STACK_VERSION_NONE;
}
static void ts_parser__recover(TSParser *self, StackVersion version, Subtree lookahead)
/*R static R*/ void ts_parser__recover(TSParser *self, StackVersion version, Subtree lookahead)
{
bool did_recover = false;
t_u32 previous_version_count = ts_stack_version_count(self->stack);
@ -1167,7 +1147,7 @@ static void ts_parser__recover(TSParser *self, StackVersion version, Subtree loo
}
}
static void ts_parser__handle_error(TSParser *self, StackVersion version, Subtree lookahead)
/*R static R*/ void ts_parser__handle_error(TSParser *self, StackVersion version, Subtree lookahead)
{
t_u32 previous_version_count = ts_stack_version_count(self->stack);
@ -1242,7 +1222,7 @@ static void ts_parser__handle_error(TSParser *self, StackVersion version, Subtre
LOG_STACK();
}
static bool ts_parser__advance(TSParser *self, StackVersion version, bool allow_node_reuse)
/*R static R*/ bool ts_parser__advance(TSParser *self, StackVersion version, bool allow_node_reuse)
{
(void)(allow_node_reuse);
TSStateId state = ts_stack_state(self->stack, version);
@ -1451,7 +1431,7 @@ static bool ts_parser__advance(TSParser *self, StackVersion version, bool allow_
}
}
static t_u32 ts_parser__condense_stack(TSParser *self)
/*R static R*/ t_u32 ts_parser__condense_stack(TSParser *self)
{
bool made_changes = false;
t_u32 min_error_cost = UINT_MAX;
@ -1571,7 +1551,7 @@ static t_u32 ts_parser__condense_stack(TSParser *self)
return min_error_cost;
}
static bool ts_parser_has_outstanding_parse(TSParser *self)
/*R static R*/ bool ts_parser_has_outstanding_parse(TSParser *self)
{
return (self->external_scanner_payload || ts_stack_state(self->stack, 0) != 1 || ts_stack_node_count_since_error(self->stack, 0) != 0);
}

View file

@ -57,22 +57,22 @@ typedef struct Scanner
Array(Heredoc) heredocs;
} Scanner;
static inline void advance(TSLexer *lexer)
/*R static inline R*/ void advance(TSLexer *lexer)
{
lexer->advance(lexer, false);
}
static inline void skip(TSLexer *lexer)
/*R static inline R*/ void skip(TSLexer *lexer)
{
lexer->advance(lexer, true);
}
static inline bool in_error_recovery(const bool *valid_symbols)
/*R static inline R*/ bool in_error_recovery(const bool *valid_symbols)
{
return valid_symbols[ERROR_RECOVERY];
}
static inline void reset_string(String *string)
/*R static inline R*/ void reset_string(String *string)
{
if (string->size > 0)
{
@ -81,7 +81,7 @@ static inline void reset_string(String *string)
}
}
static inline void reset_heredoc(Heredoc *heredoc)
/*R static inline R*/ void reset_heredoc(Heredoc *heredoc)
{
heredoc->is_raw = false;
heredoc->started = false;
@ -89,7 +89,7 @@ static inline void reset_heredoc(Heredoc *heredoc)
reset_string(&heredoc->delimiter);
}
static inline void reset(Scanner *scanner)
/*R static inline R*/ void reset(Scanner *scanner)
{
for (t_u32 i = 0; i < scanner->heredocs.size; i++)
{
@ -129,7 +129,7 @@ static t_u32 serialize(Scanner *scanner, t_u8 *buffer)
return size;
}
static void deserialize(Scanner *scanner, const t_u8 *buffer, t_u32 length)
/*R static R*/ void deserialize(Scanner *scanner, const t_u8 *buffer, t_u32 length)
{
if (length == 0)
{
@ -181,7 +181,7 @@ static void deserialize(Scanner *scanner, const t_u8 *buffer, t_u32 length)
* POSIX-mandated substitution, and assumes the default value for
* IFS.
*/
static bool advance_word(TSLexer *lexer, String *unquoted_word)
/*R static R*/ bool advance_word(TSLexer *lexer, String *unquoted_word)
{
bool empty = true;
t_i32 quote = 0;
@ -213,7 +213,7 @@ static bool advance_word(TSLexer *lexer, String *unquoted_word)
return !empty;
}
static inline bool scan_bare_dollar(TSLexer *lexer)
/*R static inline R*/ bool scan_bare_dollar(TSLexer *lexer)
{
while (iswspace(lexer->lookahead) && lexer->lookahead != '\n' && !lexer->eof(lexer))
skip(lexer);
@ -229,7 +229,7 @@ static inline bool scan_bare_dollar(TSLexer *lexer)
return false;
}
static bool scan_heredoc_start(Heredoc *heredoc, TSLexer *lexer)
/*R static R*/ bool scan_heredoc_start(Heredoc *heredoc, TSLexer *lexer)
{
while (iswspace(lexer->lookahead))
{
@ -248,7 +248,7 @@ static bool scan_heredoc_start(Heredoc *heredoc, TSLexer *lexer)
return found_delimiter;
}
static bool scan_heredoc_end_identifier(Heredoc *heredoc, TSLexer *lexer)
/*R static R*/ bool scan_heredoc_end_identifier(Heredoc *heredoc, TSLexer *lexer)
{
reset_string(&heredoc->current_leading_word);
// Scan the first 'n' characters on this line, to see if they match the
@ -268,7 +268,7 @@ static bool scan_heredoc_end_identifier(Heredoc *heredoc, TSLexer *lexer)
return heredoc->delimiter.size == 0 ? false : strcmp(heredoc->current_leading_word.contents, heredoc->delimiter.contents) == 0;
}
static bool scan_heredoc_content(Scanner *scanner, TSLexer *lexer, enum TokenType middle_type, enum TokenType end_type)
/*R static R*/ bool scan_heredoc_content(Scanner *scanner, TSLexer *lexer, enum TokenType middle_type, enum TokenType end_type)
{
bool did_advance = false;
Heredoc *heredoc = array_back(&scanner->heredocs);
@ -394,7 +394,7 @@ static bool scan_heredoc_content(Scanner *scanner, TSLexer *lexer, enum TokenTyp
}
}
static bool scan(Scanner *scanner, TSLexer *lexer, const bool *valid_symbols)
/*R static R*/ bool scan(Scanner *scanner, TSLexer *lexer, const bool *valid_symbols)
{
if (valid_symbols[CONCAT] && !in_error_recovery(valid_symbols))
{

View file

@ -66,8 +66,7 @@ struct Stack
Array(StackHead) heads;
StackSliceArray slices;
Array(StackIterator) iterators;
StackNodeArray node_pool;
StackNode *base_node;
StackNode *base_node;
};
typedef t_u32 StackAction;
@ -80,7 +79,7 @@ enum StackAction
typedef StackAction (*StackCallback)(void *, const StackIterator *);
static void stack_node_retain(StackNode *self)
/*R static R*/ void stack_node_retain(StackNode *self)
{
if (!self)
return;
@ -89,7 +88,7 @@ static void stack_node_retain(StackNode *self)
assert(self->ref_count != 0);
}
static void stack_node_release(StackNode *self, StackNodeArray *pool)
/*R static R*/ void stack_node_release(StackNode *self)
{
recur:
assert(self->ref_count != 0);
@ -105,23 +104,14 @@ recur:
StackLink link = self->links[i];
if (link.subtree.ptr)
ts_subtree_release(link.subtree);
stack_node_release(link.node, pool);
stack_node_release(link.node);
}
StackLink link = self->links[0];
if (link.subtree.ptr)
ts_subtree_release(link.subtree);
first_predecessor = self->links[0].node;
}
if (pool->size < MAX_NODE_POOL_SIZE)
{
array_push(pool, self);
}
else
{
mem_free(self);
}
mem_free(self);
if (first_predecessor)
{
self = first_predecessor;
@ -131,7 +121,7 @@ recur:
/// Get the number of nodes in the subtree, for the purpose of measuring
/// how much progress has been made by a given version of the stack.
static t_u32 stack__subtree_node_count(Subtree subtree)
/*R static R*/ t_u32 stack__subtree_node_count(Subtree subtree)
{
t_u32 count = ts_subtree_visible_descendant_count(subtree);
if (ts_subtree_visible(subtree))
@ -146,9 +136,9 @@ static t_u32 stack__subtree_node_count(Subtree subtree)
return count;
}
static StackNode *stack_node_new(StackNode *previous_node, Subtree subtree, bool is_pending, TSStateId state, StackNodeArray *pool)
/*R static R*/ StackNode *stack_node_new(StackNode *previous_node, Subtree subtree, bool is_pending, TSStateId state)
{
StackNode *node = pool->size > 0 ? array_pop(pool) : mem_alloc(sizeof(StackNode));
StackNode *node = mem_alloc(sizeof(*node));
*node = (StackNode){.ref_count = 1, .link_count = 0, .state = state};
if (previous_node)
@ -182,7 +172,7 @@ static StackNode *stack_node_new(StackNode *previous_node, Subtree subtree, bool
return node;
}
static bool stack__subtree_is_equivalent(Subtree left, Subtree right)
/*R static R*/ bool stack__subtree_is_equivalent(Subtree left, Subtree right)
{
if (left.ptr == right.ptr)
return true;
@ -202,7 +192,7 @@ static bool stack__subtree_is_equivalent(Subtree left, Subtree right)
ts_subtree_extra(left) == ts_subtree_extra(right) && ts_subtree_external_scanner_state_eq(left, right));
}
static void stack_node_add_link(StackNode *self, StackLink link)
/*R static R*/ void stack_node_add_link(StackNode *self, StackLink link)
{
if (link.node == self)
return;
@ -271,7 +261,7 @@ static void stack_node_add_link(StackNode *self, StackLink link)
self->dynamic_precedence = dynamic_precedence;
}
static void stack_head_delete(StackHead *self, StackNodeArray *pool)
/*R static R*/ void stack_head_delete(StackHead *self)
{
if (self->node)
{
@ -288,11 +278,11 @@ static void stack_head_delete(StackHead *self, StackNodeArray *pool)
array_delete(self->summary);
mem_free(self->summary);
}
stack_node_release(self->node, pool);
stack_node_release(self->node);
}
}
static StackVersion ts_stack__add_version(Stack *self, StackVersion original_version, StackNode *node)
/*R static R*/ StackVersion ts_stack__add_version(Stack *self, StackVersion original_version, StackNode *node)
{
StackHead head = {
.node = node,
@ -308,7 +298,7 @@ static StackVersion ts_stack__add_version(Stack *self, StackVersion original_ver
return (StackVersion)(self->heads.size - 1);
}
static void ts_stack__add_slice(Stack *self, StackVersion original_version, StackNode *node, SubtreeArray *subtrees)
/*R static R*/ void ts_stack__add_slice(Stack *self, StackVersion original_version, StackNode *node, SubtreeArray *subtrees)
{
for (t_u32 i = self->slices.size - 1; i + 1 > 0; i--)
{
@ -326,7 +316,7 @@ static void ts_stack__add_slice(Stack *self, StackVersion original_version, Stac
array_push(&self->slices, slice);
}
static StackSliceArray stack__iter(Stack *self, StackVersion version, StackCallback callback, void *payload, int goal_subtree_count)
/*R static R*/ StackSliceArray stack__iter(Stack *self, StackVersion version, StackCallback callback, void *payload, int goal_subtree_count)
{
array_clear(&self->slices);
array_clear(&self->iterators);
@ -433,18 +423,16 @@ static StackSliceArray stack__iter(Stack *self, StackVersion version, StackCallb
Stack *ts_stack_new(void)
{
Stack *self = mem_alloc_array(1, sizeof(Stack));
Stack *self = mem_alloc(sizeof(*self));
array_init(&self->heads);
array_init(&self->slices);
array_init(&self->iterators);
array_init(&self->node_pool);
array_reserve(&self->heads, 4);
array_reserve(&self->slices, 4);
array_reserve(&self->iterators, 4);
array_reserve(&self->node_pool, MAX_NODE_POOL_SIZE);
self->base_node = stack_node_new(NULL, NULL_SUBTREE, false, 1, &self->node_pool);
self->base_node = stack_node_new(NULL, NULL_SUBTREE, false, 1);
ts_stack_clear(self);
return self;
@ -456,18 +444,12 @@ void ts_stack_delete(Stack *self)
array_delete(&self->slices);
if (self->iterators.contents)
array_delete(&self->iterators);
stack_node_release(self->base_node, &self->node_pool);
stack_node_release(self->base_node);
for (t_u32 i = 0; i < self->heads.size; i++)
{
stack_head_delete(&self->heads.contents[i], &self->node_pool);
stack_head_delete(&self->heads.contents[i]);
}
array_clear(&self->heads);
if (self->node_pool.contents)
{
for (t_u32 i = 0; i < self->node_pool.size; i++)
mem_free(self->node_pool.contents[i]);
array_delete(&self->node_pool);
}
array_delete(&self->heads);
mem_free(self);
}
@ -526,7 +508,7 @@ t_u32 ts_stack_node_count_since_error(const Stack *self, StackVersion version)
void ts_stack_push(Stack *self, StackVersion version, Subtree subtree, bool pending, TSStateId state)
{
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);
if (!subtree.ptr)
head->node_count_at_last_error = new_node->node_count;
head->node = new_node;
@ -718,7 +700,7 @@ bool ts_stack_has_advanced_since_error(const Stack *self, StackVersion version)
void ts_stack_remove_version(Stack *self, StackVersion version)
{
stack_head_delete(array_get(&self->heads, version), &self->node_pool);
stack_head_delete(array_get(&self->heads, version));
array_erase(&self->heads, version);
}
@ -735,7 +717,7 @@ void ts_stack_renumber_version(Stack *self, StackVersion v1, StackVersion v2)
source_head->summary = target_head->summary;
target_head->summary = NULL;
}
stack_head_delete(target_head, &self->node_pool);
stack_head_delete(target_head);
*target_head = *source_head;
array_erase(&self->heads, v1);
}
@ -828,9 +810,7 @@ void ts_stack_clear(Stack *self)
{
stack_node_retain(self->base_node);
for (t_u32 i = 0; i < self->heads.size; i++)
{
stack_head_delete(&self->heads.contents[i], &self->node_pool);
}
stack_head_delete(&self->heads.contents[i]);
array_clear(&self->heads);
array_push(&self->heads, ((StackHead){
.node = self->base_node,
@ -839,5 +819,3 @@ void ts_stack_clear(Stack *self)
.lookahead_when_paused = NULL_SUBTREE,
}));
}
#undef forceinline

View file

@ -15,49 +15,37 @@
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#pragma clang diagnostic ignored "-Wunused-parameter"
typedef struct
typedef struct s_edit Edit;
struct s_edit
{
Length start;
Length old_end;
Length new_end;
} Edit;
};
#define TS_MAX_INLINE_TREE_LENGTH UINT8_MAX
#define TS_MAX_TREE_POOL_SIZE 32
#define TS_MAX_TREE_POOL_SIZE 0
// ExternalScannerState
void ts_external_scanner_state_init(ExternalScannerState *self, const t_u8 *data, t_u32 length)
{
self->length = length;
if (length > sizeof(self->short_data))
{
self->long_data = mem_alloc(length);
memcpy(self->long_data, data, length);
}
else
{
memcpy(self->short_data, data, length);
}
self->long_data = mem_alloc(length);
memcpy(self->long_data, data, length);
}
ExternalScannerState ts_external_scanner_state_copy(const ExternalScannerState *self)
{
ExternalScannerState result = *self;
if (self->length > sizeof(self->short_data))
{
result.long_data = mem_alloc(self->length);
memcpy(result.long_data, self->long_data, self->length);
}
result.long_data = mem_alloc(self->length);
memcpy(result.long_data, self->long_data, self->length);
return result;
}
void ts_external_scanner_state_delete(ExternalScannerState *self)
{
if (self->length > sizeof(self->short_data))
{
mem_free(self->long_data);
}
mem_free(self->long_data);
}
const t_u8 *ts_external_scanner_state_data(const ExternalScannerState *self)
@ -140,12 +128,12 @@ void ts_subtree_array_reverse(SubtreeArray *self)
}
}
static SubtreeHeapData *ts_subtree_pool_allocate()
/*R static R*/ SubtreeHeapData *ts_subtree_pool_allocate()
{
return mem_alloc(sizeof(SubtreeHeapData));
}
// static void ts_subtree_pool_free(SubtreeHeapData *tree)
// /*R static R*/ void ts_subtree_pool_free(SubtreeHeapData *tree)
//{
// mem_free(tree);
// }
@ -239,7 +227,7 @@ MutableSubtree ts_subtree_make_mut(Subtree self)
}
/*
static void ts_subtree__compress(MutableSubtree self, t_u32 count, const TSLanguage *language, MutableSubtreeArray *stack)
static void ts_subtree__compress(MutableSubtree self, t_u32 count, const TSLanguage *language, MutableSubtreeArray *stack)
{
t_u32 initial_stack_size = stack->size;
@ -530,7 +518,7 @@ void ts_subtree_release(Subtree self)
{
t_usize i;
Subtree *children;
if (self.ptr->ref_count != 0 && --(*(t_u32 *)(&self.ptr->ref_count)) == 0)
if (self.ptr->ref_count > 0 && --(*(t_u32 *)(&self.ptr->ref_count)) == 0)
{
if (self.ptr->child_count > 0)
@ -545,9 +533,7 @@ void ts_subtree_release(Subtree self)
{
if (self.ptr->has_external_tokens)
{
ts_external_scanner_state_delete((void *)&self.ptr->external_scanner_state);
}
mem_free((void *)self.ptr);
}
}
@ -629,137 +615,11 @@ int ts_subtree_compare(Subtree left, Subtree right)
return 0;
}
static inline void ts_subtree_set_has_changes(MutableSubtree *self)
/*R static inline R*/ void ts_subtree_set_has_changes(MutableSubtree *self)
{
self->ptr->has_changes = true;
}
Subtree ts_subtree_edit(Subtree self, const TSInputEdit *input_edit)
{
typedef struct
{
Subtree *tree;
Edit edit;
} EditEntry;
Array(EditEntry) stack = array_new();
array_push(&stack, ((EditEntry){
.tree = &self,
.edit =
(Edit){
.start = {input_edit->start_byte, input_edit->start_point},
.old_end = {input_edit->old_end_byte, input_edit->old_end_point},
.new_end = {input_edit->new_end_byte, input_edit->new_end_point},
},
}));
while (stack.size)
{
EditEntry entry = array_pop(&stack);
Edit edit = entry.edit;
bool is_noop = edit.old_end.bytes == edit.start.bytes && edit.new_end.bytes == edit.start.bytes;
bool is_pure_insertion = edit.old_end.bytes == edit.start.bytes;
bool invalidate_first_row = ts_subtree_depends_on_column(*entry.tree);
Length size = ts_subtree_size(*entry.tree);
Length padding = ts_subtree_padding(*entry.tree);
Length total_size = length_add(padding, size);
t_u32 lookahead_bytes = ts_subtree_lookahead_bytes(*entry.tree);
t_u32 end_byte = total_size.bytes + lookahead_bytes;
if (edit.start.bytes > end_byte || (is_noop && edit.start.bytes == end_byte))
continue;
// If the edit is entirely within the space before this subtree, then shift this
// subtree over according to the edit without changing its size.
if (edit.old_end.bytes <= padding.bytes)
{
padding = length_add(edit.new_end, length_sub(padding, edit.old_end));
}
// If the edit starts in the space before this subtree and extends into this subtree,
// shrink the subtree's content to compensate for the change in the space before it.
else if (edit.start.bytes < padding.bytes)
{
size = length_saturating_sub(size, length_sub(edit.old_end, padding));
padding = edit.new_end;
}
// If the edit is a pure insertion right at the start of the subtree,
// shift the subtree over according to the insertion.
else if (edit.start.bytes == padding.bytes && is_pure_insertion)
{
padding = edit.new_end;
}
// If the edit is within this subtree, resize the subtree to reflect the edit.
else if (edit.start.bytes < total_size.bytes || (edit.start.bytes == total_size.bytes && is_pure_insertion))
{
size = length_add(length_sub(edit.new_end, padding), length_saturating_sub(total_size, edit.old_end));
}
MutableSubtree result = ts_subtree_make_mut(*entry.tree);
result.ptr->padding = padding;
result.ptr->size = size;
ts_subtree_set_has_changes(&result);
*entry.tree = ts_subtree_from_mut(result);
Length child_left, child_right = length_zero();
for (t_u32 i = 0, n = ts_subtree_child_count(*entry.tree); i < n; i++)
{
Subtree *child = &ts_subtree_children(*entry.tree)[i];
Length child_size = ts_subtree_total_size(*child);
child_left = child_right;
child_right = length_add(child_left, child_size);
// If this child ends before the edit, it is not affected.
if (child_right.bytes + ts_subtree_lookahead_bytes(*child) < edit.start.bytes)
continue;
// Keep editing child nodes until a node is reached that starts after the edit.
// Also, if this node's validity depends on its column position, then continue
// invaliditing child nodes until reaching a line break.
if (((child_left.bytes > edit.old_end.bytes) || (child_left.bytes == edit.old_end.bytes && child_size.bytes > 0 && i > 0)) &&
(!invalidate_first_row || child_left.extent.row > entry.tree->ptr->padding.extent.row))
{
break;
}
// Transform edit into the child's coordinate space.
Edit child_edit = {
.start = length_saturating_sub(edit.start, child_left),
.old_end = length_saturating_sub(edit.old_end, child_left),
.new_end = length_saturating_sub(edit.new_end, child_left),
};
// Interpret all inserted text as applying to the *first* child that touches the edit.
// Subsequent children are only never have any text inserted into them; they are only
// shrunk to compensate for the edit.
if (child_right.bytes > edit.start.bytes || (child_right.bytes == edit.start.bytes && is_pure_insertion))
{
edit.new_end = edit.start;
}
// Children that occur before the edit are not reshaped by the edit.
else
{
child_edit.old_end = child_edit.start;
child_edit.new_end = child_edit.start;
}
// Queue processing of this child's subtree.
array_push(&stack, ((EditEntry){
.tree = child,
.edit = child_edit,
}));
}
}
array_delete(&stack);
return self;
}
Subtree ts_subtree_last_external_token(Subtree tree)
{
if (!ts_subtree_has_external_tokens(tree))
@ -783,13 +643,9 @@ const ExternalScannerState *ts_subtree_external_scanner_state(Subtree self)
{
static const ExternalScannerState empty_state = {{.short_data = {0}}, .length = 0};
if (self.ptr && self.ptr->has_external_tokens && self.ptr->child_count == 0)
{
return &self.ptr->external_scanner_state;
}
else
{
return &empty_state;
}
}
bool ts_subtree_external_scanner_state_eq(Subtree self, Subtree other)

View file

@ -50,52 +50,3 @@ const TSLanguage *ts_tree_language(const TSTree *self)
{
return self->language;
}
void ts_tree_edit(TSTree *self, const TSInputEdit *edit)
{
for (t_u32 i = 0; i < self->included_range_count; i++)
{
TSRange *range = &self->included_ranges[i];
if (range->end_byte >= edit->old_end_byte)
{
if (range->end_byte != UINT32_MAX)
{
range->end_byte = edit->new_end_byte + (range->end_byte - edit->old_end_byte);
range->end_point = point_add(edit->new_end_point, point_sub(range->end_point, edit->old_end_point));
if (range->end_byte < edit->new_end_byte)
{
range->end_byte = UINT32_MAX;
range->end_point = POINT_MAX;
}
}
}
else if (range->end_byte > edit->start_byte)
{
range->end_byte = edit->start_byte;
range->end_point = edit->start_point;
}
if (range->start_byte >= edit->old_end_byte)
{
range->start_byte = edit->new_end_byte + (range->start_byte - edit->old_end_byte);
range->start_point = point_add(edit->new_end_point, point_sub(range->start_point, edit->old_end_point));
if (range->start_byte < edit->new_end_byte)
{
range->start_byte = UINT32_MAX;
range->start_point = POINT_MAX;
}
}
else if (range->start_byte > edit->start_byte)
{
range->start_byte = edit->start_byte;
range->start_point = edit->start_point;
}
}
}
TSRange *ts_tree_included_ranges(const TSTree *self, t_u32 *length)
{
*length = self->included_range_count;
TSRange *ranges = mem_alloc_array(self->included_range_count, sizeof(TSRange));
memcpy(ranges, self->included_ranges, self->included_range_count * sizeof(TSRange));
return ranges;
}