update: normed lots of stuff
This commit is contained in:
parent
978636b6ef
commit
50a2f3d4be
118 changed files with 1145 additions and 1330 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/22 13:54:54 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/11 16:40:31 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/19 16:45:08 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -28,65 +28,64 @@
|
|||
#define TREE_SITTER_LANGUAGE_VERSION 14
|
||||
#define TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION 13
|
||||
|
||||
TSTree *ts_tree_copy(const TSTree *self);
|
||||
void ts_tree_delete(TSTree *self);
|
||||
TSNode ts_tree_root_node(const TSTree *self);
|
||||
TSNode ts_tree_root_node_with_offset(const TSTree *self, t_u32 offset_bytes, TSPoint offset_extent);
|
||||
const TSLanguage *ts_tree_language(const TSTree *self);
|
||||
t_tree *ts_tree_copy(const t_tree *self);
|
||||
void ts_tree_delete(t_tree *self);
|
||||
t_node ts_tree_root_node(const t_tree *self);
|
||||
t_node ts_tree_root_node_with_offset(const t_tree *self, t_u32 offset_bytes, t_point offset_extent);
|
||||
const t_language *ts_tree_language(const t_tree *self);
|
||||
|
||||
t_const_str ts_node_type(TSNode self);
|
||||
TSSymbol ts_node_symbol(TSNode self);
|
||||
const TSLanguage *ts_node_language(TSNode self);
|
||||
t_const_str ts_node_grammar_type(TSNode self);
|
||||
TSSymbol ts_node_grammar_symbol(TSNode self);
|
||||
t_u32 ts_node_start_byte(TSNode self);
|
||||
TSPoint ts_node_start_point(TSNode self);
|
||||
t_u32 ts_node_end_byte(TSNode self);
|
||||
TSPoint ts_node_end_point(TSNode self);
|
||||
char *ts_node_string(TSNode self);
|
||||
bool ts_node_is_null(TSNode self);
|
||||
bool ts_node_is_named(TSNode self);
|
||||
bool ts_node_is_missing(TSNode self);
|
||||
bool ts_node_is_extra(TSNode self);
|
||||
bool ts_node_has_changes(TSNode self);
|
||||
bool ts_node_has_error(TSNode self);
|
||||
bool ts_node_is_error(TSNode self);
|
||||
TSStateId ts_node_parse_state(TSNode self);
|
||||
TSStateId ts_node_next_parse_state(TSNode self);
|
||||
TSNode ts_node_parent(TSNode self);
|
||||
TSNode ts_node_child_containing_descendant(TSNode self, TSNode descendant);
|
||||
TSNode ts_node_child(TSNode self, t_u32 child_index);
|
||||
t_const_str ts_node_field_name_for_child(TSNode self, t_u32 child_index);
|
||||
TSFieldId ts_node_field_id_for_child(TSNode self, t_u32 child_index);
|
||||
t_u32 ts_node_child_count(TSNode self);
|
||||
TSNode ts_node_named_child(TSNode self, t_u32 child_index);
|
||||
t_u32 ts_node_named_child_count(TSNode self);
|
||||
TSNode ts_node_child_by_field_name(TSNode self, t_const_str name, t_u32 name_length);
|
||||
TSNode ts_node_child_by_field_id(TSNode self, TSFieldId field_id);
|
||||
TSNode ts_node_next_sibling(TSNode self);
|
||||
TSNode ts_node_prev_sibling(TSNode self);
|
||||
TSNode ts_node_next_named_sibling(TSNode self);
|
||||
TSNode ts_node_prev_named_sibling(TSNode self);
|
||||
TSNode ts_node_first_child_for_byte(TSNode self, t_u32 byte);
|
||||
TSNode ts_node_first_named_child_for_byte(TSNode self, t_u32 byte);
|
||||
t_u32 ts_node_descendant_count(TSNode self);
|
||||
TSNode ts_node_descendant_for_byte_range(TSNode self, t_u32 start, t_u32 end);
|
||||
TSNode ts_node_descendant_for_point_range(TSNode self, TSPoint start, TSPoint end);
|
||||
TSNode ts_node_named_descendant_for_byte_range(TSNode self, t_u32 start, t_u32 end);
|
||||
TSNode ts_node_named_descendant_for_point_range(TSNode self, TSPoint start, TSPoint end);
|
||||
bool ts_node_eq(TSNode self, TSNode other);
|
||||
t_const_str ts_node_type(t_node self);
|
||||
t_symbol ts_node_symbol(t_node self);
|
||||
const t_language *ts_node_language(t_node self);
|
||||
t_symbol ts_node_grammar_symbol(t_node self);
|
||||
t_u32 ts_node_start_byte(t_node self);
|
||||
t_point ts_node_start_point(t_node self);
|
||||
t_u32 ts_node_end_byte(t_node self);
|
||||
t_point ts_node_end_point(t_node self);
|
||||
char *ts_node_string(t_node self);
|
||||
bool ts_node_is_null(t_node self);
|
||||
bool ts_node_is_named(t_node self);
|
||||
bool ts_node_is_missing(t_node self);
|
||||
bool ts_node_is_extra(t_node self);
|
||||
bool ts_node_has_changes(t_node self);
|
||||
bool ts_node_has_error(t_node self);
|
||||
bool ts_node_is_error(t_node self);
|
||||
t_state_id ts_node_parse_state(t_node self);
|
||||
t_state_id ts_node_next_parse_state(t_node self);
|
||||
t_node ts_node_parent(t_node self);
|
||||
t_node ts_node_child_containing_descendant(t_node self, t_node descendant);
|
||||
t_node ts_node_child(t_node self, t_u32 child_index);
|
||||
t_const_str ts_node_field_name_for_child(t_node self, t_u32 child_index);
|
||||
t_field_id ts_node_field_id_for_child(t_node self, t_u32 child_index);
|
||||
t_u32 ts_node_child_count(t_node self);
|
||||
t_node ts_node_named_child(t_node self, t_u32 child_index);
|
||||
t_u32 ts_node_named_child_count(t_node self);
|
||||
t_node ts_node_child_by_field_name(t_node self, t_const_str name, t_u32 name_length);
|
||||
t_node ts_node_child_by_field_id(t_node self, t_field_id field_id);
|
||||
t_node ts_node_next_sibling(t_node self);
|
||||
t_node ts_node_prev_sibling(t_node self);
|
||||
t_node ts_node_next_named_sibling(t_node self);
|
||||
t_node ts_node_prev_named_sibling(t_node self);
|
||||
t_node ts_node_first_child_for_byte(t_node self, t_u32 byte);
|
||||
t_node ts_node_first_named_child_for_byte(t_node self, t_u32 byte);
|
||||
t_u32 ts_node_descendant_count(t_node self);
|
||||
t_node ts_node_descendant_for_byte_range(t_node self, t_u32 start, t_u32 end);
|
||||
t_node ts_node_descendant_for_point_range(t_node self, t_point start, t_point end);
|
||||
t_node ts_node_named_descendant_for_byte_range(t_node self, t_u32 start, t_u32 end);
|
||||
t_node ts_node_named_descendant_for_point_range(t_node self, t_point start, t_point end);
|
||||
bool ts_node_eq(t_node self, t_node other);
|
||||
|
||||
const TSLanguage *ts_language_copy(const TSLanguage *self);
|
||||
void ts_language_delete(const TSLanguage *self);
|
||||
t_u32 ts_language_symbol_count(const TSLanguage *self);
|
||||
t_u32 ts_language_state_count(const TSLanguage *self);
|
||||
t_const_str ts_language_symbol_name(const TSLanguage *self, TSSymbol symbol);
|
||||
TSSymbol ts_language_symbol_for_name(const TSLanguage *self, t_const_str string, t_u32 length, bool is_named);
|
||||
t_u32 ts_language_field_count(const TSLanguage *self);
|
||||
t_const_str ts_language_field_name_for_id(const TSLanguage *self, TSFieldId id);
|
||||
TSFieldId ts_language_field_id_for_name(const TSLanguage *self, t_const_str name, t_u32 name_length);
|
||||
TSSymbolType ts_language_symbol_type(const TSLanguage *self, TSSymbol symbol);
|
||||
t_u32 ts_language_version(const TSLanguage *self);
|
||||
TSStateId ts_language_next_state(const TSLanguage *self, TSStateId state, TSSymbol symbol);
|
||||
const t_language *ts_language_copy(const t_language *self);
|
||||
void ts_language_delete(const t_language *self);
|
||||
t_u32 ts_language_symbol_count(const t_language *self);
|
||||
t_u32 ts_language_state_count(const t_language *self);
|
||||
t_const_str ts_language_symbol_name(const t_language *self, t_symbol symbol);
|
||||
t_symbol ts_language_symbol_for_name(const t_language *self, t_const_str string, t_u32 length, bool is_named);
|
||||
t_u32 ts_language_field_count(const t_language *self);
|
||||
t_const_str ts_language_field_name_for_id(const t_language *self, t_field_id id);
|
||||
t_field_id ts_language_field_id_for_name(const t_language *self, t_const_str name, t_u32 name_length);
|
||||
t_symbol_type ts_language_symbol_type(const t_language *self, t_symbol symbol);
|
||||
t_u32 ts_language_version(const t_language *self);
|
||||
t_state_id ts_language_next_state(const t_language *self, t_state_id state, t_symbol symbol);
|
||||
|
||||
#endif // TREE_SITTER_API_H_
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/24 13:56:34 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/02 18:14:43 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/19 16:54:04 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -20,16 +20,17 @@ struct s_external_scanner_state
|
|||
char *long_data;
|
||||
t_u32 length;
|
||||
};
|
||||
|
||||
typedef struct s_external_scanner_state t_external_scanner_state;
|
||||
typedef struct s_subtree_data t_subtree_data;
|
||||
typedef t_subtree_data *t_subtree;
|
||||
|
||||
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);
|
||||
const t_external_scanner_state *ts_subtree_external_scanner_state(t_subtree self);
|
||||
const t_u8 *ts_external_scanner_state_data(const t_external_scanner_state *self);
|
||||
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);
|
||||
void ts_external_scanner_state_init(t_external_scanner_state *self, const t_u8 *data, t_u32 length);
|
||||
|
||||
#endif /* EXTERNAL_SCANNER_STATE_H */
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/02 20:03:42 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/02 20:16:55 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/19 16:35:42 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,7 +17,6 @@
|
|||
#include "parser/inner/point_inner.h"
|
||||
|
||||
typedef struct s_length t_length;
|
||||
typedef t_length Length;
|
||||
|
||||
struct s_length
|
||||
{
|
||||
|
|
@ -25,4 +24,12 @@ struct s_length
|
|||
t_point extent;
|
||||
};
|
||||
|
||||
t_length length_add(t_length len1, t_length len2);
|
||||
t_length length_min(t_length len1, t_length len2);
|
||||
t_length length_saturating_sub(t_length len1, t_length len2);
|
||||
t_length length_sub(t_length len1, t_length len2);
|
||||
t_length length_zero(void);
|
||||
bool length_is_undefined(t_length length);
|
||||
|
||||
|
||||
#endif /* LENGTH_INNER_H */
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* 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 */
|
||||
/* Updated: 2024/09/19 16:45:08 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -20,24 +20,24 @@
|
|||
typedef struct s_node_child_iterator NodeChildIterator;
|
||||
struct s_node_child_iterator
|
||||
{
|
||||
t_subtree parent;
|
||||
const TSTree *tree;
|
||||
Length position;
|
||||
t_subtree parent;
|
||||
const t_tree *tree;
|
||||
t_length position;
|
||||
t_u32 child_index;
|
||||
t_u32 structural_child_index;
|
||||
const TSSymbol *alias_sequence;
|
||||
const t_symbol *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);
|
||||
NodeChildIterator ts_node_iterate_children(const t_node *node);
|
||||
t_field_id ts_node__field_id_from_language(t_node self, t_u32 structural_child_index);
|
||||
t_node ts_node__child(t_node self, t_u32 child_index, bool include_anonymous);
|
||||
t_node ts_node__null(void);
|
||||
bool ts_node__is_relevant(t_node 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);
|
||||
t_subtree ts_node__subtree(TSNode self);
|
||||
t_u32 ts_node__alias(const TSNode *self);
|
||||
bool ts_node_child_iterator_next(NodeChildIterator *self, t_node *result);
|
||||
t_const_str ts_node__field_name_from_language(t_node self, t_u32 structural_child_index);
|
||||
t_u32 ts_node__relevant_child_count(t_node self, bool include_anonymous);
|
||||
t_subtree ts_node__subtree(t_node self);
|
||||
t_u32 ts_node__alias(const t_node *self);
|
||||
|
||||
#endif /* NODE_H */
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/10 13:56:47 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/11 17:25:29 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/19 16:44:59 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -23,7 +23,7 @@
|
|||
#include "parser/length.h"
|
||||
#include "parser/lexer.h"
|
||||
#include "parser/reduce_action.h"
|
||||
#include "parser/stack.h"
|
||||
#include "parser/inner/stack_inner.h"
|
||||
#include "parser/subtree.h"
|
||||
#include "parser/tree.h"
|
||||
#include <assert.h>
|
||||
|
|
@ -34,16 +34,17 @@
|
|||
#define MAX_SUMMARY_DEPTH 1
|
||||
#define MAX_COST_DIFFERENCE 16 * ERROR_COST_PER_SKIPPED_TREE
|
||||
|
||||
typedef enum e_error_comparison t_error_comparison;
|
||||
typedef struct s_error_status t_error_status;
|
||||
typedef enum e_error_comparison t_error_comparison;
|
||||
typedef struct s_string_input t_string_input;
|
||||
typedef struct s_parser t_parser;
|
||||
|
||||
struct TSParser
|
||||
struct s_parser
|
||||
{
|
||||
t_lexer lexer;
|
||||
t_stack *stack;
|
||||
const TSLanguage *language;
|
||||
ReduceActionSet reduce_actions;
|
||||
const t_language *language;
|
||||
t_vec_reduce_action reduce_actions;
|
||||
t_subtree finished_tree;
|
||||
t_vec_subtree trailing_extras;
|
||||
t_vec_subtree trailing_extras2;
|
||||
|
|
@ -78,36 +79,34 @@ struct s_string_input
|
|||
t_u32 length;
|
||||
};
|
||||
|
||||
TSParser *ts_parser_new(TSLanguage *language);
|
||||
void ts_parser_delete(TSParser *self);
|
||||
t_parser *ts_parser_new(t_language *language);
|
||||
t_tree *ts_parser_parse(t_parser *self, t_input input);
|
||||
t_tree *ts_parser_parse_string(t_parser *self, t_const_str string, t_u32 length);
|
||||
bool _parse_condition(t_parser *self, t_u32 *version_count, t_stack_version *version);
|
||||
bool ts_parser__advance(t_parser *self, t_stack_version version);
|
||||
bool ts_parser__better_version_exists(t_parser *self, t_stack_version version, bool is_in_error, t_u32 cost);
|
||||
bool ts_parser__breakdown_top_of_stack(t_parser *self, t_stack_version version);
|
||||
bool ts_parser__do_all_potential_reductions(t_parser *self, t_stack_version starting_version, t_symbol lookahead_symbol);
|
||||
bool ts_parser__external_scanner_scan(t_parser *self, t_state_id external_lex_state);
|
||||
bool ts_parser__recover_to_state(t_parser *self, t_stack_version version, t_u32 depth, t_state_id goal_state);
|
||||
bool ts_parser__select_children(t_parser *self, t_subtree left, const t_vec_subtree *children);
|
||||
bool ts_parser__select_tree(t_parser *self, t_subtree left, t_subtree right);
|
||||
bool ts_parser_has_outstanding_parse(t_parser *self);
|
||||
const t_u8 *ts_string_input_read(void *_self, t_u32 byte, t_point point, t_u32 *length);
|
||||
t_error_comparison ts_parser__compare_versions(t_parser *self, t_error_status a, t_error_status b);
|
||||
t_error_status ts_parser__version_status(t_parser *self, t_stack_version version);
|
||||
t_stack_version ts_parser__reduce(t_parser *self, t_stack_version version, t_symbol symbol, t_u32 count, int dynamic_precedence, t_u16 production_id, bool is_fragile, bool end_of_non_terminal_extra);
|
||||
t_subtree ts_parser__lex(t_parser *self, t_stack_version version, t_state_id parse_state);
|
||||
t_u32 ts_parser__condense_stack(t_parser *self);
|
||||
t_u32 ts_parser__external_scanner_serialize(t_parser *self);
|
||||
void ts_parser__accept(t_parser *self, t_stack_version version, t_subtree lookahead);
|
||||
void ts_parser__external_scanner_create(t_parser *self);
|
||||
void ts_parser__external_scanner_deserialize(t_parser *self, t_subtree external_token);
|
||||
void ts_parser__external_scanner_destroy(t_parser *self);
|
||||
void ts_parser__handle_error(t_parser *self, t_stack_version version, t_subtree lookahead);
|
||||
void ts_parser__recover(t_parser *self, t_stack_version version, t_subtree lookahead);
|
||||
void ts_parser__shift(t_parser *self, t_stack_version version, t_state_id state, t_subtree lookahead, bool extra);
|
||||
void ts_parser_delete(t_parser *self);
|
||||
void ts_parser_reset(t_parser *self);
|
||||
|
||||
void ts_parser__accept(TSParser *self, t_stack_version version, t_subtree lookahead);
|
||||
bool ts_parser__advance(TSParser *self, t_stack_version version);
|
||||
bool ts_parser__better_version_exists(TSParser *self, t_stack_version version, bool is_in_error, t_u32 cost);
|
||||
bool ts_parser__breakdown_top_of_stack(TSParser *self, t_stack_version version);
|
||||
t_error_comparison ts_parser__compare_versions(TSParser *self, t_error_status a, t_error_status b);
|
||||
t_u32 ts_parser__condense_stack(TSParser *self);
|
||||
bool ts_parser__do_all_potential_reductions(TSParser *self, t_stack_version starting_version, TSSymbol lookahead_symbol);
|
||||
void ts_parser__external_scanner_create(TSParser *self);
|
||||
void ts_parser__external_scanner_deserialize(TSParser *self, t_subtree external_token);
|
||||
void ts_parser__external_scanner_destroy(TSParser *self);
|
||||
bool ts_parser__external_scanner_scan(TSParser *self, TSStateId external_lex_state);
|
||||
t_u32 ts_parser__external_scanner_serialize(TSParser *self);
|
||||
void ts_parser__handle_error(TSParser *self, t_stack_version version, t_subtree lookahead);
|
||||
t_subtree ts_parser__lex(TSParser *self, t_stack_version version, TSStateId parse_state);
|
||||
void ts_parser__recover(TSParser *self, t_stack_version version, t_subtree lookahead);
|
||||
bool ts_parser__recover_to_state(TSParser *self, t_stack_version version, t_u32 depth, TSStateId goal_state);
|
||||
t_stack_version ts_parser__reduce(TSParser *self, t_stack_version version, TSSymbol symbol, t_u32 count, int dynamic_precedence,
|
||||
t_u16 production_id, bool is_fragile, bool end_of_non_terminal_extra);
|
||||
bool ts_parser__select_children(TSParser *self, t_subtree left, const t_vec_subtree *children);
|
||||
bool ts_parser__select_tree(TSParser *self, t_subtree left, t_subtree right);
|
||||
void ts_parser__shift(TSParser *self, t_stack_version version, TSStateId state, t_subtree lookahead, bool extra);
|
||||
t_error_status ts_parser__version_status(TSParser *self, t_stack_version version);
|
||||
bool ts_parser_has_outstanding_parse(TSParser *self);
|
||||
const TSLanguage *ts_parser_language(const TSParser *self);
|
||||
TSTree *ts_parser_parse(TSParser *self, TSInput input);
|
||||
TSTree *ts_parser_parse_string(TSParser *self, t_const_str string, t_u32 length);
|
||||
void ts_parser_reset(TSParser *self);
|
||||
bool ts_parser_set_language(TSParser *self, const TSLanguage *language);
|
||||
const t_u8 *ts_string_input_read(void *_self, t_u32 byte, TSPoint point, t_u32 *length);
|
||||
#endif /* PARSER_INNER_H */
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/02 20:05:43 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/02 20:07:26 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/19 16:38:38 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -16,7 +16,6 @@
|
|||
#include "me/types.h"
|
||||
|
||||
typedef struct s_point t_point;
|
||||
typedef t_point TSPoint;
|
||||
|
||||
struct s_point
|
||||
{
|
||||
|
|
@ -24,4 +23,16 @@ struct s_point
|
|||
t_u32 column;
|
||||
};
|
||||
|
||||
t_point point__new(t_u32 row, t_u32 column);
|
||||
t_point point_add(t_point a, t_point b);
|
||||
t_point point_max(t_point a, t_point b);
|
||||
t_point point_min(t_point a, t_point b);
|
||||
t_point point_sub(t_point a, t_point b);
|
||||
bool point_eq(t_point a, t_point b);
|
||||
bool point_gt(t_point a, t_point b);
|
||||
bool point_gte(t_point a, t_point b);
|
||||
bool point_lt(t_point a, t_point b);
|
||||
bool point_lte(t_point a, t_point b);
|
||||
|
||||
|
||||
#endif /* POINT_INNER_H */
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/02 20:08:11 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/02 20:20:55 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/19 16:45:06 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,47 +17,42 @@
|
|||
#include "parser/inner/length_inner.h"
|
||||
#include "parser/inner/point_inner.h"
|
||||
|
||||
typedef t_u16 TSStateId;
|
||||
typedef t_u16 TSSymbol;
|
||||
typedef t_u16 TSFieldId;
|
||||
typedef struct TSLanguage TSLanguage;
|
||||
typedef struct TSParser TSParser;
|
||||
typedef struct s_tree TSTree;
|
||||
typedef t_u16 t_state_id;
|
||||
typedef t_u16 t_symbol;
|
||||
typedef t_u16 t_field_id;
|
||||
typedef struct s_language t_language;
|
||||
typedef struct s_parser t_parser;
|
||||
typedef struct s_tree t_tree;
|
||||
|
||||
typedef enum TSSymbolType
|
||||
typedef enum e_symbol_type
|
||||
{
|
||||
TSSymbolTypeRegular,
|
||||
TSSymbolTypeAnonymous,
|
||||
TSSymbolTypeAuxiliary,
|
||||
} TSSymbolType;
|
||||
t_symbol_typeRegular,
|
||||
t_symbol_typeAnonymous,
|
||||
t_symbol_typeAuxiliary,
|
||||
} t_symbol_type;
|
||||
|
||||
typedef struct s_srange
|
||||
{
|
||||
TSPoint start_point;
|
||||
TSPoint end_point;
|
||||
t_point start_point;
|
||||
t_point end_point;
|
||||
t_u32 start_byte;
|
||||
t_u32 end_byte;
|
||||
} TSRange;
|
||||
} t_range;
|
||||
|
||||
typedef struct t_input
|
||||
typedef struct s_input
|
||||
{
|
||||
void *payload;
|
||||
const t_u8 *(*read)(void *payload, t_u32 byte_index, TSPoint position, t_u32 *bytes_read);
|
||||
} TSInput;
|
||||
const t_u8 *(*read)(void *payload, t_u32 byte_index, t_point position, t_u32 *bytes_read);
|
||||
} t_input;
|
||||
|
||||
typedef struct t_parse_node
|
||||
typedef struct s_node
|
||||
{
|
||||
t_u32 start_byte;
|
||||
t_u32 start_row;
|
||||
t_u32 start_col;
|
||||
t_u32 alias;
|
||||
const void *id;
|
||||
const TSTree *tree;
|
||||
} TSNode;
|
||||
const t_tree *tree;
|
||||
} t_node;
|
||||
|
||||
typedef TSNode t_parse_node;
|
||||
typedef TSSymbol t_symbol;
|
||||
typedef TSParser t_first_parser;
|
||||
typedef TSLanguage t_language;
|
||||
typedef TSTree t_first_tree;
|
||||
#endif /* PTYPES_H */
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
struct s_reduce_action
|
||||
{
|
||||
t_u32 count;
|
||||
TSSymbol symbol;
|
||||
t_symbol symbol;
|
||||
int dynamic_precedence;
|
||||
t_u16 production_id;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,111 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* stack.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/31 16:37:50 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/08/31 18:36:27 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 8
|
||||
#define MAX_NODE_POOL_SIZE 50
|
||||
#define MAX_ITERATOR_COUNT 64
|
||||
|
||||
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;
|
||||
t_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;
|
||||
t_vec_subtree 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;
|
||||
t_subtree last_external_token;
|
||||
t_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(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(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);
|
||||
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, t_vec_subtree *subtrees);
|
||||
|
||||
#endif /* STACK_H */
|
||||
177
parser/include/parser/inner/stack_inner.h
Normal file
177
parser/include/parser/inner/stack_inner.h
Normal file
|
|
@ -0,0 +1,177 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* stack_inner.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/31 16:37:50 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/19 16:42:26 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STACK_INNER_H
|
||||
#define STACK_INNER_H
|
||||
|
||||
#include "me/types.h"
|
||||
#include "parser/inner/length_inner.h"
|
||||
#include "parser/subtree.h"
|
||||
|
||||
#define MAX_LINK_COUNT 8
|
||||
#define MAX_NODE_POOL_SIZE 50
|
||||
#define MAX_ITERATOR_COUNT 64
|
||||
#define STACK_VERSION_NONE -1
|
||||
|
||||
typedef struct s_stack t_stack;
|
||||
typedef t_u32 t_stack_version;
|
||||
typedef struct s_stack_slice t_stack_slice;
|
||||
typedef struct s_stack_summary_entry t_stack_summary_entry;
|
||||
typedef Array(t_stack_slice) t_stack_slice_array;
|
||||
typedef Array(t_stack_summary_entry) t_stack_summary;
|
||||
|
||||
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;
|
||||
t_subtree subtree;
|
||||
bool is_pending;
|
||||
};
|
||||
|
||||
struct s_stack_node
|
||||
{
|
||||
t_state_id state;
|
||||
t_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;
|
||||
t_vec_subtree 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;
|
||||
t_subtree last_external_token;
|
||||
t_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;
|
||||
};
|
||||
|
||||
struct s_stack_slice
|
||||
{
|
||||
t_vec_subtree subtrees;
|
||||
t_stack_version version;
|
||||
};
|
||||
|
||||
struct s_stack_summary_entry
|
||||
{
|
||||
t_length position;
|
||||
t_u32 depth;
|
||||
t_state_id state;
|
||||
};
|
||||
|
||||
struct s_stack_push_arg
|
||||
{
|
||||
t_stack_version version;
|
||||
t_subtree subtree;
|
||||
bool pending;
|
||||
t_state_id state;
|
||||
};
|
||||
|
||||
t_length ts_stack_position(const t_stack *self, t_stack_version version);
|
||||
t_state_id ts_stack_state(const t_stack *self, t_stack_version version);
|
||||
bool stack__subtree_is_equivalent(t_subtree left, t_subtree right);
|
||||
bool ts_stack_can_merge(t_stack *self, t_stack_version version1, t_stack_version version2);
|
||||
bool ts_stack_has_advanced_since_error(const t_stack *self, t_stack_version version);
|
||||
bool ts_stack_is_active(const t_stack *self, t_stack_version version);
|
||||
bool ts_stack_is_halted(const t_stack *self, t_stack_version version);
|
||||
bool ts_stack_is_paused(const t_stack *self, t_stack_version version);
|
||||
bool ts_stack_merge(t_stack *self, t_stack_version version1, t_stack_version version2);
|
||||
int ts_stack_dynamic_precedence(t_stack *self, t_stack_version version);
|
||||
t_stack *ts_stack_new(void);
|
||||
t_stack_action pop_all_callback(void *payload, const t_stack_iterator *iterator);
|
||||
t_stack_action pop_count_callback(void *payload, const t_stack_iterator *iterator);
|
||||
t_stack_action pop_error_callback(void *payload, const t_stack_iterator *iterator);
|
||||
t_stack_action pop_pending_callback(void *payload, const t_stack_iterator *iterator);
|
||||
t_stack_action summarize_stack_callback(void *payload, const t_stack_iterator *iterator);
|
||||
t_stack_node *stack_node_new(t_stack_node *previous_node, t_subtree subtree, bool is_pending, t_state_id 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_slice_array ts_stack_pop_all(t_stack *self, t_stack_version version);
|
||||
t_stack_slice_array ts_stack_pop_count(t_stack *self, t_stack_version version, t_u32 count);
|
||||
t_stack_slice_array ts_stack_pop_pending(t_stack *self, t_stack_version version);
|
||||
t_stack_summary *ts_stack_get_summary(t_stack *self, t_stack_version version);
|
||||
t_stack_version ts_stack__add_version(t_stack *self, t_stack_version original_version, t_stack_node *node);
|
||||
t_stack_version ts_stack_copy_version(t_stack *self, t_stack_version version);
|
||||
t_subtree ts_stack_last_external_token(const t_stack *self, t_stack_version version);
|
||||
t_subtree ts_stack_resume(t_stack *self, t_stack_version version);
|
||||
t_u32 stack__subtree_node_count(t_subtree subtree);
|
||||
t_u32 ts_stack_error_cost(const t_stack *self, t_stack_version version);
|
||||
t_u32 ts_stack_node_count_since_error(const t_stack *self, t_stack_version version);
|
||||
t_u32 ts_stack_version_count(const t_stack *self);
|
||||
t_vec_subtree ts_stack_pop_error(t_stack *self, t_stack_version version);
|
||||
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, t_vec_subtree *subtrees);
|
||||
void ts_stack_clear(t_stack *self);
|
||||
void ts_stack_delete(t_stack *self);
|
||||
void ts_stack_halt(t_stack *self, t_stack_version version);
|
||||
void ts_stack_pause(t_stack *self, t_stack_version version, t_subtree lookahead);
|
||||
void ts_stack_push(t_stack *self, struct s_stack_push_arg args);
|
||||
void ts_stack_record_summary(t_stack *self, t_stack_version version, t_u32 max_depth);
|
||||
void ts_stack_remove_version(t_stack *self, t_stack_version version);
|
||||
void ts_stack_renumber_version(t_stack *self, t_stack_version v1, t_stack_version v2);
|
||||
void ts_stack_set_last_external_token(t_stack *self, t_stack_version version, t_subtree token);
|
||||
void ts_stack_swap_versions(t_stack *self, t_stack_version v1, t_stack_version v2);
|
||||
|
||||
|
||||
#endif /* STACK_INNER_H */
|
||||
|
|
@ -28,13 +28,13 @@ typedef struct s_subtree_data t_subtree_data;
|
|||
struct s_subtree_data
|
||||
{
|
||||
t_u32 ref_count;
|
||||
Length padding;
|
||||
Length size;
|
||||
t_length padding;
|
||||
t_length size;
|
||||
t_u32 lookahead_bytes;
|
||||
t_u32 error_cost;
|
||||
t_u32 child_count;
|
||||
TSSymbol symbol;
|
||||
TSStateId parse_state;
|
||||
t_symbol symbol;
|
||||
t_state_id parse_state;
|
||||
|
||||
bool visible;
|
||||
bool named;
|
||||
|
|
@ -60,8 +60,8 @@ struct s_subtree_data
|
|||
t_u16 production_id;
|
||||
struct
|
||||
{
|
||||
TSSymbol symbol;
|
||||
TSStateId parse_state;
|
||||
t_symbol symbol;
|
||||
t_state_id parse_state;
|
||||
} first_leaf;
|
||||
};
|
||||
|
||||
|
|
@ -81,31 +81,31 @@ typedef struct s_subtree_new_error_args t_st_newerr_args;
|
|||
|
||||
struct s_subtree_new_leaf_args
|
||||
{
|
||||
TSSymbol symbol;
|
||||
Length padding;
|
||||
Length size;
|
||||
t_symbol symbol;
|
||||
t_length padding;
|
||||
t_length size;
|
||||
t_u32 lookahead_bytes;
|
||||
TSStateId parse_state;
|
||||
t_state_id parse_state;
|
||||
bool has_external_tokens;
|
||||
bool depends_on_column;
|
||||
bool is_keyword;
|
||||
const TSLanguage *language;
|
||||
const t_language *language;
|
||||
};
|
||||
|
||||
struct s_subtree_new_error_args
|
||||
{
|
||||
t_i32 lookahead_char;
|
||||
Length padding;
|
||||
Length size;
|
||||
t_length padding;
|
||||
t_length size;
|
||||
t_u32 bytes_scanned;
|
||||
TSStateId parse_state;
|
||||
const TSLanguage *language;
|
||||
t_state_id parse_state;
|
||||
const t_language *language;
|
||||
};
|
||||
|
||||
struct s_summarize_state
|
||||
{
|
||||
t_u32 structural_index;
|
||||
const TSSymbol *alias_sequence;
|
||||
const t_symbol *alias_sequence;
|
||||
t_u32 lookahead_end_byte;
|
||||
t_subtree *children;
|
||||
t_subtree child;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/31 12:03:18 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/08/31 12:03:29 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/19 16:54:21 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -21,28 +21,28 @@
|
|||
#define LANGUAGE_VERSION_WITH_PRIMARY_STATES 14
|
||||
#define LANGUAGE_VERSION_USABLE_VIA_WASM 13
|
||||
|
||||
struct TableEntry
|
||||
struct s_table_entry
|
||||
{
|
||||
const TSParseAction *actions;
|
||||
t_u32 action_count;
|
||||
bool is_reusable;
|
||||
};
|
||||
|
||||
typedef struct TableEntry TableEntry;
|
||||
typedef struct s_table_entry TableEntry;
|
||||
|
||||
void ts_language_table_entry(const TSLanguage *, TSStateId, TSSymbol, TableEntry *);
|
||||
TSSymbolMetadata ts_language_symbol_metadata(const TSLanguage *, TSSymbol);
|
||||
TSSymbol ts_language_public_symbol(const TSLanguage *, TSSymbol);
|
||||
TSStateId ts_language_next_state(const TSLanguage *self, TSStateId state, TSSymbol symbol);
|
||||
bool ts_language_is_symbol_external(const TSLanguage *self, TSSymbol symbol);
|
||||
const TSParseAction *ts_language_actions(const TSLanguage *self, TSStateId state, TSSymbol symbol, t_u32 *count);
|
||||
bool ts_language_has_reduce_action(const TSLanguage *self, TSStateId state, TSSymbol symbol);
|
||||
t_u16 ts_language_lookup(const TSLanguage *self, TSStateId state, TSSymbol symbol);
|
||||
bool ts_language_has_actions(const TSLanguage *self, TSStateId state, TSSymbol symbol);
|
||||
const bool *ts_language_enabled_external_tokens(const TSLanguage *self, t_u32 external_scanner_state);
|
||||
const TSSymbol *ts_language_alias_sequence(const TSLanguage *self, t_u32 production_id);
|
||||
TSSymbol ts_language_alias_at(const TSLanguage *self, t_u32 production_id, t_u32 child_index);
|
||||
void ts_language_field_map(const TSLanguage *self, t_u32 production_id, const TSFieldMapEntry **start, const TSFieldMapEntry **end);
|
||||
void ts_language_aliases_for_symbol(const TSLanguage *self, TSSymbol original_symbol, const TSSymbol **start, const TSSymbol **end);
|
||||
void ts_language_table_entry(const t_language *, t_state_id, t_symbol, TableEntry *);
|
||||
t_symbol_metadata ts_language_symbol_metadata(const t_language *, t_symbol);
|
||||
t_symbol ts_language_public_symbol(const t_language *, t_symbol);
|
||||
t_state_id ts_language_next_state(const t_language *self, t_state_id state, t_symbol symbol);
|
||||
bool ts_language_is_symbol_external(const t_language *self, t_symbol symbol);
|
||||
const TSParseAction *ts_language_actions(const t_language *self, t_state_id state, t_symbol symbol, t_u32 *count);
|
||||
bool ts_language_has_reduce_action(const t_language *self, t_state_id state, t_symbol symbol);
|
||||
t_u16 ts_language_lookup(const t_language *self, t_state_id state, t_symbol symbol);
|
||||
bool ts_language_has_actions(const t_language *self, t_state_id state, t_symbol symbol);
|
||||
const bool *ts_language_enabled_external_tokens(const t_language *self, t_u32 external_scanner_state);
|
||||
const t_symbol *ts_language_alias_sequence(const t_language *self, t_u32 production_id);
|
||||
t_symbol ts_language_alias_at(const t_language *self, t_u32 production_id, t_u32 child_index);
|
||||
void ts_language_field_map(const t_language *self, t_u32 production_id, const TSFieldMapEntry **start, const TSFieldMapEntry **end);
|
||||
void ts_language_aliases_for_symbol(const t_language *self, t_symbol original_symbol, const t_symbol **start, const t_symbol **end);
|
||||
|
||||
#endif // LANGUAGE_H
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/31 12:03:16 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/02 20:05:01 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/19 16:36:07 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,15 +15,7 @@
|
|||
|
||||
#include "parser/inner/length_inner.h"
|
||||
|
||||
static const Length LENGTH_UNDEFINED = {0, {0, 1}};
|
||||
static const Length LENGTH_MAX = {UINT32_MAX, {UINT32_MAX, UINT32_MAX}};
|
||||
|
||||
Length length_saturating_sub(Length len1, Length len2);
|
||||
Length length_zero(void);
|
||||
Length length_sub(Length len1, Length len2);
|
||||
Length length_add(Length len1, Length len2);
|
||||
Length length_min(Length len1, Length len2);
|
||||
Length length_max(Length len1, Length len2);
|
||||
bool length_is_undefined(Length length);
|
||||
static const t_length LENGTH_UNDEFINED = {0, {0, 1}};
|
||||
static const t_length LENGTH_MAX = {UINT32_MAX, {UINT32_MAX, UINT32_MAX}};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/31 12:03:15 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/02 20:21:08 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/19 16:52:25 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,35 +18,36 @@
|
|||
#include "parser/parser.h"
|
||||
#include "me/types.h"
|
||||
|
||||
typedef struct s_lexer t_lexer;
|
||||
|
||||
struct s_lexer
|
||||
{
|
||||
TSLexer data;
|
||||
Length current_position;
|
||||
Length token_start_position;
|
||||
Length token_end_position;
|
||||
TSRange *included_ranges;
|
||||
const t_u8 *chunk;
|
||||
TSInput input;
|
||||
t_u32 included_range_count;
|
||||
t_u32 current_included_range_index;
|
||||
t_u32 chunk_start;
|
||||
t_u32 chunk_size;
|
||||
t_u32 lookahead_size;
|
||||
bool did_get_column;
|
||||
t_u8 debug_buffer[TREE_SITTER_SERIALIZATION_BUFFER_SIZE];
|
||||
struct s_lexer_functions funcs;
|
||||
t_length current_position;
|
||||
t_length token_start_position;
|
||||
t_length token_end_position;
|
||||
t_range *included_ranges;
|
||||
const t_u8 *chunk;
|
||||
t_input input;
|
||||
t_u32 included_range_count;
|
||||
t_u32 current_included_range_index;
|
||||
t_u32 chunk_start;
|
||||
t_u32 chunk_size;
|
||||
t_u32 lookahead_size;
|
||||
bool did_get_column;
|
||||
t_u8 debug_buffer[TREE_SITTER_SERIALIZATION_BUFFER_SIZE];
|
||||
};
|
||||
|
||||
typedef struct s_lexer t_lexer;
|
||||
|
||||
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_set_input(t_lexer *self, t_input input);
|
||||
void ts_lexer_reset(t_lexer *self, t_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);
|
||||
bool ts_lexer_set_included_ranges(t_lexer *self, const t_range *ranges, t_u32 count);
|
||||
t_range *ts_lexer_included_ranges(const t_lexer *self, t_u32 *count);
|
||||
|
||||
#endif // LEXER_H
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/31 12:03:13 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/08/31 18:45:04 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/19 16:57:51 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,50 +15,47 @@
|
|||
|
||||
#include "me/types.h"
|
||||
|
||||
#define ts_builtin_sym_error ((TSSymbol)-1)
|
||||
#define ts_builtin_sym_error ((t_symbol)-1)
|
||||
#define ts_builtin_sym_end 0
|
||||
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
|
||||
|
||||
#ifndef TREE_SITTER_API_H_
|
||||
typedef t_u16 TSStateId;
|
||||
typedef t_u16 TSSymbol;
|
||||
typedef t_u16 TSFieldId;
|
||||
typedef struct TSLanguage TSLanguage;
|
||||
#endif
|
||||
typedef t_u16 t_state_id;
|
||||
typedef t_u16 t_symbol;
|
||||
typedef t_u16 t_field_id;
|
||||
typedef struct s_language t_language;
|
||||
typedef struct s_lexer t_lexer;
|
||||
|
||||
typedef struct TSFieldMapEntry
|
||||
typedef struct s_field_map_entry
|
||||
{
|
||||
TSFieldId field_id;
|
||||
t_field_id field_id;
|
||||
t_u8 child_index;
|
||||
bool inherited;
|
||||
} TSFieldMapEntry;
|
||||
|
||||
typedef struct TSFieldMapSlice
|
||||
typedef struct s_field_map_slice
|
||||
{
|
||||
t_u16 index;
|
||||
t_u16 length;
|
||||
} TSFieldMapSlice;
|
||||
|
||||
typedef struct TSSymbolMetadata
|
||||
typedef struct s_symbol_metadata
|
||||
{
|
||||
bool visible;
|
||||
bool named;
|
||||
bool supertype;
|
||||
} TSSymbolMetadata;
|
||||
|
||||
typedef struct s_lexer_functions TSLexer;
|
||||
} t_symbol_metadata;
|
||||
|
||||
struct s_lexer_functions
|
||||
{
|
||||
t_i32 lookahead;
|
||||
TSSymbol result_symbol;
|
||||
void (*advance)(TSLexer *, bool);
|
||||
void (*mark_end)(TSLexer *);
|
||||
t_u32 (*get_column)(TSLexer *);
|
||||
bool (*eof)(const TSLexer *);
|
||||
t_symbol result_symbol;
|
||||
void (*advance)(t_lexer *, bool);
|
||||
void (*mark_end)(t_lexer *);
|
||||
t_u32 (*get_column)(t_lexer *);
|
||||
bool (*eof)(const t_lexer *);
|
||||
};
|
||||
|
||||
typedef enum TSParseActionType
|
||||
typedef enum e_parse_action_type
|
||||
{
|
||||
TSParseActionTypeShift,
|
||||
TSParseActionTypeReduce,
|
||||
|
|
@ -66,47 +63,47 @@ typedef enum TSParseActionType
|
|||
TSParseActionTypeRecover,
|
||||
} TSParseActionType;
|
||||
|
||||
typedef union TSParseAction {
|
||||
struct TSParseActionShift
|
||||
typedef union u_parse_action {
|
||||
struct s_parse_action_shift
|
||||
{
|
||||
t_u8 type;
|
||||
TSStateId state;
|
||||
t_state_id state;
|
||||
bool extra;
|
||||
bool repetition;
|
||||
} shift;
|
||||
struct TSParseActionReduce
|
||||
struct s_parse_action_reduce
|
||||
{
|
||||
t_u8 type;
|
||||
t_u8 child_count;
|
||||
TSSymbol symbol;
|
||||
t_symbol symbol;
|
||||
t_i16 dynamic_precedence;
|
||||
t_u16 production_id;
|
||||
} reduce;
|
||||
t_u8 type;
|
||||
} TSParseAction;
|
||||
|
||||
typedef struct TSLexMode
|
||||
typedef struct s_lex_mode
|
||||
{
|
||||
t_u16 lex_state;
|
||||
t_u16 external_lex_state;
|
||||
} TSLexMode;
|
||||
|
||||
typedef union TSParseActionEntry {
|
||||
typedef union u_parse_action_entry {
|
||||
TSParseAction action;
|
||||
struct TSParseActionEntryInner
|
||||
struct s_parse_action_entry_inner
|
||||
{
|
||||
t_u8 count;
|
||||
bool reusable;
|
||||
} entry;
|
||||
} TSParseActionEntry;
|
||||
|
||||
typedef struct TSCharacterRange
|
||||
typedef struct s_character_range
|
||||
{
|
||||
t_i32 start;
|
||||
t_i32 end;
|
||||
} TSCharacterRange;
|
||||
|
||||
struct TSLanguage
|
||||
struct s_language
|
||||
{
|
||||
t_u32 version;
|
||||
t_u32 symbol_count;
|
||||
|
|
@ -126,25 +123,25 @@ struct TSLanguage
|
|||
t_const_str const *field_names;
|
||||
const TSFieldMapSlice *field_map_slices;
|
||||
const TSFieldMapEntry *field_map_entries;
|
||||
const TSSymbolMetadata *symbol_metadata;
|
||||
const TSSymbol *public_symbol_map;
|
||||
const t_symbol_metadata *symbol_metadata;
|
||||
const t_symbol *public_symbol_map;
|
||||
const t_u16 *alias_map;
|
||||
const TSSymbol *alias_sequences;
|
||||
const t_symbol *alias_sequences;
|
||||
const TSLexMode *lex_modes;
|
||||
bool (*lex_fn)(TSLexer *, TSStateId);
|
||||
bool (*keyword_lex_fn)(TSLexer *, TSStateId);
|
||||
TSSymbol keyword_capture_token;
|
||||
bool (*lex_fn)(t_lexer *, t_state_id);
|
||||
bool (*keyword_lex_fn)(t_lexer *, t_state_id);
|
||||
t_symbol keyword_capture_token;
|
||||
struct ExternalScannerDefinition
|
||||
{
|
||||
const bool *states;
|
||||
const TSSymbol *symbol_map;
|
||||
const t_symbol *symbol_map;
|
||||
void *(*create)(void);
|
||||
void (*destroy)(void *);
|
||||
bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist);
|
||||
bool (*scan)(void *, t_lexer *, const bool *symbol_whitelist);
|
||||
t_u32 (*serialize)(void *, t_u8 *);
|
||||
void (*deserialize)(void *, const t_u8 *, t_u32);
|
||||
} external_scanner;
|
||||
const TSStateId *primary_state_ids;
|
||||
const t_state_id *primary_state_ids;
|
||||
};
|
||||
|
||||
static inline bool set_contains(TSCharacterRange *ranges, t_u32 len, t_i32 lookahead)
|
||||
|
|
@ -184,10 +181,10 @@ static inline bool set_contains(TSCharacterRange *ranges, t_u32 len, t_i32 looka
|
|||
t_i32 lookahead; \
|
||||
goto start; \
|
||||
next_state: \
|
||||
lexer->data.advance((void *)lexer, skip); \
|
||||
lexer->funcs.advance((void *)lexer, skip); \
|
||||
start: \
|
||||
skip = false; \
|
||||
lookahead = lexer->data.lookahead;
|
||||
lookahead = lexer->funcs.lookahead;
|
||||
|
||||
#define ADVANCE(state_value) \
|
||||
{ \
|
||||
|
|
@ -217,8 +214,8 @@ start:
|
|||
|
||||
#define ACCEPT_TOKEN(symbol_value) \
|
||||
result = true; \
|
||||
lexer->data.result_symbol = symbol_value; \
|
||||
lexer->data.mark_end((void *)lexer);
|
||||
lexer->funcs.result_symbol = symbol_value; \
|
||||
lexer->funcs.mark_end((void *)lexer);
|
||||
|
||||
#define END_STATE() return result;
|
||||
|
||||
|
|
|
|||
|
|
@ -16,18 +16,18 @@
|
|||
#include "parser/api.h"
|
||||
#include "me/types.h"
|
||||
|
||||
#define POINT_ZERO ((TSPoint){0, 0})
|
||||
#define POINT_MAX ((TSPoint){UINT32_MAX, UINT32_MAX})
|
||||
#define POINT_ZERO ((t_point){0, 0})
|
||||
#define POINT_MAX ((t_point){UINT32_MAX, UINT32_MAX})
|
||||
|
||||
TSPoint point_max(TSPoint a, TSPoint b);
|
||||
TSPoint point_min(TSPoint a, TSPoint b);
|
||||
TSPoint point__new(t_u32 row, t_u32 column);
|
||||
TSPoint point_add(TSPoint a, TSPoint b);
|
||||
TSPoint point_sub(TSPoint a, TSPoint b);
|
||||
bool point_lte(TSPoint a, TSPoint b);
|
||||
bool point_lt(TSPoint a, TSPoint b);
|
||||
bool point_gte(TSPoint a, TSPoint b);
|
||||
bool point_gt(TSPoint a, TSPoint b);
|
||||
bool point_eq(TSPoint a, TSPoint b);
|
||||
t_point point_max(t_point a, t_point b);
|
||||
t_point point_min(t_point a, t_point b);
|
||||
t_point point__new(t_u32 row, t_u32 column);
|
||||
t_point point_add(t_point a, t_point b);
|
||||
t_point point_sub(t_point a, t_point b);
|
||||
bool point_lte(t_point a, t_point b);
|
||||
bool point_lt(t_point a, t_point b);
|
||||
bool point_gte(t_point a, t_point b);
|
||||
bool point_gt(t_point a, t_point b);
|
||||
bool point_eq(t_point a, t_point b);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@
|
|||
#include "parser/inner/reduce_action_inner.h"
|
||||
#include "me/vec/vec_reduce_action.h"
|
||||
|
||||
typedef t_vec_reduce_action ReduceActionSet;
|
||||
typedef t_vec_reduce_action t_vec_reduce_action;
|
||||
|
||||
void ts_reduce_action_set_add(ReduceActionSet *self, t_reduce_action new_action);
|
||||
void ts_reduce_action_set_add(t_vec_reduce_action *self, t_reduce_action new_action);
|
||||
|
||||
#endif // REDUCE_ACTION_H
|
||||
|
|
|
|||
|
|
@ -1,74 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* stack.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/31 12:03:07 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/08/31 18:34:46 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PARSE_STACK_H
|
||||
#define PARSE_STACK_H
|
||||
|
||||
#include "me/types.h"
|
||||
#include "parser/array.h"
|
||||
#include "parser/subtree.h"
|
||||
|
||||
typedef struct s_stack t_stack;
|
||||
typedef t_u32 t_stack_version;
|
||||
typedef struct s_stack_slice t_stack_slice;
|
||||
typedef struct s_stack_summary_entry t_stack_summary_entry;
|
||||
typedef Array(t_stack_slice) t_stack_slice_array;
|
||||
typedef Array(t_stack_summary_entry) t_stack_summary;
|
||||
|
||||
#define STACK_VERSION_NONE ((t_stack_version) - 1)
|
||||
|
||||
struct s_stack_slice
|
||||
{
|
||||
t_vec_subtree subtrees;
|
||||
t_stack_version version;
|
||||
};
|
||||
|
||||
struct s_stack_summary_entry
|
||||
{
|
||||
Length position;
|
||||
t_u32 depth;
|
||||
TSStateId state;
|
||||
};
|
||||
|
||||
t_stack *ts_stack_new(void);
|
||||
void ts_stack_delete(t_stack *);
|
||||
t_u32 ts_stack_version_count(const t_stack *);
|
||||
TSStateId ts_stack_state(const t_stack *, t_stack_version);
|
||||
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);
|
||||
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);
|
||||
t_vec_subtree ts_stack_pop_error(t_stack *, t_stack_version);
|
||||
t_stack_slice_array ts_stack_pop_pending(t_stack *, t_stack_version);
|
||||
t_stack_slice_array ts_stack_pop_all(t_stack *, t_stack_version);
|
||||
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);
|
||||
void ts_stack_record_summary(t_stack *, t_stack_version, t_u32 max_depth);
|
||||
t_stack_summary *ts_stack_get_summary(t_stack *, t_stack_version);
|
||||
t_u32 ts_stack_error_cost(const t_stack *, t_stack_version version);
|
||||
bool ts_stack_merge(t_stack *, t_stack_version, t_stack_version);
|
||||
bool ts_stack_can_merge(t_stack *, t_stack_version, t_stack_version);
|
||||
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);
|
||||
void ts_stack_remove_version(t_stack *, t_stack_version);
|
||||
void ts_stack_clear(t_stack *);
|
||||
|
||||
#endif // PARSE_STACK_H
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/31 12:03:06 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/14 14:14:46 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/19 16:37:37 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -31,35 +31,37 @@
|
|||
|
||||
typedef t_vec_subtree t_vec_subtree;
|
||||
|
||||
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);
|
||||
bool _subtree_compress_inner(t_subtree *tree, t_symbol symbol, t_vec_subtree *stack);
|
||||
int subtree_compare_func(t_subtree left, t_subtree right);
|
||||
int ts_subtree_compare(t_subtree left, t_subtree right);
|
||||
struct s_summarize_state _init_sumnarize_state(t_subtree self, const t_language *language);
|
||||
t_subtree ts_subtree_clone(t_subtree self);
|
||||
t_subtree ts_subtree_ensure_owner(t_subtree self);
|
||||
t_subtree ts_subtree_last_external_token(t_subtree tree);
|
||||
t_subtree ts_subtree_new_error(t_st_newerr_args args);
|
||||
t_subtree ts_subtree_new_error_node(t_vec_subtree *children, bool extra, const t_language *language);
|
||||
t_subtree ts_subtree_new_leaf(t_st_newleaf_args args);
|
||||
t_subtree ts_subtree_new_missing_leaf(t_symbol symbol, t_length padding, t_u32 lookahead_bytes, const t_language *language);
|
||||
t_subtree ts_subtree_new_node(t_symbol symbol, t_vec_subtree *children, t_u32 production_id, const t_language *language);
|
||||
void _subtree_balance_inner(const t_language *language, t_vec_subtree *tree_stack);
|
||||
void _subtree_balance_repush(t_vec_subtree *tree_stack, t_subtree tree);
|
||||
void _subtree_release_inner(t_vec_subtree *to_free);
|
||||
void _sumarize_end(t_subtree self, t_subtree *children);
|
||||
void _summarize_loop_inner1(t_subtree self, const t_language *language, struct s_summarize_state *s);
|
||||
void _summarize_loop_inner2(t_subtree self, const t_language *language, struct s_summarize_state *s);
|
||||
void _summarize_loop_inner3(t_subtree self, const t_language *language, struct s_summarize_state *s);
|
||||
void _summarize_loop_inner4(t_subtree self, const t_language *language, struct s_summarize_state *s);
|
||||
void ts_subtree__compress(t_subtree self, t_u32 count, const t_language *language, t_vec_subtree *stack);
|
||||
void ts_subtree_array_clear(t_vec_subtree *self);
|
||||
void ts_subtree_array_copy(t_vec_subtree self, t_vec_subtree *dest);
|
||||
void ts_subtree_array_delete(t_vec_subtree *self);
|
||||
void ts_subtree_array_remove_trailing_extras(t_vec_subtree *self, t_vec_subtree *destination);
|
||||
void ts_subtree_balance(t_subtree self, const t_language *language);
|
||||
void ts_subtree_release(t_subtree self);
|
||||
void ts_subtree_set_symbol(t_subtree *self, t_symbol symbol, const t_language *language);
|
||||
void ts_subtree_summarize_children(t_subtree self, const t_language *language);
|
||||
|
||||
void ts_subtree_array_copy(t_vec_subtree, t_vec_subtree *);
|
||||
void ts_subtree_array_clear(t_vec_subtree *);
|
||||
void ts_subtree_array_delete(t_vec_subtree *);
|
||||
void ts_subtree_array_remove_trailing_extras(t_vec_subtree *, t_vec_subtree *);
|
||||
void ts_subtree_array_reverse(t_vec_subtree *);
|
||||
|
||||
t_subtree ts_subtree_new_leaf(t_st_newleaf_args args);
|
||||
t_subtree ts_subtree_new_error(t_st_newerr_args args);
|
||||
t_subtree ts_subtree_new_node(TSSymbol, t_vec_subtree *, t_u32, const TSLanguage *);
|
||||
t_subtree ts_subtree_new_error_node(t_vec_subtree *, bool, const TSLanguage *);
|
||||
t_subtree ts_subtree_new_missing_leaf(TSSymbol, Length, t_u32, const TSLanguage *);
|
||||
t_subtree ts_subtree_ensure_owner(t_subtree);
|
||||
void ts_subtree_release(t_subtree);
|
||||
int ts_subtree_compare(t_subtree, t_subtree);
|
||||
void ts_subtree_set_symbol(t_subtree *, TSSymbol, const TSLanguage *);
|
||||
void ts_subtree_summarize(t_subtree, const t_subtree *, t_u32, const TSLanguage *);
|
||||
void ts_subtree_summarize_children(t_subtree, const TSLanguage *);
|
||||
void ts_subtree_balance(t_subtree, const TSLanguage *);
|
||||
char *ts_subtree_string(t_subtree, TSSymbol, bool, const TSLanguage *, bool include_all);
|
||||
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(t_subtree self)
|
||||
static inline t_symbol ts_subtree_symbol(t_subtree self)
|
||||
{
|
||||
return ((self)->symbol);
|
||||
}
|
||||
|
|
@ -87,7 +89,7 @@ static inline bool ts_subtree_is_keyword(t_subtree self)
|
|||
{
|
||||
return ((self)->is_keyword);
|
||||
}
|
||||
static inline TSStateId ts_subtree_parse_state(t_subtree self)
|
||||
static inline t_state_id ts_subtree_parse_state(t_subtree self)
|
||||
{
|
||||
return ((self)->parse_state);
|
||||
}
|
||||
|
|
@ -115,31 +117,31 @@ static inline void ts_subtree_set_extra(t_subtree *self, bool is_extra)
|
|||
(*self)->extra = is_extra;
|
||||
}
|
||||
|
||||
static inline TSSymbol ts_subtree_leaf_symbol(t_subtree self)
|
||||
static inline t_symbol 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(t_subtree self)
|
||||
static inline t_state_id 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(t_subtree self)
|
||||
static inline t_length ts_subtree_padding(t_subtree self)
|
||||
{
|
||||
return self->padding;
|
||||
}
|
||||
|
||||
static inline Length ts_subtree_size(t_subtree self)
|
||||
static inline t_length ts_subtree_size(t_subtree self)
|
||||
{
|
||||
return self->size;
|
||||
}
|
||||
|
||||
static inline Length ts_subtree_total_size(t_subtree self)
|
||||
static inline t_length ts_subtree_total_size(t_subtree self)
|
||||
{
|
||||
return (length_add(ts_subtree_padding(self), ts_subtree_size(self)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,10 +19,10 @@
|
|||
struct s_tree
|
||||
{
|
||||
t_subtree root;
|
||||
const TSLanguage *language;
|
||||
const t_language *language;
|
||||
};
|
||||
|
||||
TSTree *ts_tree_new(t_subtree root, const TSLanguage *language);
|
||||
TSNode ts_node_new(const TSTree *, const t_subtree *, Length, TSSymbol);
|
||||
t_tree *ts_tree_new(t_subtree root, const t_language *language);
|
||||
t_node ts_node_new(const t_tree *, const t_subtree *, t_length, t_symbol);
|
||||
|
||||
#endif // TREE_H
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/24 23:01:45 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/08/31 18:41:24 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/19 16:57:31 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -21,11 +21,11 @@
|
|||
#include "parser/parser.h"
|
||||
#include "me/types.h"
|
||||
|
||||
typedef TSSymbolMetadata t_symbol_metadata;
|
||||
typedef TSSymbol t_symbol;
|
||||
typedef TSStateId t_state_id;
|
||||
typedef TSFieldId t_field_id;
|
||||
typedef TSLexer t_lexer_funcs;
|
||||
typedef t_symbol_metadata t_symbol_metadata;
|
||||
typedef t_symbol t_symbol;
|
||||
typedef t_state_id t_state_id;
|
||||
typedef t_field_id t_field_id;
|
||||
typedef t_lexer t_lexer_funcs;
|
||||
typedef TSFieldMapSlice t_field_map_slice;
|
||||
typedef TSFieldMapEntry t_field_map_entry;
|
||||
typedef TSParseActionEntry t_parse_action_entry;
|
||||
|
|
@ -71,8 +71,8 @@ static inline bool lex_advance(t_state_id state_value, t_lexer_funcs *lexer, t_l
|
|||
static inline bool lex_accept_token(t_symbol symbol_value, t_lexer_funcs *lexer, t_lexer_state *s)
|
||||
{
|
||||
s->result = true;
|
||||
lexer->result_symbol = symbol_value;
|
||||
lexer->mark_end(lexer);
|
||||
lexer->funcs.result_symbol = symbol_value;
|
||||
lexer->funcs.mark_end(lexer);
|
||||
return (true);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
#include "parser/language.h"
|
||||
#include "parser/parser.h"
|
||||
|
||||
t_const_str ts_language_field_name_for_id(const TSLanguage *self, TSFieldId id)
|
||||
t_const_str ts_language_field_name_for_id(const t_language *self, t_field_id id)
|
||||
{
|
||||
t_u32 count;
|
||||
|
||||
|
|
@ -27,11 +27,11 @@ t_const_str ts_language_field_name_for_id(const TSLanguage *self, TSFieldId id)
|
|||
return (NULL);
|
||||
}
|
||||
|
||||
TSFieldId ts_language_field_id_for_name(const TSLanguage *self,
|
||||
t_field_id ts_language_field_id_for_name(const t_language *self,
|
||||
t_const_str name, t_u32 name_length)
|
||||
{
|
||||
t_u16 count;
|
||||
TSSymbol i;
|
||||
t_symbol i;
|
||||
|
||||
count = (t_u16)ts_language_field_count(self);
|
||||
i = 1;
|
||||
|
|
@ -45,7 +45,7 @@ TSFieldId ts_language_field_id_for_name(const TSLanguage *self,
|
|||
return (0);
|
||||
}
|
||||
|
||||
void ts_language_field_map(const TSLanguage *self, t_u32 production_id,
|
||||
void ts_language_field_map(const t_language *self, t_u32 production_id,
|
||||
const TSFieldMapEntry **start, const TSFieldMapEntry **end)
|
||||
{
|
||||
TSFieldMapSlice slice;
|
||||
|
|
|
|||
|
|
@ -13,22 +13,22 @@
|
|||
#include "me/types.h"
|
||||
#include "parser/language.h"
|
||||
|
||||
t_u32 ts_language_symbol_count(const TSLanguage *self)
|
||||
t_u32 ts_language_symbol_count(const t_language *self)
|
||||
{
|
||||
return (self->symbol_count + self->alias_count);
|
||||
}
|
||||
|
||||
t_u32 ts_language_state_count(const TSLanguage *self)
|
||||
t_u32 ts_language_state_count(const t_language *self)
|
||||
{
|
||||
return (self->state_count);
|
||||
}
|
||||
|
||||
t_u32 ts_language_version(const TSLanguage *self)
|
||||
t_u32 ts_language_version(const t_language *self)
|
||||
{
|
||||
return (self->version);
|
||||
}
|
||||
|
||||
t_u32 ts_language_field_count(const TSLanguage *self)
|
||||
t_u32 ts_language_field_count(const t_language *self)
|
||||
{
|
||||
return (self->field_count);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,13 +15,13 @@
|
|||
#include "parser/language.h"
|
||||
#include "parser/parser.h"
|
||||
|
||||
bool ts_language_has_actions(const TSLanguage *self, TSStateId state,
|
||||
TSSymbol symbol)
|
||||
bool ts_language_has_actions(const t_language *self, t_state_id state,
|
||||
t_symbol symbol)
|
||||
{
|
||||
return (ts_language_lookup(self, state, symbol) != 0);
|
||||
}
|
||||
|
||||
const bool *ts_language_enabled_external_tokens(const TSLanguage *self,
|
||||
const bool *ts_language_enabled_external_tokens(const t_language *self,
|
||||
t_u32 external_scanner_state)
|
||||
{
|
||||
if (external_scanner_state == 0)
|
||||
|
|
@ -31,7 +31,7 @@ const bool *ts_language_enabled_external_tokens(const TSLanguage *self,
|
|||
+ self->external_token_count * external_scanner_state);
|
||||
}
|
||||
|
||||
const TSSymbol *ts_language_alias_sequence(const TSLanguage *self,
|
||||
const t_symbol *ts_language_alias_sequence(const t_language *self,
|
||||
t_u32 production_id)
|
||||
{
|
||||
if (production_id)
|
||||
|
|
@ -41,7 +41,7 @@ const TSSymbol *ts_language_alias_sequence(const TSLanguage *self,
|
|||
return (NULL);
|
||||
}
|
||||
|
||||
TSSymbol ts_language_alias_at(const TSLanguage *self, t_u32 production_id,
|
||||
t_symbol ts_language_alias_at(const t_language *self, t_u32 production_id,
|
||||
t_u32 child_index)
|
||||
{
|
||||
if (production_id)
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@
|
|||
#include "parser/language.h"
|
||||
#include "parser/parser.h"
|
||||
|
||||
void ts_language_table_entry(const TSLanguage *self, TSStateId state,
|
||||
TSSymbol symbol, TableEntry *result)
|
||||
void ts_language_table_entry(const t_language *self, t_state_id state,
|
||||
t_symbol symbol, TableEntry *result)
|
||||
{
|
||||
t_u32 action_index;
|
||||
const TSParseActionEntry *entry;
|
||||
|
|
@ -37,8 +37,8 @@ void ts_language_table_entry(const TSLanguage *self, TSStateId state,
|
|||
}
|
||||
}
|
||||
|
||||
TSStateId ts_language_next_state(const TSLanguage *self, TSStateId state,
|
||||
TSSymbol symbol)
|
||||
t_state_id ts_language_next_state(const t_language *self, t_state_id state,
|
||||
t_symbol symbol)
|
||||
{
|
||||
t_u32 count;
|
||||
const TSParseAction *actions;
|
||||
|
|
@ -67,8 +67,8 @@ TSStateId ts_language_next_state(const TSLanguage *self, TSStateId state,
|
|||
return (ts_language_lookup(self, state, symbol));
|
||||
}
|
||||
|
||||
const TSParseAction *ts_language_actions(const TSLanguage *self,
|
||||
TSStateId state, TSSymbol symbol, t_u32 *count)
|
||||
const TSParseAction *ts_language_actions(const t_language *self,
|
||||
t_state_id state, t_symbol symbol, t_u32 *count)
|
||||
{
|
||||
TableEntry entry;
|
||||
|
||||
|
|
@ -77,8 +77,8 @@ const TSParseAction *ts_language_actions(const TSLanguage *self,
|
|||
return (entry.actions);
|
||||
}
|
||||
|
||||
bool ts_language_has_reduce_action(const TSLanguage *self, TSStateId state,
|
||||
TSSymbol symbol)
|
||||
bool ts_language_has_reduce_action(const t_language *self, t_state_id state,
|
||||
t_symbol symbol)
|
||||
{
|
||||
TableEntry entry;
|
||||
|
||||
|
|
@ -94,8 +94,8 @@ bool ts_language_has_reduce_action(const TSLanguage *self, TSStateId state,
|
|||
// For 'large' parse states, this is a direct lookup. For 'small' parse
|
||||
// states, this requires searching through the symbol groups to find
|
||||
// the given symbol.
|
||||
t_u16 ts_language_lookup(const TSLanguage *self, TSStateId state,
|
||||
TSSymbol symbol)
|
||||
t_u16 ts_language_lookup(const t_language *self, t_state_id state,
|
||||
t_symbol symbol)
|
||||
{
|
||||
if (state >= self->large_state_count)
|
||||
return (me_abort("we got a small parse table, which isn't supported"),
|
||||
|
|
|
|||
|
|
@ -16,25 +16,25 @@
|
|||
#include "parser/language.h"
|
||||
#include "parser/parser.h"
|
||||
|
||||
TSSymbolMetadata ts_language_symbol_metadata(const TSLanguage *self,
|
||||
TSSymbol symbol)
|
||||
t_symbol_metadata ts_language_symbol_metadata(const t_language *self,
|
||||
t_symbol symbol)
|
||||
{
|
||||
if (symbol == ts_builtin_sym_error)
|
||||
return ((TSSymbolMetadata){.visible = true, .named = true});
|
||||
return ((t_symbol_metadata){.visible = true, .named = true});
|
||||
else if (symbol == ts_builtin_sym_error_repeat)
|
||||
return ((TSSymbolMetadata){.visible = false, .named = false});
|
||||
return ((t_symbol_metadata){.visible = false, .named = false});
|
||||
else
|
||||
return (self->symbol_metadata[symbol]);
|
||||
}
|
||||
|
||||
TSSymbol ts_language_public_symbol(const TSLanguage *self, TSSymbol symbol)
|
||||
t_symbol ts_language_public_symbol(const t_language *self, t_symbol symbol)
|
||||
{
|
||||
if (symbol == ts_builtin_sym_error)
|
||||
return (symbol);
|
||||
return (self->public_symbol_map[symbol]);
|
||||
}
|
||||
|
||||
t_const_str ts_language_symbol_name(const TSLanguage *self, TSSymbol symbol)
|
||||
t_const_str ts_language_symbol_name(const t_language *self, t_symbol symbol)
|
||||
{
|
||||
if (symbol == ts_builtin_sym_error)
|
||||
return ("ERROR");
|
||||
|
|
@ -46,12 +46,12 @@ t_const_str ts_language_symbol_name(const TSLanguage *self, TSSymbol symbol)
|
|||
return (NULL);
|
||||
}
|
||||
|
||||
TSSymbol ts_language_symbol_for_name(const TSLanguage *self,
|
||||
t_symbol ts_language_symbol_for_name(const t_language *self,
|
||||
t_const_str string, t_u32 length, bool is_named)
|
||||
{
|
||||
TSSymbolMetadata metadata;
|
||||
t_symbol_metadata metadata;
|
||||
t_u16 count;
|
||||
TSSymbol i;
|
||||
t_symbol i;
|
||||
t_const_str symbol_name;
|
||||
|
||||
if (str_n_compare(string, "ERROR", length))
|
||||
|
|
@ -75,15 +75,15 @@ TSSymbol ts_language_symbol_for_name(const TSLanguage *self,
|
|||
return (0);
|
||||
}
|
||||
|
||||
TSSymbolType ts_language_symbol_type(const TSLanguage *self, TSSymbol symbol)
|
||||
t_symbol_type ts_language_symbol_type(const t_language *self, t_symbol symbol)
|
||||
{
|
||||
TSSymbolMetadata metadata;
|
||||
t_symbol_metadata metadata;
|
||||
|
||||
metadata = ts_language_symbol_metadata(self, symbol);
|
||||
if (metadata.named && metadata.visible)
|
||||
return (TSSymbolTypeRegular);
|
||||
return (t_symbol_typeRegular);
|
||||
else if (metadata.visible)
|
||||
return (TSSymbolTypeAnonymous);
|
||||
return (t_symbol_typeAnonymous);
|
||||
else
|
||||
return (TSSymbolTypeAuxiliary);
|
||||
return (t_symbol_typeAuxiliary);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,11 +15,11 @@
|
|||
#include "parser/language.h"
|
||||
#include "parser/parser.h"
|
||||
|
||||
void ts_language_aliases_for_symbol(const TSLanguage *self,
|
||||
TSSymbol original_symbol, const TSSymbol **start, const TSSymbol **end)
|
||||
void ts_language_aliases_for_symbol(const t_language *self,
|
||||
t_symbol original_symbol, const t_symbol **start, const t_symbol **end)
|
||||
{
|
||||
t_u32 idx;
|
||||
TSSymbol symbol;
|
||||
t_symbol symbol;
|
||||
t_u16 count;
|
||||
|
||||
*start = &self->public_symbol_map[original_symbol];
|
||||
|
|
@ -41,7 +41,7 @@ void ts_language_aliases_for_symbol(const TSLanguage *self,
|
|||
}
|
||||
}
|
||||
|
||||
bool ts_language_is_symbol_external(const TSLanguage *self, TSSymbol symbol)
|
||||
bool ts_language_is_symbol_external(const t_language *self, t_symbol symbol)
|
||||
{
|
||||
return (0 < symbol && symbol < self->external_token_count + 1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,30 +13,30 @@
|
|||
#include "parser/length.h"
|
||||
#include "parser/point.h"
|
||||
|
||||
bool length_is_undefined(Length length)
|
||||
bool length_is_undefined(t_length length)
|
||||
{
|
||||
return (length.bytes == 0 && length.extent.column != 0);
|
||||
}
|
||||
|
||||
Length length_min(Length len1, Length len2)
|
||||
t_length length_min(t_length len1, t_length len2)
|
||||
{
|
||||
if (len1.bytes < len2.bytes)
|
||||
return (len1);
|
||||
return (len2);
|
||||
}
|
||||
|
||||
Length length_add(Length len1, Length len2)
|
||||
t_length length_add(t_length len1, t_length len2)
|
||||
{
|
||||
Length result;
|
||||
t_length result;
|
||||
|
||||
result.bytes = len1.bytes + len2.bytes;
|
||||
result.extent = point_add(len1.extent, len2.extent);
|
||||
return (result);
|
||||
}
|
||||
|
||||
Length length_sub(Length len1, Length len2)
|
||||
t_length length_sub(t_length len1, t_length len2)
|
||||
{
|
||||
Length result;
|
||||
t_length result;
|
||||
|
||||
result.bytes = len1.bytes - len2.bytes;
|
||||
result.extent = point_sub(len1.extent, len2.extent);
|
||||
|
|
|
|||
|
|
@ -13,12 +13,12 @@
|
|||
#include "parser/length.h"
|
||||
#include "parser/point.h"
|
||||
|
||||
Length length_zero(void)
|
||||
t_length length_zero(void)
|
||||
{
|
||||
return ((Length){0, {0, 0}});
|
||||
return ((t_length){0, {0, 0}});
|
||||
}
|
||||
|
||||
Length length_saturating_sub(Length len1, Length len2)
|
||||
t_length length_saturating_sub(t_length len1, t_length len2)
|
||||
{
|
||||
if (len1.bytes > len2.bytes)
|
||||
return (length_sub(len1, len2));
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
bool ts_lex(t_lexer *lexer, t_state_id state) {
|
||||
START_LEXER();
|
||||
eof = lexer->data.eof((void *)lexer);
|
||||
eof = lexer->funcs.eof((void *)lexer);
|
||||
switch (state) {
|
||||
case 0:
|
||||
if (eof) ADVANCE(127);
|
||||
|
|
@ -2423,7 +2423,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->data.eof((void *)lexer);
|
||||
eof = lexer->funcs.eof((void *)lexer);
|
||||
switch (state) {
|
||||
case 0:
|
||||
ACCEPT_TOKEN(ts_builtin_sym_end);
|
||||
|
|
|
|||
|
|
@ -6,37 +6,37 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/31 18:06:07 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/08/31 18:23:07 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/19 16:58:25 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/types.h"
|
||||
#include "parser/lexer.h"
|
||||
|
||||
bool ts_lexer__eof(const TSLexer *_self);
|
||||
t_u32 ts_lexer__get_column(TSLexer *_self);
|
||||
void ts_lexer__advance(TSLexer *_self, bool skip);
|
||||
bool ts_lexer__eof(const t_lexer *_self);
|
||||
t_u32 ts_lexer__get_column(t_lexer *_self);
|
||||
void ts_lexer__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__mark_end(t_lexer *_self);
|
||||
void ts_lexer_advance_to_end(t_lexer *self);
|
||||
void ts_lexer_goto(t_lexer *self, Length position);
|
||||
void ts_lexer_goto(t_lexer *self, t_length position);
|
||||
|
||||
bool ts_lexer__do_advance_loop(t_lexer *self, const TSRange **current_range);
|
||||
bool ts_lexer__do_advance_loop(t_lexer *self, const t_range **current_range);
|
||||
void ts_lexer__do_advance_after_loop(t_lexer *self, bool skip,
|
||||
const TSRange *cur);
|
||||
const t_range *cur);
|
||||
|
||||
// Intended to be called only from functions that control logging.
|
||||
void ts_lexer__do_advance(t_lexer *self, bool skip)
|
||||
{
|
||||
const TSRange *cur = \
|
||||
const t_range *cur = \
|
||||
&self->included_ranges[self->current_included_range_index];
|
||||
|
||||
if (self->lookahead_size)
|
||||
{
|
||||
self->current_position.bytes += self->lookahead_size;
|
||||
if (self->data.lookahead == '\n')
|
||||
if (self->funcs.lookahead == '\n')
|
||||
{
|
||||
self->current_position.extent.row++;
|
||||
self->current_position.extent.column = 0;
|
||||
|
|
@ -53,7 +53,7 @@ void ts_lexer__do_advance(t_lexer *self, bool skip)
|
|||
|
||||
// Advance to the next character in the source code, retrieving a new
|
||||
// chunk of source code if needed.
|
||||
void ts_lexer__advance(TSLexer *_self, bool skip)
|
||||
void ts_lexer__advance(t_lexer *_self, bool skip)
|
||||
{
|
||||
t_lexer *self;
|
||||
|
||||
|
|
@ -63,14 +63,14 @@ void ts_lexer__advance(TSLexer *_self, bool skip)
|
|||
ts_lexer__do_advance(self, skip);
|
||||
}
|
||||
|
||||
bool ts_lexer__do_advance_loop(t_lexer *self, const TSRange **current_range)
|
||||
bool ts_lexer__do_advance_loop(t_lexer *self, const t_range **current_range)
|
||||
{
|
||||
if (self->current_included_range_index < self->included_range_count)
|
||||
self->current_included_range_index++;
|
||||
if (self->current_included_range_index < self->included_range_count)
|
||||
{
|
||||
(*current_range)++;
|
||||
self->current_position = (Length){
|
||||
self->current_position = (t_length){
|
||||
(*current_range)->start_byte,
|
||||
(*current_range)->start_point,
|
||||
};
|
||||
|
|
@ -84,7 +84,7 @@ 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)
|
||||
const t_range *cur)
|
||||
{
|
||||
if (skip)
|
||||
self->token_start_position = self->current_position;
|
||||
|
|
@ -99,7 +99,7 @@ void ts_lexer__do_advance_after_loop(t_lexer *self, bool skip,
|
|||
else
|
||||
{
|
||||
ts_lexer__clear_chunk(self);
|
||||
self->data.lookahead = '\0';
|
||||
self->funcs.lookahead = '\0';
|
||||
self->lookahead_size = 1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,16 +13,16 @@
|
|||
#include "me/types.h"
|
||||
#include "parser/lexer.h"
|
||||
|
||||
bool ts_lexer__eof(const TSLexer *_self);
|
||||
t_u32 ts_lexer__get_column(TSLexer *_self);
|
||||
void ts_lexer__advance(TSLexer *_self, bool skip);
|
||||
bool ts_lexer__eof(const t_lexer *_self);
|
||||
t_u32 ts_lexer__get_column(t_lexer *_self);
|
||||
void ts_lexer__advance(t_lexer *_self, bool skip);
|
||||
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__mark_end(t_lexer *_self);
|
||||
void ts_lexer_advance_to_end(t_lexer *self);
|
||||
void ts_lexer_goto(t_lexer *self, Length position);
|
||||
void ts_lexer_goto(t_lexer *self, t_length position);
|
||||
|
||||
// Clear the currently stored chunk of source code, because the lexer's
|
||||
// position has changed.
|
||||
|
|
|
|||
|
|
@ -6,28 +6,28 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/31 18:07:07 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/08/31 18:12:10 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/19 16:58:53 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/types.h"
|
||||
#include "parser/lexer.h"
|
||||
|
||||
bool ts_lexer__eof(const TSLexer *_self);
|
||||
t_u32 ts_lexer__get_column(TSLexer *_self);
|
||||
void ts_lexer__advance(TSLexer *_self, bool skip);
|
||||
bool ts_lexer__eof(const t_lexer *_self);
|
||||
t_u32 ts_lexer__get_column(t_lexer *_self);
|
||||
void ts_lexer__advance(t_lexer *_self, bool skip);
|
||||
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__mark_end(t_lexer *_self);
|
||||
void ts_lexer_advance_to_end(t_lexer *self);
|
||||
void ts_lexer_goto(t_lexer *self, Length position);
|
||||
void ts_lexer_goto(t_lexer *self, t_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)
|
||||
bool ts_lexer__eof(const t_lexer *_self)
|
||||
{
|
||||
t_lexer *self;
|
||||
|
||||
|
|
@ -37,14 +37,14 @@ bool ts_lexer__eof(const TSLexer *_self)
|
|||
|
||||
// Mark that a token match has completed. This can be called multiple
|
||||
// times if a longer match is found later.
|
||||
void ts_lexer__mark_end(TSLexer *_self)
|
||||
void ts_lexer__mark_end(t_lexer *_self)
|
||||
{
|
||||
t_lexer *self;
|
||||
TSRange *current_included_range;
|
||||
TSRange *previous_included_range;
|
||||
t_range *current_included_range;
|
||||
t_range *previous_included_range;
|
||||
|
||||
self = (t_lexer *)_self;
|
||||
if (!ts_lexer__eof(&self->data))
|
||||
if (!ts_lexer__eof(self))
|
||||
{
|
||||
current_included_range = \
|
||||
&self->included_ranges[self->current_included_range_index];
|
||||
|
|
@ -52,7 +52,7 @@ void ts_lexer__mark_end(TSLexer *_self)
|
|||
&& self->current_position.bytes == current_included_range->start_byte)
|
||||
{
|
||||
previous_included_range = current_included_range - 1;
|
||||
self->token_end_position = (Length){
|
||||
self->token_end_position = (t_length){
|
||||
previous_included_range->end_byte,
|
||||
previous_included_range->end_point,
|
||||
};
|
||||
|
|
@ -65,5 +65,5 @@ void ts_lexer__mark_end(TSLexer *_self)
|
|||
void ts_lexer_advance_to_end(t_lexer *self)
|
||||
{
|
||||
while (self->chunk)
|
||||
ts_lexer__advance(&self->data, false);
|
||||
ts_lexer__advance(self, false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,18 +13,18 @@
|
|||
#include "me/types.h"
|
||||
#include "parser/lexer.h"
|
||||
|
||||
bool ts_lexer__eof(const TSLexer *_self);
|
||||
t_u32 ts_lexer__get_column(TSLexer *_self);
|
||||
void ts_lexer__advance(TSLexer *_self, bool skip);
|
||||
bool ts_lexer__eof(const t_lexer *_self);
|
||||
t_u32 ts_lexer__get_column(t_lexer *_self);
|
||||
void ts_lexer__advance(t_lexer *_self, bool skip);
|
||||
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__mark_end(t_lexer *_self);
|
||||
void ts_lexer_advance_to_end(t_lexer *self);
|
||||
void ts_lexer_goto(t_lexer *self, Length position);
|
||||
void ts_lexer_goto(t_lexer *self, t_length position);
|
||||
|
||||
t_u32 ts_lexer__get_column(TSLexer *_self)
|
||||
t_u32 ts_lexer__get_column(t_lexer *_self)
|
||||
{
|
||||
t_lexer *self;
|
||||
t_u32 goal_byte;
|
||||
|
|
|
|||
|
|
@ -6,32 +6,32 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/31 18:08:11 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/08/31 18:39:32 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/19 16:59:09 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/types.h"
|
||||
#include "parser/lexer.h"
|
||||
|
||||
bool ts_lexer__eof(const TSLexer *_self);
|
||||
t_u32 ts_lexer__get_column(TSLexer *_self);
|
||||
void ts_lexer__advance(TSLexer *_self, bool skip);
|
||||
bool ts_lexer__eof(const t_lexer *_self);
|
||||
t_u32 ts_lexer__get_column(t_lexer *_self);
|
||||
void ts_lexer__advance(t_lexer *_self, bool skip);
|
||||
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__mark_end(t_lexer *_self);
|
||||
void ts_lexer_advance_to_end(t_lexer *self);
|
||||
void ts_lexer_goto(t_lexer *self, Length position);
|
||||
void ts_lexer_goto(t_lexer *self, t_length position);
|
||||
|
||||
void ts_lexer_goto_inside_loop(t_lexer *self, bool *found_included_range,
|
||||
TSRange *included_range, t_usize i);
|
||||
t_range *included_range, t_usize i);
|
||||
void ts_lexer_goto_after_loop(t_lexer *self, bool found_included_range);
|
||||
|
||||
void ts_lexer_goto(t_lexer *self, Length position)
|
||||
void ts_lexer_goto(t_lexer *self, t_length position)
|
||||
{
|
||||
bool found_included_range;
|
||||
TSRange *included_range;
|
||||
t_range *included_range;
|
||||
t_u32 i;
|
||||
|
||||
included_range = NULL;
|
||||
|
|
@ -54,11 +54,11 @@ void ts_lexer_goto(t_lexer *self, Length position)
|
|||
}
|
||||
|
||||
void ts_lexer_goto_inside_loop(t_lexer *self, bool *found_included_range,
|
||||
TSRange *included_range, t_usize i)
|
||||
t_range *included_range, t_usize i)
|
||||
{
|
||||
if (included_range->start_byte >= self->current_position.bytes)
|
||||
{
|
||||
self->current_position = (Length){
|
||||
self->current_position = (t_length){
|
||||
.bytes = included_range->start_byte,
|
||||
.extent = included_range->start_point,
|
||||
};
|
||||
|
|
@ -69,7 +69,7 @@ void ts_lexer_goto_inside_loop(t_lexer *self, bool *found_included_range,
|
|||
|
||||
void ts_lexer_goto_after_loop(t_lexer *self, bool found_included_range)
|
||||
{
|
||||
TSRange *last_included_range;
|
||||
t_range *last_included_range;
|
||||
|
||||
if (found_included_range)
|
||||
{
|
||||
|
|
@ -78,19 +78,19 @@ void ts_lexer_goto_after_loop(t_lexer *self, bool found_included_range)
|
|||
+ self->chunk_size))
|
||||
ts_lexer__clear_chunk(self);
|
||||
self->lookahead_size = 0;
|
||||
self->data.lookahead = '\0';
|
||||
self->funcs.lookahead = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
self->current_included_range_index = self->included_range_count;
|
||||
last_included_range = &self->included_ranges[self->included_range_count
|
||||
- 1];
|
||||
self->current_position = (Length){
|
||||
self->current_position = (t_length){
|
||||
.bytes = last_included_range->end_byte,
|
||||
.extent = last_included_range->end_point,
|
||||
};
|
||||
ts_lexer__clear_chunk(self);
|
||||
self->lookahead_size = 1;
|
||||
self->data.lookahead = '\0';
|
||||
self->funcs.lookahead = '\0';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/31 17:58:01 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/08/31 18:25:16 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/19 16:59:58 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,27 +15,27 @@
|
|||
|
||||
#define BYTE_ORDER_MARK 0xFEFF
|
||||
|
||||
bool ts_lexer__eof(const TSLexer *_self);
|
||||
t_u32 ts_lexer__get_column(TSLexer *_self);
|
||||
void ts_lexer__advance(TSLexer *_self, bool skip);
|
||||
bool ts_lexer__eof(const t_lexer *_self);
|
||||
t_u32 ts_lexer__get_column(t_lexer *_self);
|
||||
void ts_lexer__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__mark_end(t_lexer *_self);
|
||||
void ts_lexer_advance_to_end(t_lexer *self);
|
||||
void ts_lexer_goto(t_lexer *self, Length position);
|
||||
void ts_lexer_goto(t_lexer *self, t_length position);
|
||||
|
||||
void ts_lexer_init(t_lexer *self)
|
||||
{
|
||||
static TSRange default_range = {.start_point = {\
|
||||
static t_range default_range = {.start_point = {\
|
||||
.row = 0, .column = 0, }, .end_point = {.row = UINT32_MAX, \
|
||||
.column = UINT32_MAX, }, .start_byte = 0, .end_byte = UINT32_MAX};
|
||||
|
||||
*self = (t_lexer){
|
||||
.data = {
|
||||
.funcs = {
|
||||
.advance = ts_lexer__advance,
|
||||
.mark_end = ts_lexer__mark_end,
|
||||
.get_column = ts_lexer__get_column,
|
||||
.get_column = NULL, //ts_lexer__get_column,
|
||||
.eof = ts_lexer__eof,
|
||||
.lookahead = 0,
|
||||
.result_symbol = 0, },
|
||||
|
|
@ -49,14 +49,14 @@ void ts_lexer_init(t_lexer *self)
|
|||
};
|
||||
}
|
||||
|
||||
void ts_lexer_set_input(t_lexer *self, TSInput input)
|
||||
void ts_lexer_set_input(t_lexer *self, t_input input)
|
||||
{
|
||||
self->input = input;
|
||||
ts_lexer__clear_chunk(self);
|
||||
ts_lexer_goto(self, self->current_position);
|
||||
}
|
||||
|
||||
void ts_lexer_reset(t_lexer *self, Length position)
|
||||
void ts_lexer_reset(t_lexer *self, t_length position)
|
||||
{
|
||||
if (position.bytes != self->current_position.bytes)
|
||||
ts_lexer_goto(self, position);
|
||||
|
|
@ -66,24 +66,24 @@ void ts_lexer_start(t_lexer *self)
|
|||
{
|
||||
self->token_start_position = self->current_position;
|
||||
self->token_end_position = LENGTH_UNDEFINED;
|
||||
self->data.result_symbol = 0;
|
||||
self->funcs.result_symbol = 0;
|
||||
self->did_get_column = false;
|
||||
if (!ts_lexer__eof(&self->data))
|
||||
if (!ts_lexer__eof(self))
|
||||
{
|
||||
if (!self->chunk_size)
|
||||
ts_lexer__get_chunk(self);
|
||||
if (!self->lookahead_size)
|
||||
ts_lexer__get_lookahead(self);
|
||||
if (self->current_position.bytes == 0
|
||||
&& self->data.lookahead == BYTE_ORDER_MARK)
|
||||
ts_lexer__advance(&self->data, true);
|
||||
&& self->funcs.lookahead == BYTE_ORDER_MARK)
|
||||
ts_lexer__advance(self, true);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
ts_lexer__mark_end(self);
|
||||
(void)(lookahead_end_byte);
|
||||
if (self->token_end_position.bytes < self->token_start_position.bytes)
|
||||
self->token_start_position = self->token_end_position;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/31 18:09:03 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/08/31 18:09:03 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/19 17:00:15 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,16 +14,16 @@
|
|||
#include "parser/input.h"
|
||||
#include "parser/lexer.h"
|
||||
|
||||
bool ts_lexer__eof(const TSLexer *_self);
|
||||
t_u32 ts_lexer__get_column(TSLexer *_self);
|
||||
void ts_lexer__advance(TSLexer *_self, bool skip);
|
||||
bool ts_lexer__eof(const t_lexer *_self);
|
||||
t_u32 ts_lexer__get_column(t_lexer *_self);
|
||||
void ts_lexer__advance(t_lexer *_self, bool skip);
|
||||
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__mark_end(t_lexer *_self);
|
||||
void ts_lexer_advance_to_end(t_lexer *self);
|
||||
void ts_lexer_goto(t_lexer *self, Length position);
|
||||
void ts_lexer_goto(t_lexer *self, t_length position);
|
||||
|
||||
void ts_lexer__get_lookahead(t_lexer *self)
|
||||
{
|
||||
|
|
@ -36,11 +36,11 @@ void ts_lexer__get_lookahead(t_lexer *self)
|
|||
if (size == 0)
|
||||
{
|
||||
self->lookahead_size = 1;
|
||||
self->data.lookahead = '\0';
|
||||
self->funcs.lookahead = '\0';
|
||||
return ;
|
||||
}
|
||||
chunk = (const t_u8 *)self->chunk + position_in_chunk;
|
||||
self->lookahead_size = ts_decode_ascii(chunk, size, &self->data.lookahead);
|
||||
if (self->data.lookahead == TS_DECODE_ERROR)
|
||||
self->lookahead_size = ts_decode_ascii(chunk, size, &self->funcs.lookahead);
|
||||
if (self->funcs.lookahead == TS_DECODE_ERROR)
|
||||
self->lookahead_size = 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@
|
|||
#include "me/types.h"
|
||||
#include "parser/parser.h"
|
||||
|
||||
// bool lex_keywords_main(TSLexer *lexer, TSStateId state);
|
||||
// bool lex_normal_main(TSLexer *lexer, TSStateId state);
|
||||
bool tree_sitter_sh_external_scanner_scan(void *ctx, TSLexer *lexer, \
|
||||
// bool lex_keywords_main(t_lexer *lexer, t_state_id state);
|
||||
// bool lex_normal_main(t_lexer *lexer, t_state_id state);
|
||||
bool tree_sitter_sh_external_scanner_scan(void *ctx, t_lexer *lexer, \
|
||||
const bool *ret);
|
||||
void *create_external_scanner_states(void);
|
||||
void *create_field_names(void);
|
||||
|
|
@ -33,8 +33,8 @@ void *create_non_terminal_alias_map(void);
|
|||
void *create_unique_symbols_map(void);
|
||||
void *create_symbols_metadata(void);
|
||||
void *create_parse_table(void);
|
||||
bool ts_lex_keywords(TSLexer *lexer, TSStateId state);
|
||||
bool ts_lex(TSLexer *lexer, TSStateId state);
|
||||
bool ts_lex_keywords(t_lexer *lexer, t_state_id state);
|
||||
bool ts_lex(t_lexer *lexer, t_state_id state);
|
||||
t_u32 tree_sitter_sh_external_scanner_serialize(void *ctx, t_u8 *state);
|
||||
void tree_sitter_sh_external_scanner_deserialize(void *ctx, \
|
||||
const t_u8 *state, t_u32 val);
|
||||
|
|
@ -54,7 +54,7 @@ static struct ExternalScannerDefinition init_scanner(void)
|
|||
});
|
||||
}
|
||||
|
||||
static void init_language(TSLanguage *language)
|
||||
static void init_language(t_language *language)
|
||||
{
|
||||
static uint32_t empty_map[] = {0, 0, 0};
|
||||
|
||||
|
|
@ -78,10 +78,10 @@ static void init_language(TSLanguage *language)
|
|||
language->external_scanner = init_scanner();
|
||||
}
|
||||
|
||||
const TSLanguage *tree_sitter_sh(void)
|
||||
const t_language *tree_sitter_sh(void)
|
||||
{
|
||||
static bool init = false;
|
||||
static TSLanguage language = {
|
||||
static t_language language = {
|
||||
.version = LANGUAGE_VERSION,
|
||||
.symbol_count = SYMBOL_COUNT,
|
||||
.alias_count = ALIAS_COUNT,
|
||||
|
|
@ -99,5 +99,5 @@ const TSLanguage *tree_sitter_sh(void)
|
|||
init_language(&language);
|
||||
init = true;
|
||||
}
|
||||
return ((TSLanguage *)&language);
|
||||
return ((t_language *)&language);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
#include "me/vec/vec_reduce_action.h"
|
||||
|
||||
void ts_reduce_action_set_add(\
|
||||
ReduceActionSet *self, t_reduce_action new_action)
|
||||
t_vec_reduce_action *self, t_reduce_action new_action)
|
||||
{
|
||||
t_reduce_action action;
|
||||
t_u32 i;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include "parser/inner/node.h"
|
||||
|
||||
t_u32 ts_node_child_count(TSNode self)
|
||||
t_u32 ts_node_child_count(t_node self)
|
||||
{
|
||||
t_subtree tree;
|
||||
|
||||
|
|
@ -23,7 +23,7 @@ t_u32 ts_node_child_count(TSNode self)
|
|||
return (0);
|
||||
}
|
||||
|
||||
t_u32 ts_node_named_child_count(TSNode self)
|
||||
t_u32 ts_node_named_child_count(t_node self)
|
||||
{
|
||||
t_subtree tree;
|
||||
|
||||
|
|
@ -34,17 +34,17 @@ t_u32 ts_node_named_child_count(TSNode self)
|
|||
return (0);
|
||||
}
|
||||
|
||||
TSFieldId ts_node_field_id_for_child(TSNode self, t_u32 child_index)
|
||||
t_field_id ts_node_field_id_for_child(t_node self, t_u32 child_index)
|
||||
{
|
||||
TSNode result;
|
||||
t_node result;
|
||||
bool did_descend;
|
||||
TSFieldId inherited_field_id;
|
||||
TSNode child;
|
||||
t_field_id inherited_field_id;
|
||||
t_node child;
|
||||
t_u32 index;
|
||||
NodeChildIterator iterator;
|
||||
t_u32 grandchild_index;
|
||||
t_u32 grandchild_count;
|
||||
TSFieldId field_id;
|
||||
t_field_id field_id;
|
||||
|
||||
result = self;
|
||||
did_descend = true;
|
||||
|
|
|
|||
|
|
@ -12,11 +12,11 @@
|
|||
|
||||
#include "parser/inner/node.h"
|
||||
|
||||
TSNode ts_node__child(TSNode self, t_u32 child_index, bool include_anonymous)
|
||||
t_node ts_node__child(t_node self, t_u32 child_index, bool include_anonymous)
|
||||
{
|
||||
TSNode result;
|
||||
t_node result;
|
||||
bool did_descend;
|
||||
TSNode child;
|
||||
t_node child;
|
||||
t_u32 index;
|
||||
NodeChildIterator iterator;
|
||||
t_u32 grandchild_index;
|
||||
|
|
|
|||
|
|
@ -14,16 +14,16 @@
|
|||
#include "parser/length.h"
|
||||
#include "parser/subtree.h"
|
||||
|
||||
TSNode ts_node_new(const TSTree *tree, const t_subtree *subtree, \
|
||||
Length position, TSSymbol alias)
|
||||
t_node ts_node_new(const t_tree *tree, const t_subtree *subtree, \
|
||||
t_length position, t_symbol alias)
|
||||
{
|
||||
return ((TSNode){
|
||||
return ((t_node){
|
||||
position.bytes, position.extent.row, position.extent.column, \
|
||||
alias, subtree, tree,
|
||||
});
|
||||
}
|
||||
|
||||
TSNode ts_node__null(void)
|
||||
t_node ts_node__null(void)
|
||||
{
|
||||
return (ts_node_new(NULL, NULL, length_zero(), 0));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
#include "parser/language.h"
|
||||
#include "parser/tree.h"
|
||||
|
||||
t_const_str ts_node__field_name_from_language(TSNode self,
|
||||
t_const_str ts_node__field_name_from_language(t_node self,
|
||||
t_u32 structural_child_index)
|
||||
{
|
||||
const TSFieldMapEntry *field_map;
|
||||
|
|
@ -33,7 +33,7 @@ t_const_str ts_node__field_name_from_language(TSNode self,
|
|||
return (NULL);
|
||||
}
|
||||
|
||||
TSFieldId ts_node__field_id_from_language(TSNode self,
|
||||
t_field_id ts_node__field_id_from_language(t_node self,
|
||||
t_u32 structural_child_index)
|
||||
{
|
||||
const TSFieldMapEntry *field_map;
|
||||
|
|
|
|||
|
|
@ -14,14 +14,14 @@
|
|||
#include "parser/language.h"
|
||||
#include "parser/tree.h"
|
||||
|
||||
bool ts_node_is_extra(TSNode self)
|
||||
bool ts_node_is_extra(t_node self)
|
||||
{
|
||||
return (ts_subtree_extra(ts_node__subtree(self)));
|
||||
}
|
||||
|
||||
bool ts_node_is_named(TSNode self)
|
||||
bool ts_node_is_named(t_node self)
|
||||
{
|
||||
TSSymbol alias;
|
||||
t_symbol alias;
|
||||
|
||||
alias = ts_node__alias(&self);
|
||||
if (alias)
|
||||
|
|
@ -29,12 +29,12 @@ bool ts_node_is_named(TSNode self)
|
|||
return (ts_subtree_named(ts_node__subtree(self)));
|
||||
}
|
||||
|
||||
TSNode ts_node_child(TSNode self, t_u32 child_index)
|
||||
t_node ts_node_child(t_node self, t_u32 child_index)
|
||||
{
|
||||
return (ts_node__child(self, child_index, true));
|
||||
}
|
||||
|
||||
TSNode ts_node_named_child(TSNode self, t_u32 child_index)
|
||||
t_node ts_node_named_child(t_node self, t_u32 child_index)
|
||||
{
|
||||
return (ts_node__child(self, child_index, false));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,27 +14,27 @@
|
|||
#include "parser/language.h"
|
||||
#include "parser/tree.h"
|
||||
|
||||
t_u32 ts_node_start_byte(TSNode self)
|
||||
t_u32 ts_node_start_byte(t_node self)
|
||||
{
|
||||
return (self.start_byte);
|
||||
}
|
||||
|
||||
const TSLanguage *ts_node_language(TSNode self)
|
||||
const t_language *ts_node_language(t_node self)
|
||||
{
|
||||
return (self.tree->language);
|
||||
}
|
||||
|
||||
TSPoint ts_node_start_point(TSNode self)
|
||||
t_point ts_node_start_point(t_node self)
|
||||
{
|
||||
return ((TSPoint){self.start_row, self.start_col});
|
||||
return ((t_point){self.start_row, self.start_col});
|
||||
}
|
||||
|
||||
t_u32 ts_node__alias(const TSNode *self)
|
||||
t_u32 ts_node__alias(const t_node *self)
|
||||
{
|
||||
return (self->alias);
|
||||
}
|
||||
|
||||
t_subtree ts_node__subtree(TSNode self)
|
||||
t_subtree ts_node__subtree(t_node self)
|
||||
{
|
||||
return (*(const t_subtree *)self.id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,15 +14,15 @@
|
|||
#include "parser/language.h"
|
||||
#include "parser/tree.h"
|
||||
|
||||
t_u32 ts_node_end_byte(TSNode self)
|
||||
t_u32 ts_node_end_byte(t_node self)
|
||||
{
|
||||
return (ts_node_start_byte(self)
|
||||
+ ts_subtree_size(ts_node__subtree(self)).bytes);
|
||||
}
|
||||
|
||||
TSSymbol ts_node_symbol(TSNode self)
|
||||
t_symbol ts_node_symbol(t_node self)
|
||||
{
|
||||
TSSymbol symbol;
|
||||
t_symbol symbol;
|
||||
|
||||
symbol = ts_node__alias(&self);
|
||||
if (!symbol)
|
||||
|
|
@ -30,9 +30,9 @@ TSSymbol ts_node_symbol(TSNode self)
|
|||
return (ts_language_public_symbol(self.tree->language, symbol));
|
||||
}
|
||||
|
||||
t_const_str ts_node_type(TSNode self)
|
||||
t_const_str ts_node_type(t_node self)
|
||||
{
|
||||
TSSymbol symbol;
|
||||
t_symbol symbol;
|
||||
|
||||
symbol = ts_node__alias(&self);
|
||||
if (!symbol)
|
||||
|
|
@ -40,14 +40,14 @@ t_const_str ts_node_type(TSNode self)
|
|||
return (ts_language_symbol_name(self.tree->language, symbol));
|
||||
}
|
||||
|
||||
TSSymbol ts_node_grammar_symbol(TSNode self)
|
||||
t_symbol ts_node_grammar_symbol(t_node self)
|
||||
{
|
||||
return (ts_subtree_symbol(ts_node__subtree(self)));
|
||||
}
|
||||
|
||||
t_const_str ts_node_grammar_type(TSNode self)
|
||||
t_const_str ts_node_grammar_type(t_node self)
|
||||
{
|
||||
TSSymbol symbol;
|
||||
t_symbol symbol;
|
||||
|
||||
symbol = ts_subtree_symbol(ts_node__subtree(self));
|
||||
return (ts_language_symbol_name(self.tree->language, symbol));
|
||||
|
|
|
|||
|
|
@ -14,10 +14,10 @@
|
|||
#include "parser/language.h"
|
||||
#include "parser/tree.h"
|
||||
|
||||
NodeChildIterator ts_node_iterate_children(const TSNode *node)
|
||||
NodeChildIterator ts_node_iterate_children(const t_node *node)
|
||||
{
|
||||
t_subtree subtree;
|
||||
const TSSymbol *alias_sequence;
|
||||
const t_symbol *alias_sequence;
|
||||
|
||||
subtree = ts_node__subtree(*node);
|
||||
if (ts_subtree_child_count(subtree) == 0)
|
||||
|
|
@ -40,10 +40,10 @@ bool ts_node_child_iterator_done(NodeChildIterator *self)
|
|||
return (self->child_index == self->parent->child_count);
|
||||
}
|
||||
|
||||
bool ts_node_child_iterator_next(NodeChildIterator *self, TSNode *result)
|
||||
bool ts_node_child_iterator_next(NodeChildIterator *self, t_node *result)
|
||||
{
|
||||
const t_subtree *child;
|
||||
TSSymbol alias_symbol;
|
||||
t_symbol alias_symbol;
|
||||
|
||||
if (!self->parent || ts_node_child_iterator_done(self))
|
||||
return (false);
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@
|
|||
#include "parser/language.h"
|
||||
#include "parser/tree.h"
|
||||
|
||||
bool ts_node__is_relevant(TSNode self, bool include_anonymous)
|
||||
bool ts_node__is_relevant(t_node self, bool include_anonymous)
|
||||
{
|
||||
TSSymbol alias;
|
||||
t_symbol alias;
|
||||
t_subtree tree;
|
||||
|
||||
tree = ts_node__subtree(self);
|
||||
|
|
@ -29,7 +29,7 @@ bool ts_node__is_relevant(TSNode self, bool include_anonymous)
|
|||
return (ts_subtree_visible(tree) && ts_subtree_named(tree));
|
||||
}
|
||||
|
||||
t_u32 ts_node__relevant_child_count(TSNode self, bool include_anonymous)
|
||||
t_u32 ts_node__relevant_child_count(t_node self, bool include_anonymous)
|
||||
{
|
||||
t_subtree tree;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/13 14:02:35 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/13 14:02:44 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/19 17:23:29 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/inner/parser_inner.h"
|
||||
|
||||
void ts_parser__accept(TSParser *self, t_stack_version version,
|
||||
void ts_parser__accept(t_parser *self, t_stack_version version,
|
||||
t_subtree lookahead)
|
||||
{
|
||||
t_u32 child_count;
|
||||
|
|
@ -26,7 +26,7 @@ void ts_parser__accept(TSParser *self, t_stack_version version,
|
|||
t_subtree tree;
|
||||
|
||||
assert(ts_subtree_is_eof(lookahead));
|
||||
ts_stack_push(self->stack, version, lookahead, false, 1);
|
||||
ts_stack_push(self->stack, (struct s_stack_push_arg){version, lookahead, false, 1});
|
||||
pop = ts_stack_pop_all(self->stack, version);
|
||||
i = 0;
|
||||
while (i < pop.size)
|
||||
|
|
|
|||
|
|
@ -6,15 +6,15 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/13 14:01:20 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/13 14:01:26 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/19 17:24:14 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/inner/parser_inner.h"
|
||||
|
||||
bool ts_parser__advance(TSParser *self, t_stack_version version)
|
||||
bool ts_parser__advance(t_parser *self, t_stack_version version)
|
||||
{
|
||||
TSStateId state;
|
||||
t_state_id state;
|
||||
t_subtree mutable_lookahead;
|
||||
t_subtree lookahead;
|
||||
TableEntry table_entry;
|
||||
|
|
@ -22,7 +22,7 @@ bool ts_parser__advance(TSParser *self, t_stack_version version)
|
|||
t_u32 i;
|
||||
t_stack_version last_reduction_version;
|
||||
TSParseAction action;
|
||||
TSStateId next_state;
|
||||
t_state_id next_state;
|
||||
bool is_fragile;
|
||||
bool end_of_non_terminal_extra;
|
||||
t_stack_version reduction_version;
|
||||
|
|
@ -78,7 +78,7 @@ bool ts_parser__advance(TSParser *self, t_stack_version version)
|
|||
action.reduce.dynamic_precedence,
|
||||
action.reduce.production_id, is_fragile,
|
||||
end_of_non_terminal_extra);
|
||||
if (reduction_version != STACK_VERSION_NONE)
|
||||
if (reduction_version != (t_stack_version)STACK_VERSION_NONE)
|
||||
last_reduction_version = reduction_version;
|
||||
i++;
|
||||
}
|
||||
|
|
@ -87,7 +87,7 @@ bool ts_parser__advance(TSParser *self, t_stack_version version)
|
|||
if (action.type == TSParseActionTypeRecover)
|
||||
return (ts_parser__recover(self, version, lookahead), true);
|
||||
}
|
||||
if (last_reduction_version != STACK_VERSION_NONE)
|
||||
if (last_reduction_version != (t_stack_version)STACK_VERSION_NONE)
|
||||
{
|
||||
ts_stack_renumber_version(self->stack, last_reduction_version,
|
||||
version);
|
||||
|
|
|
|||
|
|
@ -6,16 +6,16 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/13 13:36:06 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/13 13:36:14 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/19 17:19:45 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/inner/parser_inner.h"
|
||||
|
||||
bool ts_parser__breakdown_top_of_stack(TSParser *self,
|
||||
bool ts_parser__breakdown_top_of_stack(t_parser *self,
|
||||
t_stack_version version)
|
||||
{
|
||||
TSStateId state;
|
||||
t_state_id state;
|
||||
bool did_break_down;
|
||||
bool pending;
|
||||
t_stack_slice slice;
|
||||
|
|
@ -57,15 +57,15 @@ bool ts_parser__breakdown_top_of_stack(TSParser *self,
|
|||
state = ts_language_next_state(self->language, state,
|
||||
ts_subtree_symbol(child));
|
||||
child->ref_count++;
|
||||
ts_stack_push(self->stack, slice.version, child, pending,
|
||||
state);
|
||||
ts_stack_push(self->stack, \
|
||||
(struct s_stack_push_arg){slice.version, child, pending, state});
|
||||
j++;
|
||||
}
|
||||
j = 1;
|
||||
while (j < slice.subtrees.len)
|
||||
{
|
||||
tree = slice.subtrees.buffer[j];
|
||||
ts_stack_push(self->stack, slice.version, tree, false, state);
|
||||
ts_stack_push(self->stack, (struct s_stack_push_arg){slice.version, tree, false, state});
|
||||
j++;
|
||||
}
|
||||
ts_subtree_release(parent);
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include "parser/inner/parser_inner.h"
|
||||
|
||||
t_u32 ts_parser__condense_stack(TSParser *self)
|
||||
t_u32 ts_parser__condense_stack(t_parser *self)
|
||||
{
|
||||
bool has_unpaused_version;
|
||||
t_error_comparison cmp;
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/13 14:04:20 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/13 14:04:29 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/19 17:21:23 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/inner/parser_inner.h"
|
||||
|
||||
bool ts_parser__do_all_potential_reductions(TSParser *self,
|
||||
t_stack_version starting_version, TSSymbol lookahead_symbol)
|
||||
bool ts_parser__do_all_potential_reductions(t_parser *self,
|
||||
t_stack_version starting_version, t_symbol lookahead_symbol)
|
||||
{
|
||||
t_u32 initial_version_count;
|
||||
bool can_shift_lookahead_symbol;
|
||||
|
|
@ -22,14 +22,14 @@ bool ts_parser__do_all_potential_reductions(TSParser *self,
|
|||
t_u32 version_count;
|
||||
bool merged;
|
||||
t_stack_version j;
|
||||
TSStateId state;
|
||||
t_state_id state;
|
||||
bool has_shift_action;
|
||||
TSSymbol first_symbol;
|
||||
TSSymbol end_symbol;
|
||||
t_symbol first_symbol;
|
||||
t_symbol end_symbol;
|
||||
t_stack_version reduction_version;
|
||||
t_reduce_action reduce_action;
|
||||
t_u32 k;
|
||||
TSSymbol symbol;
|
||||
t_symbol symbol;
|
||||
TableEntry entry;
|
||||
TSParseAction action;
|
||||
|
||||
|
|
@ -109,7 +109,7 @@ bool ts_parser__do_all_potential_reductions(TSParser *self,
|
|||
}
|
||||
if (has_shift_action)
|
||||
can_shift_lookahead_symbol = true;
|
||||
else if (reduction_version != STACK_VERSION_NONE
|
||||
else if (reduction_version != (t_stack_version)STACK_VERSION_NONE
|
||||
&& i < MAX_VERSION_COUNT)
|
||||
{
|
||||
ts_stack_renumber_version(self->stack, reduction_version, version);
|
||||
|
|
|
|||
|
|
@ -6,18 +6,18 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/11 16:44:11 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/13 14:14:07 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/19 17:23:41 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/inner/parser_inner.h"
|
||||
|
||||
void ts_parser__external_scanner_create(TSParser *self)
|
||||
void ts_parser__external_scanner_create(t_parser *self)
|
||||
{
|
||||
self->external_scanner_payload = self->language->external_scanner.create();
|
||||
}
|
||||
|
||||
void ts_parser__external_scanner_destroy(TSParser *self)
|
||||
void ts_parser__external_scanner_destroy(t_parser *self)
|
||||
{
|
||||
if (self->external_scanner_payload != NULL)
|
||||
{
|
||||
|
|
@ -27,7 +27,7 @@ void ts_parser__external_scanner_destroy(TSParser *self)
|
|||
}
|
||||
}
|
||||
|
||||
t_u32 ts_parser__external_scanner_serialize(TSParser *self)
|
||||
t_u32 ts_parser__external_scanner_serialize(t_parser *self)
|
||||
{
|
||||
t_u32 length;
|
||||
|
||||
|
|
@ -39,7 +39,7 @@ t_u32 ts_parser__external_scanner_serialize(TSParser *self)
|
|||
return (length);
|
||||
}
|
||||
|
||||
void ts_parser__external_scanner_deserialize(TSParser *self,
|
||||
void ts_parser__external_scanner_deserialize(t_parser *self,
|
||||
t_subtree external_token)
|
||||
{
|
||||
const t_u8 *data;
|
||||
|
|
@ -58,13 +58,13 @@ void ts_parser__external_scanner_deserialize(TSParser *self,
|
|||
data, length);
|
||||
}
|
||||
|
||||
bool ts_parser__external_scanner_scan(TSParser *self,
|
||||
TSStateId external_lex_state)
|
||||
bool ts_parser__external_scanner_scan(t_parser *self,
|
||||
t_state_id external_lex_state)
|
||||
{
|
||||
const bool *valid_external_tokens;
|
||||
|
||||
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));
|
||||
self->external_scanner_payload, &self->lexer, valid_external_tokens));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,22 +6,22 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/13 14:04:50 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/13 14:05:26 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/19 17:20:50 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/inner/parser_inner.h"
|
||||
|
||||
void ts_lexer__mark_end(TSLexer *_self);
|
||||
void ts_lexer__mark_end(t_lexer *_self);
|
||||
|
||||
void ts_parser__handle_error(TSParser *self, t_stack_version version,
|
||||
void ts_parser__handle_error(t_parser *self, t_stack_version version,
|
||||
t_subtree lookahead)
|
||||
{
|
||||
Length padding;
|
||||
Length position;
|
||||
TSStateId state;
|
||||
TSStateId state_after_missing_symbol;
|
||||
TSSymbol missing_symbol;
|
||||
t_length padding;
|
||||
t_length position;
|
||||
t_state_id state;
|
||||
t_state_id state_after_missing_symbol;
|
||||
t_symbol missing_symbol;
|
||||
bool did_insert_missing_token;
|
||||
t_stack_version v;
|
||||
t_stack_version version_with_missing_tree;
|
||||
|
|
@ -67,8 +67,8 @@ void ts_parser__handle_error(TSParser *self, t_stack_version version,
|
|||
v);
|
||||
missing_tree = ts_subtree_new_missing_leaf(missing_symbol,
|
||||
padding, lookahead_bytes, self->language);
|
||||
ts_stack_push(self->stack, version_with_missing_tree,
|
||||
missing_tree, false, state_after_missing_symbol);
|
||||
ts_stack_push(self->stack, (struct s_stack_push_arg){version_with_missing_tree,
|
||||
missing_tree, false, state_after_missing_symbol});
|
||||
if (ts_parser__do_all_potential_reductions(self,
|
||||
version_with_missing_tree,
|
||||
ts_subtree_leaf_symbol(lookahead)))
|
||||
|
|
@ -80,7 +80,7 @@ void ts_parser__handle_error(TSParser *self, t_stack_version version,
|
|||
missing_symbol++;
|
||||
}
|
||||
}
|
||||
ts_stack_push(self->stack, v, NULL, false, ERROR_STATE);
|
||||
ts_stack_push(self->stack, (struct s_stack_push_arg){v, NULL, false, ERROR_STATE});
|
||||
if (v == version)
|
||||
v = previous_version_count;
|
||||
else
|
||||
|
|
|
|||
|
|
@ -6,23 +6,23 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/13 13:54:24 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/14 14:32:56 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/19 17:22:48 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/inner/parser_inner.h"
|
||||
|
||||
t_subtree ts_parser__lex(TSParser *self, t_stack_version version,
|
||||
TSStateId parse_state)
|
||||
t_subtree ts_parser__lex(t_parser *self, t_stack_version version,
|
||||
t_state_id parse_state)
|
||||
{
|
||||
Length current_position;
|
||||
Length error_end_position;
|
||||
Length error_start_position;
|
||||
Length padding;
|
||||
Length size;
|
||||
Length start_position;
|
||||
t_length current_position;
|
||||
t_length error_end_position;
|
||||
t_length error_start_position;
|
||||
t_length padding;
|
||||
t_length size;
|
||||
t_length start_position;
|
||||
TSLexMode lex_mode;
|
||||
TSSymbol symbol;
|
||||
t_symbol symbol;
|
||||
bool called_get_column;
|
||||
bool error_mode;
|
||||
bool external_scanner_state_changed;
|
||||
|
|
@ -87,7 +87,7 @@ t_subtree ts_parser__lex(TSParser *self, t_stack_version version,
|
|||
ts_lexer_reset(&self->lexer, current_position);
|
||||
}
|
||||
ts_lexer_start(&self->lexer);
|
||||
found_token = self->language->lex_fn(&self->lexer.data,
|
||||
found_token = self->language->lex_fn(&self->lexer,
|
||||
lex_mode.lex_state);
|
||||
ts_lexer_finish(&self->lexer, &lookahead_end_byte);
|
||||
if (found_token)
|
||||
|
|
@ -104,16 +104,16 @@ t_subtree ts_parser__lex(TSParser *self, t_stack_version version,
|
|||
skipped_error = true;
|
||||
error_start_position = self->lexer.token_start_position;
|
||||
error_end_position = self->lexer.token_start_position;
|
||||
first_error_character = self->lexer.data.lookahead;
|
||||
first_error_character = self->lexer.funcs.lookahead;
|
||||
}
|
||||
if (self->lexer.current_position.bytes == error_end_position.bytes)
|
||||
{
|
||||
if (self->lexer.data.eof(&self->lexer.data))
|
||||
if (self->lexer.funcs.eof(&self->lexer))
|
||||
{
|
||||
self->lexer.data.result_symbol = ts_builtin_sym_error;
|
||||
self->lexer.funcs.result_symbol = ts_builtin_sym_error;
|
||||
break ;
|
||||
}
|
||||
self->lexer.data.advance(&self->lexer.data, false);
|
||||
self->lexer.funcs.advance(&self->lexer, false);
|
||||
}
|
||||
error_end_position = self->lexer.current_position;
|
||||
}
|
||||
|
|
@ -128,7 +128,7 @@ t_subtree ts_parser__lex(TSParser *self, t_stack_version version,
|
|||
else
|
||||
{
|
||||
is_keyword = false;
|
||||
symbol = self->lexer.data.result_symbol;
|
||||
symbol = self->lexer.funcs.result_symbol;
|
||||
padding = length_sub(self->lexer.token_start_position, start_position);
|
||||
size = length_sub(self->lexer.token_end_position,
|
||||
self->lexer.token_start_position);
|
||||
|
|
@ -143,12 +143,12 @@ t_subtree ts_parser__lex(TSParser *self, t_stack_version version,
|
|||
end_byte = self->lexer.token_end_position.bytes;
|
||||
ts_lexer_reset(&self->lexer, self->lexer.token_start_position);
|
||||
ts_lexer_start(&self->lexer);
|
||||
is_keyword = self->language->keyword_lex_fn(&self->lexer.data, 0);
|
||||
is_keyword = self->language->keyword_lex_fn(&self->lexer, 0);
|
||||
if (is_keyword && self->lexer.token_end_position.bytes == end_byte
|
||||
&& ts_language_has_actions(self->language, parse_state,
|
||||
self->lexer.data.result_symbol))
|
||||
self->lexer.funcs.result_symbol))
|
||||
{
|
||||
symbol = self->lexer.data.result_symbol;
|
||||
symbol = self->lexer.funcs.result_symbol;
|
||||
}
|
||||
}
|
||||
result = ts_subtree_new_leaf((t_st_newleaf_args){symbol, padding, size, lookahead_bytes,
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@
|
|||
|
||||
#include "parser/inner/parser_inner.h"
|
||||
|
||||
TSParser *ts_parser_new(TSLanguage *language)
|
||||
t_parser *ts_parser_new(t_language *language)
|
||||
{
|
||||
TSParser *self;
|
||||
t_parser *self;
|
||||
|
||||
self = mem_alloc(sizeof(*self));
|
||||
ts_lexer_init(&self->lexer);
|
||||
|
|
@ -28,7 +28,7 @@ TSParser *ts_parser_new(TSLanguage *language)
|
|||
return (self);
|
||||
}
|
||||
|
||||
void ts_parser_delete(TSParser *self)
|
||||
void ts_parser_delete(t_parser *self)
|
||||
{
|
||||
if (!self)
|
||||
return ;
|
||||
|
|
@ -42,7 +42,7 @@ void ts_parser_delete(TSParser *self)
|
|||
mem_free(self);
|
||||
}
|
||||
|
||||
void ts_parser_reset(TSParser *self)
|
||||
void ts_parser_reset(t_parser *self)
|
||||
{
|
||||
ts_parser__external_scanner_destroy(self);
|
||||
ts_lexer_reset(&self->lexer, length_zero());
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include "parser/inner/parser_inner.h"
|
||||
|
||||
bool ts_parser_has_outstanding_parse(TSParser *self)
|
||||
bool ts_parser_has_outstanding_parse(t_parser *self)
|
||||
{
|
||||
return (self->external_scanner_payload || ts_stack_state(self->stack,
|
||||
0) != 1 || ts_stack_node_count_since_error(self->stack, 0) != 0);
|
||||
|
|
|
|||
|
|
@ -12,16 +12,16 @@
|
|||
|
||||
#include "parser/inner/parser_inner.h"
|
||||
|
||||
bool _parse_condition(TSParser *self, t_u32 *version_count,
|
||||
bool _parse_condition(t_parser *self, t_u32 *version_count,
|
||||
t_stack_version *version)
|
||||
{
|
||||
*version_count = ts_stack_version_count(self->stack);
|
||||
return (*version < *version_count);
|
||||
}
|
||||
|
||||
TSTree *ts_parser_parse(TSParser *self, TSInput input)
|
||||
t_tree *ts_parser_parse(t_parser *self, t_input input)
|
||||
{
|
||||
TSTree *result;
|
||||
t_tree *result;
|
||||
t_u32 position;
|
||||
t_u32 last_position;
|
||||
t_u32 version_count;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include "parser/inner/parser_inner.h"
|
||||
|
||||
const t_u8 *ts_string_input_read(void *_self, t_u32 byte, TSPoint point,
|
||||
const t_u8 *ts_string_input_read(void *_self, t_u32 byte, t_point point,
|
||||
t_u32 *length)
|
||||
{
|
||||
t_string_input *self;
|
||||
|
|
@ -31,12 +31,12 @@ const t_u8 *ts_string_input_read(void *_self, t_u32 byte, TSPoint point,
|
|||
}
|
||||
}
|
||||
|
||||
TSTree *ts_parser_parse_string(TSParser *self, t_const_str string,
|
||||
t_tree *ts_parser_parse_string(t_parser *self, t_const_str string,
|
||||
t_u32 length)
|
||||
{
|
||||
t_string_input input;
|
||||
|
||||
input = (t_string_input){(const t_u8 *)string, length};
|
||||
return (ts_parser_parse(self, \
|
||||
(TSInput){&input, ts_string_input_read}));
|
||||
(t_input){&input, ts_string_input_read}));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,16 +6,16 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/13 13:46:43 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/13 13:47:27 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/19 17:18:36 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/inner/parser_inner.h"
|
||||
|
||||
void ts_parser__recover(TSParser *self, t_stack_version version,
|
||||
void ts_parser__recover(t_parser *self, t_stack_version version,
|
||||
t_subtree lookahead)
|
||||
{
|
||||
Length position;
|
||||
t_length position;
|
||||
bool did_recover;
|
||||
bool would_merge;
|
||||
t_stack_slice_array pop;
|
||||
|
|
@ -123,7 +123,8 @@ void ts_parser__recover(TSParser *self, t_stack_version version,
|
|||
{
|
||||
children = vec_subtree_new(16, NULL);
|
||||
parent = ts_subtree_new_error_node(&children, false, self->language);
|
||||
ts_stack_push(self->stack, version, parent, false, 1);
|
||||
ts_stack_push(self->stack, \
|
||||
(struct s_stack_push_arg){version, parent, false, 1});
|
||||
ts_parser__accept(self, version, lookahead);
|
||||
return ;
|
||||
}
|
||||
|
|
@ -169,7 +170,8 @@ void ts_parser__recover(TSParser *self, t_stack_version version,
|
|||
error_repeat = ts_subtree_new_node(ts_builtin_sym_error_repeat,
|
||||
&pop.contents[0].subtrees, 0, self->language);
|
||||
}
|
||||
ts_stack_push(self->stack, version, (error_repeat), false, ERROR_STATE);
|
||||
ts_stack_push(self->stack, \
|
||||
(struct s_stack_push_arg){version, (error_repeat), false, ERROR_STATE});
|
||||
if (ts_subtree_has_external_tokens(lookahead))
|
||||
ts_stack_set_last_external_token(self->stack, version,
|
||||
ts_subtree_last_external_token(lookahead));
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/13 13:48:22 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/13 13:48:25 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/19 17:23:55 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/inner/parser_inner.h"
|
||||
|
||||
bool ts_parser__recover_to_state(TSParser *self, t_stack_version version,
|
||||
t_u32 depth, TSStateId goal_state)
|
||||
bool ts_parser__recover_to_state(t_parser *self, t_stack_version version,
|
||||
t_u32 depth, t_state_id goal_state)
|
||||
{
|
||||
t_stack_slice slice;
|
||||
t_stack_slice_array pop;
|
||||
|
|
@ -71,7 +71,7 @@ bool ts_parser__recover_to_state(TSParser *self, t_stack_version version,
|
|||
{
|
||||
error = ts_subtree_new_error_node(&slice.subtrees, true,
|
||||
self->language);
|
||||
ts_stack_push(self->stack, slice.version, error, false, goal_state);
|
||||
ts_stack_push(self->stack, (struct s_stack_push_arg){slice.version, error, false, goal_state});
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -81,11 +81,11 @@ bool ts_parser__recover_to_state(TSParser *self, t_stack_version version,
|
|||
while (j < self->trailing_extras.len)
|
||||
{
|
||||
tree = self->trailing_extras.buffer[j];
|
||||
ts_stack_push(self->stack, slice.version, tree, false, goal_state);
|
||||
ts_stack_push(self->stack, (struct s_stack_push_arg){slice.version, tree, false, goal_state});
|
||||
j++;
|
||||
}
|
||||
previous_version = slice.version;
|
||||
i++;
|
||||
}
|
||||
return (previous_version != STACK_VERSION_NONE);
|
||||
return (previous_version != (t_stack_version)STACK_VERSION_NONE);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,18 +6,18 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/13 14:03:09 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/13 14:03:18 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/19 17:20:24 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/inner/parser_inner.h"
|
||||
|
||||
t_stack_version ts_parser__reduce(TSParser *self, t_stack_version version,
|
||||
TSSymbol symbol, t_u32 count, int dynamic_precedence,
|
||||
t_stack_version ts_parser__reduce(t_parser *self, t_stack_version version,
|
||||
t_symbol symbol, t_u32 count, int dynamic_precedence,
|
||||
t_u16 production_id, bool is_fragile, bool end_of_non_terminal_extra)
|
||||
{
|
||||
TSStateId next_state;
|
||||
TSStateId state;
|
||||
t_state_id next_state;
|
||||
t_state_id state;
|
||||
t_stack_slice next_slice;
|
||||
t_stack_slice slice;
|
||||
t_stack_slice_array pop;
|
||||
|
|
@ -97,12 +97,12 @@ t_stack_version ts_parser__reduce(TSParser *self, t_stack_version version,
|
|||
else
|
||||
parent->parse_state = state;
|
||||
parent->dynamic_precedence += dynamic_precedence;
|
||||
ts_stack_push(self->stack, slice_version, (parent), false, next_state);
|
||||
ts_stack_push(self->stack, (struct s_stack_push_arg){slice_version, (parent), false, next_state});
|
||||
j = 0;
|
||||
while (j < self->trailing_extras.len)
|
||||
{
|
||||
ts_stack_push(self->stack, slice_version,
|
||||
self->trailing_extras.buffer[j], false, next_state);
|
||||
ts_stack_push(self->stack, (struct s_stack_push_arg){slice_version,
|
||||
self->trailing_extras.buffer[j], false, next_state});
|
||||
j++;
|
||||
}
|
||||
k = 0;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
// 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.
|
||||
bool ts_parser__select_tree(TSParser *self, t_subtree left, t_subtree right)
|
||||
bool ts_parser__select_tree(t_parser *self, t_subtree left, t_subtree right)
|
||||
{
|
||||
int comparison;
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ bool ts_parser__select_tree(TSParser *self, t_subtree left, t_subtree right)
|
|||
|
||||
// Determine if a given tree's children should be replaced
|
||||
// by an alternative array of children.
|
||||
bool ts_parser__select_children(TSParser *self, t_subtree left,
|
||||
bool ts_parser__select_children(t_parser *self, t_subtree left,
|
||||
const t_vec_subtree *children)
|
||||
{
|
||||
t_subtree scratch_tree;
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/13 13:55:29 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/13 13:55:49 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/19 17:20:02 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/inner/parser_inner.h"
|
||||
|
||||
void ts_parser__shift(TSParser *self, t_stack_version version,
|
||||
TSStateId state, t_subtree lookahead, bool extra)
|
||||
void ts_parser__shift(t_parser *self, t_stack_version version,
|
||||
t_state_id state, t_subtree lookahead, bool extra)
|
||||
{
|
||||
bool is_leaf;
|
||||
t_subtree result;
|
||||
|
|
@ -27,7 +27,7 @@ void ts_parser__shift(TSParser *self, t_stack_version version,
|
|||
ts_subtree_set_extra(&result, extra);
|
||||
subtree_to_push = (result);
|
||||
}
|
||||
ts_stack_push(self->stack, version, subtree_to_push, !is_leaf, state);
|
||||
ts_stack_push(self->stack,(struct s_stack_push_arg){ version, subtree_to_push, !is_leaf, state});
|
||||
if (ts_subtree_has_external_tokens(subtree_to_push))
|
||||
ts_stack_set_last_external_token(self->stack, version,
|
||||
ts_subtree_last_external_token(subtree_to_push));
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include "parser/inner/parser_inner.h"
|
||||
|
||||
t_error_comparison ts_parser__compare_versions(TSParser *self,
|
||||
t_error_comparison ts_parser__compare_versions(t_parser *self,
|
||||
t_error_status a, t_error_status b)
|
||||
{
|
||||
(void)self;
|
||||
|
|
@ -51,7 +51,7 @@ t_error_comparison ts_parser__compare_versions(TSParser *self,
|
|||
return (ECNone);
|
||||
}
|
||||
|
||||
t_error_status ts_parser__version_status(TSParser *self,
|
||||
t_error_status ts_parser__version_status(t_parser *self,
|
||||
t_stack_version version)
|
||||
{
|
||||
t_u32 cost;
|
||||
|
|
@ -68,11 +68,11 @@ t_error_status ts_parser__version_status(TSParser *self,
|
|||
version) == ERROR_STATE});
|
||||
}
|
||||
|
||||
bool ts_parser__better_version_exists(TSParser *self,
|
||||
bool ts_parser__better_version_exists(t_parser *self,
|
||||
t_stack_version version, bool is_in_error, t_u32 cost)
|
||||
{
|
||||
t_error_status status_i;
|
||||
Length position;
|
||||
t_length position;
|
||||
t_error_status status;
|
||||
t_stack_version i;
|
||||
t_stack_version n;
|
||||
|
|
|
|||
|
|
@ -12,12 +12,12 @@
|
|||
|
||||
#include "parser/point.h"
|
||||
|
||||
TSPoint point__new(t_u32 row, t_u32 column)
|
||||
t_point point__new(t_u32 row, t_u32 column)
|
||||
{
|
||||
return ((TSPoint){row, column});
|
||||
return ((t_point){row, column});
|
||||
}
|
||||
|
||||
TSPoint point_add(TSPoint a, TSPoint b)
|
||||
t_point point_add(t_point a, t_point b)
|
||||
{
|
||||
if (b.row > 0)
|
||||
return (point__new(a.row + b.row, b.column));
|
||||
|
|
@ -25,7 +25,7 @@ TSPoint point_add(TSPoint a, TSPoint b)
|
|||
return (point__new(a.row, a.column + b.column));
|
||||
}
|
||||
|
||||
TSPoint point_sub(TSPoint a, TSPoint b)
|
||||
t_point point_sub(t_point a, t_point b)
|
||||
{
|
||||
if (a.row > b.row)
|
||||
return (point__new(a.row - b.row, a.column));
|
||||
|
|
@ -33,12 +33,12 @@ TSPoint point_sub(TSPoint a, TSPoint b)
|
|||
return (point__new(0, a.column - b.column));
|
||||
}
|
||||
|
||||
bool point_lte(TSPoint a, TSPoint b)
|
||||
bool point_lte(t_point a, t_point b)
|
||||
{
|
||||
return ((a.row < b.row) || (a.row == b.row && a.column <= b.column));
|
||||
}
|
||||
|
||||
bool point_lt(TSPoint a, TSPoint b)
|
||||
bool point_lt(t_point a, t_point b)
|
||||
{
|
||||
return ((a.row < b.row) || (a.row == b.row && a.column < b.column));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,22 +12,22 @@
|
|||
|
||||
#include "parser/point.h"
|
||||
|
||||
bool point_gt(TSPoint a, TSPoint b)
|
||||
bool point_gt(t_point a, t_point b)
|
||||
{
|
||||
return ((a.row > b.row) || (a.row == b.row && a.column > b.column));
|
||||
}
|
||||
|
||||
bool point_gte(TSPoint a, TSPoint b)
|
||||
bool point_gte(t_point a, t_point b)
|
||||
{
|
||||
return ((a.row > b.row) || (a.row == b.row && a.column >= b.column));
|
||||
}
|
||||
|
||||
bool point_eq(TSPoint a, TSPoint b)
|
||||
bool point_eq(t_point a, t_point b)
|
||||
{
|
||||
return (a.row == b.row && a.column == b.column);
|
||||
}
|
||||
|
||||
TSPoint point_min(TSPoint a, TSPoint b)
|
||||
t_point point_min(t_point a, t_point b)
|
||||
{
|
||||
if (a.row < b.row || (a.row == b.row && a.column < b.column))
|
||||
return (a);
|
||||
|
|
@ -35,7 +35,7 @@ TSPoint point_min(TSPoint a, TSPoint b)
|
|||
return (b);
|
||||
}
|
||||
|
||||
TSPoint point_max(TSPoint a, TSPoint b)
|
||||
t_point point_max(t_point a, t_point b)
|
||||
{
|
||||
if (a.row > b.row || (a.row == b.row && a.column > b.column))
|
||||
return (a);
|
||||
|
|
|
|||
|
|
@ -39,16 +39,16 @@ void tree_sitter_sh_external_scanner_destroy(void *payload);
|
|||
|
||||
bool scan_bare_dollar(t_lexer *lexer)
|
||||
{
|
||||
while (me_isspace(lexer->data.lookahead) && lexer->data.lookahead != '\n'
|
||||
&& !lexer->data.eof((void *)lexer))
|
||||
lexer->data.advance((void *)lexer, true);
|
||||
if (lexer->data.lookahead == '$')
|
||||
while (me_isspace(lexer->funcs.lookahead) && lexer->funcs.lookahead != '\n'
|
||||
&& !lexer->funcs.eof((void *)lexer))
|
||||
lexer->funcs.advance((void *)lexer, true);
|
||||
if (lexer->funcs.lookahead == '$')
|
||||
{
|
||||
lexer->data.advance((void *)lexer, false);
|
||||
lexer->data.result_symbol = BARE_DOLLAR;
|
||||
lexer->data.mark_end((void *)lexer);
|
||||
return (me_isspace(lexer->data.lookahead)
|
||||
|| lexer->data.eof((void *)lexer) || lexer->data.lookahead == '\"');
|
||||
lexer->funcs.advance((void *)lexer, false);
|
||||
lexer->funcs.result_symbol = BARE_DOLLAR;
|
||||
lexer->funcs.mark_end((void *)lexer);
|
||||
return (me_isspace(lexer->funcs.lookahead)
|
||||
|| lexer->funcs.eof((void *)lexer) || lexer->funcs.lookahead == '\"');
|
||||
}
|
||||
return (false);
|
||||
}
|
||||
|
|
@ -62,17 +62,17 @@ bool scan_double_hash(t_scanner *scanner, t_lexer *lexer,
|
|||
if (valid_symbols[IMMEDIATE_DOUBLE_HASH]
|
||||
&& !(valid_symbols[ERROR_RECOVERY]))
|
||||
{
|
||||
if (lexer->data.lookahead == '#')
|
||||
if (lexer->funcs.lookahead == '#')
|
||||
{
|
||||
lexer->data.mark_end((void *)lexer);
|
||||
lexer->data.advance((void *)lexer, false);
|
||||
if (lexer->data.lookahead == '#')
|
||||
lexer->funcs.mark_end((void *)lexer);
|
||||
lexer->funcs.advance((void *)lexer, false);
|
||||
if (lexer->funcs.lookahead == '#')
|
||||
{
|
||||
lexer->data.advance((void *)lexer, false);
|
||||
if (lexer->data.lookahead != '}')
|
||||
lexer->funcs.advance((void *)lexer, false);
|
||||
if (lexer->funcs.lookahead != '}')
|
||||
{
|
||||
lexer->data.result_symbol = IMMEDIATE_DOUBLE_HASH;
|
||||
lexer->data.mark_end((void *)lexer);
|
||||
lexer->funcs.result_symbol = IMMEDIATE_DOUBLE_HASH;
|
||||
lexer->funcs.mark_end((void *)lexer);
|
||||
return (true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,15 +50,15 @@ bool scan_concat(t_scanner *scanner, t_lexer *lexer,
|
|||
(void)(scanner);
|
||||
(void)(lexer);
|
||||
(void)(valid_symbols);
|
||||
lexer->data.result_symbol = CONCAT;
|
||||
if (lexer->data.lookahead == '\\')
|
||||
lexer->funcs.result_symbol = CONCAT;
|
||||
if (lexer->funcs.lookahead == '\\')
|
||||
{
|
||||
lexer->data.mark_end((void *)lexer);
|
||||
lexer->data.advance((void *)lexer, false);
|
||||
if (lexer->data.lookahead == '"' || lexer->data.lookahead == '\''
|
||||
|| lexer->data.lookahead == '\\')
|
||||
lexer->funcs.mark_end((void *)lexer);
|
||||
lexer->funcs.advance((void *)lexer, false);
|
||||
if (lexer->funcs.lookahead == '"' || lexer->funcs.lookahead == '\''
|
||||
|| lexer->funcs.lookahead == '\\')
|
||||
return (true);
|
||||
if (lexer->data.eof((void *)lexer))
|
||||
if (lexer->funcs.eof((void *)lexer))
|
||||
return (false);
|
||||
}
|
||||
return (true);
|
||||
|
|
@ -77,76 +77,76 @@ bool scan_advance_words(t_scanner *scanner, t_lexer *lexer,
|
|||
(void)(valid_symbols);
|
||||
while (true)
|
||||
{
|
||||
if (lexer->data.lookahead == '\"')
|
||||
if (lexer->funcs.lookahead == '\"')
|
||||
return (false);
|
||||
if (lexer->data.lookahead == '$')
|
||||
if (lexer->funcs.lookahead == '$')
|
||||
{
|
||||
lexer->data.mark_end((void *)lexer);
|
||||
lexer->data.advance((void *)lexer, false);
|
||||
if (lexer->data.lookahead == '{' || lexer->data.lookahead == '('
|
||||
|| lexer->data.lookahead == '\''
|
||||
|| me_isalnum(lexer->data.lookahead))
|
||||
lexer->funcs.mark_end((void *)lexer);
|
||||
lexer->funcs.advance((void *)lexer, false);
|
||||
if (lexer->funcs.lookahead == '{' || lexer->funcs.lookahead == '('
|
||||
|| lexer->funcs.lookahead == '\''
|
||||
|| me_isalnum(lexer->funcs.lookahead))
|
||||
{
|
||||
lexer->data.result_symbol = EXPANSION_WORD;
|
||||
lexer->funcs.result_symbol = EXPANSION_WORD;
|
||||
return (advanced_once);
|
||||
}
|
||||
advanced_once = true;
|
||||
}
|
||||
if (lexer->data.lookahead == '}')
|
||||
if (lexer->funcs.lookahead == '}')
|
||||
{
|
||||
lexer->data.mark_end((void *)lexer);
|
||||
lexer->data.result_symbol = EXPANSION_WORD;
|
||||
lexer->funcs.mark_end((void *)lexer);
|
||||
lexer->funcs.result_symbol = EXPANSION_WORD;
|
||||
return (advanced_once || advance_once_space);
|
||||
}
|
||||
if (lexer->data.lookahead == '(' && !(advanced_once
|
||||
if (lexer->funcs.lookahead == '(' && !(advanced_once
|
||||
|| advance_once_space))
|
||||
{
|
||||
lexer->data.mark_end((void *)lexer);
|
||||
lexer->data.advance((void *)lexer, false);
|
||||
while (lexer->data.lookahead != ')'
|
||||
&& !lexer->data.eof((void *)lexer))
|
||||
lexer->funcs.mark_end((void *)lexer);
|
||||
lexer->funcs.advance((void *)lexer, false);
|
||||
while (lexer->funcs.lookahead != ')'
|
||||
&& !lexer->funcs.eof((void *)lexer))
|
||||
{
|
||||
if (lexer->data.lookahead == '$')
|
||||
if (lexer->funcs.lookahead == '$')
|
||||
{
|
||||
lexer->data.mark_end((void *)lexer);
|
||||
lexer->data.advance((void *)lexer, false);
|
||||
if (lexer->data.lookahead == '{'
|
||||
|| lexer->data.lookahead == '('
|
||||
|| lexer->data.lookahead == '\''
|
||||
|| me_isalnum(lexer->data.lookahead))
|
||||
return (lexer->data.result_symbol = EXPANSION_WORD,
|
||||
lexer->funcs.mark_end((void *)lexer);
|
||||
lexer->funcs.advance((void *)lexer, false);
|
||||
if (lexer->funcs.lookahead == '{'
|
||||
|| lexer->funcs.lookahead == '('
|
||||
|| lexer->funcs.lookahead == '\''
|
||||
|| me_isalnum(lexer->funcs.lookahead))
|
||||
return (lexer->funcs.result_symbol = EXPANSION_WORD,
|
||||
advanced_once);
|
||||
advanced_once = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
advanced_once = advanced_once
|
||||
|| !me_isspace(lexer->data.lookahead);
|
||||
|| !me_isspace(lexer->funcs.lookahead);
|
||||
advance_once_space = advance_once_space
|
||||
|| me_isspace(lexer->data.lookahead);
|
||||
lexer->data.advance((void *)lexer, false);
|
||||
|| me_isspace(lexer->funcs.lookahead);
|
||||
lexer->funcs.advance((void *)lexer, false);
|
||||
}
|
||||
}
|
||||
lexer->data.mark_end((void *)lexer);
|
||||
if (lexer->data.lookahead == ')')
|
||||
lexer->funcs.mark_end((void *)lexer);
|
||||
if (lexer->funcs.lookahead == ')')
|
||||
{
|
||||
advanced_once = true;
|
||||
lexer->data.advance((void *)lexer, false);
|
||||
lexer->data.mark_end((void *)lexer);
|
||||
if (lexer->data.lookahead == '}')
|
||||
lexer->funcs.advance((void *)lexer, false);
|
||||
lexer->funcs.mark_end((void *)lexer);
|
||||
if (lexer->funcs.lookahead == '}')
|
||||
return (false);
|
||||
}
|
||||
else
|
||||
return (false);
|
||||
}
|
||||
if (lexer->data.lookahead == '\'')
|
||||
if (lexer->funcs.lookahead == '\'')
|
||||
return (false);
|
||||
if (lexer->data.eof((void *)lexer))
|
||||
if (lexer->funcs.eof((void *)lexer))
|
||||
return (false);
|
||||
advanced_once = advanced_once || !me_isspace(lexer->data.lookahead);
|
||||
advanced_once = advanced_once || !me_isspace(lexer->funcs.lookahead);
|
||||
advance_once_space = advance_once_space
|
||||
|| me_isspace(lexer->data.lookahead);
|
||||
lexer->data.advance((void *)lexer, false);
|
||||
|| me_isspace(lexer->funcs.lookahead);
|
||||
lexer->funcs.advance((void *)lexer, false);
|
||||
}
|
||||
return (false);
|
||||
}
|
||||
|
|
@ -158,27 +158,27 @@ bool scan_literals(t_scanner *scanner, t_lexer *lexer,
|
|||
|
||||
while (true)
|
||||
{
|
||||
if ((lexer->data.lookahead == ' ' || lexer->data.lookahead == '\t'
|
||||
|| lexer->data.lookahead == '\r'
|
||||
|| (lexer->data.lookahead == '\n' && !valid_symbols[NEWLINE]))
|
||||
if ((lexer->funcs.lookahead == ' ' || lexer->funcs.lookahead == '\t'
|
||||
|| lexer->funcs.lookahead == '\r'
|
||||
|| (lexer->funcs.lookahead == '\n' && !valid_symbols[NEWLINE]))
|
||||
&& !valid_symbols[EXPANSION_WORD])
|
||||
lexer->data.advance((void *)lexer, true);
|
||||
else if (lexer->data.lookahead == '\\')
|
||||
lexer->funcs.advance((void *)lexer, true);
|
||||
else if (lexer->funcs.lookahead == '\\')
|
||||
{
|
||||
lexer->data.advance((void *)lexer, true);
|
||||
if (lexer->data.eof((void *)lexer))
|
||||
lexer->funcs.advance((void *)lexer, true);
|
||||
if (lexer->funcs.eof((void *)lexer))
|
||||
{
|
||||
lexer->data.mark_end((void *)lexer);
|
||||
lexer->data.result_symbol = VARIABLE_NAME;
|
||||
lexer->funcs.mark_end((void *)lexer);
|
||||
lexer->funcs.result_symbol = VARIABLE_NAME;
|
||||
return (true);
|
||||
}
|
||||
if (lexer->data.lookahead == '\r')
|
||||
lexer->data.advance((void *)lexer, true);
|
||||
if (lexer->data.lookahead == '\n')
|
||||
lexer->data.advance((void *)lexer, true);
|
||||
if (lexer->funcs.lookahead == '\r')
|
||||
lexer->funcs.advance((void *)lexer, true);
|
||||
if (lexer->funcs.lookahead == '\n')
|
||||
lexer->funcs.advance((void *)lexer, true);
|
||||
else
|
||||
{
|
||||
if (lexer->data.lookahead == '\\'
|
||||
if (lexer->funcs.lookahead == '\\'
|
||||
&& valid_symbols[EXPANSION_WORD])
|
||||
return (scan_advance_words(scanner, lexer, valid_symbols));
|
||||
return (false);
|
||||
|
|
@ -187,36 +187,36 @@ bool scan_literals(t_scanner *scanner, t_lexer *lexer,
|
|||
else
|
||||
break ;
|
||||
}
|
||||
if (!valid_symbols[EXPANSION_WORD] && (lexer->data.lookahead == '*'
|
||||
|| lexer->data.lookahead == '@' || lexer->data.lookahead == '?'
|
||||
|| lexer->data.lookahead == '-' || lexer->data.lookahead == '0'
|
||||
|| lexer->data.lookahead == '_'))
|
||||
if (!valid_symbols[EXPANSION_WORD] && (lexer->funcs.lookahead == '*'
|
||||
|| lexer->funcs.lookahead == '@' || lexer->funcs.lookahead == '?'
|
||||
|| lexer->funcs.lookahead == '-' || lexer->funcs.lookahead == '0'
|
||||
|| lexer->funcs.lookahead == '_'))
|
||||
{
|
||||
lexer->data.mark_end((void *)lexer);
|
||||
lexer->data.advance((void *)lexer, false);
|
||||
if (lexer->data.lookahead == '=' || lexer->data.lookahead == '['
|
||||
|| lexer->data.lookahead == ':' || lexer->data.lookahead == '-'
|
||||
|| lexer->data.lookahead == '%' || lexer->data.lookahead == '#'
|
||||
|| lexer->data.lookahead == '/')
|
||||
lexer->funcs.mark_end((void *)lexer);
|
||||
lexer->funcs.advance((void *)lexer, false);
|
||||
if (lexer->funcs.lookahead == '=' || lexer->funcs.lookahead == '['
|
||||
|| lexer->funcs.lookahead == ':' || lexer->funcs.lookahead == '-'
|
||||
|| lexer->funcs.lookahead == '%' || lexer->funcs.lookahead == '#'
|
||||
|| lexer->funcs.lookahead == '/')
|
||||
return (false);
|
||||
if (valid_symbols[EXTGLOB_PATTERN] && me_isspace(lexer->data.lookahead))
|
||||
if (valid_symbols[EXTGLOB_PATTERN] && me_isspace(lexer->funcs.lookahead))
|
||||
{
|
||||
lexer->data.mark_end((void *)lexer);
|
||||
lexer->data.result_symbol = EXTGLOB_PATTERN;
|
||||
lexer->funcs.mark_end((void *)lexer);
|
||||
lexer->funcs.result_symbol = EXTGLOB_PATTERN;
|
||||
return (true);
|
||||
}
|
||||
}
|
||||
is_number = true;
|
||||
if (me_isdigit(lexer->data.lookahead))
|
||||
lexer->data.advance((void *)lexer, false);
|
||||
else if (me_isalpha(lexer->data.lookahead) || lexer->data.lookahead == '_')
|
||||
if (me_isdigit(lexer->funcs.lookahead))
|
||||
lexer->funcs.advance((void *)lexer, false);
|
||||
else if (me_isalpha(lexer->funcs.lookahead) || lexer->funcs.lookahead == '_')
|
||||
{
|
||||
is_number = false;
|
||||
lexer->data.advance((void *)lexer, false);
|
||||
lexer->funcs.advance((void *)lexer, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (lexer->data.lookahead == '{')
|
||||
if (lexer->funcs.lookahead == '{')
|
||||
return (false);
|
||||
if (valid_symbols[EXPANSION_WORD])
|
||||
return (scan_advance_words(scanner, lexer, valid_symbols));
|
||||
|
|
@ -224,48 +224,48 @@ bool scan_literals(t_scanner *scanner, t_lexer *lexer,
|
|||
}
|
||||
while (true)
|
||||
{
|
||||
if (me_isdigit(lexer->data.lookahead))
|
||||
lexer->data.advance((void *)lexer, false);
|
||||
else if (me_isalpha(lexer->data.lookahead)
|
||||
|| lexer->data.lookahead == '_')
|
||||
if (me_isdigit(lexer->funcs.lookahead))
|
||||
lexer->funcs.advance((void *)lexer, false);
|
||||
else if (me_isalpha(lexer->funcs.lookahead)
|
||||
|| lexer->funcs.lookahead == '_')
|
||||
{
|
||||
is_number = false;
|
||||
lexer->data.advance((void *)lexer, false);
|
||||
lexer->funcs.advance((void *)lexer, false);
|
||||
}
|
||||
else
|
||||
break ;
|
||||
}
|
||||
if (is_number && valid_symbols[FILE_DESCRIPTOR]
|
||||
&& (lexer->data.lookahead == '>' || lexer->data.lookahead == '<'))
|
||||
return (lexer->data.result_symbol = FILE_DESCRIPTOR, true);
|
||||
&& (lexer->funcs.lookahead == '>' || lexer->funcs.lookahead == '<'))
|
||||
return (lexer->funcs.result_symbol = FILE_DESCRIPTOR, true);
|
||||
if (valid_symbols[VARIABLE_NAME])
|
||||
{
|
||||
if (lexer->data.lookahead == '+')
|
||||
if (lexer->funcs.lookahead == '+')
|
||||
{
|
||||
lexer->data.mark_end((void *)lexer);
|
||||
lexer->data.advance((void *)lexer, false);
|
||||
if (lexer->data.lookahead == '=' || lexer->data.lookahead == ':')
|
||||
return (lexer->data.result_symbol = VARIABLE_NAME, true);
|
||||
lexer->funcs.mark_end((void *)lexer);
|
||||
lexer->funcs.advance((void *)lexer, false);
|
||||
if (lexer->funcs.lookahead == '=' || lexer->funcs.lookahead == ':')
|
||||
return (lexer->funcs.result_symbol = VARIABLE_NAME, true);
|
||||
return (false);
|
||||
}
|
||||
if (lexer->data.lookahead == '/')
|
||||
if (lexer->funcs.lookahead == '/')
|
||||
return (false);
|
||||
if (lexer->data.lookahead == '=' || lexer->data.lookahead == '['
|
||||
|| (lexer->data.lookahead == ':' && !valid_symbols[OPENING_PAREN])
|
||||
|| lexer->data.lookahead == '%' || (lexer->data.lookahead == '#'
|
||||
&& !is_number) || lexer->data.lookahead == '@'
|
||||
|| (lexer->data.lookahead == '-'))
|
||||
if (lexer->funcs.lookahead == '=' || lexer->funcs.lookahead == '['
|
||||
|| (lexer->funcs.lookahead == ':' && !valid_symbols[OPENING_PAREN])
|
||||
|| lexer->funcs.lookahead == '%' || (lexer->funcs.lookahead == '#'
|
||||
&& !is_number) || lexer->funcs.lookahead == '@'
|
||||
|| (lexer->funcs.lookahead == '-'))
|
||||
{
|
||||
lexer->data.mark_end((void *)lexer);
|
||||
lexer->data.result_symbol = VARIABLE_NAME;
|
||||
lexer->funcs.mark_end((void *)lexer);
|
||||
lexer->funcs.result_symbol = VARIABLE_NAME;
|
||||
return (true);
|
||||
}
|
||||
if (lexer->data.lookahead == '?')
|
||||
if (lexer->funcs.lookahead == '?')
|
||||
{
|
||||
lexer->data.mark_end((void *)lexer);
|
||||
lexer->data.advance((void *)lexer, false);
|
||||
lexer->data.result_symbol = VARIABLE_NAME;
|
||||
return (me_isalpha(lexer->data.lookahead));
|
||||
lexer->funcs.mark_end((void *)lexer);
|
||||
lexer->funcs.advance((void *)lexer, false);
|
||||
lexer->funcs.result_symbol = VARIABLE_NAME;
|
||||
return (me_isalpha(lexer->funcs.lookahead));
|
||||
}
|
||||
}
|
||||
return (false);
|
||||
|
|
@ -274,19 +274,19 @@ bool scan_literals(t_scanner *scanner, t_lexer *lexer,
|
|||
bool scan(t_scanner *scanner, t_lexer *lexer, const bool *valid_symbols)
|
||||
{
|
||||
if (valid_symbols[CONCAT] && !(valid_symbols[ERROR_RECOVERY])
|
||||
&& (!(lexer->data.lookahead == 0 || me_isspace(lexer->data.lookahead)
|
||||
|| lexer->data.lookahead == '>' || lexer->data.lookahead == '<'
|
||||
|| lexer->data.lookahead == ')' || lexer->data.lookahead == '('
|
||||
|| lexer->data.lookahead == ';' || lexer->data.lookahead == '&'
|
||||
|| lexer->data.lookahead == '|' || lexer->data.lookahead == '{'
|
||||
|| lexer->data.lookahead == '}')))
|
||||
&& (!(lexer->funcs.lookahead == 0 || me_isspace(lexer->funcs.lookahead)
|
||||
|| lexer->funcs.lookahead == '>' || lexer->funcs.lookahead == '<'
|
||||
|| lexer->funcs.lookahead == ')' || lexer->funcs.lookahead == '('
|
||||
|| lexer->funcs.lookahead == ';' || lexer->funcs.lookahead == '&'
|
||||
|| lexer->funcs.lookahead == '|' || lexer->funcs.lookahead == '{'
|
||||
|| lexer->funcs.lookahead == '}')))
|
||||
return (scan_concat(scanner, lexer, valid_symbols));
|
||||
if (scan_double_hash(scanner, lexer, valid_symbols))
|
||||
return (true);
|
||||
if (valid_symbols[EMPTY_VALUE] && (me_isspace(lexer->data.lookahead)
|
||||
|| lexer->data.eof((void *)lexer) || lexer->data.lookahead == ';'
|
||||
|| lexer->data.lookahead == '&'))
|
||||
return (lexer->data.result_symbol = EMPTY_VALUE, true);
|
||||
if (valid_symbols[EMPTY_VALUE] && (me_isspace(lexer->funcs.lookahead)
|
||||
|| lexer->funcs.eof((void *)lexer) || lexer->funcs.lookahead == ';'
|
||||
|| lexer->funcs.lookahead == '&'))
|
||||
return (lexer->funcs.result_symbol = EMPTY_VALUE, true);
|
||||
if ((valid_symbols[VARIABLE_NAME] || valid_symbols[FILE_DESCRIPTOR])
|
||||
&& !(valid_symbols[ERROR_RECOVERY]))
|
||||
return (scan_literals(scanner, lexer, valid_symbols));
|
||||
|
|
|
|||
|
|
@ -45,29 +45,29 @@ bool advance_word(t_lexer *lexer, t_string *unquoted_word)
|
|||
|
||||
empty = true;
|
||||
quote = 0;
|
||||
if (lexer->data.lookahead == '\'' || lexer->data.lookahead == '"')
|
||||
if (lexer->funcs.lookahead == '\'' || lexer->funcs.lookahead == '"')
|
||||
{
|
||||
quote = lexer->data.lookahead;
|
||||
lexer->data.advance((void *)lexer, false);
|
||||
quote = lexer->funcs.lookahead;
|
||||
lexer->funcs.advance((void *)lexer, false);
|
||||
}
|
||||
while (lexer->data.lookahead && !((quote && (lexer->data.lookahead == quote
|
||||
|| lexer->data.lookahead == '\r'
|
||||
|| lexer->data.lookahead == '\n')) || (!quote
|
||||
&& me_isspace(lexer->data.lookahead))))
|
||||
while (lexer->funcs.lookahead && !((quote && (lexer->funcs.lookahead == quote
|
||||
|| lexer->funcs.lookahead == '\r'
|
||||
|| lexer->funcs.lookahead == '\n')) || (!quote
|
||||
&& me_isspace(lexer->funcs.lookahead))))
|
||||
{
|
||||
if (lexer->data.lookahead == '\\')
|
||||
if (lexer->funcs.lookahead == '\\')
|
||||
{
|
||||
lexer->data.advance((void *)lexer, false);
|
||||
if (!lexer->data.lookahead)
|
||||
lexer->funcs.advance((void *)lexer, false);
|
||||
if (!lexer->funcs.lookahead)
|
||||
return (false);
|
||||
}
|
||||
empty = false;
|
||||
string_push_char(unquoted_word, lexer->data.lookahead);
|
||||
lexer->data.advance((void *)lexer, false);
|
||||
string_push_char(unquoted_word, lexer->funcs.lookahead);
|
||||
lexer->funcs.advance((void *)lexer, false);
|
||||
}
|
||||
string_push_char(unquoted_word, '\0');
|
||||
if (quote && lexer->data.lookahead == quote)
|
||||
lexer->data.advance((void *)lexer, false);
|
||||
if (quote && lexer->funcs.lookahead == quote)
|
||||
lexer->funcs.advance((void *)lexer, false);
|
||||
return (!empty);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/stack.h"
|
||||
#include "parser/inner/stack.h"
|
||||
#include "parser/inner/stack_inner.h"
|
||||
#include "parser/inner/stack_inner.h"
|
||||
|
||||
// In general,
|
||||
// we preserve ambiguities until they are removed from the stack
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/stack.h"
|
||||
#include "parser/inner/stack.h"
|
||||
#include "parser/inner/stack_inner.h"
|
||||
#include "parser/inner/stack_inner.h"
|
||||
|
||||
bool ts_stack_is_active(const t_stack *self, t_stack_version version)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/stack.h"
|
||||
#include "parser/inner/stack.h"
|
||||
#include "parser/inner/stack_inner.h"
|
||||
#include "parser/inner/stack_inner.h"
|
||||
|
||||
t_u32 ts_stack_error_cost(const t_stack *self, t_stack_version version)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/stack.h"
|
||||
#include "parser/inner/stack.h"
|
||||
#include "parser/inner/stack_inner.h"
|
||||
#include "parser/inner/stack_inner.h"
|
||||
|
||||
bool stack__subtree_is_equivalent(t_subtree left, t_subtree right)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,20 +10,20 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/stack.h"
|
||||
#include "parser/inner/stack.h"
|
||||
#include "parser/inner/stack_inner.h"
|
||||
#include "parser/inner/stack_inner.h"
|
||||
|
||||
t_u32 ts_stack_version_count(const t_stack *self)
|
||||
{
|
||||
return (self->heads.size);
|
||||
}
|
||||
|
||||
TSStateId ts_stack_state(const t_stack *self, t_stack_version version)
|
||||
t_state_id ts_stack_state(const t_stack *self, t_stack_version version)
|
||||
{
|
||||
return (array_get(&self->heads, version)->node->state);
|
||||
}
|
||||
|
||||
Length ts_stack_position(const t_stack *self, t_stack_version version)
|
||||
t_length ts_stack_position(const t_stack *self, t_stack_version version)
|
||||
{
|
||||
return (array_get(&self->heads, version)->node->position);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@
|
|||
/* ************************************************************************** */
|
||||
|
||||
#include "me/vec/vec_subtree.h"
|
||||
#include "parser/inner/stack.h"
|
||||
#include "parser/stack.h"
|
||||
#include "parser/inner/stack_inner.h"
|
||||
#include "parser/inner/stack_inner.h"
|
||||
|
||||
t_stack_slice_array stack__iter(t_stack *self, t_stack_version version,
|
||||
t_stack_callback callback, void *payload, int goal_subtree_count)
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/inner/stack.h"
|
||||
#include "parser/stack.h"
|
||||
#include "parser/inner/stack_inner.h"
|
||||
#include "parser/inner/stack_inner.h"
|
||||
|
||||
t_stack *ts_stack_new(void)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,22 +6,21 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/31 16:50:04 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/08/31 17:00:34 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/19 14:44:37 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/inner/stack.h"
|
||||
#include "parser/inner/stack_inner.h"
|
||||
#include "parser/language.h"
|
||||
|
||||
void ts_stack_push(t_stack *self, t_stack_version version, t_subtree subtree,
|
||||
bool pending, TSStateId state)
|
||||
void ts_stack_push(t_stack *self, struct s_stack_push_arg args)
|
||||
{
|
||||
t_stack_head *head;
|
||||
t_stack_node *new_node;
|
||||
|
||||
head = array_get(&self->heads, version);
|
||||
new_node = stack_node_new(head->node, subtree, pending, state);
|
||||
if (!subtree)
|
||||
head = array_get(&self->heads, args.version);
|
||||
new_node = stack_node_new(head->node, args.subtree, args.pending, args.state);
|
||||
if (!args.subtree)
|
||||
head->node_count_at_last_error = new_node->node_count;
|
||||
head->node = new_node;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@
|
|||
/* ************************************************************************** */
|
||||
|
||||
#include "me/types.h"
|
||||
#include "parser/stack.h"
|
||||
#include "parser/inner/stack.h"
|
||||
#include "parser/inner/stack_inner.h"
|
||||
#include "parser/inner/stack_inner.h"
|
||||
|
||||
bool ts_stack_merge(t_stack *self, t_stack_version version1,
|
||||
t_stack_version version2)
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/stack.h"
|
||||
#include "parser/inner/stack.h"
|
||||
#include "parser/inner/stack_inner.h"
|
||||
#include "parser/inner/stack_inner.h"
|
||||
|
||||
t_stack_action pop_error_callback(void *payload,
|
||||
const t_stack_iterator *iterator)
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/inner/stack.h"
|
||||
#include "parser/inner/stack_inner.h"
|
||||
#include "parser/language.h"
|
||||
#include "parser/stack.h"
|
||||
#include "parser/inner/stack_inner.h"
|
||||
|
||||
void stack_node_retain(t_stack_node *self)
|
||||
{
|
||||
|
|
@ -83,7 +83,7 @@ t_u32 stack__subtree_node_count(t_subtree subtree)
|
|||
}
|
||||
|
||||
t_stack_node *stack_node_new(t_stack_node *previous_node,
|
||||
t_subtree subtree, bool is_pending, TSStateId state)
|
||||
t_subtree subtree, bool is_pending, t_state_id state)
|
||||
{
|
||||
t_stack_node *node;
|
||||
|
||||
|
|
|
|||
|
|
@ -10,14 +10,14 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/stack.h"
|
||||
#include "parser/inner/stack.h"
|
||||
#include "parser/inner/stack_inner.h"
|
||||
#include "parser/inner/stack_inner.h"
|
||||
|
||||
t_stack_action summarize_stack_callback(void *payload,
|
||||
const t_stack_iterator *iterator)
|
||||
{
|
||||
t_summarize_stack_session *session;
|
||||
TSStateId state;
|
||||
t_state_id state;
|
||||
t_u32 depth;
|
||||
t_stack_summary_entry entry;
|
||||
t_usize i;
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/stack.h"
|
||||
#include "parser/inner/stack.h"
|
||||
#include "parser/inner/stack_inner.h"
|
||||
#include "parser/inner/stack_inner.h"
|
||||
|
||||
void ts_stack_remove_version(t_stack *self, t_stack_version version)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,10 +13,10 @@
|
|||
#include "parser/language.h"
|
||||
#include "parser/subtree.h"
|
||||
|
||||
void ts_subtree_set_symbol(t_subtree *self, TSSymbol symbol,
|
||||
const TSLanguage *language)
|
||||
void ts_subtree_set_symbol(t_subtree *self, t_symbol symbol,
|
||||
const t_language *language)
|
||||
{
|
||||
TSSymbolMetadata metadata;
|
||||
t_symbol_metadata metadata;
|
||||
|
||||
metadata = ts_language_symbol_metadata(language, symbol);
|
||||
(*self)->symbol = symbol;
|
||||
|
|
|
|||
|
|
@ -16,10 +16,10 @@
|
|||
// Create a new parent node with the given children.
|
||||
//
|
||||
// This takes ownership of the children array.
|
||||
t_subtree ts_subtree_new_node(TSSymbol symbol, t_vec_subtree *children, \
|
||||
t_u32 production_id, const TSLanguage *language)
|
||||
t_subtree ts_subtree_new_node(t_symbol symbol, t_vec_subtree *children, \
|
||||
t_u32 production_id, const t_language *language)
|
||||
{
|
||||
TSSymbolMetadata metadata;
|
||||
t_symbol_metadata metadata;
|
||||
bool fragile;
|
||||
t_subtree data;
|
||||
|
||||
|
|
@ -44,7 +44,7 @@ t_subtree ts_subtree_new_node(TSSymbol symbol, t_vec_subtree *children, \
|
|||
// This node is treated as 'extra'. Its children are prevented from having
|
||||
// having any effect on the parse state.
|
||||
t_subtree ts_subtree_new_error_node(t_vec_subtree *children, bool extra,
|
||||
const TSLanguage *language)
|
||||
const t_language *language)
|
||||
{
|
||||
t_subtree result;
|
||||
|
||||
|
|
@ -57,8 +57,8 @@ t_subtree ts_subtree_new_error_node(t_vec_subtree *children, bool extra,
|
|||
//
|
||||
// This node is treated as 'extra'. Its children are prevented from having
|
||||
// having any effect on the parse state.
|
||||
t_subtree ts_subtree_new_missing_leaf(TSSymbol symbol, Length padding,
|
||||
t_u32 lookahead_bytes, const TSLanguage *language)
|
||||
t_subtree ts_subtree_new_missing_leaf(t_symbol symbol, t_length padding,
|
||||
t_u32 lookahead_bytes, const t_language *language)
|
||||
{
|
||||
t_subtree result;
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ t_subtree ts_subtree_new_missing_leaf(TSSymbol symbol, Length padding,
|
|||
|
||||
t_subtree ts_subtree_new_leaf(t_st_newleaf_args args)
|
||||
{
|
||||
TSSymbolMetadata metadata;
|
||||
t_symbol_metadata metadata;
|
||||
bool extra;
|
||||
t_subtree_data *data;
|
||||
|
||||
|
|
|
|||
|
|
@ -14,13 +14,13 @@
|
|||
#include "parser/subtree.h"
|
||||
|
||||
void _summarize_loop_inner1(t_subtree self, \
|
||||
const TSLanguage *language, struct s_summarize_state *s);
|
||||
const t_language *language, struct s_summarize_state *s);
|
||||
void _summarize_loop_inner2(t_subtree self, \
|
||||
const TSLanguage *language, struct s_summarize_state *s);
|
||||
const t_language *language, struct s_summarize_state *s);
|
||||
void _summarize_loop_inner3(t_subtree self, \
|
||||
const TSLanguage *language, struct s_summarize_state *s);
|
||||
const t_language *language, struct s_summarize_state *s);
|
||||
void _summarize_loop_inner4(t_subtree self, \
|
||||
const TSLanguage *language, struct s_summarize_state *s);
|
||||
const t_language *language, struct s_summarize_state *s);
|
||||
|
||||
void _sumarize_end(t_subtree self, t_subtree *children)
|
||||
{
|
||||
|
|
@ -50,7 +50,7 @@ void _sumarize_end(t_subtree self, t_subtree *children)
|
|||
}
|
||||
|
||||
struct s_summarize_state _init_sumnarize_state(t_subtree self,
|
||||
const TSLanguage *language)
|
||||
const t_language *language)
|
||||
{
|
||||
struct s_summarize_state s;
|
||||
|
||||
|
|
@ -75,7 +75,7 @@ struct s_summarize_state _init_sumnarize_state(t_subtree self,
|
|||
|
||||
// Assign all of the node's properties that depend on its children.
|
||||
void ts_subtree_summarize_children(t_subtree self,
|
||||
const TSLanguage *language)
|
||||
const t_language *language)
|
||||
{
|
||||
struct s_summarize_state s;
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
#include "parser/subtree.h"
|
||||
|
||||
void _summarize_loop_inner1(t_subtree self,
|
||||
const TSLanguage *language, struct s_summarize_state *s)
|
||||
const t_language *language, struct s_summarize_state *s)
|
||||
{
|
||||
(void)(language);
|
||||
s->child = s->children[s->i];
|
||||
|
|
@ -39,7 +39,7 @@ void _summarize_loop_inner1(t_subtree self,
|
|||
}
|
||||
|
||||
void _summarize_loop_inner2(t_subtree self,
|
||||
const TSLanguage *language, struct s_summarize_state *s)
|
||||
const t_language *language, struct s_summarize_state *s)
|
||||
{
|
||||
(void)(language);
|
||||
if (self->symbol == ts_builtin_sym_error
|
||||
|
|
@ -61,7 +61,7 @@ void _summarize_loop_inner2(t_subtree self,
|
|||
}
|
||||
|
||||
void _summarize_loop_inner3(t_subtree self,
|
||||
const TSLanguage *language, struct s_summarize_state *s)
|
||||
const t_language *language, struct s_summarize_state *s)
|
||||
{
|
||||
(void)(language);
|
||||
if (s->alias_sequence && s->alias_sequence[s->structural_index] != 0
|
||||
|
|
@ -88,7 +88,7 @@ void _summarize_loop_inner3(t_subtree self,
|
|||
}
|
||||
|
||||
void _summarize_loop_inner4(t_subtree self,
|
||||
const TSLanguage *language, struct s_summarize_state *s)
|
||||
const t_language *language, struct s_summarize_state *s)
|
||||
{
|
||||
(void)(language);
|
||||
if (ts_subtree_has_external_tokens(s->child))
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@
|
|||
#include "parser/subtree.h"
|
||||
#include "parser/tree.h"
|
||||
|
||||
TSTree *ts_tree_new(t_subtree root, const TSLanguage *language)
|
||||
t_tree *ts_tree_new(t_subtree root, const t_language *language)
|
||||
{
|
||||
TSTree *result;
|
||||
t_tree *result;
|
||||
|
||||
result = mem_alloc(sizeof(*result));
|
||||
result->root = root;
|
||||
|
|
@ -24,13 +24,13 @@ TSTree *ts_tree_new(t_subtree root, const TSLanguage *language)
|
|||
return (result);
|
||||
}
|
||||
|
||||
TSTree *ts_tree_copy(const TSTree *self)
|
||||
t_tree *ts_tree_copy(const t_tree *self)
|
||||
{
|
||||
(self->root->ref_count++);
|
||||
return (ts_tree_new(self->root, self->language));
|
||||
}
|
||||
|
||||
void ts_tree_delete(TSTree *self)
|
||||
void ts_tree_delete(t_tree *self)
|
||||
{
|
||||
if (self == NULL)
|
||||
return ;
|
||||
|
|
|
|||
|
|
@ -14,22 +14,22 @@
|
|||
#include "parser/subtree.h"
|
||||
#include "parser/tree.h"
|
||||
|
||||
TSNode ts_tree_root_node(const TSTree *self)
|
||||
t_node ts_tree_root_node(const t_tree *self)
|
||||
{
|
||||
return (ts_node_new(self, &self->root, ts_subtree_padding(self->root), 0));
|
||||
}
|
||||
|
||||
TSNode ts_tree_root_node_with_offset(const TSTree *self, t_u32 offset_bytes,
|
||||
TSPoint offset_extent)
|
||||
t_node ts_tree_root_node_with_offset(const t_tree *self, t_u32 offset_bytes,
|
||||
t_point offset_extent)
|
||||
{
|
||||
Length offset;
|
||||
t_length offset;
|
||||
|
||||
offset = (Length){offset_bytes, offset_extent};
|
||||
offset = (t_length){offset_bytes, offset_extent};
|
||||
return (ts_node_new(self, &self->root, length_add(offset,
|
||||
ts_subtree_padding(self->root)), 0));
|
||||
}
|
||||
|
||||
const TSLanguage *ts_tree_language(const TSTree *self)
|
||||
const t_language *ts_tree_language(const t_tree *self)
|
||||
{
|
||||
return (self->language);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue