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

@ -20,7 +20,7 @@
typedef struct s_node_child_iterator NodeChildIterator;
struct s_node_child_iterator
{
Subtree parent;
t_subtree parent;
const TSTree *tree;
Length position;
t_u32 child_index;
@ -37,7 +37,7 @@ bool ts_node_child_iterator_done(NodeChildIterator *self);
bool ts_node_child_iterator_next(NodeChildIterator *self, TSNode *result);
t_const_str ts_node__field_name_from_language(TSNode self, t_u32 structural_child_index);
t_u32 ts_node__relevant_child_count(TSNode self, bool include_anonymous);
Subtree ts_node__subtree(TSNode self);
t_subtree ts_node__subtree(TSNode self);
t_u32 ts_node__alias(const TSNode *self);
#endif /* NODE_H */

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/31 16:37:50 by maiboyer #+# #+# */
/* Updated: 2024/08/31 16:53:40 by maiboyer ### ########.fr */
/* Updated: 2024/08/31 18:36:27 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -35,7 +35,7 @@ typedef t_stack_action (*t_stack_callback)(void *,
struct s_stack_link
{
t_stack_node *node;
Subtree subtree;
t_subtree subtree;
bool is_pending;
};
@ -71,8 +71,8 @@ struct s_stack_head
t_stack_node *node;
t_stack_summary *summary;
t_u32 node_count_at_last_error;
Subtree last_external_token;
Subtree lookahead_when_paused;
t_subtree last_external_token;
t_subtree lookahead_when_paused;
t_stack_status status;
};
@ -97,11 +97,11 @@ struct s_summarize_stack_session
t_u32 max_depth;
};
bool stack__subtree_is_equivalent(Subtree left, Subtree right);
t_stack_node *stack_node_new(t_stack_node *previous_node, Subtree subtree, bool is_pending, TSStateId state);
bool stack__subtree_is_equivalent(t_subtree left, t_subtree right);
t_stack_node *stack_node_new(t_stack_node *previous_node, t_subtree subtree, bool is_pending, TSStateId state);
t_stack_slice_array stack__iter(t_stack *self, t_stack_version version, t_stack_callback callback, void *payload, int goal_subtree_count);
t_stack_version ts_stack__add_version(t_stack *self, t_stack_version original_version, t_stack_node *node);
t_u32 stack__subtree_node_count(Subtree subtree);
t_u32 stack__subtree_node_count(t_subtree subtree);
void stack_head_delete(t_stack_head *self);
void stack_node_add_link(t_stack_node *self, t_stack_link link);
void stack_node_release(t_stack_node *self);

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/24 13:56:34 by maiboyer #+# #+# */
/* Updated: 2024/08/24 14:00:11 by maiboyer ### ########.fr */
/* Updated: 2024/08/31 18:34:46 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,21 +15,21 @@
#include "me/types.h"
struct ExternalScannerState
struct s_external_scanner_state
{
char *long_data;
t_u32 length;
};
typedef struct ExternalScannerState ExternalScannerState;
typedef struct SubtreeHeapData SubtreeHeapData;
typedef const SubtreeHeapData *Subtree;
typedef struct s_external_scanner_state t_external_scanner_state;
typedef struct s_subtree_data t_subtree_data;
typedef const t_subtree_data *t_subtree;
void ts_external_scanner_state_init(ExternalScannerState *self, const t_u8 *data, t_u32 length);
ExternalScannerState ts_external_scanner_state_copy(const ExternalScannerState *self);
void ts_external_scanner_state_delete(ExternalScannerState *self);
const t_u8 *ts_external_scanner_state_data(const ExternalScannerState *self);
bool ts_external_scanner_state_eq(const ExternalScannerState *self, const t_u8 *buffer, t_u32 length);
const ExternalScannerState *ts_subtree_external_scanner_state(Subtree self);
bool ts_subtree_external_scanner_state_eq(Subtree self, Subtree other);
void ts_external_scanner_state_init(t_external_scanner_state *self, const t_u8 *data, t_u32 length);
t_external_scanner_state ts_external_scanner_state_copy(const t_external_scanner_state *self);
void ts_external_scanner_state_delete(t_external_scanner_state *self);
const t_u8 *ts_external_scanner_state_data(const t_external_scanner_state *self);
bool ts_external_scanner_state_eq(const t_external_scanner_state *self, const t_u8 *buffer, t_u32 length);
const t_external_scanner_state *ts_subtree_external_scanner_state(t_subtree self);
bool ts_subtree_external_scanner_state_eq(t_subtree self, t_subtree other);
#endif /* EXTERNAL_SCANNER_STATE_H */

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/31 12:03:16 by maiboyer #+# #+# */
/* Updated: 2024/08/31 12:03:29 by maiboyer ### ########.fr */
/* Updated: 2024/08/31 18:30:26 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,13 +16,13 @@
#include "parser/api.h"
#include "me/types.h"
struct Length
struct s_length
{
t_u32 bytes;
TSPoint extent;
};
typedef struct Length Length;
typedef struct s_length Length;
static const Length LENGTH_UNDEFINED = {0, {0, 1}};
static const Length LENGTH_MAX = {UINT32_MAX, {UINT32_MAX, UINT32_MAX}};

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/31 12:03:15 by maiboyer #+# #+# */
/* Updated: 2024/08/31 12:03:29 by maiboyer ### ########.fr */
/* Updated: 2024/08/31 18:39:28 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,7 +18,7 @@
#include "parser/parser.h"
#include "me/types.h"
struct Lexer
struct s_lexer
{
TSLexer data;
Length current_position;
@ -37,17 +37,17 @@ struct Lexer
t_u8 debug_buffer[TREE_SITTER_SERIALIZATION_BUFFER_SIZE];
};
typedef struct Lexer Lexer;
typedef struct s_lexer t_lexer;
void ts_lexer_init(Lexer *self);
void ts_lexer_delete(Lexer *self);
void ts_lexer_set_input(Lexer *self, TSInput input);
void ts_lexer_reset(Lexer *self, Length length);
void ts_lexer_start(Lexer *self);
void ts_lexer_finish(Lexer *self, t_u32 *lookahead);
void ts_lexer_advance_to_end(Lexer *self);
void ts_lexer_mark_end(Lexer *self);
bool ts_lexer_set_included_ranges(Lexer *self, const TSRange *ranges, t_u32 count);
TSRange *ts_lexer_included_ranges(const Lexer *self, t_u32 *count);
void ts_lexer_init(t_lexer *self);
void ts_lexer_delete(t_lexer *self);
void ts_lexer_set_input(t_lexer *self, TSInput input);
void ts_lexer_reset(t_lexer *self, Length length);
void ts_lexer_start(t_lexer *self);
void ts_lexer_finish(t_lexer *self, t_u32 *lookahead);
void ts_lexer_advance_to_end(t_lexer *self);
void ts_lexer_mark_end(t_lexer *self);
bool ts_lexer_set_included_ranges(t_lexer *self, const TSRange *ranges, t_u32 count);
TSRange *ts_lexer_included_ranges(const t_lexer *self, t_u32 *count);
#endif // LEXER_H

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/31 12:03:13 by maiboyer #+# #+# */
/* Updated: 2024/08/31 12:03:29 by maiboyer ### ########.fr */
/* Updated: 2024/08/31 18:45:04 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -46,9 +46,9 @@ typedef struct TSSymbolMetadata
bool supertype;
} TSSymbolMetadata;
typedef struct TSLexer TSLexer;
typedef struct s_lexer_functions TSLexer;
struct TSLexer
struct s_lexer_functions
{
t_i32 lookahead;
TSSymbol result_symbol;
@ -184,10 +184,10 @@ static inline bool set_contains(TSCharacterRange *ranges, t_u32 len, t_i32 looka
t_i32 lookahead; \
goto start; \
next_state: \
lexer->advance(lexer, skip); \
lexer->data.advance((void *)lexer, skip); \
start: \
skip = false; \
lookahead = lexer->lookahead;
lookahead = lexer->data.lookahead;
#define ADVANCE(state_value) \
{ \
@ -217,8 +217,8 @@ start:
#define ACCEPT_TOKEN(symbol_value) \
result = true; \
lexer->result_symbol = symbol_value; \
lexer->mark_end(lexer);
lexer->data.result_symbol = symbol_value; \
lexer->data.mark_end((void *)lexer);
#define END_STATE() return result;

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/31 12:03:09 by maiboyer #+# #+# */
/* Updated: 2024/08/31 12:03:29 by maiboyer ### ########.fr */
/* Updated: 2024/08/31 18:31:33 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,7 +17,7 @@
#include "parser/array.h"
#include "me/types.h"
struct ReduceAction
struct s_reduce_action
{
t_u32 count;
TSSymbol symbol;
@ -25,7 +25,7 @@ struct ReduceAction
t_u16 production_id;
};
typedef struct ReduceAction ReduceAction;
typedef struct s_reduce_action ReduceAction;
typedef Array(ReduceAction) ReduceActionSet;
void ts_reduce_action_set_add(ReduceActionSet *self, ReduceAction new_action);

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/31 12:03:07 by maiboyer #+# #+# */
/* Updated: 2024/08/31 15:27:32 by maiboyer ### ########.fr */
/* Updated: 2024/08/31 18:34:46 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -39,98 +39,36 @@ struct s_stack_summary_entry
TSStateId state;
};
// Create a stack.
t_stack *ts_stack_new(/*SubtreePool **/);
// Release the memory reserved for a given stack.
t_stack *ts_stack_new(void);
void ts_stack_delete(t_stack *);
// Get the stack's current number of versions.
t_u32 ts_stack_version_count(const t_stack *);
// Get the state at the top of the given version of the stack. If the stack is
// empty, this returns the initial state, 0.
TSStateId ts_stack_state(const t_stack *, t_stack_version);
// Get the last external token associated with a given version of the stack.
Subtree ts_stack_last_external_token(const t_stack *, t_stack_version);
// Set the last external token associated with a given version of the stack.
void ts_stack_set_last_external_token(t_stack *, t_stack_version, Subtree);
// Get the position of the given version of the stack within the document.
t_subtree ts_stack_last_external_token(const t_stack *, t_stack_version);
void ts_stack_set_last_external_token(t_stack *, t_stack_version, t_subtree);
Length ts_stack_position(const t_stack *, t_stack_version);
// Push a tree and state onto the given version of the stack.
//
// This transfers ownership of the tree to the t_stack. Callers that
// need to retain ownership of the tree for their own purposes should
// first retain the tree.
void ts_stack_push(t_stack *, t_stack_version, Subtree, bool, TSStateId);
// 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
// versions which had previously been merged. It returns an array that
// specifies the index of each revealed version and the trees that were
// removed from that version.
void ts_stack_push(t_stack *, t_stack_version, t_subtree, bool, TSStateId);
t_stack_slice_array ts_stack_pop_count(t_stack *, t_stack_version, t_u32 count);
// Remove an error at the top of the given version of the stack.
SubtreeArray ts_stack_pop_error(t_stack *, t_stack_version);
// Remove any pending trees from the top of the given version of the stack.
t_stack_slice_array ts_stack_pop_pending(t_stack *, t_stack_version);
// Remove any all trees from the given version of the stack.
t_stack_slice_array ts_stack_pop_all(t_stack *, t_stack_version);
// Get the maximum number of tree nodes reachable from this version of the stack
// since the last error was detected.
t_u32 ts_stack_node_count_since_error(const t_stack *, t_stack_version);
int ts_stack_dynamic_precedence(t_stack *, t_stack_version);
bool ts_stack_has_advanced_since_error(const t_stack *, t_stack_version);
// Compute a summary of all the parse states near the top of the given
// version of the stack and store the summary for later retrieval.
void ts_stack_record_summary(t_stack *, t_stack_version, t_u32 max_depth);
// Retrieve a summary of all the parse states near the top of the
// given version of the stack.
t_stack_summary *ts_stack_get_summary(t_stack *, t_stack_version);
// Get the total cost of all errors on the given version of the stack.
t_u32 ts_stack_error_cost(const t_stack *, t_stack_version version);
// Merge the given two stack versions if possible, returning true
// if they were successfully merged and false otherwise.
bool ts_stack_merge(t_stack *, t_stack_version, t_stack_version);
// Determine whether the given two stack versions can be merged.
bool ts_stack_can_merge(t_stack *, t_stack_version, t_stack_version);
Subtree ts_stack_resume(t_stack *, t_stack_version);
void ts_stack_pause(t_stack *, t_stack_version, Subtree);
t_subtree ts_stack_resume(t_stack *, t_stack_version);
void ts_stack_pause(t_stack *, t_stack_version, t_subtree);
void ts_stack_halt(t_stack *, t_stack_version);
bool ts_stack_is_active(const t_stack *, t_stack_version);
bool ts_stack_is_paused(const t_stack *, t_stack_version);
bool ts_stack_is_halted(const t_stack *, t_stack_version);
void ts_stack_renumber_version(t_stack *, t_stack_version, t_stack_version);
void ts_stack_swap_versions(t_stack *, t_stack_version, t_stack_version);
t_stack_version ts_stack_copy_version(t_stack *, t_stack_version);
// Remove the given version from the stack.
void ts_stack_remove_version(t_stack *, t_stack_version);
void ts_stack_clear(t_stack *);
#endif // PARSE_STACK_H

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/31 12:03:06 by maiboyer #+# #+# */
/* Updated: 2024/08/31 12:03:06 by maiboyer ### ########.fr */
/* Updated: 2024/08/31 18:37:26 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -26,16 +26,16 @@
#define TS_BIG_ENDIAN 0
#define TS_PTR_SIZE 64
#define TS_TREE_STATE_NONE USHRT_MAX
#define NULL_SUBTREE ((Subtree)NULL)
#define NULL_SUBTREE ((t_subtree)NULL)
// A heap-allocated representation of a subtree.
//
// This representation is used for parent nodes, external tokens,
// errors, and other leaf nodes whose data is too large to fit into
// the inline representation.
typedef struct SubtreeHeapData SubtreeHeapData;
typedef struct s_subtree_data t_subtree_data;
struct SubtreeHeapData
struct s_subtree_data
{
t_u32 ref_count;
Length padding;
@ -76,7 +76,7 @@ struct SubtreeHeapData
};
// External terminal subtrees (`child_count == 0 && has_external_tokens`)
ExternalScannerState external_scanner_state;
t_external_scanner_state external_scanner_state;
// Error terminal subtrees (`child_count == 0 && symbol == ts_builtin_sym_error`)
t_i32 lookahead_char;
@ -84,18 +84,18 @@ struct SubtreeHeapData
};
// The fundamental building block of a syntax tree.
typedef const SubtreeHeapData *Subtree;
typedef const t_subtree_data *t_subtree;
// Like Subtree, but mutable.
typedef SubtreeHeapData *MutableSubtree;
// Like t_subtree, but mutable.
typedef t_subtree_data *t_mut_subtree;
typedef Array(Subtree) SubtreeArray;
typedef Array(MutableSubtree) MutableSubtreeArray;
typedef Array(t_subtree) SubtreeArray;
typedef Array(t_mut_subtree) MutableSubtreeArray;
void ts_external_scanner_state_init(ExternalScannerState *, const t_u8 *, t_u32);
const t_u8 *ts_external_scanner_state_data(const ExternalScannerState *);
bool ts_external_scanner_state_eq(const ExternalScannerState *self, const t_u8 *, t_u32);
void ts_external_scanner_state_delete(ExternalScannerState *self);
void ts_external_scanner_state_init(t_external_scanner_state *, const t_u8 *, t_u32);
const t_u8 *ts_external_scanner_state_data(const t_external_scanner_state *);
bool ts_external_scanner_state_eq(const t_external_scanner_state *self, const t_u8 *, t_u32);
void ts_external_scanner_state_delete(t_external_scanner_state *self);
void ts_subtree_array_copy(SubtreeArray, SubtreeArray *);
void ts_subtree_array_clear(SubtreeArray *);
@ -103,59 +103,59 @@ void ts_subtree_array_delete(SubtreeArray *);
void ts_subtree_array_remove_trailing_extras(SubtreeArray *, SubtreeArray *);
void ts_subtree_array_reverse(SubtreeArray *);
Subtree ts_subtree_new_leaf(TSSymbol, Length, Length, t_u32, TSStateId, bool, bool, bool, const TSLanguage *);
Subtree ts_subtree_new_error(t_i32, Length, Length, t_u32, TSStateId, const TSLanguage *);
MutableSubtree ts_subtree_new_node(TSSymbol, SubtreeArray *, t_u32, const TSLanguage *);
Subtree ts_subtree_new_error_node(SubtreeArray *, bool, const TSLanguage *);
Subtree ts_subtree_new_missing_leaf(TSSymbol, Length, t_u32, const TSLanguage *);
MutableSubtree ts_subtree_make_mut(Subtree);
void ts_subtree_retain(Subtree);
void ts_subtree_release(Subtree);
int ts_subtree_compare(Subtree, Subtree);
void ts_subtree_set_symbol(MutableSubtree *, TSSymbol, const TSLanguage *);
void ts_subtree_summarize(MutableSubtree, const Subtree *, t_u32, const TSLanguage *);
void ts_subtree_summarize_children(MutableSubtree, const TSLanguage *);
void ts_subtree_balance(Subtree, const TSLanguage *);
Subtree ts_subtree_edit(Subtree, const TSInputEdit *edit);
char *ts_subtree_string(Subtree, TSSymbol, bool, const TSLanguage *, bool include_all);
void ts_subtree_print_dot_graph(Subtree, const TSLanguage *, FILE *);
Subtree ts_subtree_last_external_token(Subtree);
const ExternalScannerState *ts_subtree_external_scanner_state(Subtree self);
bool ts_subtree_external_scanner_state_eq(Subtree, Subtree);
t_subtree ts_subtree_new_leaf(TSSymbol, Length, Length, t_u32, TSStateId, bool, bool, bool, const TSLanguage *);
t_subtree ts_subtree_new_error(t_i32, Length, Length, t_u32, TSStateId, const TSLanguage *);
t_mut_subtree ts_subtree_new_node(TSSymbol, SubtreeArray *, t_u32, const TSLanguage *);
t_subtree ts_subtree_new_error_node(SubtreeArray *, bool, const TSLanguage *);
t_subtree ts_subtree_new_missing_leaf(TSSymbol, Length, t_u32, const TSLanguage *);
t_mut_subtree ts_subtree_make_mut(t_subtree);
void ts_subtree_retain(t_subtree);
void ts_subtree_release(t_subtree);
int ts_subtree_compare(t_subtree, t_subtree);
void ts_subtree_set_symbol(t_mut_subtree *, TSSymbol, const TSLanguage *);
void ts_subtree_summarize(t_mut_subtree, const t_subtree *, t_u32, const TSLanguage *);
void ts_subtree_summarize_children(t_mut_subtree, const TSLanguage *);
void ts_subtree_balance(t_subtree, const TSLanguage *);
t_subtree ts_subtree_edit(t_subtree, const TSInputEdit *edit);
char *ts_subtree_string(t_subtree, TSSymbol, bool, const TSLanguage *, bool include_all);
void ts_subtree_print_dot_graph(t_subtree, const TSLanguage *, FILE *);
t_subtree ts_subtree_last_external_token(t_subtree);
const t_external_scanner_state *ts_subtree_external_scanner_state(t_subtree self);
bool ts_subtree_external_scanner_state_eq(t_subtree, t_subtree);
static inline TSSymbol ts_subtree_symbol(Subtree self)
static inline TSSymbol ts_subtree_symbol(t_subtree self)
{
return ((self)->symbol);
}
static inline bool ts_subtree_visible(Subtree self)
static inline bool ts_subtree_visible(t_subtree self)
{
return ((self)->visible);
}
static inline bool ts_subtree_named(Subtree self)
static inline bool ts_subtree_named(t_subtree self)
{
return ((self)->named);
}
static inline bool ts_subtree_extra(Subtree self)
static inline bool ts_subtree_extra(t_subtree self)
{
return ((self)->extra);
}
static inline bool ts_subtree_has_changes(Subtree self)
static inline bool ts_subtree_has_changes(t_subtree self)
{
return ((self)->has_changes);
}
static inline bool ts_subtree_missing(Subtree self)
static inline bool ts_subtree_missing(t_subtree self)
{
return ((self)->is_missing);
}
static inline bool ts_subtree_is_keyword(Subtree self)
static inline bool ts_subtree_is_keyword(t_subtree self)
{
return ((self)->is_keyword);
}
static inline TSStateId ts_subtree_parse_state(Subtree self)
static inline TSStateId ts_subtree_parse_state(t_subtree self)
{
return ((self)->parse_state);
}
static inline t_u32 ts_subtree_lookahead_bytes(Subtree self)
static inline t_u32 ts_subtree_lookahead_bytes(t_subtree self)
{
return ((self)->lookahead_bytes);
}
@ -164,68 +164,68 @@ static inline t_u32 ts_subtree_lookahead_bytes(Subtree self)
// number of children.
static inline size_t ts_subtree_alloc_size(t_u32 child_count)
{
return child_count * sizeof(Subtree) + sizeof(SubtreeHeapData);
return child_count * sizeof(t_subtree) + sizeof(t_subtree_data);
}
// Get a subtree's children, which are allocated immediately before the
// tree's own heap data.
#define ts_subtree_children(self) ((Subtree *)((self)) - (self)->child_count)
#define ts_subtree_children(self) ((t_subtree *)((self)) - (self)->child_count)
static inline void ts_subtree_set_extra(MutableSubtree *self, bool is_extra)
static inline void ts_subtree_set_extra(t_mut_subtree *self, bool is_extra)
{
(*self)->extra = is_extra;
}
static inline TSSymbol ts_subtree_leaf_symbol(Subtree self)
static inline TSSymbol ts_subtree_leaf_symbol(t_subtree self)
{
if (self->child_count == 0)
return self->symbol;
return self->first_leaf.symbol;
}
static inline TSStateId ts_subtree_leaf_parse_state(Subtree self)
static inline TSStateId ts_subtree_leaf_parse_state(t_subtree self)
{
if (self->child_count == 0)
return self->parse_state;
return self->first_leaf.parse_state;
}
static inline Length ts_subtree_padding(Subtree self)
static inline Length ts_subtree_padding(t_subtree self)
{
return self->padding;
}
static inline Length ts_subtree_size(Subtree self)
static inline Length ts_subtree_size(t_subtree self)
{
return self->size;
}
static inline Length ts_subtree_total_size(Subtree self)
static inline Length ts_subtree_total_size(t_subtree self)
{
return (length_add(ts_subtree_padding(self), ts_subtree_size(self)));
}
static inline t_u32 ts_subtree_total_bytes(Subtree self)
static inline t_u32 ts_subtree_total_bytes(t_subtree self)
{
return (ts_subtree_total_size(self).bytes);
}
static inline t_u32 ts_subtree_child_count(Subtree self)
static inline t_u32 ts_subtree_child_count(t_subtree self)
{
return (self->child_count);
}
static inline t_u32 ts_subtree_repeat_depth(Subtree self)
static inline t_u32 ts_subtree_repeat_depth(t_subtree self)
{
return (self->repeat_depth);
}
static inline t_u32 ts_subtree_visible_descendant_count(Subtree self)
static inline t_u32 ts_subtree_visible_descendant_count(t_subtree self)
{
return ((self->child_count == 0) ? 0 : self->visible_descendant_count);
}
static inline t_u32 ts_subtree_error_cost(Subtree self)
static inline t_u32 ts_subtree_error_cost(t_subtree self)
{
if (ts_subtree_missing(self))
return (ERROR_COST_PER_MISSING_TREE + ERROR_COST_PER_RECOVERY);
@ -233,54 +233,54 @@ static inline t_u32 ts_subtree_error_cost(Subtree self)
return (self->error_cost);
}
static inline t_i32 ts_subtree_dynamic_precedence(Subtree self)
static inline t_i32 ts_subtree_dynamic_precedence(t_subtree self)
{
return ((self->child_count == 0) ? 0 : self->dynamic_precedence);
}
static inline bool ts_subtree_fragile_left(Subtree self)
static inline bool ts_subtree_fragile_left(t_subtree self)
{
return (self->fragile_left);
}
static inline bool ts_subtree_fragile_right(Subtree self)
static inline bool ts_subtree_fragile_right(t_subtree self)
{
return (self->fragile_right);
}
static inline bool ts_subtree_has_external_tokens(Subtree self)
static inline bool ts_subtree_has_external_tokens(t_subtree self)
{
return (self->has_external_tokens);
}
static inline bool ts_subtree_has_external_scanner_state_change(Subtree self)
static inline bool ts_subtree_has_external_scanner_state_change(t_subtree self)
{
return (self->has_external_scanner_state_change);
}
static inline bool ts_subtree_depends_on_column(Subtree self)
static inline bool ts_subtree_depends_on_column(t_subtree self)
{
return (self->depends_on_column);
}
static inline bool ts_subtree_is_error(Subtree self)
static inline bool ts_subtree_is_error(t_subtree self)
{
return (ts_subtree_symbol(self) == ts_builtin_sym_error);
}
static inline bool ts_subtree_is_eof(Subtree self)
static inline bool ts_subtree_is_eof(t_subtree self)
{
return (ts_subtree_symbol(self) == ts_builtin_sym_end);
}
static inline Subtree ts_subtree_from_mut(MutableSubtree self)
static inline t_subtree ts_subtree_from_mut(t_mut_subtree self)
{
return (self);
}
static inline MutableSubtree ts_subtree_to_mut_unsafe(Subtree self)
static inline t_mut_subtree ts_subtree_to_mut_unsafe(t_subtree self)
{
return ((MutableSubtree)self);
return ((t_mut_subtree)self);
}
#endif // SUBTREE_H

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/31 12:03:04 by maiboyer #+# #+# */
/* Updated: 2024/08/31 12:04:05 by maiboyer ### ########.fr */
/* Updated: 2024/08/31 18:38:49 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,23 +16,13 @@
#include "me/types.h"
#include "parser/subtree.h"
typedef struct ParentCacheEntry ParentCacheEntry;
struct TSTree
{
Subtree root;
t_subtree root;
const TSLanguage *language;
};
struct ParentCacheEntry
{
const Subtree *child;
const Subtree *parent;
Length position;
TSSymbol alias_symbol;
};
TSTree *ts_tree_new(Subtree root, const TSLanguage *language);
TSNode ts_node_new(const TSTree *, const Subtree *, Length, TSSymbol);
TSTree *ts_tree_new(t_subtree root, const TSLanguage *language);
TSNode ts_node_new(const TSTree *, const t_subtree *, Length, TSSymbol);
#endif // TREE_H