splitted more stuff

This commit is contained in:
Maieul BOYER 2024-08-31 17:18:02 +00:00
parent 749fdf627f
commit 009be4a4b4
28 changed files with 1595 additions and 1287 deletions

View file

@ -0,0 +1,43 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* node.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/31 17:04:59 by maiboyer #+# #+# */
/* Updated: 2024/08/31 17:12:08 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef NODE_H
#define NODE_H
#include "me/types.h"
#include "parser/length.h"
#include "parser/subtree.h"
typedef struct s_node_child_iterator NodeChildIterator;
struct s_node_child_iterator
{
Subtree parent;
const TSTree *tree;
Length position;
t_u32 child_index;
t_u32 structural_child_index;
const TSSymbol *alias_sequence;
};
NodeChildIterator ts_node_iterate_children(const TSNode *node);
TSFieldId ts_node__field_id_from_language(TSNode self, t_u32 structural_child_index);
TSNode ts_node__child(TSNode self, t_u32 child_index, bool include_anonymous);
TSNode ts_node__null(void);
bool ts_node__is_relevant(TSNode self, bool include_anonymous);
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_u32 ts_node__alias(const TSNode *self);
#endif /* NODE_H */

View file

@ -0,0 +1,111 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* stack.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* 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 */
/* */
/* ************************************************************************** */
#ifndef STACK_H
#define STACK_H
#include "me/types.h"
#include "parser/subtree.h"
#include "parser/stack.h"
#define MAX_LINK_COUNT 1
#define MAX_NODE_POOL_SIZE 0
#define MAX_ITERATOR_COUNT 0
typedef enum e_stack_status t_stack_status;
typedef struct s_stack_head t_stack_head;
typedef struct s_stack_iterator t_stack_iterator;
typedef struct s_stack_link t_stack_link;
typedef struct s_stack_node t_stack_node;
typedef struct s_summarize_stack_session t_summarize_stack_session;
typedef t_u32 t_stack_action;
typedef t_stack_action (*t_stack_callback)(void *,
const t_stack_iterator *);
struct s_stack_link
{
t_stack_node *node;
Subtree subtree;
bool is_pending;
};
struct s_stack_node
{
TSStateId state;
Length position;
t_stack_link links[MAX_LINK_COUNT];
t_u16 link_count;
t_u32 ref_count;
t_u32 error_cost;
t_u32 node_count;
int dynamic_precedence;
};
struct s_stack_iterator
{
t_stack_node *node;
SubtreeArray subtrees;
t_u32 subtree_count;
bool is_pending;
};
enum e_stack_status
{
SStatusActive,
SStatusPaused,
SStatusHalted,
};
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_stack_status status;
};
struct s_stack
{
Array(t_stack_head) heads;
t_stack_slice_array slices;
Array(t_stack_iterator) iterators;
t_stack_node *base_node;
};
enum e_stack_action
{
SActionNone,
SActionStop = 1,
SActionPop = 2,
};
struct s_summarize_stack_session
{
t_stack_summary *summary;
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);
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);
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);
void stack_node_retain(t_stack_node *self);
void ts_stack__add_slice(t_stack *self, t_stack_version original_version, t_stack_node *node, SubtreeArray *subtrees);
#endif /* STACK_H */