Updates...

This commit is contained in:
Maix0 2024-05-01 21:19:14 +02:00
parent 43480c35e4
commit a192af9ad4
12 changed files with 1836 additions and 1787 deletions

View file

@ -28,7 +28,7 @@ typedef struct s_node
struct s_node *childs;
} t_node;
t_node build_node(TSNode curr, t_const_str input);
t_node build_node(t_parse_node curr, t_const_str input);
t_str node_getstr(t_node *node);
void free_node(t_node t);

View file

@ -32,7 +32,7 @@
typedef struct s_parser
{
TSParser *parser;
t_first_parser *parser;
} t_parser;
typedef struct s_utils

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -63,9 +63,9 @@ typedef struct {
Array(Heredoc) heredocs;
} Scanner;
static inline void advance(TSLexer *lexer) { lexer->advance(lexer, false); }
static inline void advance(t_lexer_data *lexer) { lexer->advance(lexer, false); }
static inline void skip(TSLexer *lexer) { lexer->advance(lexer, true); }
static inline void skip(t_lexer_data *lexer) { lexer->advance(lexer, true); }
static inline bool in_error_recovery(const bool *valid_symbols) { return valid_symbols[ERROR_RECOVERY]; }
@ -160,7 +160,7 @@ static void deserialize(Scanner *scanner, const char *buffer, unsigned length) {
* POSIX-mandated substitution, and assumes the default value for
* IFS.
*/
static bool advance_word(TSLexer *lexer, String *unquoted_word) {
static bool advance_word(t_lexer_data *lexer, String *unquoted_word) {
bool empty = true;
int32_t quote = 0;
@ -191,7 +191,7 @@ static bool advance_word(TSLexer *lexer, String *unquoted_word) {
return !empty;
}
static inline bool scan_bare_dollar(TSLexer *lexer) {
static inline bool scan_bare_dollar(t_lexer_data *lexer) {
while (iswspace(lexer->lookahead) && lexer->lookahead != '\n' && !lexer->eof(lexer)) {
skip(lexer);
}
@ -206,7 +206,7 @@ static inline bool scan_bare_dollar(TSLexer *lexer) {
return false;
}
static bool scan_heredoc_start(Heredoc *heredoc, TSLexer *lexer) {
static bool scan_heredoc_start(Heredoc *heredoc, t_lexer_data *lexer) {
while (iswspace(lexer->lookahead)) {
skip(lexer);
}
@ -222,7 +222,7 @@ static bool scan_heredoc_start(Heredoc *heredoc, TSLexer *lexer) {
return found_delimiter;
}
static bool scan_heredoc_end_identifier(Heredoc *heredoc, TSLexer *lexer) {
static bool scan_heredoc_end_identifier(Heredoc *heredoc, t_lexer_data *lexer) {
reset_string(&heredoc->current_leading_word);
// Scan the first 'n' characters on this line, to see if they match the
// heredoc delimiter
@ -242,7 +242,7 @@ static bool scan_heredoc_end_identifier(Heredoc *heredoc, TSLexer *lexer) {
: strcmp(heredoc->current_leading_word.contents, heredoc->delimiter.contents) == 0;
}
static bool scan_heredoc_content(Scanner *scanner, TSLexer *lexer, enum TokenType middle_type,
static bool scan_heredoc_content(Scanner *scanner, t_lexer_data *lexer, enum TokenType middle_type,
enum TokenType end_type) {
bool did_advance = false;
Heredoc *heredoc = array_back(&scanner->heredocs);
@ -345,7 +345,7 @@ static bool scan_heredoc_content(Scanner *scanner, TSLexer *lexer, enum TokenTyp
}
}
static bool scan(Scanner *scanner, TSLexer *lexer, const bool *valid_symbols) {
static bool scan(Scanner *scanner, t_lexer_data *lexer, const bool *valid_symbols) {
if (valid_symbols[CONCAT] && !in_error_recovery(valid_symbols)) {
if (!(lexer->lookahead == 0 || iswspace(lexer->lookahead) || lexer->lookahead == '>' ||
lexer->lookahead == '<' || lexer->lookahead == ')' || lexer->lookahead == '(' ||
@ -1189,7 +1189,7 @@ void *tree_sitter_bash_external_scanner_create() {
return scanner;
}
bool tree_sitter_bash_external_scanner_scan(void *payload, TSLexer *lexer, const bool *valid_symbols) {
bool tree_sitter_bash_external_scanner_scan(void *payload, t_lexer_data *lexer, const bool *valid_symbols) {
Scanner *scanner = (Scanner *)payload;
return scan(scanner, lexer, valid_symbols);
}

View file

@ -12,7 +12,7 @@
#include "../includes/minishell.h"
void ts_parser_delete(TSParser *self);
void ts_parser_delete(t_first_parser *self);
void ft_free(void *ptr)
{

View file

@ -15,13 +15,13 @@
#include "me/string/str_len.h"
#include "parser/api.h"
TSParser *ts_parser_new();
void ts_tree_delete(TSTree *);
TSNode ts_tree_root_node(TSTree *);
TSTree *ts_parser_parse_string(TSParser *, TSTree *oldtree, t_const_str input,
t_first_parser *ts_parser_new();
void ts_tree_delete(t_first_tree *);
t_parse_node ts_tree_root_node(t_first_tree *);
t_first_tree *ts_parser_parse_string(t_first_parser *, t_first_tree *oldtree, t_const_str input,
t_usize len);
void ts_parser_delete(TSParser *self);
void ts_parser_set_language(TSParser *self, TSLanguage *lang);
void ts_parser_delete(t_first_parser *self);
void ts_parser_set_language(t_first_parser *self, t_language *lang);
void print_node_data(t_node *t, t_usize depth)
{
@ -36,10 +36,10 @@ void print_node_data(t_node *t, t_usize depth)
print_node_data(&t->childs[idx++], depth + 1);
}
t_node parse_to_nodes(TSParser *parser, t_const_str input)
t_node parse_to_nodes(t_first_parser *parser, t_const_str input)
{
TSTree *tree;
TSNode node;
t_first_tree *tree;
t_parse_node node;
t_node ret;
tree = ts_parser_parse_string(parser, NULL, input, str_len(input));
@ -112,12 +112,12 @@ void ft_find_path(t_str arge[], t_utils *utils)
utils->path = ft_split(PATH_FILES, ':');
}
TSLanguage *tree_sitter_bash(void);
t_language *tree_sitter_bash(void);
t_parser create_myparser(void)
{
TSLanguage *lang;
TSParser *parser;
t_language *lang;
t_first_parser *parser;
lang = tree_sitter_bash();
parser = ts_parser_new();

View file

@ -16,19 +16,19 @@
#include "me/string/str_l_copy.h"
#include "parser/api.h"
t_node build_node(TSNode current, t_const_str input);
TSNode ts_node_child(TSNode parent, t_usize idx);
TSSymbol ts_node_symbol(TSNode self);
t_const_str ts_node_type(TSNode self);
t_u32 ts_node_start_byte(TSNode self);
t_u32 ts_node_end_byte(TSNode self);
t_u32 ts_node_child_count(TSNode self);
t_node build_node(t_parse_node current, t_const_str input);
t_parse_node ts_node_child(t_parse_node parent, t_usize idx);
t_symbol ts_node_symbol(t_parse_node self);
t_const_str ts_node_type(t_parse_node self);
t_u32 ts_node_start_byte(t_parse_node self);
t_u32 ts_node_end_byte(t_parse_node self);
t_u32 ts_node_child_count(t_parse_node self);
t_node *build_childs(TSNode parent, t_const_str input, t_usize count)
t_node *build_childs(t_parse_node parent, t_const_str input, t_usize count)
{
t_node *ret;
t_usize idx;
TSNode child;
t_parse_node child;
ret = mem_alloc_array(sizeof(*ret), count);
if (ret == NULL)
@ -43,7 +43,7 @@ t_node *build_childs(TSNode parent, t_const_str input, t_usize count)
return (ret);
}
t_node build_node(TSNode curr, t_const_str input)
t_node build_node(t_parse_node curr, t_const_str input)
{
t_node out;

View file

@ -1 +0,0 @@
use flake

View file

@ -6,7 +6,7 @@
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
# Updated: 2024/04/28 20:00:43 by maiboyer ### ########.fr #
# Updated: 2024/05/01 20:31:58 by maiboyer ### ########.fr #
# #
# **************************************************************************** #
@ -52,23 +52,19 @@ all: $(NAME)
$(NAME): $(TARGET)
$(TARGET): $(OBJ)
@printf \\n$(COL_GRAY)Building\ Output\ $(COL_WHITE)$(COL_BOLD)%-28s$(COL_RESET)\ \
$(NAME)
@echo -e "$(COL_GRAY) Linking\t$(COL_GREEN)$(TARGET)$(COL_RESET)"
@#$(CC) $(INCLUDES) $(OBJ) $(CFLAGS) -o $(NAME)
@ar rcs $(BUILD_DIR)/$(NAME) $(OBJ)
@printf $(COL_GREEN)done$(COL_RESET)\\n
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(dir $@)
@printf $(COL_GRAY)Building\ $(COL_BOLD)$(COL_WHITE)%-50s\ $(LIB_NAME)$<
@echo -e "$(COL_GRAY) Building\t$(COL_GREEN)$<$(COL_RESET)"
@$(CC) $(CFLAGS) $(WERROR) $(INCLUDES) -c $< -o $@
@printf $(COL_RESET)$(COL_GREEN)done$(COL_RESET)\\n
$(BUILD_DIR)/%.o: $(GENERIC_DIR)/%.c
@mkdir -p $(dir $@)
@printf $(COL_GRAY)Building\ $(COL_BOLD)$(COL_WHITE)%-50s\ $(LIB_NAME)$<
@echo -e "$(COL_GRAY) Building\t$(COL_GREEN)$<$(COL_RESET)"
@$(CC) $(CFLAGS) $(WERROR) $(INCLUDES) -c $< -o $@
@printf $(COL_RESET)$(COL_GREEN)done$(COL_RESET)\\n
clean:
@- $(foreach LIB,$(LIBS), \

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/08 12:45:06 by maiboyer #+# #+# */
/* Updated: 2024/04/28 19:42:10 by maiboyer ### ########.fr */
/* Updated: 2024/05/01 20:29:59 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -37,10 +37,10 @@ static void me_inner(t_u64 nb, t_str out, t_usize *idx)
void me_putnbr_fd(t_i32 n, t_file file)
{
t_usize idx;
t_u64 nb;
t_i64 nb;
char out[15];
nb = (t_u64)n;
nb = (t_i64)n;
idx = 0;
if (nb < 0)
{

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/04 17:29:13 by maiboyer #+# #+# */
/* Updated: 2024/04/28 19:42:46 by maiboyer ### ########.fr */
/* Updated: 2024/05/01 20:30:38 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,7 +15,7 @@
char *str_find_rev_chr(t_const_str str, char chr)
{
t_usize index;
t_isize index;
if (str == NULL)
return (NULL);