Finished the norm (expcept too_many_*

This commit is contained in:
Raphaël 2024-09-02 11:56:14 +02:00
parent 4f66a053a3
commit 7540096f6d
2 changed files with 91 additions and 71 deletions

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/09 16:25:02 by rparodi #+# #+# */
/* Updated: 2024/08/10 18:26:15 by maiboyer ### ########.fr */
/* Updated: 2024/09/02 11:37:38 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
@ -57,4 +57,3 @@ t_error build_sym_file_descriptor(\
ret->data.raw_string.len = str_len(ret->data.raw_string.str);
return (*out = ret, NO_ERROR);
}

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/26 10:55:52 by rparodi #+# #+# */
/* Updated: 2024/08/14 17:37:41 by maiboyer ### ########.fr */
/* Updated: 2024/09/02 11:55:51 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
@ -112,7 +112,8 @@ t_error ast_from_node(t_parse_node node, t_const_str input, t_ast_node *out);
// RAPH
// PLUS RAPH
t_error build_sym_command_substitution(t_parse_node self, t_const_str input, t_ast_node *out)
t_error build_sym_command_substitution(\
t_parse_node self, t_const_str input, t_ast_node *out)
{
t_ast_node ret;
t_ast_node tmp;
@ -127,11 +128,12 @@ t_error build_sym_command_substitution(t_parse_node self, t_const_str input, t_a
while (i < ts_node_child_count(self))
{
if (!ts_node_is_named(ts_node_child(self, i)) && (i++, true))
continue;
continue ;
if (ts_node_symbol(ts_node_child(self, i)) == field_term)
{
if (ret->data.command_substitution.body.len != 0)
ast_set_term(&ret->data.command_substitution.body.buffer[ret->data.command_substitution.body.len - 1],
ast_set_term(&ret->data.command_substitution.body.buffer[\
ret->data.command_substitution.body.len - 1], \
_select_term(ts_node_child(self, i)));
}
else
@ -152,7 +154,8 @@ t_error build_sym_command_substitution(t_parse_node self, t_const_str input, t_a
/* ret->data.file_redirection.input = tmp; */
/* } */
t_error build_sym_do_group(t_parse_node self, t_const_str input, t_ast_node *out)
t_error build_sym_do_group(\
t_parse_node self, t_const_str input, t_ast_node *out)
{
t_ast_node ret;
t_ast_node tmp;
@ -170,15 +173,18 @@ t_error build_sym_do_group(t_parse_node self, t_const_str input, t_ast_node *out
i = 0;
while (i < ts_node_child_count(self))
{
if (ts_node_symbol(ts_node_child(self, i)) == anon_sym_do || ts_node_symbol(ts_node_child(self, i)) == anon_sym_done)
if (ts_node_symbol(ts_node_child(self, i)) == anon_sym_do || \
ts_node_symbol(ts_node_child(self, i)) == anon_sym_done)
{
i++;
continue;
continue ;
}
if (ts_node_field_id_for_child(self, i) == field_term && ret->data.compound_statement.body.len != 0)
if (ts_node_field_id_for_child(self, i) == field_term && \
ret->data.compound_statement.body.len != 0)
{
term = _select_term(ts_node_child(self, i));
ast_set_term(&ret->data.compound_statement.body.buffer[ret->data.compound_statement.body.len - 1], term);
ast_set_term(&ret->data.compound_statement.body.buffer[\
ret->data.compound_statement.body.len - 1], term);
}
else
{
@ -191,7 +197,8 @@ t_error build_sym_do_group(t_parse_node self, t_const_str input, t_ast_node *out
return (*out = ret, NO_ERROR);
}
t_error build_sym_subshell(t_parse_node self, t_const_str input, t_ast_node *out)
t_error build_sym_subshell(\
t_parse_node self, t_const_str input, t_ast_node *out)
{
t_ast_node ret;
t_ast_node tmp;
@ -209,15 +216,17 @@ t_error build_sym_subshell(t_parse_node self, t_const_str input, t_ast_node *out
i = 0;
while (i < ts_node_child_count(self))
{
if (ts_node_field_id_for_child(self, i) == field_term && ret->data.subshell.body.len != 0)
if (ts_node_field_id_for_child(self, i) == field_term && \
ret->data.subshell.body.len != 0)
{
term = _select_term(ts_node_child(self, i));
ast_set_term(&ret->data.subshell.body.buffer[ret->data.subshell.body.len - 1], term);
ast_set_term(&ret->data.subshell.body.buffer[\
ret->data.subshell.body.len - 1], term);
}
else
{
if (!ts_node_is_named(ts_node_child(self, i)) && (i++, true))
continue;
continue ;
if (ast_from_node(ts_node_child(self, i), input, &tmp))
return (ast_free(ret), ERROR);
vec_ast_push(&ret->data.subshell.body, tmp);
@ -229,7 +238,8 @@ t_error build_sym_subshell(t_parse_node self, t_const_str input, t_ast_node *out
// t_error buildw
t_error build_sym_compound_statement(t_parse_node self, t_const_str input, t_ast_node *out)
t_error build_sym_compound_statement(\
t_parse_node self, t_const_str input, t_ast_node *out)
{
t_ast_node ret;
t_ast_node tmp;
@ -247,15 +257,17 @@ t_error build_sym_compound_statement(t_parse_node self, t_const_str input, t_ast
i = 0;
while (i < ts_node_child_count(self))
{
if (ts_node_field_id_for_child(self, i) == field_term && ret->data.compound_statement.body.len != 0)
if (ts_node_field_id_for_child(self, i) == field_term && \
ret->data.compound_statement.body.len != 0)
{
term = _select_term(ts_node_child(self, i));
ast_set_term(&ret->data.compound_statement.body.buffer[ret->data.compound_statement.body.len - 1], term);
ast_set_term(&ret->data.compound_statement.body.buffer[\
ret->data.compound_statement.body.len - 1], term);
}
else
{
if (!ts_node_is_named(ts_node_child(self, i)) && (i++, true))
continue;
continue ;
if (ast_from_node(ts_node_child(self, i), input, &tmp))
return (ast_free(ret), ERROR);
vec_ast_push(&ret->data.compound_statement.body, tmp);
@ -265,7 +277,8 @@ t_error build_sym_compound_statement(t_parse_node self, t_const_str input, t_ast
return (*out = ret, NO_ERROR);
}
t_error build_sym_string(t_parse_node self, t_const_str input, t_ast_node *out)
t_error build_sym_string(\
t_parse_node self, t_const_str input, t_ast_node *out)
{
t_ast_node ret;
t_usize i;
@ -284,7 +297,7 @@ t_error build_sym_string(t_parse_node self, t_const_str input, t_ast_node *out)
while (i < ts_node_child_count(self))
{
if (!ts_node_is_named(ts_node_child(self, i)) && (i++, true))
continue;
continue ;
if (ast_from_node(ts_node_child(self, i), input, &temp))
return (ast_free(ret), ERROR);
vec_ast_push(&ret->data.word.inner, temp);
@ -293,7 +306,8 @@ t_error build_sym_string(t_parse_node self, t_const_str input, t_ast_node *out)
return (*out = ret, NO_ERROR);
}
t_error build_sym_concatenation(t_parse_node self, t_const_str input, t_ast_node *out)
t_error build_sym_concatenation(\
t_parse_node self, t_const_str input, t_ast_node *out)
{
t_ast_node ret;
t_usize i;
@ -319,7 +333,8 @@ t_error build_sym_concatenation(t_parse_node self, t_const_str input, t_ast_node
return (*out = ret, NO_ERROR);
}
t_error build_sym_string_content(t_parse_node self, t_const_str input, t_ast_node *out)
t_error build_sym_string_content(\
t_parse_node self, t_const_str input, t_ast_node *out)
{
t_ast_node ret;
t_str temp_str;
@ -336,7 +351,8 @@ t_error build_sym_string_content(t_parse_node self, t_const_str input, t_ast_nod
return (*out = ret, NO_ERROR);
}
t_error build_sym_raw_string(t_parse_node self, t_const_str input, t_ast_node *out)
t_error build_sym_raw_string(\
t_parse_node self, t_const_str input, t_ast_node *out)
{
t_ast_node ret;
t_ast_node temp;
@ -383,15 +399,18 @@ t_error build_sym_program(t_parse_node self, t_const_str input, t_ast_node *out)
if (ts_node_field_id_for_child(self, i) == field_term)
{
if (ret->data.program.body.len == 0 && (i++, true))
continue;
ast_set_term(&ret->data.program.body.buffer[ret->data.program.body.len - 1], _select_term(ts_node_child(self, i)));
continue ;
ast_set_term(&ret->data.program.body.buffer[\
ret->data.program.body.len - 1], \
_select_term(ts_node_child(self, i)));
}
i++;
}
return (*out = ret, NO_ERROR);
}
t_error build_sym_command_name(t_parse_node self, t_const_str input, t_ast_node *out)
t_error build_sym_command_name(\
t_parse_node self, t_const_str input, t_ast_node *out)
{
if (out == NULL)
return (ERROR);
@ -400,7 +419,8 @@ t_error build_sym_command_name(t_parse_node self, t_const_str input, t_ast_node
return (ast_from_node(ts_node_child(self, 0), input, out));
}
t_error build_sym_word(t_parse_node self, t_const_str input, t_ast_node *out)
t_error build_sym_word(\
t_parse_node self, t_const_str input, t_ast_node *out)
{
t_ast_node ret;
t_str temp_str;
@ -555,7 +575,8 @@ sym_while_statement
sym_word
*/
t_error ast_from_node(t_parse_node node, t_const_str input, t_ast_node *out)
t_error ast_from_node(\
t_parse_node node, t_const_str input, t_ast_node *out)
{
if (out == NULL)
return (ERROR);