Updated to support heredocs

This commit is contained in:
Maieul BOYER 2024-09-04 16:43:14 +00:00
parent 92823aff80
commit 980cae5597
5 changed files with 42 additions and 202 deletions

View file

@ -11,67 +11,34 @@
/* ************************************************************************** */
#include "app/node.h"
#include "ast/_from_node.h"
#include "ast/ast.h"
#include "gmr/symbols.h"
#include "gmr/field_identifiers.h"
#include "me/str/str.h"
#include "me/types.h"
#include "parser/api.h"
#include <stdio.h>
t_error build_sym_heredoc_body(t_parse_node self, t_const_str input, \
t_ast_node *out)
{
printf("This function is not done '%s'", __func__);
(void)(self);
(void)(input);
(void)(out);
return (ERROR);
}
t_error build_sym_heredoc_content(t_parse_node self, t_const_str input, \
t_ast_node *out)
{
printf("This function is not done '%s'", __func__);
(void)(self);
(void)(input);
(void)(out);
return (ERROR);
}
t_error build_sym_heredoc_end(t_parse_node self, t_const_str input, \
t_ast_node *out)
{
printf("This function is not done '%s'", __func__);
(void)(self);
(void)(input);
(void)(out);
return (ERROR);
}
t_error build_sym_heredoc_redirect(t_parse_node self, t_const_str input, \
t_ast_node *out)
{
printf("This function is not done '%s'", __func__);
(void)(self);
(void)(input);
(void)(out);
return (ERROR);
}
t_ast_node ret;
t_usize i;
t_error build_sym_heredoc_start(t_parse_node self, t_const_str input, \
t_ast_node *out)
{
printf("This function is not done '%s'", __func__);
(void)(self);
(void)(input);
(void)(out);
return (ERROR);
}
t_error build_sym_simple_heredoc_body(t_parse_node self, t_const_str input, \
t_ast_node *out)
{
printf("This function is not done '%s'", __func__);
(void)(self);
(void)(input);
(void)(out);
return (ERROR);
}
if (ts_node_symbol(self) != sym_heredoc_redirect || input == NULL || out == NULL)
return (ERROR);
ret = ast_alloc(AST_HEREDOC_REDIRECTION);
i = 0;
while (i < ts_node_child_count(self))
{
if (ts_node_field_id_for_child(self, i) == field_op)
ret->data.heredoc_redirection.op = _get_redirection_op(ts_node_child(self, i));
else if (ts_node_symbol(ts_node_child(self, i)) == sym_heredoc_start)
ret->data.heredoc_redirection.delimiter = _extract_str(ts_node_child(self, i), input);
else if (ts_node_symbol(ts_node_child(self, i)) == sym_heredoc_body)
ret->data.heredoc_redirection.content = _extract_str(ts_node_child(self, i), input);
i++;
}
return (*out = ret, NO_ERROR);
}