did stuff, done stuff

This commit is contained in:
Maieul BOYER 2024-08-31 18:48:20 +00:00
parent 4a8fb259dc
commit 62a4f377a1
37 changed files with 325 additions and 399 deletions

View file

@ -5,7 +5,7 @@
bool ts_lex(t_lexer *lexer, t_state_id state)
{
START_LEXER();
eof = lexer->eof(lexer);
eof = lexer->data.eof((void *)lexer);
switch (state)
{
case 0:
@ -3460,7 +3460,7 @@ bool ts_lex(t_lexer *lexer, t_state_id state)
bool ts_lex_keywords(t_lexer *lexer, t_state_id state)
{
START_LEXER();
eof = lexer->eof(lexer);
eof = lexer->data.eof((void *)lexer);
switch (state)
{
case 0:
@ -3597,4 +3597,4 @@ bool ts_lex_keywords(t_lexer *lexer, t_state_id state)
default:
return false;
}
}
}

View file

@ -16,19 +16,19 @@
bool ts_lexer__eof(const TSLexer *_self);
t_u32 ts_lexer__get_column(TSLexer *_self);
void ts_lexer__advance(TSLexer *_self, bool skip);
void ts_lexer__clear_chunk(Lexer *self);
void ts_lexer__get_chunk(Lexer *self);
void ts_lexer__get_lookahead(Lexer *self);
void ts_lexer__clear_chunk(t_lexer *self);
void ts_lexer__get_chunk(t_lexer *self);
void ts_lexer__get_lookahead(t_lexer *self);
void ts_lexer__mark_end(TSLexer *_self);
void ts_lexer_advance_to_end(Lexer *self);
void ts_lexer_goto(Lexer *self, Length position);
void ts_lexer_advance_to_end(t_lexer *self);
void ts_lexer_goto(t_lexer *self, Length position);
bool ts_lexer__do_advance_loop(Lexer *self, const TSRange **current_range);
void ts_lexer__do_advance_after_loop(Lexer *self, bool skip,
bool ts_lexer__do_advance_loop(t_lexer *self, const TSRange **current_range);
void ts_lexer__do_advance_after_loop(t_lexer *self, bool skip,
const TSRange *cur);
// Intended to be called only from functions that control logging.
void ts_lexer__do_advance(Lexer *self, bool skip)
void ts_lexer__do_advance(t_lexer *self, bool skip)
{
const TSRange *cur = \
&self->included_ranges[self->current_included_range_index];
@ -55,15 +55,15 @@ void ts_lexer__do_advance(Lexer *self, bool skip)
// chunk of source code if needed.
void ts_lexer__advance(TSLexer *_self, bool skip)
{
Lexer *self;
t_lexer *self;
self = (Lexer *)_self;
self = (t_lexer *)_self;
if (!self->chunk)
return ;
ts_lexer__do_advance(self, skip);
}
bool ts_lexer__do_advance_loop(Lexer *self, const TSRange **current_range)
bool ts_lexer__do_advance_loop(t_lexer *self, const TSRange **current_range)
{
if (self->current_included_range_index < self->included_range_count)
self->current_included_range_index++;
@ -83,7 +83,7 @@ bool ts_lexer__do_advance_loop(Lexer *self, const TSRange **current_range)
return (false);
}
void ts_lexer__do_advance_after_loop(Lexer *self, bool skip,
void ts_lexer__do_advance_after_loop(t_lexer *self, bool skip,
const TSRange *cur)
{
if (skip)

View file

@ -16,17 +16,17 @@
bool ts_lexer__eof(const TSLexer *_self);
t_u32 ts_lexer__get_column(TSLexer *_self);
void ts_lexer__advance(TSLexer *_self, bool skip);
void ts_lexer__do_advance(Lexer *self, bool skip);
void ts_lexer__clear_chunk(Lexer *self);
void ts_lexer__get_chunk(Lexer *self);
void ts_lexer__get_lookahead(Lexer *self);
void ts_lexer__do_advance(t_lexer *self, bool skip);
void ts_lexer__clear_chunk(t_lexer *self);
void ts_lexer__get_chunk(t_lexer *self);
void ts_lexer__get_lookahead(t_lexer *self);
void ts_lexer__mark_end(TSLexer *_self);
void ts_lexer_advance_to_end(Lexer *self);
void ts_lexer_goto(Lexer *self, Length position);
void ts_lexer_advance_to_end(t_lexer *self);
void ts_lexer_goto(t_lexer *self, Length position);
// Clear the currently stored chunk of source code, because the lexer's
// position has changed.
void ts_lexer__clear_chunk(Lexer *self)
void ts_lexer__clear_chunk(t_lexer *self)
{
self->chunk = NULL;
self->chunk_size = 0;
@ -35,7 +35,7 @@ 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.
void ts_lexer__get_chunk(Lexer *self)
void ts_lexer__get_chunk(t_lexer *self)
{
self->chunk_start = self->current_position.bytes;
self->chunk = self->input.read(self->input.payload,

View file

@ -16,22 +16,22 @@
bool ts_lexer__eof(const TSLexer *_self);
t_u32 ts_lexer__get_column(TSLexer *_self);
void ts_lexer__advance(TSLexer *_self, bool skip);
void ts_lexer__do_advance(Lexer *self, bool skip);
void ts_lexer__clear_chunk(Lexer *self);
void ts_lexer__get_chunk(Lexer *self);
void ts_lexer__get_lookahead(Lexer *self);
void ts_lexer__do_advance(t_lexer *self, bool skip);
void ts_lexer__clear_chunk(t_lexer *self);
void ts_lexer__get_chunk(t_lexer *self);
void ts_lexer__get_lookahead(t_lexer *self);
void ts_lexer__mark_end(TSLexer *_self);
void ts_lexer_advance_to_end(Lexer *self);
void ts_lexer_goto(Lexer *self, Length position);
void ts_lexer_advance_to_end(t_lexer *self);
void ts_lexer_goto(t_lexer *self, Length position);
// 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.
bool ts_lexer__eof(const TSLexer *_self)
{
Lexer *self;
t_lexer *self;
self = (Lexer *)_self;
self = (t_lexer *)_self;
return (self->current_included_range_index == self->included_range_count);
}
@ -39,11 +39,11 @@ bool ts_lexer__eof(const TSLexer *_self)
// times if a longer match is found later.
void ts_lexer__mark_end(TSLexer *_self)
{
Lexer *self;
t_lexer *self;
TSRange *current_included_range;
TSRange *previous_included_range;
self = (Lexer *)_self;
self = (t_lexer *)_self;
if (!ts_lexer__eof(&self->data))
{
current_included_range = \
@ -62,7 +62,7 @@ void ts_lexer__mark_end(TSLexer *_self)
self->token_end_position = self->current_position;
}
void ts_lexer_advance_to_end(Lexer *self)
void ts_lexer_advance_to_end(t_lexer *self)
{
while (self->chunk)
ts_lexer__advance(&self->data, false);

View file

@ -16,21 +16,21 @@
bool ts_lexer__eof(const TSLexer *_self);
t_u32 ts_lexer__get_column(TSLexer *_self);
void ts_lexer__advance(TSLexer *_self, bool skip);
void ts_lexer__do_advance(Lexer *self, bool skip);
void ts_lexer__clear_chunk(Lexer *self);
void ts_lexer__get_chunk(Lexer *self);
void ts_lexer__get_lookahead(Lexer *self);
void ts_lexer__do_advance(t_lexer *self, bool skip);
void ts_lexer__clear_chunk(t_lexer *self);
void ts_lexer__get_chunk(t_lexer *self);
void ts_lexer__get_lookahead(t_lexer *self);
void ts_lexer__mark_end(TSLexer *_self);
void ts_lexer_advance_to_end(Lexer *self);
void ts_lexer_goto(Lexer *self, Length position);
void ts_lexer_advance_to_end(t_lexer *self);
void ts_lexer_goto(t_lexer *self, Length position);
t_u32 ts_lexer__get_column(TSLexer *_self)
{
Lexer *self;
t_lexer *self;
t_u32 goal_byte;
t_u32 result;
self = (Lexer *)_self;
self = (t_lexer *)_self;
goal_byte = self->current_position.bytes;
self->did_get_column = true;
self->current_position.bytes -= self->current_position.extent.column;

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/31 18:08:11 by maiboyer #+# #+# */
/* Updated: 2024/08/31 18:25:58 by maiboyer ### ########.fr */
/* Updated: 2024/08/31 18:39:32 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,19 +16,19 @@
bool ts_lexer__eof(const TSLexer *_self);
t_u32 ts_lexer__get_column(TSLexer *_self);
void ts_lexer__advance(TSLexer *_self, bool skip);
void ts_lexer__do_advance(Lexer *self, bool skip);
void ts_lexer__clear_chunk(Lexer *self);
void ts_lexer__get_chunk(Lexer *self);
void ts_lexer__get_lookahead(Lexer *self);
void ts_lexer__do_advance(t_lexer *self, bool skip);
void ts_lexer__clear_chunk(t_lexer *self);
void ts_lexer__get_chunk(t_lexer *self);
void ts_lexer__get_lookahead(t_lexer *self);
void ts_lexer__mark_end(TSLexer *_self);
void ts_lexer_advance_to_end(Lexer *self);
void ts_lexer_goto(Lexer *self, Length position);
void ts_lexer_advance_to_end(t_lexer *self);
void ts_lexer_goto(t_lexer *self, Length position);
void ts_lexer_goto_inside_loop(Lexer *self, bool *found_included_range,
void ts_lexer_goto_inside_loop(t_lexer *self, bool *found_included_range,
TSRange *included_range, t_usize i);
void ts_lexer_goto_after_loop(Lexer *self, bool found_included_range);
void ts_lexer_goto_after_loop(t_lexer *self, bool found_included_range);
void ts_lexer_goto(Lexer *self, Length position)
void ts_lexer_goto(t_lexer *self, Length position)
{
bool found_included_range;
TSRange *included_range;
@ -53,7 +53,7 @@ void ts_lexer_goto(Lexer *self, Length position)
ts_lexer_goto_after_loop(self, found_included_range);
}
void ts_lexer_goto_inside_loop(Lexer *self, bool *found_included_range,
void ts_lexer_goto_inside_loop(t_lexer *self, bool *found_included_range,
TSRange *included_range, t_usize i)
{
if (included_range->start_byte >= self->current_position.bytes)
@ -67,7 +67,7 @@ void ts_lexer_goto_inside_loop(Lexer *self, bool *found_included_range,
*found_included_range = true;
}
void ts_lexer_goto_after_loop(Lexer *self, bool found_included_range)
void ts_lexer_goto_after_loop(t_lexer *self, bool found_included_range)
{
TSRange *last_included_range;

View file

@ -18,20 +18,20 @@
bool ts_lexer__eof(const TSLexer *_self);
t_u32 ts_lexer__get_column(TSLexer *_self);
void ts_lexer__advance(TSLexer *_self, bool skip);
void ts_lexer__clear_chunk(Lexer *self);
void ts_lexer__get_chunk(Lexer *self);
void ts_lexer__get_lookahead(Lexer *self);
void ts_lexer__clear_chunk(t_lexer *self);
void ts_lexer__get_chunk(t_lexer *self);
void ts_lexer__get_lookahead(t_lexer *self);
void ts_lexer__mark_end(TSLexer *_self);
void ts_lexer_advance_to_end(Lexer *self);
void ts_lexer_goto(Lexer *self, Length position);
void ts_lexer_advance_to_end(t_lexer *self);
void ts_lexer_goto(t_lexer *self, Length position);
void ts_lexer_init(Lexer *self)
void ts_lexer_init(t_lexer *self)
{
static TSRange default_range = {.start_point = {\
.row = 0, .column = 0, }, .end_point = {.row = UINT32_MAX, \
.column = UINT32_MAX, }, .start_byte = 0, .end_byte = UINT32_MAX};
*self = (Lexer){
*self = (t_lexer){
.data = {
.advance = ts_lexer__advance,
.mark_end = ts_lexer__mark_end,
@ -49,20 +49,20 @@ void ts_lexer_init(Lexer *self)
};
}
void ts_lexer_set_input(Lexer *self, TSInput input)
void ts_lexer_set_input(t_lexer *self, TSInput input)
{
self->input = input;
ts_lexer__clear_chunk(self);
ts_lexer_goto(self, self->current_position);
}
void ts_lexer_reset(Lexer *self, Length position)
void ts_lexer_reset(t_lexer *self, Length position)
{
if (position.bytes != self->current_position.bytes)
ts_lexer_goto(self, position);
}
void ts_lexer_start(Lexer *self)
void ts_lexer_start(t_lexer *self)
{
self->token_start_position = self->current_position;
self->token_end_position = LENGTH_UNDEFINED;
@ -80,7 +80,7 @@ void ts_lexer_start(Lexer *self)
}
}
void ts_lexer_finish(Lexer *self, t_u32 *lookahead_end_byte)
void ts_lexer_finish(t_lexer *self, t_u32 *lookahead_end_byte)
{
if (length_is_undefined(self->token_end_position))
ts_lexer__mark_end(&self->data);

View file

@ -17,15 +17,15 @@
bool ts_lexer__eof(const TSLexer *_self);
t_u32 ts_lexer__get_column(TSLexer *_self);
void ts_lexer__advance(TSLexer *_self, bool skip);
void ts_lexer__do_advance(Lexer *self, bool skip);
void ts_lexer__clear_chunk(Lexer *self);
void ts_lexer__get_chunk(Lexer *self);
void ts_lexer__get_lookahead(Lexer *self);
void ts_lexer__do_advance(t_lexer *self, bool skip);
void ts_lexer__clear_chunk(t_lexer *self);
void ts_lexer__get_chunk(t_lexer *self);
void ts_lexer__get_lookahead(t_lexer *self);
void ts_lexer__mark_end(TSLexer *_self);
void ts_lexer_advance_to_end(Lexer *self);
void ts_lexer_goto(Lexer *self, Length position);
void ts_lexer_advance_to_end(t_lexer *self);
void ts_lexer_goto(t_lexer *self, Length position);
void ts_lexer__get_lookahead(Lexer *self)
void ts_lexer__get_lookahead(t_lexer *self)
{
t_u32 position_in_chunk;
t_u32 size;

View file

@ -13,7 +13,7 @@
#include "parser/external_scanner_state.h"
#include "parser/subtree.h"
void ts_external_scanner_state_init(ExternalScannerState *self,
void ts_external_scanner_state_init(t_external_scanner_state *self,
const t_u8 *data, t_u32 length)
{
self->length = length;
@ -21,10 +21,10 @@ void ts_external_scanner_state_init(ExternalScannerState *self,
mem_copy(self->long_data, data, length);
}
ExternalScannerState ts_external_scanner_state_copy(\
const ExternalScannerState *self)
t_external_scanner_state ts_external_scanner_state_copy(\
const t_external_scanner_state *self)
{
ExternalScannerState result;
t_external_scanner_state result;
result = *self;
result.long_data = mem_alloc(self->length);
@ -32,17 +32,17 @@ ExternalScannerState ts_external_scanner_state_copy(\
return (result);
}
void ts_external_scanner_state_delete(ExternalScannerState *self)
void ts_external_scanner_state_delete(t_external_scanner_state *self)
{
mem_free(self->long_data);
}
const t_u8 *ts_external_scanner_state_data(const ExternalScannerState *self)
const t_u8 *ts_external_scanner_state_data(const t_external_scanner_state *self)
{
return ((const t_u8 *)self->long_data);
}
bool ts_external_scanner_state_eq(const ExternalScannerState *self,
bool ts_external_scanner_state_eq(const t_external_scanner_state *self,
const t_u8 *buffer, t_u32 length)
{
return (self->length == length

View file

@ -13,9 +13,9 @@
#include "parser/external_scanner_state.h"
#include "parser/subtree.h"
const ExternalScannerState *ts_subtree_external_scanner_state(Subtree self)
const t_external_scanner_state *ts_subtree_external_scanner_state(t_subtree self)
{
static const ExternalScannerState empty_state = {NULL, .length = 0};
static const t_external_scanner_state empty_state = {NULL, .length = 0};
if (self && self->has_external_tokens && self->child_count == 0)
return (&self->external_scanner_state);
@ -23,11 +23,11 @@ const ExternalScannerState *ts_subtree_external_scanner_state(Subtree self)
return (&empty_state);
}
bool ts_subtree_external_scanner_state_eq(Subtree self, Subtree other)
bool ts_subtree_external_scanner_state_eq(t_subtree self, t_subtree other)
{
const ExternalScannerState *state_self = \
const t_external_scanner_state *state_self = \
ts_subtree_external_scanner_state(self);
const ExternalScannerState *state_other = \
const t_external_scanner_state *state_other = \
ts_subtree_external_scanner_state(other);
return (ts_external_scanner_state_eq(state_self,

View file

@ -14,7 +14,7 @@
t_u32 ts_node_child_count(TSNode self)
{
Subtree tree;
t_subtree tree;
tree = ts_node__subtree(self);
if (ts_subtree_child_count(tree) > 0)
@ -25,7 +25,7 @@ t_u32 ts_node_child_count(TSNode self)
t_u32 ts_node_named_child_count(TSNode self)
{
Subtree tree;
t_subtree tree;
tree = ts_node__subtree(self);
if (ts_subtree_child_count(tree) > 0)

View file

@ -14,7 +14,7 @@
#include "parser/length.h"
#include "parser/subtree.h"
TSNode ts_node_new(const TSTree *tree, const Subtree *subtree, \
TSNode ts_node_new(const TSTree *tree, const t_subtree *subtree, \
Length position, TSSymbol alias)
{
return ((TSNode){

View file

@ -34,7 +34,7 @@ t_u32 ts_node__alias(const TSNode *self)
return (self->alias);
}
Subtree ts_node__subtree(TSNode self)
t_subtree ts_node__subtree(TSNode self)
{
return (*(const Subtree *)self.id);
return (*(const t_subtree *)self.id);
}

View file

@ -16,7 +16,7 @@
NodeChildIterator ts_node_iterate_children(const TSNode *node)
{
Subtree subtree;
t_subtree subtree;
const TSSymbol *alias_sequence;
subtree = ts_node__subtree(*node);
@ -42,7 +42,7 @@ bool ts_node_child_iterator_done(NodeChildIterator *self)
bool ts_node_child_iterator_next(NodeChildIterator *self, TSNode *result)
{
const Subtree *child;
const t_subtree *child;
TSSymbol alias_symbol;
if (!self->parent || ts_node_child_iterator_done(self))

View file

@ -17,7 +17,7 @@
bool ts_node__is_relevant(TSNode self, bool include_anonymous)
{
TSSymbol alias;
Subtree tree;
t_subtree tree;
tree = ts_node__subtree(self);
if (include_anonymous)
@ -31,7 +31,7 @@ bool ts_node__is_relevant(TSNode self, bool include_anonymous)
t_u32 ts_node__relevant_child_count(TSNode self, bool include_anonymous)
{
Subtree tree;
t_subtree tree;
tree = ts_node__subtree(self);
if (ts_subtree_child_count(tree) > 0)

View file

@ -1,5 +1,3 @@
#define _POSIX_C_SOURCE 200112L
#include "me/mem/mem.h"
#include "me/types.h"
#include "parser/api.h"
@ -25,11 +23,11 @@ typedef struct s_string_input t_string_input;
struct TSParser
{
Lexer lexer;
t_lexer lexer;
t_stack *stack;
const TSLanguage *language;
ReduceActionSet reduce_actions;
Subtree finished_tree;
t_subtree finished_tree;
SubtreeArray trailing_extras;
SubtreeArray trailing_extras2;
SubtreeArray scratch_trees;
@ -101,11 +99,11 @@ static bool ts_parser__breakdown_top_of_stack(TSParser *self, t_stack_version ve
{
t_stack_slice slice = pop.contents[i];
TSStateId state = ts_stack_state(self->stack, slice.version);
Subtree parent = *array_front(&slice.subtrees);
t_subtree parent = *array_front(&slice.subtrees);
for (t_u32 j = 0, n = ts_subtree_child_count(parent); j < n; j++)
{
Subtree child = ts_subtree_children(parent)[j];
t_subtree child = ts_subtree_children(parent)[j];
pending = ts_subtree_child_count(child) > 0;
if (ts_subtree_is_error(child))
@ -123,7 +121,7 @@ static bool ts_parser__breakdown_top_of_stack(TSParser *self, t_stack_version ve
for (t_u32 j = 1; j < slice.subtrees.size; j++)
{
Subtree tree = slice.subtrees.contents[j];
t_subtree tree = slice.subtrees.contents[j];
ts_stack_push(self->stack, slice.version, tree, false, state);
}
@ -283,7 +281,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)
static void ts_parser__external_scanner_deserialize(TSParser *self, t_subtree external_token)
{
const t_u8 *data = NULL;
t_u32 length = 0;
@ -302,14 +300,14 @@ static bool ts_parser__external_scanner_scan(TSParser *self, TSStateId external_
return self->language->external_scanner.scan(self->external_scanner_payload, &self->lexer.data, valid_external_tokens);
}
static Subtree ts_parser__lex(TSParser *self, t_stack_version version, TSStateId parse_state)
static t_subtree ts_parser__lex(TSParser *self, t_stack_version version, TSStateId parse_state)
{
TSLexMode lex_mode = self->language->lex_modes[parse_state];
if (lex_mode.lex_state == (t_u16)-1)
return NULL;
const Length start_position = ts_stack_position(self->stack, version);
const Subtree external_token = ts_stack_last_external_token(self->stack, version);
const t_subtree external_token = ts_stack_last_external_token(self->stack, version);
bool found_external_token = false;
bool error_mode = parse_state == ERROR_STATE;
@ -406,7 +404,7 @@ static Subtree ts_parser__lex(TSParser *self, t_stack_version version, TSStateId
error_end_position = self->lexer.current_position;
}
Subtree result;
t_subtree result;
if (skipped_error)
{
Length padding = length_sub(error_start_position, start_position);
@ -447,7 +445,7 @@ static Subtree ts_parser__lex(TSParser *self, t_stack_version version, TSStateId
if (found_external_token)
{
MutableSubtree mut_result = ts_subtree_to_mut_unsafe(result);
t_mut_subtree mut_result = ts_subtree_to_mut_unsafe(result);
ts_external_scanner_state_init(&mut_result->external_scanner_state, self->lexer.debug_buffer, external_scanner_state_len);
mut_result->has_external_scanner_state_change = external_scanner_state_changed;
}
@ -460,7 +458,7 @@ static Subtree ts_parser__lex(TSParser *self, t_stack_version version, TSStateId
//
// 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)
static bool ts_parser__select_tree(TSParser *self, t_subtree left, t_subtree right)
{
(void)(self);
if (!left)
@ -505,7 +503,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)
static bool ts_parser__select_children(TSParser *self, t_subtree left, const SubtreeArray *children)
{
array_assign(&self->scratch_trees, children);
@ -513,18 +511,18 @@ static bool ts_parser__select_children(TSParser *self, Subtree left, const Subtr
// not perform any allocation except for possibly growing the array to make
// room for its own heap data. The scratch tree is never explicitly released,
// so the same 'scratch trees' array can be reused again later.
MutableSubtree scratch_tree = ts_subtree_new_node(ts_subtree_symbol(left), &self->scratch_trees, 0, self->language);
t_mut_subtree scratch_tree = ts_subtree_new_node(ts_subtree_symbol(left), &self->scratch_trees, 0, self->language);
return ts_parser__select_tree(self, left, ts_subtree_from_mut(scratch_tree));
}
static void ts_parser__shift(TSParser *self, t_stack_version version, TSStateId state, Subtree lookahead, bool extra)
static void ts_parser__shift(TSParser *self, t_stack_version version, TSStateId state, t_subtree lookahead, bool extra)
{
bool is_leaf = ts_subtree_child_count(lookahead) == 0;
Subtree subtree_to_push = lookahead;
t_subtree subtree_to_push = lookahead;
if (extra != ts_subtree_extra(lookahead) && is_leaf)
{
MutableSubtree result = ts_subtree_make_mut(/*&self->tree_pool,*/ lookahead);
t_mut_subtree result = ts_subtree_make_mut(/*&self->tree_pool,*/ lookahead);
ts_subtree_set_extra(&result, extra);
subtree_to_push = ts_subtree_from_mut(result);
}
@ -579,7 +577,7 @@ static t_stack_version ts_parser__reduce(TSParser *self, t_stack_version version
SubtreeArray children = slice.subtrees;
ts_subtree_array_remove_trailing_extras(&children, &self->trailing_extras);
MutableSubtree parent = ts_subtree_new_node(symbol, &children, production_id, self->language);
t_mut_subtree parent = ts_subtree_new_node(symbol, &children, production_id, self->language);
// This pop operation may have caused multiple stack versions to collapse
// into one, because they all diverged from a common state. In that case,
@ -651,7 +649,7 @@ static t_stack_version ts_parser__reduce(TSParser *self, t_stack_version version
return ts_stack_version_count(self->stack) > initial_version_count ? initial_version_count : STACK_VERSION_NONE;
}
static void ts_parser__accept(TSParser *self, t_stack_version version, Subtree lookahead)
static void ts_parser__accept(TSParser *self, t_stack_version version, t_subtree lookahead)
{
assert(ts_subtree_is_eof(lookahead));
ts_stack_push(self->stack, version, lookahead, false, 1);
@ -661,14 +659,14 @@ static void ts_parser__accept(TSParser *self, t_stack_version version, Subtree l
{
SubtreeArray trees = pop.contents[i].subtrees;
Subtree root = NULL;
t_subtree root = NULL;
for (t_u32 j = trees.size - 1; j + 1 > 0; j--)
{
Subtree tree = trees.contents[j];
t_subtree tree = trees.contents[j];
if (!ts_subtree_extra(tree))
{
t_u32 child_count = ts_subtree_child_count(tree);
const Subtree *children = ts_subtree_children(tree);
const t_subtree *children = ts_subtree_children(tree);
for (t_u32 k = 0; k < child_count; k++)
{
ts_subtree_retain(children[k]);
@ -838,7 +836,7 @@ static bool ts_parser__recover_to_state(TSParser *self, t_stack_version version,
if (error_trees.size > 0)
{
assert(error_trees.size == 1);
Subtree error_tree = error_trees.contents[0];
t_subtree error_tree = error_trees.contents[0];
t_u32 error_child_count = ts_subtree_child_count(error_tree);
if (error_child_count > 0)
{
@ -855,7 +853,7 @@ static bool ts_parser__recover_to_state(TSParser *self, t_stack_version version,
if (slice.subtrees.size > 0)
{
Subtree error = ts_subtree_new_error_node(&slice.subtrees, true, self->language);
t_subtree error = ts_subtree_new_error_node(&slice.subtrees, true, self->language);
ts_stack_push(self->stack, slice.version, error, false, goal_state);
}
else
@ -865,7 +863,7 @@ static bool ts_parser__recover_to_state(TSParser *self, t_stack_version version,
for (t_u32 j = 0; j < self->trailing_extras.size; j++)
{
Subtree tree = self->trailing_extras.contents[j];
t_subtree tree = self->trailing_extras.contents[j];
ts_stack_push(self->stack, slice.version, tree, false, goal_state);
}
@ -875,7 +873,7 @@ static bool ts_parser__recover_to_state(TSParser *self, t_stack_version version,
return previous_version != STACK_VERSION_NONE;
}
static void ts_parser__recover(TSParser *self, t_stack_version version, Subtree lookahead)
static void ts_parser__recover(TSParser *self, t_stack_version version, t_subtree lookahead)
{
bool did_recover = false;
t_u32 previous_version_count = ts_stack_version_count(self->stack);
@ -977,7 +975,7 @@ static void ts_parser__recover(TSParser *self, t_stack_version version, Subtree
if (ts_subtree_is_eof(lookahead))
{
SubtreeArray children = array_new();
Subtree parent = ts_subtree_new_error_node(&children, false, self->language);
t_subtree parent = ts_subtree_new_error_node(&children, false, self->language);
ts_stack_push(self->stack, version, parent, false, 1);
ts_parser__accept(self, version, lookahead);
return;
@ -999,7 +997,7 @@ static void ts_parser__recover(TSParser *self, t_stack_version version, Subtree
const TSParseAction *actions = ts_language_actions(self->language, 1, ts_subtree_symbol(lookahead), &n);
if (n > 0 && actions[n - 1].type == TSParseActionTypeShift && actions[n - 1].shift.extra)
{
MutableSubtree mutable_lookahead = ts_subtree_make_mut(/*&self->tree_pool,*/ lookahead);
t_mut_subtree mutable_lookahead = ts_subtree_make_mut(/*&self->tree_pool,*/ lookahead);
ts_subtree_set_extra(&mutable_lookahead, true);
lookahead = ts_subtree_from_mut(mutable_lookahead);
}
@ -1008,7 +1006,7 @@ static void ts_parser__recover(TSParser *self, t_stack_version version, Subtree
SubtreeArray children = array_new();
array_reserve(&children, 1);
array_push(&children, lookahead);
MutableSubtree error_repeat = ts_subtree_new_node(ts_builtin_sym_error_repeat, &children, 0, self->language);
t_mut_subtree error_repeat = ts_subtree_new_node(ts_builtin_sym_error_repeat, &children, 0, self->language);
// If other tokens have already been skipped, so there is already an ERROR at the top of the
// stack, then pop that ERROR off the stack and wrap the two ERRORs together into one larger
@ -1046,7 +1044,7 @@ static void ts_parser__recover(TSParser *self, t_stack_version version, Subtree
}
}
static void ts_parser__handle_error(TSParser *self, t_stack_version version, Subtree lookahead)
static void ts_parser__handle_error(TSParser *self, t_stack_version version, t_subtree lookahead)
{
t_u32 previous_version_count = ts_stack_version_count(self->stack);
@ -1084,7 +1082,7 @@ static void ts_parser__handle_error(TSParser *self, t_stack_version version, Sub
t_u32 lookahead_bytes = ts_subtree_total_bytes(lookahead) + ts_subtree_lookahead_bytes(lookahead);
t_stack_version version_with_missing_tree = ts_stack_copy_version(self->stack, v);
Subtree missing_tree =
t_subtree missing_tree =
ts_subtree_new_missing_leaf(/*&self->tree_pool,*/ missing_symbol, padding, lookahead_bytes, self->language);
ts_stack_push(self->stack, version_with_missing_tree, missing_tree, false, state_after_missing_symbol);
@ -1123,7 +1121,7 @@ static bool ts_parser__advance(TSParser *self, t_stack_version version, bool all
(void)(allow_node_reuse);
TSStateId state = ts_stack_state(self->stack, version);
Subtree lookahead = NULL;
t_subtree lookahead = NULL;
TableEntry table_entry = {.action_count = 0};
bool needs_lex = true;
@ -1248,7 +1246,7 @@ static bool ts_parser__advance(TSParser *self, t_stack_version version, bool all
ts_language_table_entry(self->language, state, self->language->keyword_capture_token, &table_entry);
if (table_entry.action_count > 0)
{
MutableSubtree mutable_lookahead = ts_subtree_make_mut(/*&self->tree_pool,*/ lookahead);
t_mut_subtree mutable_lookahead = ts_subtree_make_mut(/*&self->tree_pool,*/ lookahead);
ts_subtree_set_symbol(&mutable_lookahead, self->language->keyword_capture_token, self->language);
lookahead = ts_subtree_from_mut(mutable_lookahead);
continue;
@ -1373,7 +1371,7 @@ static t_u32 ts_parser__condense_stack(TSParser *self)
if (!has_unpaused_version && self->accept_count < MAX_VERSION_COUNT)
{
min_error_cost = ts_stack_error_cost(self->stack, i);
Subtree lookahead = ts_stack_resume(self->stack, i);
t_subtree lookahead = ts_stack_resume(self->stack, i);
ts_parser__handle_error(self, i, lookahead);
has_unpaused_version = true;
}

View file

@ -28,10 +28,10 @@ bool ts_stack_is_paused(const t_stack *self, t_stack_version version)
return (array_get(&self->heads, version)->status == SStatusPaused);
}
Subtree ts_stack_resume(t_stack *self, t_stack_version version)
t_subtree ts_stack_resume(t_stack *self, t_stack_version version)
{
t_stack_head *head;
Subtree result;
t_subtree result;
head = array_get(&self->heads, version);
assert(head->status == SStatusPaused);

View file

@ -51,7 +51,7 @@ bool ts_stack_has_advanced_since_error(const t_stack *self,
{
const t_stack_head *head = array_get(&self->heads, version);
const t_stack_node *node = head->node;
Subtree subtree;
t_subtree subtree;
if (node->error_cost == 0)
return (true);

View file

@ -13,7 +13,7 @@
#include "parser/stack.h"
#include "parser/_inner/stack.h"
bool stack__subtree_is_equivalent(Subtree left, Subtree right)
bool stack__subtree_is_equivalent(t_subtree left, t_subtree right)
{
if (left == right)
return (true);
@ -97,7 +97,7 @@ t_stack_version original_version, t_stack_node *node, SubtreeArray *subtrees)
}
void ts_stack_set_last_external_token(t_stack *self, t_stack_version version,
Subtree token)
t_subtree token)
{
t_stack_head *head;

View file

@ -28,7 +28,7 @@ Length ts_stack_position(const t_stack *self, t_stack_version version)
return (array_get(&self->heads, version)->node->position);
}
Subtree ts_stack_last_external_token(const t_stack *self,
t_subtree ts_stack_last_external_token(const t_stack *self,
t_stack_version version)
{
return (array_get(&self->heads, version)->last_external_token);

View file

@ -46,7 +46,7 @@ t_stack_slice_array stack__iter(t_stack *self, t_stack_version version,
{
include_subtrees = true;
array_reserve(&new_iterator.subtrees,
(t_u32)ts_subtree_alloc_size(goal_subtree_count) / sizeof(Subtree));
(t_u32)ts_subtree_alloc_size(goal_subtree_count) / sizeof(t_subtree));
}
array_push(&self->iterators, new_iterator);
while (self->iterators.size > 0)

View file

@ -13,7 +13,7 @@
#include "parser/_inner/stack.h"
#include "parser/language.h"
void ts_stack_push(t_stack *self, t_stack_version version, Subtree subtree,
void ts_stack_push(t_stack *self, t_stack_version version, t_subtree subtree,
bool pending, TSStateId state)
{
t_stack_head *head;

View file

@ -56,7 +56,7 @@ void ts_stack_halt(t_stack *self, t_stack_version version)
}
void ts_stack_pause(t_stack *self, t_stack_version version,
Subtree lookahead)
t_subtree lookahead)
{
t_stack_head *head;

View file

@ -70,7 +70,7 @@ void stack_node_release(t_stack_node *self)
// Count intermediate error nodes even though they are not visible,
// because a stack version's node count is used to check whether it
// has made any progress since the last time it encountered an error.
t_u32 stack__subtree_node_count(Subtree subtree)
t_u32 stack__subtree_node_count(t_subtree subtree)
{
t_u32 count;
@ -83,7 +83,7 @@ t_u32 stack__subtree_node_count(Subtree subtree)
}
t_stack_node *stack_node_new(t_stack_node *previous_node,
Subtree subtree, bool is_pending, TSStateId state)
t_subtree subtree, bool is_pending, TSStateId state)
{
t_stack_node *node;

View file

@ -21,8 +21,8 @@ void ts_subtree_array_copy(SubtreeArray self, SubtreeArray *dest)
dest->contents = self.contents;
if (self.capacity > 0)
{
dest->contents = mem_alloc_array(self.capacity, sizeof(Subtree));
mem_copy(dest->contents, self.contents, self.size * sizeof(Subtree));
dest->contents = mem_alloc_array(self.capacity, sizeof(t_subtree));
mem_copy(dest->contents, self.contents, self.size * sizeof(t_subtree));
for (t_u32 i = 0; i < self.size; i++)
{
ts_subtree_retain(dest->contents[i]);
@ -50,7 +50,7 @@ void ts_subtree_array_remove_trailing_extras(SubtreeArray *self, SubtreeArray *d
array_clear(destination);
while (self->size > 0)
{
Subtree last = self->contents[self->size - 1];
t_subtree last = self->contents[self->size - 1];
if (ts_subtree_extra(last))
{
self->size--;
@ -69,21 +69,21 @@ void ts_subtree_array_reverse(SubtreeArray *self)
for (t_u32 i = 0, limit = self->size / 2; i < limit; i++)
{
size_t reverse_index = self->size - 1 - i;
Subtree swap = self->contents[i];
t_subtree swap = self->contents[i];
self->contents[i] = self->contents[reverse_index];
self->contents[reverse_index] = swap;
}
}
Subtree ts_subtree_new_leaf(TSSymbol symbol, Length padding, Length size, t_u32 lookahead_bytes, TSStateId parse_state,
t_subtree ts_subtree_new_leaf(TSSymbol symbol, Length padding, Length size, t_u32 lookahead_bytes, TSStateId parse_state,
bool has_external_tokens, bool depends_on_column, bool is_keyword, const TSLanguage *language)
{
TSSymbolMetadata metadata = ts_language_symbol_metadata(language, symbol);
bool extra = symbol == ts_builtin_sym_end;
{
SubtreeHeapData *data = mem_alloc(sizeof(*data));
*data = (SubtreeHeapData){.ref_count = 1,
t_subtree_data *data = mem_alloc(sizeof(*data));
*data = (t_subtree_data){.ref_count = 1,
.padding = padding,
.size = size,
.lookahead_bytes = lookahead_bytes,
@ -103,11 +103,11 @@ Subtree ts_subtree_new_leaf(TSSymbol symbol, Length padding, Length size, t_u32
.is_missing = false,
.is_keyword = is_keyword,
{{.first_leaf = {.symbol = 0, .parse_state = 0}}}};
return (Subtree)data;
return (t_subtree)data;
}
}
void ts_subtree_set_symbol(MutableSubtree *self, TSSymbol symbol, const TSLanguage *language)
void ts_subtree_set_symbol(t_mut_subtree *self, TSSymbol symbol, const TSLanguage *language)
{
TSSymbolMetadata metadata = ts_language_symbol_metadata(language, symbol);
{
@ -117,11 +117,11 @@ void ts_subtree_set_symbol(MutableSubtree *self, TSSymbol symbol, const TSLangua
}
}
Subtree ts_subtree_new_error(t_i32 lookahead_char, Length padding, Length size, t_u32 bytes_scanned, TSStateId parse_state,
t_subtree ts_subtree_new_error(t_i32 lookahead_char, Length padding, Length size, t_u32 bytes_scanned, TSStateId parse_state,
const TSLanguage *language)
{
Subtree result = ts_subtree_new_leaf(ts_builtin_sym_error, padding, size, bytes_scanned, parse_state, false, false, false, language);
SubtreeHeapData *data = (SubtreeHeapData *)result;
t_subtree result = ts_subtree_new_leaf(ts_builtin_sym_error, padding, size, bytes_scanned, parse_state, false, false, false, language);
t_subtree_data *data = (t_subtree_data *)result;
data->fragile_left = true;
data->fragile_right = true;
data->lookahead_char = lookahead_char;
@ -129,13 +129,13 @@ Subtree ts_subtree_new_error(t_i32 lookahead_char, Length padding, Length size,
}
// Clone a subtree.
MutableSubtree ts_subtree_clone(Subtree self)
t_mut_subtree ts_subtree_clone(t_subtree self)
{
size_t alloc_size = ts_subtree_alloc_size(self->child_count);
Subtree *new_children = mem_alloc(alloc_size);
Subtree *old_children = ts_subtree_children(self);
t_subtree *new_children = mem_alloc(alloc_size);
t_subtree *old_children = ts_subtree_children(self);
mem_copy(new_children, old_children, alloc_size);
SubtreeHeapData *result = (SubtreeHeapData *)&new_children[self->child_count];
t_subtree_data *result = (t_subtree_data *)&new_children[self->child_count];
if (self->child_count > 0)
{
for (t_u32 i = 0; i < self->child_count; i++)
@ -148,7 +148,7 @@ MutableSubtree ts_subtree_clone(Subtree self)
result->external_scanner_state = ts_external_scanner_state_copy(&self->external_scanner_state);
}
result->ref_count = 1;
return (MutableSubtree)result;
return (t_mut_subtree)result;
}
// Get mutable version of a subtree.
@ -156,31 +156,31 @@ MutableSubtree ts_subtree_clone(Subtree self)
// This takes ownership of the subtree. If the subtree has only one owner,
// this will directly convert it into a mutable version. Otherwise, it will
// perform a copy.
MutableSubtree ts_subtree_make_mut(Subtree self)
t_mut_subtree ts_subtree_make_mut(t_subtree self)
{
if (self->ref_count == 1)
return ts_subtree_to_mut_unsafe(self);
MutableSubtree result = ts_subtree_clone(self);
t_mut_subtree result = ts_subtree_clone(self);
ts_subtree_release(self);
return result;
}
static void ts_subtree__compress(MutableSubtree self, t_u32 count, const TSLanguage *language, MutableSubtreeArray *stack)
static void ts_subtree__compress(t_mut_subtree self, t_u32 count, const TSLanguage *language, MutableSubtreeArray *stack)
{
t_u32 initial_stack_size = stack->size;
MutableSubtree tree = self;
t_mut_subtree tree = self;
TSSymbol symbol = tree->symbol;
for (t_u32 i = 0; i < count; i++)
{
if (tree->ref_count > 1 || tree->child_count < 2)
break;
MutableSubtree child = ts_subtree_to_mut_unsafe(ts_subtree_children(tree)[0]);
t_mut_subtree child = ts_subtree_to_mut_unsafe(ts_subtree_children(tree)[0]);
if (child->child_count < 2 || child->ref_count > 1 || child->symbol != symbol)
break;
MutableSubtree grandchild = ts_subtree_to_mut_unsafe(ts_subtree_children(child)[0]);
t_mut_subtree grandchild = ts_subtree_to_mut_unsafe(ts_subtree_children(child)[0]);
if (grandchild->child_count < 2 || grandchild->ref_count > 1 || grandchild->symbol != symbol)
break;
@ -194,15 +194,15 @@ static void ts_subtree__compress(MutableSubtree self, t_u32 count, const TSLangu
while (stack->size > initial_stack_size)
{
tree = array_pop(stack);
MutableSubtree child = ts_subtree_to_mut_unsafe(ts_subtree_children(tree)[0]);
MutableSubtree grandchild = ts_subtree_to_mut_unsafe(ts_subtree_children(child)[child->child_count - 1]);
t_mut_subtree child = ts_subtree_to_mut_unsafe(ts_subtree_children(tree)[0]);
t_mut_subtree grandchild = ts_subtree_to_mut_unsafe(ts_subtree_children(child)[child->child_count - 1]);
ts_subtree_summarize_children(grandchild, language);
ts_subtree_summarize_children(child, language);
ts_subtree_summarize_children(tree, language);
}
}
void ts_subtree_balance(Subtree self, const TSLanguage *language)
void ts_subtree_balance(t_subtree self, const TSLanguage *language)
{
MutableSubtreeArray balance_stack = array_new();
@ -215,12 +215,12 @@ void ts_subtree_balance(Subtree self, const TSLanguage *language)
while (balance_stack.size > 0)
{
MutableSubtree tree = array_pop(&balance_stack);
t_mut_subtree tree = array_pop(&balance_stack);
if (tree->repeat_depth > 0)
{
Subtree child1 = ts_subtree_children(tree)[0];
Subtree child2 = ts_subtree_children(tree)[tree->child_count - 1];
t_subtree child1 = ts_subtree_children(tree)[0];
t_subtree child2 = ts_subtree_children(tree)[tree->child_count - 1];
long repeat_delta = (long)ts_subtree_repeat_depth(child1) - (long)ts_subtree_repeat_depth(child2);
if (repeat_delta > 0)
{
@ -235,7 +235,7 @@ void ts_subtree_balance(Subtree self, const TSLanguage *language)
for (t_u32 i = 0; i < tree->child_count; i++)
{
Subtree child = ts_subtree_children(tree)[i];
t_subtree child = ts_subtree_children(tree)[i];
if (ts_subtree_child_count(child) > 0 && child->ref_count == 1)
{
array_push(&balance_stack, ts_subtree_to_mut_unsafe(child));
@ -246,7 +246,7 @@ void ts_subtree_balance(Subtree self, const TSLanguage *language)
}
// Assign all of the node's properties that depend on its children.
void ts_subtree_summarize_children(MutableSubtree self, const TSLanguage *language)
void ts_subtree_summarize_children(t_mut_subtree self, const TSLanguage *language)
{
self->named_child_count = 0;
self->visible_child_count = 0;
@ -262,10 +262,10 @@ void ts_subtree_summarize_children(MutableSubtree self, const TSLanguage *langua
const TSSymbol *alias_sequence = ts_language_alias_sequence(language, self->production_id);
t_u32 lookahead_end_byte = 0;
const Subtree *children = ts_subtree_children(self);
const t_subtree *children = ts_subtree_children(self);
for (t_u32 i = 0; i < self->child_count; i++)
{
Subtree child = children[i];
t_subtree child = children[i];
if (self->size.extent.row == 0 && ts_subtree_depends_on_column(child))
{
@ -362,8 +362,8 @@ void ts_subtree_summarize_children(MutableSubtree self, const TSLanguage *langua
if (self->child_count > 0)
{
Subtree first_child = children[0];
Subtree last_child = children[self->child_count - 1];
t_subtree first_child = children[0];
t_subtree last_child = children[self->child_count - 1];
self->first_leaf.symbol = ts_subtree_leaf_symbol(first_child);
self->first_leaf.parse_state = ts_subtree_leaf_parse_state(first_child);
@ -390,21 +390,21 @@ void ts_subtree_summarize_children(MutableSubtree self, const TSLanguage *langua
// Create a new parent node with the given children.
//
// This takes ownership of the children array.
MutableSubtree ts_subtree_new_node(TSSymbol symbol, SubtreeArray *children, t_u32 production_id, const TSLanguage *language)
t_mut_subtree ts_subtree_new_node(TSSymbol symbol, SubtreeArray *children, t_u32 production_id, const TSLanguage *language)
{
TSSymbolMetadata metadata = ts_language_symbol_metadata(language, symbol);
bool fragile = symbol == ts_builtin_sym_error || symbol == ts_builtin_sym_error_repeat;
// Allocate the node's data at the end of the array of children.
size_t new_byte_size = ts_subtree_alloc_size(children->size);
if (children->capacity * sizeof(Subtree) < new_byte_size)
if (children->capacity * sizeof(t_subtree) < new_byte_size)
{
children->contents = mem_realloc(children->contents, new_byte_size);
children->capacity = (t_u32)(new_byte_size / sizeof(Subtree));
children->capacity = (t_u32)(new_byte_size / sizeof(t_subtree));
}
SubtreeHeapData *data = (SubtreeHeapData *)&children->contents[children->size];
t_subtree_data *data = (t_subtree_data *)&children->contents[children->size];
*data = (SubtreeHeapData){.ref_count = 1,
*data = (t_subtree_data){.ref_count = 1,
.symbol = symbol,
.child_count = children->size,
.visible = metadata.visible,
@ -419,7 +419,7 @@ MutableSubtree ts_subtree_new_node(TSSymbol symbol, SubtreeArray *children, t_u3
.production_id = production_id,
.first_leaf = {.symbol = 0, .parse_state = 0},
}}};
MutableSubtree result = data;
t_mut_subtree result = data;
ts_subtree_summarize_children(result, language);
return result;
}
@ -428,9 +428,9 @@ MutableSubtree ts_subtree_new_node(TSSymbol symbol, SubtreeArray *children, t_u3
//
// This node is treated as 'extra'. Its children are prevented from having
// having any effect on the parse state.
Subtree ts_subtree_new_error_node(SubtreeArray *children, bool extra, const TSLanguage *language)
t_subtree ts_subtree_new_error_node(SubtreeArray *children, bool extra, const TSLanguage *language)
{
MutableSubtree result = ts_subtree_new_node(ts_builtin_sym_error, children, 0, language);
t_mut_subtree result = ts_subtree_new_node(ts_builtin_sym_error, children, 0, language);
result->extra = extra;
return ts_subtree_from_mut(result);
}
@ -439,21 +439,21 @@ Subtree ts_subtree_new_error_node(SubtreeArray *children, bool extra, const TSLa
//
// This node is treated as 'extra'. Its children are prevented from having
// having any effect on the parse state.
Subtree ts_subtree_new_missing_leaf(TSSymbol symbol, Length padding, t_u32 lookahead_bytes, const TSLanguage *language)
t_subtree ts_subtree_new_missing_leaf(TSSymbol symbol, Length padding, t_u32 lookahead_bytes, const TSLanguage *language)
{
Subtree result = ts_subtree_new_leaf(symbol, padding, length_zero(), lookahead_bytes, 0, false, false, false, language);
((SubtreeHeapData *)result)->is_missing = true;
t_subtree result = ts_subtree_new_leaf(symbol, padding, length_zero(), lookahead_bytes, 0, false, false, false, language);
((t_subtree_data *)result)->is_missing = true;
return result;
}
void ts_subtree_retain(Subtree self)
void ts_subtree_retain(t_subtree self)
{
assert(self->ref_count > 0);
(*(t_u32 *)(&self->ref_count))++;
assert(self->ref_count != 0);
}
void ts_subtree_release(Subtree self)
void ts_subtree_release(t_subtree self)
{
MutableSubtreeArray to_free;
@ -469,13 +469,13 @@ void ts_subtree_release(Subtree self)
while (to_free.size > 0)
{
MutableSubtree tree = array_pop(&to_free);
t_mut_subtree tree = array_pop(&to_free);
if (tree->child_count > 0)
{
Subtree *children = ts_subtree_children(tree);
t_subtree *children = ts_subtree_children(tree);
for (t_u32 i = 0; i < tree->child_count; i++)
{
Subtree child = children[i];
t_subtree child = children[i];
assert(child->ref_count > 0);
if (--(*(t_u32 *)(&child->ref_count)) == 0)
{
@ -494,7 +494,7 @@ void ts_subtree_release(Subtree self)
array_delete(&to_free);
}
int ts_subtree_compare(Subtree left, Subtree right)
int ts_subtree_compare(t_subtree left, t_subtree right)
{
MutableSubtreeArray compare_stack = array_new();
@ -524,8 +524,8 @@ int ts_subtree_compare(Subtree left, Subtree right)
for (t_u32 i = ts_subtree_child_count(left); i > 0; i--)
{
Subtree left_child = ts_subtree_children(left)[i - 1];
Subtree right_child = ts_subtree_children(right)[i - 1];
t_subtree left_child = ts_subtree_children(left)[i - 1];
t_subtree right_child = ts_subtree_children(right)[i - 1];
array_push(&compare_stack, ts_subtree_to_mut_unsafe(left_child));
array_push(&compare_stack, ts_subtree_to_mut_unsafe(right_child));
}
@ -535,7 +535,7 @@ int ts_subtree_compare(Subtree left, Subtree right)
return 0;
}
Subtree ts_subtree_last_external_token(Subtree tree)
t_subtree ts_subtree_last_external_token(t_subtree tree)
{
if (!ts_subtree_has_external_tokens(tree))
return NULL;
@ -543,7 +543,7 @@ Subtree ts_subtree_last_external_token(Subtree tree)
{
for (t_u32 i = tree->child_count - 1; i + 1 > 0; i--)
{
Subtree child = ts_subtree_children(tree)[i];
t_subtree child = ts_subtree_children(tree)[i];
if (ts_subtree_has_external_tokens(child))
{
tree = child;

View file

@ -14,7 +14,7 @@
#include "parser/subtree.h"
#include "parser/tree.h"
TSTree *ts_tree_new(Subtree root, const TSLanguage *language)
TSTree *ts_tree_new(t_subtree root, const TSLanguage *language)
{
TSTree *result;