Working on scanner.c

This commit is contained in:
Maieul BOYER 2024-09-05 17:17:53 +00:00
parent f925aea552
commit c5bc77f467
6 changed files with 722 additions and 762 deletions

View file

@ -28,18 +28,20 @@ struct s_heredoc
static inline t_heredoc heredoc_new(void)
{
return ((t_heredoc){
return (t_heredoc){
.is_raw = false,
.started = false,
.allows_indent = false,
.delimiter = string_new(0),
.current_leading_word = string_new(0),
});
.delimiter = string_new(16),
.current_leading_word = string_new(16),
};
}
static inline void reset_heredoc(t_heredoc *heredoc)
{
if (heredoc == NULL)
return;
heredoc->is_raw = false;
heredoc->started = false;
heredoc->allows_indent = false;

View file

@ -17,65 +17,65 @@
#include "me/vec/vec_heredoc.h"
#include "parser/parser.h"
typedef struct s_scanner t_scanner;
// typedef struct s_scanner t_scanner;
struct s_scanner
{
t_u8 last_glob_paren_depth;
bool ext_was_in_double_quote;
bool ext_saw_outside_quote;
t_vec_heredoc heredocs;
};
// struct s_scanner
// {
// t_u8 last_glob_paren_depth;
// bool ext_was_in_double_quote;
// bool ext_saw_outside_quote;
// t_vec_heredoc heredocs;
// };
enum e_token_type
{
HEREDOC_START,
SIMPLE_HEREDOC_BODY,
HEREDOC_BODY_BEGINNING,
HEREDOC_CONTENT,
HEREDOC_END,
FILE_DESCRIPTOR,
EMPTY_VALUE,
CONCAT,
VARIABLE_NAME,
REGEX,
EXPANSION_WORD,
EXTGLOB_PATTERN,
BARE_DOLLAR,
IMMEDIATE_DOUBLE_HASH,
HEREDOC_ARROW,
HEREDOC_ARROW_DASH,
NEWLINE,
OPENING_PAREN,
ESAC,
ERROR_RECOVERY,
};
// enum e_token_type
// {
// HEREDOC_START,
// SIMPLE_HEREDOC_BODY,
// HEREDOC_BODY_BEGINNING,
// HEREDOC_CONTENT,
// HEREDOC_END,
// FILE_DESCRIPTOR,
// EMPTY_VALUE,
// CONCAT,
// VARIABLE_NAME,
// REGEX,
// EXPANSION_WORD,
// EXTGLOB_PATTERN,
// BARE_DOLLAR,
// IMMEDIATE_DOUBLE_HASH,
// HEREDOC_ARROW,
// HEREDOC_ARROW_DASH,
// NEWLINE,
// OPENING_PAREN,
// ESAC,
// ERROR_RECOVERY,
// };
struct s_heredoc_scan_state
{
t_scanner *scanner;
TSLexer *lexer;
enum e_token_type middle_type;
enum e_token_type end_type;
bool did_advance;
t_heredoc *heredoc;
bool return_value;
};
// struct s_heredoc_scan_state
// {
// t_scanner *scanner;
// TSLexer *lexer;
// enum e_token_type middle_type;
// enum e_token_type end_type;
// bool did_advance;
// t_heredoc *heredoc;
// bool return_value;
// };
typedef bool (*t_heredoc_content_func)(struct s_heredoc_scan_state *state);
// typedef bool (*t_heredoc_content_func)(struct s_heredoc_scan_state *state);
bool advance_word(TSLexer *lexer, t_string *unquoted_word);
bool check_scan_concat(t_scanner *scanner, TSLexer *lexer, const bool *valid_symbols);
bool scan(t_scanner *scanner, TSLexer *lexer, const bool *valid_symbols);
bool scan_bare_dollar(TSLexer *lexer);
bool scan_concat(t_scanner *scanner, TSLexer *lexer, const bool *valid_symbols);
bool scan_double_hash(t_scanner *scanner, TSLexer *lexer, const bool *valid_symbols);
bool scan_expansion_word(t_scanner *scanner, TSLexer *lexer, const bool *valid_symbols);
bool scan_heredoc_content(t_scanner *scanner, TSLexer *lexer, enum e_token_type middle_type, enum e_token_type end_type);
bool scan_heredoc_end(t_scanner *scanner, TSLexer *lexer);
bool scan_heredoc_end_identifier(t_heredoc *heredoc, TSLexer *lexer);
bool scan_heredoc_start(t_heredoc *heredoc, TSLexer *lexer);
bool scan_varname(t_scanner *scanner, TSLexer *lexer, const bool *valid_symbols);
void reset(t_scanner *scanner);
// bool advance_word(TSLexer *lexer, t_string *unquoted_word);
// bool check_scan_concat(t_scanner *scanner, TSLexer *lexer, const bool *valid_symbols);
// bool scan(t_scanner *scanner, TSLexer *lexer, const bool *valid_symbols);
// bool scan_bare_dollar(TSLexer *lexer);
// bool scan_concat(t_scanner *scanner, TSLexer *lexer, const bool *valid_symbols);
// bool scan_double_hash(t_scanner *scanner, TSLexer *lexer, const bool *valid_symbols);
// bool scan_expansion_word(t_scanner *scanner, TSLexer *lexer, const bool *valid_symbols);
// bool scan_heredoc_content(t_scanner *scanner, TSLexer *lexer, enum e_token_type middle_type, enum e_token_type end_type);
// bool scan_heredoc_end(t_scanner *scanner, TSLexer *lexer);
// bool scan_heredoc_end_identifier(t_heredoc *heredoc, TSLexer *lexer);
// bool scan_heredoc_start(t_heredoc *heredoc, TSLexer *lexer);
// bool scan_varname(t_scanner *scanner, TSLexer *lexer, const bool *valid_symbols);
// void reset(t_scanner *scanner);
#endif

File diff suppressed because it is too large Load diff

View file

@ -37,28 +37,28 @@ t_error _handle_redirections_inherited(t_spawn_info *info, t_process *process)
t_error _handle_redirections_fds(t_spawn_info *info, t_process *process)
{
t_fd *tmp;
// t_fd *tmp;
if (info->stdin.tag == R_FD)
{
tmp = info->stdin.fd.fd;
// tmp = info->stdin.fd.fd;
info->stdin = fd(dup_fd(info->stdin.fd.fd));
process->stdin = dup_fd(info->stdin.fd.fd);
close_fd(tmp);
// close_fd(tmp);
}
if (info->stdout.tag == R_FD)
{
tmp = info->stdin.fd.fd;
// tmp = info->stdin.fd.fd;
info->stdout = fd(dup_fd(info->stdout.fd.fd));
process->stdout = dup_fd(info->stdout.fd.fd);
close_fd(tmp);
// close_fd(tmp);
}
if (info->stderr.tag == R_FD)
{
tmp = info->stdin.fd.fd;
// tmp = info->stdin.fd.fd;
info->stderr = fd(dup_fd(info->stderr.fd.fd));
process->stderr = dup_fd(info->stderr.fd.fd);
close_fd(tmp);
// close_fd(tmp);
}
return (NO_ERROR);
}

View file

@ -21,6 +21,8 @@ t_str str_clone(t_const_str source)
t_str res;
t_usize len;
if (source == NULL)
return (NULL);
len = str_len(source) + 1;
res = mem_alloc_array(sizeof(*res), len);
if (res == NULL)

View file

@ -1,5 +1,6 @@
make
valgrind --leak-check=full --show-leak-kinds=none --track-origins=yes --track-fds=yes --trace-children=yes ./minishell <<<'cat <<EOF
#!/usr/bin/env bash
make && valgrind --leak-check=full --show-leak-kinds=none --track-origins=yes --track-fds=yes --trace-children=yes --read-var-info=yes --read-inline-info=yes ./minishell <<<'cat <<EOF
bonjour je suis un heredoc
le saviez tu je dois finir par EOF mais qui est sur la ligne
donc par example si j ai cette ligne qui fini avec EOF