Normed the from_node
This commit is contained in:
parent
b744ceb755
commit
78a595ef60
6 changed files with 372 additions and 325 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/06 18:43:35 by rparodi #+# #+# */
|
||||
/* Updated: 2024/08/06 18:44:55 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/09/02 17:32:38 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -125,3 +125,46 @@ t_error build_sym_while_statement(\
|
|||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
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;
|
||||
t_usize i;
|
||||
t_ast_terminator_kind term;
|
||||
|
||||
(void)(out);
|
||||
(void)(input);
|
||||
(void)(self);
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_do_group)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_COMPOUND_STATEMENT);
|
||||
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)
|
||||
{
|
||||
i++;
|
||||
continue ;
|
||||
}
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
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);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
|
|
|||
131
ast/src/from_node/exec_node.c
Normal file
131
ast/src/from_node/exec_node.c
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* exec_node.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/02 17:33:20 by rparodi #+# #+# */
|
||||
/* Updated: 2024/09/02 17:33:41 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ast/_from_node.h"
|
||||
#include "ast/ast.h"
|
||||
#include "gmr/field_identifiers.h"
|
||||
#include "gmr/symbols.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_ast.h"
|
||||
#include "parser/api.h"
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
t_usize i;
|
||||
t_ast_terminator_kind term;
|
||||
|
||||
(void)(out);
|
||||
(void)(input);
|
||||
(void)(self);
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_compound_statement)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_COMPOUND_STATEMENT);
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ts_node_is_named(ts_node_child(self, i)) && (i++, true))
|
||||
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);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_program(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_usize i;
|
||||
t_ast_node temp;
|
||||
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_program)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_PROGRAM);
|
||||
i = 0;
|
||||
while (i < ts_node_child_count(self))
|
||||
{
|
||||
temp = NULL;
|
||||
if (ts_node_field_id_for_child(self, i) == field_stmt)
|
||||
{
|
||||
if (ast_from_node(ts_node_child(self, i), input, &temp))
|
||||
return (ast_free(ret), ERROR);
|
||||
vec_ast_push(&ret->data.program.body, temp);
|
||||
}
|
||||
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)));
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_command_name(\
|
||||
t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_command_name)
|
||||
return (ERROR);
|
||||
return (ast_from_node(ts_node_child(self, 0), input, out));
|
||||
}
|
||||
|
||||
t_error build_sym_command(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_usize i;
|
||||
t_usize vec_idx;
|
||||
t_ast_node temp;
|
||||
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_command)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_COMMAND);
|
||||
i = 0;
|
||||
vec_idx = 0;
|
||||
while (i < ts_node_child_count(self))
|
||||
{
|
||||
temp = NULL;
|
||||
if (ts_node_field_id_for_child(self, i) == field_name)
|
||||
vec_idx++;
|
||||
if (ast_from_node(ts_node_child(self, i), input, &temp))
|
||||
return (ast_free(ret), ERROR);
|
||||
vec_ast_push(_vec_command(&ret->data.command, vec_idx), temp);
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/06 18:26:15 by rparodi #+# #+# */
|
||||
/* Updated: 2024/08/06 18:31:32 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/09/02 17:34:28 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -121,3 +121,38 @@ t_error build_sym_simple_expansion(\
|
|||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
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;
|
||||
t_usize i;
|
||||
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_command_substitution)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_COMMAND_SUBSTITUTION);
|
||||
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_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], \
|
||||
_select_term(ts_node_child(self, i)));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ast_from_node(ts_node_child(self, i), input, &tmp))
|
||||
return (ast_free(ret), ERROR);
|
||||
vec_ast_push(&ret->data.command_substitution.body, tmp);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/26 10:55:52 by rparodi #+# #+# */
|
||||
/* Updated: 2024/09/02 11:55:51 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/09/02 17:34:02 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -112,41 +112,6 @@ 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_ast_node ret;
|
||||
t_ast_node tmp;
|
||||
t_usize i;
|
||||
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_command_substitution)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_COMMAND_SUBSTITUTION);
|
||||
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_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], \
|
||||
_select_term(ts_node_child(self, i)));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ast_from_node(ts_node_child(self, i), input, &tmp))
|
||||
return (ast_free(ret), ERROR);
|
||||
vec_ast_push(&ret->data.command_substitution.body, tmp);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
/* if (ts_node_field_id_for_child(self, i) == field_fd) */
|
||||
/* { */
|
||||
/* if (ast_from_node(ts_node_child(self, i), input, &tmp)) */
|
||||
|
|
@ -154,49 +119,6 @@ t_error build_sym_command_substitution(\
|
|||
/* 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_ast_node ret;
|
||||
t_ast_node tmp;
|
||||
t_usize i;
|
||||
t_ast_terminator_kind term;
|
||||
|
||||
(void)(out);
|
||||
(void)(input);
|
||||
(void)(self);
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_do_group)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_COMPOUND_STATEMENT);
|
||||
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)
|
||||
{
|
||||
i++;
|
||||
continue ;
|
||||
}
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
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);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_subshell(\
|
||||
t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
|
|
@ -238,236 +160,6 @@ t_error build_sym_subshell(\
|
|||
|
||||
// t_error buildw
|
||||
|
||||
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;
|
||||
t_usize i;
|
||||
t_ast_terminator_kind term;
|
||||
|
||||
(void)(out);
|
||||
(void)(input);
|
||||
(void)(self);
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_compound_statement)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_COMPOUND_STATEMENT);
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ts_node_is_named(ts_node_child(self, i)) && (i++, true))
|
||||
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);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_string(\
|
||||
t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_usize i;
|
||||
t_ast_node temp;
|
||||
|
||||
(void)(self);
|
||||
(void)(input);
|
||||
(void)(out);
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_string)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_WORD);
|
||||
ret->data.word.kind = AST_WORD_DOUBLE_QUOTE;
|
||||
i = 0;
|
||||
while (i < ts_node_child_count(self))
|
||||
{
|
||||
if (!ts_node_is_named(ts_node_child(self, i)) && (i++, true))
|
||||
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);
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_concatenation(\
|
||||
t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_usize i;
|
||||
t_ast_node temp;
|
||||
|
||||
(void)(self);
|
||||
(void)(input);
|
||||
(void)(out);
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_concatenation)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_WORD);
|
||||
ret->data.word.kind = AST_WORD_NO_QUOTE;
|
||||
i = 0;
|
||||
while (i < ts_node_child_count(self))
|
||||
{
|
||||
if (ast_from_node(ts_node_child(self, i), input, &temp))
|
||||
return (ast_free(ret), ERROR);
|
||||
vec_ast_push(&ret->data.word.inner, temp);
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_string_content)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_RAW_STRING);
|
||||
temp_str = _extract_str(self, input);
|
||||
ret->data.raw_string.str = temp_str;
|
||||
ret->data.raw_string.len = str_len(temp_str);
|
||||
ret->data.raw_string.kind = AST_WORD_DOUBLE_QUOTE;
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
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;
|
||||
t_str temp_str;
|
||||
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_raw_string)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_WORD);
|
||||
temp = ast_alloc(AST_RAW_STRING);
|
||||
temp_str = _extract_str(self, input);
|
||||
temp->data.raw_string.str = temp_str;
|
||||
temp->data.raw_string.len = str_len(temp_str);
|
||||
temp->data.raw_string.kind = AST_WORD_SINGLE_QUOTE;
|
||||
temp->data.raw_string.start = true;
|
||||
temp->data.raw_string.end = true;
|
||||
ret->data.word.kind = AST_WORD_SINGLE_QUOTE;
|
||||
vec_ast_push(&ret->data.word.inner, temp);
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_program(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_usize i;
|
||||
t_ast_node temp;
|
||||
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_program)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_PROGRAM);
|
||||
i = 0;
|
||||
while (i < ts_node_child_count(self))
|
||||
{
|
||||
temp = NULL;
|
||||
if (ts_node_field_id_for_child(self, i) == field_stmt)
|
||||
{
|
||||
if (ast_from_node(ts_node_child(self, i), input, &temp))
|
||||
return (ast_free(ret), ERROR);
|
||||
vec_ast_push(&ret->data.program.body, temp);
|
||||
}
|
||||
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)));
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_command_name(\
|
||||
t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_command_name)
|
||||
return (ERROR);
|
||||
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_ast_node ret;
|
||||
t_str temp_str;
|
||||
t_ast_node temp;
|
||||
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_word)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_WORD);
|
||||
ret->data.word.kind = AST_WORD_NO_QUOTE;
|
||||
temp = ast_alloc(AST_RAW_STRING);
|
||||
temp_str = _extract_str(self, input);
|
||||
temp->data.raw_string.str = temp_str;
|
||||
temp->data.raw_string.len = str_len(temp_str);
|
||||
temp->data.raw_string.kind = AST_WORD_NO_QUOTE;
|
||||
vec_ast_push(&ret->data.word.inner, temp);
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_command(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_usize i;
|
||||
t_usize vec_idx;
|
||||
t_ast_node temp;
|
||||
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_command)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_COMMAND);
|
||||
i = 0;
|
||||
vec_idx = 0;
|
||||
while (i < ts_node_child_count(self))
|
||||
{
|
||||
temp = NULL;
|
||||
if (ts_node_field_id_for_child(self, i) == field_name)
|
||||
vec_idx++;
|
||||
if (ast_from_node(ts_node_child(self, i), input, &temp))
|
||||
return (ast_free(ret), ERROR);
|
||||
vec_ast_push(_vec_command(&ret->data.command, vec_idx), temp);
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_list(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
|
|
@ -587,7 +279,8 @@ t_error ast_from_node(\
|
|||
if (ts_node_symbol(node) == sym_arithmetic_literal)
|
||||
return (build_sym_arithmetic_literal(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_arithmetic_parenthesized_expression)
|
||||
return (build_sym_arithmetic_parenthesized_expression(node, input, out));
|
||||
return (build_sym_arithmetic_parenthesized_expression(\
|
||||
node, input, out));
|
||||
if (ts_node_symbol(node) == sym_arithmetic_postfix_expression)
|
||||
return (build_sym_arithmetic_postfix_expression(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_arithmetic_ternary_expression)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/06 18:27:48 by rparodi #+# #+# */
|
||||
/* Updated: 2024/08/14 17:31:57 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/02 17:04:40 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -20,13 +20,14 @@
|
|||
#include "parser/api.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void _append_redirection(t_ast_node node, t_ast_node redirection)
|
||||
void _append_redirection(t_ast_node node, t_ast_node redirection)
|
||||
{
|
||||
t_vec_ast *vec;
|
||||
t_vec_ast *vec;
|
||||
|
||||
vec = NULL;
|
||||
|
||||
if (node == NULL || redirection == NULL || !(redirection->kind == AST_FILE_REDIRECTION || redirection->kind == AST_HEREDOC_REDIRECTION))
|
||||
if (node == NULL || redirection == NULL || \
|
||||
!(redirection->kind == AST_FILE_REDIRECTION || \
|
||||
redirection->kind == AST_HEREDOC_REDIRECTION))
|
||||
return (ast_free(redirection));
|
||||
if (node->kind == AST_CASE)
|
||||
vec = &node->data.case_.suffixes_redirections;
|
||||
|
|
@ -35,9 +36,12 @@ void _append_redirection(t_ast_node node, t_ast_node redirection)
|
|||
else if (node->kind == AST_COMPOUND_STATEMENT)
|
||||
vec = &node->data.compound_statement.suffixes_redirections;
|
||||
else if (node->kind == AST_LIST)
|
||||
return (_append_redirection(node->data.list.right, redirection));
|
||||
else if (node->kind == AST_PIPELINE && node->data.pipeline.statements.len != 0)
|
||||
return (_append_redirection(node->data.pipeline.statements.buffer[node->data.pipeline.statements.len - 1], redirection));
|
||||
return (_append_redirection(\
|
||||
node->data.list.right, redirection));
|
||||
else if (node->kind == AST_PIPELINE && \
|
||||
node->data.pipeline.statements.len != 0)
|
||||
return (_append_redirection(node->data.pipeline.statements.buffer[\
|
||||
node->data.pipeline.statements.len - 1], redirection));
|
||||
else if (node->kind == AST_SUBSHELL)
|
||||
vec = &node->data.subshell.suffixes_redirections;
|
||||
else
|
||||
|
|
@ -48,9 +52,9 @@ void _append_redirection(t_ast_node node, t_ast_node redirection)
|
|||
(ast_free(redirection));
|
||||
}
|
||||
|
||||
t_ast_terminator_kind _select_term(t_parse_node node)
|
||||
t_ast_terminator_kind _select_term(t_parse_node node)
|
||||
{
|
||||
t_symbol symbol;
|
||||
t_symbol symbol;
|
||||
|
||||
symbol = ts_node_grammar_symbol(ts_node_child(node, 0));
|
||||
if (symbol == anon_sym_SEMI)
|
||||
|
|
@ -61,10 +65,10 @@ t_ast_terminator_kind _select_term(t_parse_node node)
|
|||
return (AST_TERM_NONE);
|
||||
}
|
||||
|
||||
t_str _extract_str(t_parse_node self, t_const_str input)
|
||||
t_str _extract_str(t_parse_node self, t_const_str input)
|
||||
{
|
||||
t_usize start;
|
||||
t_usize end;
|
||||
t_usize start;
|
||||
t_usize end;
|
||||
t_str result;
|
||||
|
||||
start = ts_node_start_byte(self);
|
||||
|
|
|
|||
141
ast/src/from_node/string_node.c
Normal file
141
ast/src/from_node/string_node.c
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* string_node.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/02 17:27:10 by rparodi #+# #+# */
|
||||
/* Updated: 2024/09/02 17:35:01 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ast/_from_node.h"
|
||||
#include "ast/ast.h"
|
||||
#include "gmr/field_identifiers.h"
|
||||
#include "gmr/symbols.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_ast.h"
|
||||
#include "parser/api.h"
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
t_ast_node temp;
|
||||
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_word)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_WORD);
|
||||
ret->data.word.kind = AST_WORD_NO_QUOTE;
|
||||
temp = ast_alloc(AST_RAW_STRING);
|
||||
temp_str = _extract_str(self, input);
|
||||
temp->data.raw_string.str = temp_str;
|
||||
temp->data.raw_string.len = str_len(temp_str);
|
||||
temp->data.raw_string.kind = AST_WORD_NO_QUOTE;
|
||||
vec_ast_push(&ret->data.word.inner, temp);
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_string(\
|
||||
t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_usize i;
|
||||
t_ast_node temp;
|
||||
|
||||
(void)(self);
|
||||
(void)(input);
|
||||
(void)(out);
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_string)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_WORD);
|
||||
ret->data.word.kind = AST_WORD_DOUBLE_QUOTE;
|
||||
i = 0;
|
||||
while (i < ts_node_child_count(self))
|
||||
{
|
||||
if (!ts_node_is_named(ts_node_child(self, i)) && (i++, true))
|
||||
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);
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_concatenation(\
|
||||
t_parse_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_usize i;
|
||||
t_ast_node temp;
|
||||
|
||||
(void)(self);
|
||||
(void)(input);
|
||||
(void)(out);
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_concatenation)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_WORD);
|
||||
ret->data.word.kind = AST_WORD_NO_QUOTE;
|
||||
i = 0;
|
||||
while (i < ts_node_child_count(self))
|
||||
{
|
||||
if (ast_from_node(ts_node_child(self, i), input, &temp))
|
||||
return (ast_free(ret), ERROR);
|
||||
vec_ast_push(&ret->data.word.inner, temp);
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_string_content)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_RAW_STRING);
|
||||
temp_str = _extract_str(self, input);
|
||||
ret->data.raw_string.str = temp_str;
|
||||
ret->data.raw_string.len = str_len(temp_str);
|
||||
ret->data.raw_string.kind = AST_WORD_DOUBLE_QUOTE;
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
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;
|
||||
t_str temp_str;
|
||||
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_raw_string)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_WORD);
|
||||
temp = ast_alloc(AST_RAW_STRING);
|
||||
temp_str = _extract_str(self, input);
|
||||
temp->data.raw_string.str = temp_str;
|
||||
temp->data.raw_string.len = str_len(temp_str);
|
||||
temp->data.raw_string.kind = AST_WORD_SINGLE_QUOTE;
|
||||
temp->data.raw_string.start = true;
|
||||
temp->data.raw_string.end = true;
|
||||
ret->data.word.kind = AST_WORD_SINGLE_QUOTE;
|
||||
vec_ast_push(&ret->data.word.inner, temp);
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue