Fixed some issue (relink) and removed more unused stuff from parser lib

This commit is contained in:
Maix0 2024-08-19 14:32:26 +02:00
parent c1209452cd
commit 5b7eb9784b
6 changed files with 27 additions and 70 deletions

View file

@ -6,7 +6,7 @@
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ # # By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2024/04/28 17:28:30 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)' @echo -e '$(GREY) Linking \t$(END)$(GOLD)$(NAME)$(END)'
@$(CC) $(CFLAGS) -o $(NAME) -L$(BUILD_DIR) $(call link_group,$(LIBS_FLAGS)) @$(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) @ar rcs $(BUILD_DIR)/lib$(ANAME).a $(OBJ)

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/22 13:54:54 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 * [`encoding`]: TSInput::encoding
* [`bytes_read`]: TSInput::read * [`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. * 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 * above. The second two parameters indicate the location of the buffer and its
* length in bytes. * 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 * 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 * [`ts_parser_parse_string`] method above. The final parameter indicates whether
* the text is encoded as UTF8 or UTF16. * 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. * Instruct the parser to start the next parse from the beginning.

View file

@ -3,8 +3,9 @@
t_u32 ts_decode_ascii(const t_u8 *string, t_u32 length, t_i32 *code_point) 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; *code_point = 0;
*(t_u8 *)code_point = *string; *(t_u8 *)code_point = *string;
return (1); return (1);
} }

View file

@ -1,7 +1,7 @@
#include "parser/language.h" #include "parser/language.h"
#include "me/types.h"
#include "parser/api.h" #include "parser/api.h"
#include "parser/parser.h" #include "parser/parser.h"
#include "me/types.h"
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
@ -216,31 +216,8 @@ bool ts_language_has_reduce_action(const TSLanguage *self, TSStateId state, TSSy
// the given symbol. // the given symbol.
t_u16 ts_language_lookup(const TSLanguage *self, TSStateId state, TSSymbol 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) if (state >= self->large_state_count)
{ return (me_abort("we got a small parse table, which isn't supported"), -1);
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);
}
else else
return (self->parse_table[state * self->symbol_count + symbol]); 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; idx += count;
} }
} }

View file

@ -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_SUMMARY_DEPTH = 1;
static const t_u32 MAX_COST_DIFFERENCE = 16 * ERROR_COST_PER_SKIPPED_TREE; 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 struct TSParser
{ {
Lexer lexer; Lexer lexer;
Stack *stack; Stack *stack;
/* SubtreePool tree_pool; */
const TSLanguage *language; const TSLanguage *language;
ReduceActionSet reduce_actions; ReduceActionSet reduce_actions;
Subtree finished_tree; Subtree finished_tree;
SubtreeArray trailing_extras; SubtreeArray trailing_extras;
SubtreeArray trailing_extras2; SubtreeArray trailing_extras2;
SubtreeArray scratch_trees; SubtreeArray scratch_trees;
TokenCache token_cache;
void *external_scanner_payload; void *external_scanner_payload;
t_u32 accept_count; t_u32 accept_count;
t_u32 operation_count; t_u32 operation_count;
@ -1506,7 +1497,6 @@ TSParser *ts_parser_new(void)
self->has_scanner_error = false; self->has_scanner_error = false;
self->external_scanner_payload = NULL; self->external_scanner_payload = NULL;
self->operation_count = 0; self->operation_count = 0;
self->old_tree = NULL_SUBTREE;
self->included_range_difference_index = 0; self->included_range_difference_index = 0;
return self; return self;
} }
@ -1522,11 +1512,6 @@ void ts_parser_delete(TSParser *self)
{ {
array_delete(&self->reduce_actions); 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_lexer_delete(&self->lexer);
/* ts_subtree_pool_delete(&self->tree_pool); */ /* ts_subtree_pool_delete(&self->tree_pool); */
array_delete(&self->trailing_extras); 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) void ts_parser_reset(TSParser *self)
{ {
ts_parser__external_scanner_destroy(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_lexer_reset(&self->lexer, length_zero());
ts_stack_clear(self->stack); ts_stack_clear(self->stack);
if (self->finished_tree.ptr) if (self->finished_tree.ptr)
@ -1576,9 +1555,8 @@ void ts_parser_reset(TSParser *self)
self->has_scanner_error = false; 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; TSTree *result = NULL;
if (!self->language || !input.read) if (!self->language || !input.read)
return NULL; return NULL;
@ -1660,20 +1638,19 @@ exit:
return result; 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}; TSStringInput input = {(const t_u8 *)string, length};
return ts_parser_parse(self, old_tree, return ts_parser_parse(self, (TSInput){
(TSInput){ &input,
&input, ts_string_input_read,
ts_string_input_read, encoding,
encoding, });
});
} }
#undef LOG #undef LOG

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/28 14:40:38 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_node ret;
t_ast_node out; 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); node = ts_tree_root_node(tree);
if (ast_from_node(node, state->str_input, &out)) if (ast_from_node(node, state->str_input, &out))
(state->ast = NULL, printf("Error when building node\n")); (state->ast = NULL, printf("Error when building node\n"));