diff --git a/Minishell.mk b/Minishell.mk index 894991ff..6df733d6 100644 --- a/Minishell.mk +++ b/Minishell.mk @@ -6,7 +6,7 @@ # By: maiboyer +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2024/04/28 17:28:30 by maiboyer #+# #+# # -# Updated: 2024/08/17 23:30:58 by maiboyer ### ########.fr # +# Updated: 2024/08/19 14:31:41 by maiboyer ### ########.fr # # # # **************************************************************************** # @@ -82,7 +82,9 @@ $(NAME): $(LIBS_FILES) @echo -e '$(GREY) Linking \t$(END)$(GOLD)$(NAME)$(END)' @$(CC) $(CFLAGS) -o $(NAME) -L$(BUILD_DIR) $(call link_group,$(LIBS_FLAGS)) -lib$(ANAME).a: $(OBJ) +lib$(ANAME).a: $(BUILD_DIR)/lib$(ANAME).a + +$(BUILD_DIR)/lib$(ANAME).a: $(OBJ) @ar rcs $(BUILD_DIR)/lib$(ANAME).a $(OBJ) diff --git a/parser/include/parser/api.h b/parser/include/parser/api.h index 93805047..e565ab7b 100644 --- a/parser/include/parser/api.h +++ b/parser/include/parser/api.h @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/22 13:54:54 by maiboyer #+# #+# */ -/* Updated: 2024/07/22 13:55:02 by maiboyer ### ########.fr */ +/* Updated: 2024/08/19 14:21:45 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -285,7 +285,7 @@ const TSRange *ts_parser_included_ranges(const TSParser *self, t_u32 *count); * [`encoding`]: TSInput::encoding * [`bytes_read`]: TSInput::read */ -TSTree *ts_parser_parse(TSParser *self, const TSTree *old_tree, TSInput input); +TSTree *ts_parser_parse(TSParser *self, TSInput input); /** * Use the parser to parse some source code stored in one contiguous buffer. @@ -293,7 +293,7 @@ TSTree *ts_parser_parse(TSParser *self, const TSTree *old_tree, TSInput input); * above. The second two parameters indicate the location of the buffer and its * length in bytes. */ -TSTree *ts_parser_parse_string(TSParser *self, const TSTree *old_tree, t_const_str string, t_u32 length); +TSTree *ts_parser_parse_string(TSParser *self, t_const_str string, t_u32 length); /** * Use the parser to parse some source code stored in one contiguous buffer with @@ -301,7 +301,7 @@ TSTree *ts_parser_parse_string(TSParser *self, const TSTree *old_tree, t_const_s * [`ts_parser_parse_string`] method above. The final parameter indicates whether * the text is encoded as UTF8 or UTF16. */ -TSTree *ts_parser_parse_string_encoding(TSParser *self, const TSTree *old_tree, t_const_str string, t_u32 length, TSInputEncoding encoding); +TSTree *ts_parser_parse_string_encoding(TSParser *self, t_const_str string, t_u32 length, TSInputEncoding encoding); /** * Instruct the parser to start the next parse from the beginning. diff --git a/parser/src/input.c b/parser/src/input.c index 6b69169f..d9c55c35 100644 --- a/parser/src/input.c +++ b/parser/src/input.c @@ -3,8 +3,9 @@ t_u32 ts_decode_ascii(const t_u8 *string, t_u32 length, t_i32 *code_point) { - (void)(length); + if (string == NULL || length == 0 || code_point == 0) + return (0); *code_point = 0; *(t_u8 *)code_point = *string; return (1); -} \ No newline at end of file +} diff --git a/parser/src/language.c b/parser/src/language.c index 2d6c65d3..efe9f91a 100644 --- a/parser/src/language.c +++ b/parser/src/language.c @@ -1,7 +1,7 @@ #include "parser/language.h" +#include "me/types.h" #include "parser/api.h" #include "parser/parser.h" -#include "me/types.h" #include #include @@ -216,31 +216,8 @@ bool ts_language_has_reduce_action(const TSLanguage *self, TSStateId state, TSSy // the given symbol. t_u16 ts_language_lookup(const TSLanguage *self, TSStateId state, TSSymbol symbol) { - t_u32 index; - const t_u16 *data; - t_u16 group_count; - t_u16 section_value; - t_u16 symbol_count; - t_u32 i; - t_u32 j; - if (state >= self->large_state_count) - { - index = self->small_parse_table_map[state - self->large_state_count]; - data = &self->small_parse_table[index]; - group_count = *(data++); - i = 0; - while (i++ < group_count) - { - section_value = *(data++); - symbol_count = *(data++); - j = 0; - while (j++ < symbol_count) - if (*(data++) == symbol) - return (section_value); - } - return (0); - } + return (me_abort("we got a small parse table, which isn't supported"), -1); else return (self->parse_table[state * self->symbol_count + symbol]); } @@ -308,4 +285,4 @@ void ts_language_aliases_for_symbol(const TSLanguage *self, TSSymbol original_sy } idx += count; } -} \ No newline at end of file +} diff --git a/parser/src/parser.c b/parser/src/parser.c index 620d7bdd..a6bde1f9 100644 --- a/parser/src/parser.c +++ b/parser/src/parser.c @@ -27,25 +27,16 @@ static const t_u32 MAX_VERSION_COUNT_OVERFLOW = 4; static const t_u32 MAX_SUMMARY_DEPTH = 1; static const t_u32 MAX_COST_DIFFERENCE = 16 * ERROR_COST_PER_SKIPPED_TREE; -typedef struct TokenCache -{ - Subtree token; - Subtree last_external_token; - t_u32 byte_index; -} TokenCache; - struct TSParser { - Lexer lexer; - Stack *stack; - /* SubtreePool tree_pool; */ + Lexer lexer; + Stack *stack; const TSLanguage *language; ReduceActionSet reduce_actions; Subtree finished_tree; SubtreeArray trailing_extras; SubtreeArray trailing_extras2; SubtreeArray scratch_trees; - TokenCache token_cache; void *external_scanner_payload; t_u32 accept_count; t_u32 operation_count; @@ -1506,7 +1497,6 @@ TSParser *ts_parser_new(void) self->has_scanner_error = false; self->external_scanner_payload = NULL; self->operation_count = 0; - self->old_tree = NULL_SUBTREE; self->included_range_difference_index = 0; return self; } @@ -1522,11 +1512,6 @@ void ts_parser_delete(TSParser *self) { array_delete(&self->reduce_actions); } - if (self->old_tree.ptr) - { - ts_subtree_release(/*&self->tree_pool,*/ self->old_tree); - self->old_tree = NULL_SUBTREE; - } ts_lexer_delete(&self->lexer); /* ts_subtree_pool_delete(&self->tree_pool); */ array_delete(&self->trailing_extras); @@ -1559,12 +1544,6 @@ bool ts_parser_set_language(TSParser *self, const TSLanguage *language) void ts_parser_reset(TSParser *self) { ts_parser__external_scanner_destroy(self); - if (self->old_tree.ptr) - { - ts_subtree_release(/*&self->tree_pool,*/ self->old_tree); - self->old_tree = NULL_SUBTREE; - } - ts_lexer_reset(&self->lexer, length_zero()); ts_stack_clear(self->stack); if (self->finished_tree.ptr) @@ -1576,9 +1555,8 @@ void ts_parser_reset(TSParser *self) self->has_scanner_error = false; } -TSTree *ts_parser_parse(TSParser *self, const TSTree *old_tree, TSInput input) +TSTree *ts_parser_parse(TSParser *self, TSInput input) { - (void)(old_tree); TSTree *result = NULL; if (!self->language || !input.read) return NULL; @@ -1660,20 +1638,19 @@ exit: return result; } -TSTree *ts_parser_parse_string(TSParser *self, const TSTree *old_tree, t_const_str string, t_u32 length) +TSTree *ts_parser_parse_string(TSParser *self, t_const_str string, t_u32 length) { - return ts_parser_parse_string_encoding(self, old_tree, string, length, TSInputEncodingUTF8); + return ts_parser_parse_string_encoding(self, string, length, TSInputEncodingUTF8); } -TSTree *ts_parser_parse_string_encoding(TSParser *self, const TSTree *old_tree, t_const_str string, t_u32 length, TSInputEncoding encoding) +TSTree *ts_parser_parse_string_encoding(TSParser *self, t_const_str string, t_u32 length, TSInputEncoding encoding) { TSStringInput input = {(const t_u8 *)string, length}; - return ts_parser_parse(self, old_tree, - (TSInput){ - &input, - ts_string_input_read, - encoding, - }); + return ts_parser_parse(self, (TSInput){ + &input, + ts_string_input_read, + encoding, + }); } #undef LOG diff --git a/sources/main.c b/sources/main.c index 108006fd..f035ea80 100644 --- a/sources/main.c +++ b/sources/main.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */ -/* Updated: 2024/08/12 16:58:25 by maiboyer ### ########.fr */ +/* Updated: 2024/08/19 14:22:34 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -101,7 +101,7 @@ t_node parse_str(t_state *state) t_node ret; t_ast_node out; - tree = ts_parser_parse_string(state->parser, NULL, state->str_input, str_len(state->str_input)); + tree = ts_parser_parse_string(state->parser, state->str_input, str_len(state->str_input)); node = ts_tree_root_node(tree); if (ast_from_node(node, state->str_input, &out)) (state->ast = NULL, printf("Error when building node\n"));