style: adding normed to scanner.c

This commit is contained in:
Raphael 2024-09-13 18:22:59 +02:00
parent 25ec735d0c
commit 05ebcbef50
2 changed files with 21 additions and 16 deletions

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/10 15:41:11 by rparodi #+# #+# */ /* Created: 2024/09/10 15:41:11 by rparodi #+# #+# */
/* Updated: 2024/09/10 13:58:06 by maiboyer ### ########.fr */ /* Updated: 2024/09/13 18:22:23 by rparodi ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -183,39 +183,44 @@ bool scan_heredoc_start(t_heredoc *heredoc, t_lexer *lexer)
if (!found_delimiter) if (!found_delimiter)
{ {
string_clear(&heredoc->delimiter); string_clear(&heredoc->delimiter);
return false; return (false);
} }
return (found_delimiter); return (found_delimiter);
} }
// Scan the first 'n' characters on this line, to see if they match the
// heredoc delimiter
bool scan_heredoc_end_identifier(t_heredoc *heredoc, t_lexer *lexer) bool scan_heredoc_end_identifier(t_heredoc *heredoc, t_lexer *lexer)
{ {
t_i32 size; t_i32 size;
size = 0; size = 0;
string_clear(&heredoc->current_leading_word); string_clear(&heredoc->current_leading_word);
// Scan the first 'n' characters on this line, to see if they match the
// heredoc delimiter
if (heredoc->delimiter.len > 0) if (heredoc->delimiter.len > 0)
{ {
while (lexer->data.lookahead != '\0' && lexer->data.lookahead != '\n' && while (lexer->data.lookahead != '\0' \
(t_i32) * (&heredoc->delimiter.buf[size]) == lexer->data.lookahead && && lexer->data.lookahead != '\n' && \
(t_i32) * (&heredoc->delimiter.buf[size]) == lexer->data.lookahead && \
heredoc->current_leading_word.len < heredoc->delimiter.len) heredoc->current_leading_word.len < heredoc->delimiter.len)
{ {
string_push_char(&heredoc->current_leading_word, lexer->data.lookahead); string_push_char(&heredoc->current_leading_word, \
lexer->data.lookahead);
lexer->data.advance((void *)lexer, false); lexer->data.advance((void *)lexer, false);
size++; size++;
} }
} }
string_push_char(&heredoc->current_leading_word, '\0'); string_push_char(&heredoc->current_leading_word, '\0');
return (heredoc->delimiter.len == 0 ? false : str_compare(heredoc->current_leading_word.buf, heredoc->delimiter.buf)); return (heredoc->delimiter.len == 0 ? false : str_compare(\
heredoc->current_leading_word.buf, heredoc->delimiter.buf));
} }
bool scan_heredoc_content(t_scanner *scanner, t_lexer *lexer, enum e_token_type middle_type, enum e_token_type end_type) bool scan_heredoc_content(t_scanner *scanner, t_lexer *lexer, \
enum e_token_type middle_type, enum e_token_type end_type)
{ {
bool did_advance = false; bool did_advance;
t_heredoc *heredoc = vec_heredoc_last(&scanner->heredocs); t_heredoc *heredoc = vec_heredoc_last(&scanner->heredocs);
did_advance = false;
for (;;) for (;;)
{ {
switch (lexer->data.lookahead) switch (lexer->data.lookahead)

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/06 16:31:41 by rparodi #+# #+# */ /* Created: 2024/09/06 16:31:41 by rparodi #+# #+# */
/* Updated: 2024/09/11 18:29:04 by maiboyer ### ########.fr */ /* Updated: 2024/09/13 18:15:08 by rparodi ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -54,12 +54,12 @@ t_error get_user_input(t_state *state)
return (NO_ERROR); return (NO_ERROR);
} }
//for the norme line 62: print_node_data(&state->current_node, 0);
void exec_shcat(t_state *state) void exec_shcat(t_state *state)
{ {
t_program_result prog_res; t_program_result prog_res;
prog_res = (t_program_result){.exit = 0}; prog_res = (t_program_result){.exit = 0};
//print_node_data(&state->current_node, 0);
free_node(state->current_node); free_node(state->current_node);
if (state->ast != NULL && run_program(\ if (state->ast != NULL && run_program(\
&state->ast->data.program, state, &prog_res)) &state->ast->data.program, state, &prog_res))