added truc
This commit is contained in:
parent
313652be47
commit
8d192a0abc
58 changed files with 116828 additions and 37 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/17 12:41:56 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/06/30 00:52:11 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/06/30 16:50:25 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -467,6 +467,9 @@ t_error ast_from_node(t_parse_node node, t_const_str input, t_ast_node *out);
|
|||
/* FUNCTION THAT ARE DONE */
|
||||
|
||||
t_error build_sym__bare_dollar(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_case_item(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||
t_error build_sym__case_item_last(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_case_statement(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_command(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);
|
||||
t_error build_sym_comment(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||
|
|
@ -474,6 +477,7 @@ t_error build_sym_compound_statement(t_parse_node self, t_const_str input, t_ast
|
|||
t_error build_sym_elif_clause(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_else_clause(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_for_statement(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_function_definition(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_if_statement(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_list(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_negated_command(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||
|
|
@ -496,11 +500,6 @@ t_error build_sym_arithmetic_postfix_expression(t_parse_node self, t_const_str i
|
|||
t_error build_sym_arithmetic_ternary_expression(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_arithmetic_unary_expression(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||
|
||||
t_error build_sym_case_statement(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_case_item(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||
|
||||
t_error build_sym_function_definition(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||
|
||||
t_error build_sym_arithmetic_expansion(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_error build_sym_expansion(t_parse_node self, t_const_str input, t_ast_node *out);
|
||||
|
|
@ -524,6 +523,151 @@ t_error build_sym_heredoc_start(t_parse_node self, t_const_str input, t_ast_node
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
t_error build_sym_function_definition(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_ast_node tmp;
|
||||
t_usize i;
|
||||
|
||||
(void)(out);
|
||||
(void)(input);
|
||||
(void)(self);
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_grammar_symbol(self) != sym_function_definition)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_FUNCTION_DEFINITION);
|
||||
i = 0;
|
||||
while (i < ts_node_child_count(self))
|
||||
{
|
||||
if (!ts_node_is_named(ts_node_child(self, i)) && (i++, true))
|
||||
continue;
|
||||
if (ts_node_field_id_for_child(self, i) == field_name)
|
||||
{
|
||||
ret->data.function_definition.name =
|
||||
str_substring(input, ts_node_start_byte(ts_node_child(self, i)),
|
||||
ts_node_end_byte(ts_node_child(self, i)) - ts_node_start_byte(ts_node_child(self, i)));
|
||||
}
|
||||
if (ts_node_field_id_for_child(self, i) == field_body)
|
||||
{
|
||||
if (ast_from_node(ts_node_child(self, i), input, &tmp))
|
||||
return (ast_free(ret), ERROR);
|
||||
vec_ast_push(&ret->data.function_definition.body, tmp);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_case_statement(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_ast_node tmp;
|
||||
t_usize i;
|
||||
|
||||
(void)(out);
|
||||
(void)(input);
|
||||
(void)(self);
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_grammar_symbol(self) != sym_case_statement)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_CASE);
|
||||
i = 0;
|
||||
while (i < ts_node_child_count(self))
|
||||
{
|
||||
if (!ts_node_is_named(ts_node_child(self, i)) && (i++, true))
|
||||
continue;
|
||||
if (ts_node_field_id_for_child(self, i) == field_value)
|
||||
{
|
||||
if (ast_from_node(ts_node_child(self, i), input, &ret->data.case_.word))
|
||||
return (ast_free(ret), ERROR);
|
||||
}
|
||||
if (ts_node_field_id_for_child(self, i) == field_cases)
|
||||
{
|
||||
if (ast_from_node(ts_node_child(self, i), input, &tmp))
|
||||
return (ast_free(ret), ERROR);
|
||||
vec_ast_push(&ret->data.case_.cases, tmp);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym__case_item_last(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_ast_node tmp;
|
||||
t_usize i;
|
||||
|
||||
(void)(out);
|
||||
(void)(input);
|
||||
(void)(self);
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_grammar_symbol(self) != sym__case_item_last)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_CASE_ITEM);
|
||||
i = 0;
|
||||
while (i < ts_node_child_count(self))
|
||||
{
|
||||
if (!ts_node_is_named(ts_node_child(self, i)) && (i++, true))
|
||||
continue;
|
||||
if (ts_node_field_id_for_child(self, i) == field_value)
|
||||
{
|
||||
if (ast_from_node(ts_node_child(self, i), input, &tmp))
|
||||
return (ast_free(ret), ERROR);
|
||||
vec_ast_push(&ret->data.case_item.pattern, tmp);
|
||||
}
|
||||
if (ts_node_field_id_for_child(self, i) == field_body)
|
||||
{
|
||||
if (ast_from_node(ts_node_child(self, i), input, &tmp))
|
||||
return (ast_free(ret), ERROR);
|
||||
vec_ast_push(&ret->data.case_item.body, tmp);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_case_item(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_ast_node tmp;
|
||||
t_usize i;
|
||||
|
||||
(void)(out);
|
||||
(void)(input);
|
||||
(void)(self);
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_grammar_symbol(self) != sym_case_item)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_CASE_ITEM);
|
||||
i = 0;
|
||||
while (i < ts_node_child_count(self))
|
||||
{
|
||||
if (!ts_node_is_named(ts_node_child(self, i)) && (i++, true))
|
||||
continue;
|
||||
if (ts_node_field_id_for_child(self, i) == field_value)
|
||||
{
|
||||
if (ast_from_node(ts_node_child(self, i), input, &tmp))
|
||||
return (ast_free(ret), ERROR);
|
||||
vec_ast_push(&ret->data.case_item.pattern, tmp);
|
||||
}
|
||||
if (ts_node_field_id_for_child(self, i) == field_body)
|
||||
{
|
||||
if (ast_from_node(ts_node_child(self, i), input, &tmp))
|
||||
return (ast_free(ret), ERROR);
|
||||
vec_ast_push(&ret->data.case_item.body, tmp);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_if_statement(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
|
|
@ -645,7 +789,6 @@ t_error build_sym_for_statement(t_parse_node self, t_const_str input, t_ast_node
|
|||
{
|
||||
t_ast_node ret;
|
||||
t_ast_node tmp;
|
||||
t_const_str tmp_str;
|
||||
t_parse_node temp_ast;
|
||||
t_usize i;
|
||||
|
||||
|
|
@ -1317,6 +1460,8 @@ t_error ast_from_node(t_parse_node node, t_const_str input, t_ast_node *out)
|
|||
return (build_sym_arithmetic_unary_expression(node, input, out));
|
||||
if (ts_node_grammar_symbol(node) == sym_case_item)
|
||||
return (build_sym_case_item(node, input, out));
|
||||
if (ts_node_grammar_symbol(node) == sym__case_item_last)
|
||||
return (build_sym__case_item_last(node, input, out));
|
||||
if (ts_node_grammar_symbol(node) == sym_case_statement)
|
||||
return (build_sym_case_statement(node, input, out));
|
||||
if (ts_node_grammar_symbol(node) == sym_command)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue