update: WIP changed from token output to ast
This commit is contained in:
parent
e6f0f49e84
commit
d8700f45f3
28 changed files with 23 additions and 2286 deletions
10
Minishell.mk
10
Minishell.mk
|
|
@ -6,7 +6,7 @@
|
|||
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/04/28 17:28:30 by maiboyer #+# #+# #
|
||||
# Updated: 2024/10/06 14:42:55 by maiboyer ### ########.fr #
|
||||
# Updated: 2024/10/08 15:26:22 by maiboyer ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
|
@ -66,7 +66,7 @@ LIBS_FLAGS = $(addprefix -l, $(LIBS_NAMES))
|
|||
all:
|
||||
@$(MAKE) -C ./stdme/ "LIB_NAME=$(shell realpath ./stdme)/" libme.a
|
||||
@$(MAKE) -C ./allocator/ "LIB_NAME=$(shell realpath ./allocator)/" libaq.a
|
||||
#@$(MAKE) -C ./ast/ "LIB_NAME=$(shell realpath ./ast)/" libast.a
|
||||
@$(MAKE) -C ./ast/ "LIB_NAME=$(shell realpath ./ast)/" libast.a
|
||||
@$(MAKE) -C ./exec/ "LIB_NAME=$(shell realpath ./exec)/" libexec.a
|
||||
@$(MAKE) -C ./line/ "LIB_NAME=$(shell realpath ./line)/" libline.a
|
||||
@$(MAKE) -C ./parser/ "LIB_NAME=$(shell realpath ./parser)/" libparser.a
|
||||
|
|
@ -80,12 +80,6 @@ $(NAME): $(LIBS_FILES)
|
|||
@echo -e '$(GREY) Linking \t$(END)$(GOLD)$(NAME)$(END)'
|
||||
@$(CC) $(CFLAGS) -o $(NAME) -L$(BUILD_DIR) $(call link_group,$(LIBS_FLAGS))
|
||||
|
||||
# REMOVE THIS ONE DAY
|
||||
libast.a: $(BUILD_DIR)/libast.a
|
||||
$(BUILD_DIR)/libast.a:
|
||||
@echo -e '$(GREY) Mocking \t$(END)$(GOLD)libast.a$(END)'
|
||||
@ar rcs $(BUILD_DIR)/libast.a
|
||||
|
||||
lib$(ANAME).a: $(BUILD_DIR)/lib$(ANAME).a
|
||||
|
||||
$(BUILD_DIR)/lib$(ANAME).a: $(OBJ)
|
||||
|
|
|
|||
|
|
@ -1,28 +1,8 @@
|
|||
SRC_FILES = \
|
||||
_here_doc \
|
||||
_not_done_boucle_print \
|
||||
_not_done_function \
|
||||
_not_done_scripting_print \
|
||||
ast_alloc/ast_alloc \
|
||||
ast_alloc/ast_alloc_scripting \
|
||||
ast_free/ast_free \
|
||||
ast_free/ast_free_scripting \
|
||||
from_node/arithmetic_node2 \
|
||||
from_node/artihmetic_node \
|
||||
from_node/boucle_node \
|
||||
from_node/condition_node \
|
||||
from_node/dev_node \
|
||||
from_node/exec_node \
|
||||
from_node/expansion_node \
|
||||
from_node/file_node \
|
||||
from_node/from_node \
|
||||
from_node/node_utils \
|
||||
from_node/node_utils2 \
|
||||
from_node/node_utils3 \
|
||||
from_node/other_node \
|
||||
from_node/redirect_node \
|
||||
from_node/scripting_node \
|
||||
from_node/string_node \
|
||||
print_ast/ast_print \
|
||||
print_ast/ast_print_arithmetic \
|
||||
print_ast/ast_print_command \
|
||||
|
|
|
|||
|
|
@ -1,129 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* _from_node.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/02 16:54:31 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/26 18:06:39 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef _FROM_NODE_H
|
||||
# define _FROM_NODE_H
|
||||
|
||||
# include "ast/ast.h"
|
||||
# include "me/types.h"
|
||||
# include "gmr/symbols.h"
|
||||
|
||||
void _add_negation(t_ast_node *node);
|
||||
void _append_redirection(t_ast_node node,
|
||||
t_ast_node redirection);
|
||||
t_ast_expansion_operator _extract_exp_op(t_node self);
|
||||
t_str _extract_str(t_node self, t_const_str input);
|
||||
t_ast_redirection_kind _get_redirection_op(t_node self);
|
||||
t_ast_arithmetic_operator _parse_operator(t_node self);
|
||||
t_ast_terminator_kind _select_term(t_node node);
|
||||
t_vec_ast *_vec_command(t_ast_command *val, t_usize i);
|
||||
t_error ast_from_node(t_node node, t_const_str input,
|
||||
t_ast_node *out);
|
||||
void ast_set_term(t_ast_node *node,
|
||||
t_ast_terminator_kind term);
|
||||
t_error build_sym__case_item_last(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_arithmetic_binary_expression(\
|
||||
t_node self, t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_arithmetic_expansion(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_arithmetic_literal(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_arithmetic_parenthesized_expression(\
|
||||
t_node self, t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_arithmetic_postfix_expression(\
|
||||
t_node self, t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_arithmetic_ternary_expression(\
|
||||
t_node self, t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_arithmetic_unary_expression(\
|
||||
t_node self, t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_case_item(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_case_statement(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_command(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_command_name(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_command_substitution(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_comment(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_compound_statement(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_concatenation(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_do_group(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_elif_clause(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_else_clause(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_expansion(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_extglob_pattern(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_file_descriptor(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_file_redirect(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_for_statement(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_function_definition(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_if_statement(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_heredoc_redirect(\
|
||||
t_node self, t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_simple_heredoc_body(\
|
||||
t_node self, t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_heredoc_body(\
|
||||
t_node self, t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_heredoc_content(\
|
||||
t_node self, t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_heredoc_end(\
|
||||
t_node self, t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_heredoc_start(\
|
||||
t_node self, t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_list(t_node self, t_const_str input,
|
||||
t_ast_node *out);
|
||||
t_error build_sym_negated_command(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_number(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_pipeline(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_program(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_raw_string(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_redirected_statement(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_regex(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_simple_expansion(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_string(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_string_content(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_subshell(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_variable_assignment(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_while_statement(t_node self,
|
||||
t_const_str input, t_ast_node *out);
|
||||
t_error build_sym_word(t_node self, t_const_str input,
|
||||
t_ast_node *out);
|
||||
t_vec_ast *_append_scripting(t_ast_node node);
|
||||
|
||||
#endif /* _FROM_NODE_H */
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* _here_doc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/02 16:37:28 by rparodi #+# #+# */
|
||||
/* Updated: 2024/09/19 16:46:39 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#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_redirect(t_node self, t_const_str input, \
|
||||
t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_usize i;
|
||||
|
||||
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_field_id_for_child(self, i) == field_del)
|
||||
ret->data.heredoc_redirection.delimiter = \
|
||||
_extract_str(ts_node_child(self, i), input);
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* _not_done_print.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/26 11:00:25 by rparodi #+# #+# */
|
||||
/* Updated: 2024/09/02 17:01:00 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ast/_print_ast.h"
|
||||
|
||||
void ast_print_node_case(t_ast_node self)
|
||||
{
|
||||
printf("This function is not done '%s'", __func__);
|
||||
(void)(self);
|
||||
}
|
||||
|
||||
void ast_print_node_case_item(t_ast_node self)
|
||||
{
|
||||
printf("This function is not done '%s'", __func__);
|
||||
(void)(self);
|
||||
}
|
||||
|
||||
void ast_print_node_for(t_ast_node self)
|
||||
{
|
||||
printf("This function is not done '%s'", __func__);
|
||||
(void)(self);
|
||||
}
|
||||
|
||||
void ast_print_node_while(t_ast_node self)
|
||||
{
|
||||
printf("This function is not done '%s'", __func__);
|
||||
(void)(self);
|
||||
}
|
||||
|
||||
void ast_print_node_heredoc_redirection(t_ast_node self)
|
||||
{
|
||||
printf("This function is not done '%s'", __func__);
|
||||
(void)(self);
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* _not_done_function.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/17 13:04:32 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/19 16:47:11 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/inner/ptypes.h"
|
||||
#include "parser/inner/node.h"
|
||||
#include "ast/ast.h"
|
||||
#include "gmr/symbols.h"
|
||||
#include "me/types.h"
|
||||
#include <stdio.h>
|
||||
|
||||
t_error _build_not_finished(t_node self, t_const_str i, t_ast_node *out)
|
||||
{
|
||||
(void)(self);
|
||||
(void)(out);
|
||||
(void)(i);
|
||||
printf("building undefined symbol '%s'\n", ts_node_type(self));
|
||||
return (ERROR);
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* _not_done_scripting_print.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/02 16:40:12 by rparodi #+# #+# */
|
||||
/* Updated: 2024/09/02 17:00:54 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ast/_print_ast.h"
|
||||
|
||||
void ast_print_node_if(t_ast_node self)
|
||||
{
|
||||
printf("This function is not done '%s'", __func__);
|
||||
(void)(self);
|
||||
}
|
||||
|
||||
void ast_print_node_elif(t_ast_node self)
|
||||
{
|
||||
printf("This function is not done '%s'", __func__);
|
||||
(void)(self);
|
||||
}
|
||||
|
||||
void ast_print_node_else(t_ast_node self)
|
||||
{
|
||||
printf("This function is not done '%s'", __func__);
|
||||
(void)(self);
|
||||
}
|
||||
|
||||
void ast_print_node_until(t_ast_node self)
|
||||
{
|
||||
printf("This function is not done '%s'", __func__);
|
||||
(void)(self);
|
||||
}
|
||||
|
|
@ -6,18 +6,15 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/30 17:26:13 by rparodi #+# #+# */
|
||||
/* Updated: 2024/09/15 20:15:03 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/10/08 15:26:56 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ast/ast.h"
|
||||
#include "gmr/field_identifiers.h"
|
||||
#include "gmr/symbols.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_ast.h"
|
||||
#include "parser/api.h"
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -6,18 +6,15 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/30 17:57:11 by rparodi #+# #+# */
|
||||
/* Updated: 2024/07/30 18:32:33 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/10/08 15:26:51 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ast/ast.h"
|
||||
#include "gmr/field_identifiers.h"
|
||||
#include "gmr/symbols.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_ast.h"
|
||||
#include "parser/api.h"
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -6,18 +6,15 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/30 14:29:42 by rparodi #+# #+# */
|
||||
/* Updated: 2024/09/15 20:14:43 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/10/08 15:26:40 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ast/ast.h"
|
||||
#include "gmr/field_identifiers.h"
|
||||
#include "gmr/symbols.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_ast.h"
|
||||
#include "parser/api.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void ast_free_arith(t_ast_node elem);
|
||||
|
|
|
|||
|
|
@ -6,18 +6,15 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/30 14:52:55 by rparodi #+# #+# */
|
||||
/* Updated: 2024/07/30 14:53:15 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/10/08 15:26:44 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ast/ast.h"
|
||||
#include "gmr/field_identifiers.h"
|
||||
#include "gmr/symbols.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_ast.h"
|
||||
#include "parser/api.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void ast_free_condition(t_ast_node elem)
|
||||
|
|
|
|||
|
|
@ -1,129 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* arithmetic_node2.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/04 11:21:06 by rparodi #+# #+# */
|
||||
/* Updated: 2024/08/04 11:21:36 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ast/_from_node.h"
|
||||
#include "ast/ast.h"
|
||||
#include "gmr/field_identifiers.h"
|
||||
#include "gmr/field_identifiers.h"
|
||||
#include "gmr/symbols.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 check_error_ternary(t_node self, t_ast_node *out)
|
||||
{
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_child_count(self) != 5)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_arithmetic_ternary_expression)
|
||||
return (ERROR);
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_arithmetic_ternary_expression(\
|
||||
t_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_usize i;
|
||||
|
||||
if (check_error_ternary(self, out))
|
||||
return (ERROR);
|
||||
i = 0;
|
||||
ret = ast_alloc(AST_ARITHMETIC_TERNARY);
|
||||
while (i < ts_node_child_count(self))
|
||||
{
|
||||
if (ts_node_field_id_for_child(self, i) == field_cond)
|
||||
if (ast_from_node(ts_node_child(self, i), \
|
||||
input, &ret->data.arithmetic_ternary.condition))
|
||||
return (ast_free(ret), ERROR);
|
||||
if (ts_node_field_id_for_child(self, i) == field_then)
|
||||
if (ast_from_node(ts_node_child(self, i), \
|
||||
input, &ret->data.arithmetic_ternary.then))
|
||||
return (ast_free(ret), ERROR);
|
||||
if (ts_node_field_id_for_child(self, i) == field_else)
|
||||
if (ast_from_node(ts_node_child(self, i), \
|
||||
input, &ret->data.arithmetic_ternary.else_))
|
||||
return (ast_free(ret), ERROR);
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_arithmetic_unary_expression(\
|
||||
t_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_arithmetic_unary_expression)
|
||||
return (ERROR);
|
||||
if (ts_node_child_count(self) != 2)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_ARITHMETIC_UNARY);
|
||||
if (ts_node_field_id_for_child(self, 0) == field_op)
|
||||
ret->data.arithmetic_unary.operator = _parse_operator(\
|
||||
ts_node_child(self, 0));
|
||||
if (ast_from_node(ts_node_child(self, 1), \
|
||||
input, &ret->data.arithmetic_unary.value))
|
||||
return (ast_free(ret), ERROR);
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error arithmetic_choice(\
|
||||
t_node self, t_const_str input, t_ast_node *out, t_usize i)
|
||||
{
|
||||
if (ts_node_field_id_for_child(self, i) \
|
||||
== sym_arithmetic_binary_expression)
|
||||
return (build_sym_arithmetic_binary_expression(self, input, out));
|
||||
if (ts_node_field_id_for_child(self, i) == sym_arithmetic_literal)
|
||||
return (build_sym_arithmetic_literal(self, input, out));
|
||||
if (ts_node_field_id_for_child(self, i) \
|
||||
== sym_arithmetic_parenthesized_expression)
|
||||
return (build_sym_arithmetic_parenthesized_expression(\
|
||||
self, input, out));
|
||||
if (ts_node_field_id_for_child(self, i) \
|
||||
== sym_arithmetic_postfix_expression)
|
||||
return (build_sym_arithmetic_postfix_expression(self, input, out));
|
||||
if (ts_node_field_id_for_child(self, i) \
|
||||
== sym_arithmetic_ternary_expression)
|
||||
return (build_sym_arithmetic_ternary_expression(self, input, out));
|
||||
if (ts_node_field_id_for_child(self, i) \
|
||||
== sym_arithmetic_unary_expression)
|
||||
return (build_sym_arithmetic_unary_expression(self, input, out));
|
||||
return (ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_arithmetic_expansion(\
|
||||
t_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_usize i;
|
||||
t_ast_node ret;
|
||||
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_arithmetic_expansion)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_ARITHMETIC_EXPANSION);
|
||||
i = 0;
|
||||
while (i < ts_node_child_count(self))
|
||||
{
|
||||
if (arithmetic_choice(self, input, out, i))
|
||||
return (ERROR);
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
|
@ -1,128 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* artihmetic_node.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/04 11:07:59 by rparodi #+# #+# */
|
||||
/* Updated: 2024/08/04 11:21:25 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ast/_from_node.h"
|
||||
#include "ast/ast.h"
|
||||
#include "gmr/field_identifiers.h"
|
||||
#include "gmr/field_identifiers.h"
|
||||
#include "gmr/symbols.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_ast_arithmetic_operator _parse_operator(t_node self)
|
||||
{
|
||||
t_symbol symbol;
|
||||
|
||||
symbol = ts_node_grammar_symbol(self);
|
||||
if (symbol == anon_sym_PLUS)
|
||||
return (ARITH_PLUS);
|
||||
if (symbol == anon_sym_DASH)
|
||||
return (ARITH_MINUS);
|
||||
if (symbol == anon_sym_STAR)
|
||||
return (ARITH_MULT);
|
||||
if (symbol == anon_sym_SLASH)
|
||||
return (ARITH_DIVIDE);
|
||||
if (symbol == anon_sym_PERCENT)
|
||||
return (ARITH_MOD);
|
||||
if (symbol == anon_sym_PLUS_PLUS)
|
||||
return (ARITH_INCREMENT);
|
||||
if (symbol == anon_sym_DASH_DASH)
|
||||
return (ARITH_DECREMENT);
|
||||
if (symbol == anon_sym_BANG)
|
||||
return (ARITH_NOT);
|
||||
return (me_abort("invalid arithmetic operator"), 0);
|
||||
}
|
||||
|
||||
t_error build_sym_arithmetic_binary_expression(\
|
||||
t_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_usize i;
|
||||
t_ast_node ret;
|
||||
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_arithmetic_binary_expression)
|
||||
return (ERROR);
|
||||
i = 0;
|
||||
ret = ast_alloc(AST_ARITHMETIC_BINARY);
|
||||
while (i < ts_node_child_count(self))
|
||||
{
|
||||
if (ts_node_field_id_for_child(self, i) == field_lhs)
|
||||
if (ast_from_node(ts_node_child(self, i), \
|
||||
input, &ret->data.arithmetic_binary.lhs))
|
||||
return (ERROR);
|
||||
if (ts_node_field_id_for_child(self, i) == field_op)
|
||||
ret->data.arithmetic_binary.op = _parse_operator(\
|
||||
ts_node_child(self, i));
|
||||
if (ts_node_field_id_for_child(self, i) == field_rhs)
|
||||
if (ast_from_node(ts_node_child(self, i), \
|
||||
input, &ret->data.arithmetic_binary.rhs))
|
||||
return (ERROR);
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_arithmetic_literal(\
|
||||
t_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_usize i;
|
||||
t_ast_node ret;
|
||||
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_arithmetic_literal)
|
||||
return (ERROR);
|
||||
i = 0;
|
||||
ret = ast_alloc(AST_ARITHMETIC_LITTERAL);
|
||||
if (ast_from_node(\
|
||||
ts_node_child(self, i), input, &ret->data.arithmetic_literal.value))
|
||||
return (ERROR);
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_arithmetic_parenthesized_expression( \
|
||||
t_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_arithmetic_parenthesized_expression)
|
||||
return (ERROR);
|
||||
return (ast_from_node(ts_node_child(self, 1), input, out));
|
||||
}
|
||||
|
||||
t_error build_sym_arithmetic_postfix_expression(\
|
||||
t_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_arithmetic_postfix_expression)
|
||||
return (ERROR);
|
||||
if (ts_node_child_count(self) != 2)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_ARITHMETIC_POSTFIX);
|
||||
if (ast_from_node(ts_node_child(self, 0), \
|
||||
input, &ret->data.arithmetic_postfix.value))
|
||||
return (ast_free(ret), ERROR);
|
||||
if (ts_node_field_id_for_child(self, 1) == field_op)
|
||||
ret->data.arithmetic_postfix.op = _parse_operator(\
|
||||
ts_node_child(self, 1));
|
||||
else
|
||||
return (ast_free(ret), ERROR);
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
|
@ -1,188 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* boucle_node.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/06 18:43:35 by rparodi #+# #+# */
|
||||
/* Updated: 2024/09/15 20:11:43 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ast/_from_node.h"
|
||||
#include "ast/ast.h"
|
||||
#include "gmr/field_identifiers.h"
|
||||
#include "gmr/field_identifiers.h"
|
||||
#include "gmr/symbols.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_vec_ast *_append_scripting(\
|
||||
t_ast_node node)
|
||||
{
|
||||
if (node->kind == AST_WHILE)
|
||||
return (&node->data.while_.suffixes_redirections);
|
||||
if (node->kind == AST_FOR)
|
||||
return (&node->data.for_.suffixes_redirections);
|
||||
if (node->kind == AST_IF)
|
||||
return (&node->data.if_.suffixes_redirections);
|
||||
if (node->kind == AST_UNTIL)
|
||||
return (&node->data.until.suffixes_redirections);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
t_error build_sym_for_statement(\
|
||||
t_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_ast_node tmp;
|
||||
t_usize i;
|
||||
|
||||
if (out == NULL || ts_node_symbol(self) != sym_for_statement)
|
||||
return (ERROR);
|
||||
return (ERROR);
|
||||
(void)(i);
|
||||
(void)(ret);
|
||||
(void)(tmp);
|
||||
(void)(input);
|
||||
}
|
||||
|
||||
*/
|
||||
/*
|
||||
ret = ast_alloc(AST_FOR);
|
||||
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_var)
|
||||
ret->data.for_.var_name = \
|
||||
_extract_str(ts_node_child(self, i), input);
|
||||
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.for_.words, 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.for_.do_, tmp);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
*/
|
||||
/*
|
||||
|
||||
t_error build_sym_while_statement(\
|
||||
t_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_ast_node tmp;
|
||||
t_usize i;
|
||||
t_node child;
|
||||
t_ast_terminator_kind term;
|
||||
|
||||
if (out == NULL || ts_node_symbol(self) != sym_while_statement)
|
||||
return (ERROR);
|
||||
return (ERROR);
|
||||
(void)(child);
|
||||
(void)(i);
|
||||
(void)(ret);
|
||||
(void)(term);
|
||||
(void)(tmp);
|
||||
(void)(input);
|
||||
}
|
||||
|
||||
*/
|
||||
/*
|
||||
i = 0;
|
||||
if (ts_node_symbol(ts_node_child(self, 0)) == anon_sym_until)
|
||||
ret = ast_alloc(AST_UNTIL);
|
||||
else if (ts_node_symbol(ts_node_child(self, 0)) == anon_sym_while)
|
||||
ret = ast_alloc(AST_WHILE);
|
||||
else
|
||||
return (ERROR);
|
||||
while (i < ts_node_child_count(self))
|
||||
{
|
||||
child = ts_node_child(self, i);
|
||||
if (!ts_node_is_named(child) && (i++, true))
|
||||
continue ;
|
||||
if (ts_node_field_id_for_child(self, i) == field_term)
|
||||
{
|
||||
term = _select_term(ts_node_child(self, i));
|
||||
ast_set_term(\
|
||||
&ret->data.while_.condition.buffer[\
|
||||
ret->data.while_.condition.len - 1], term);
|
||||
i++;
|
||||
continue ;
|
||||
}
|
||||
if (ast_from_node(child, input, &tmp))
|
||||
return (ast_free(ret), ERROR);
|
||||
if (ts_node_field_id_for_child(self, i) == field_stmt)
|
||||
vec_ast_push(&ret->data.while_.condition, tmp);
|
||||
if (ts_node_field_id_for_child(self, i) == field_body)
|
||||
vec_ast_push(&ret->data.while_.do_, tmp);
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
*/
|
||||
/*
|
||||
|
||||
t_error build_sym_do_group(\
|
||||
t_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;
|
||||
|
||||
if (out == NULL || ts_node_symbol(self) != sym_do_group)
|
||||
return (ERROR);
|
||||
return (ERROR);
|
||||
(void)(i);
|
||||
(void)(ret);
|
||||
(void)(term);
|
||||
(void)(tmp);
|
||||
(void)(input);
|
||||
}
|
||||
*/
|
||||
/*
|
||||
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);
|
||||
}
|
||||
*/
|
||||
|
|
@ -1,186 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* condition_node.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/06 18:36:09 by rparodi #+# #+# */
|
||||
/* Updated: 2024/09/13 15:09:40 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ast/_from_node.h"
|
||||
#include "ast/ast.h"
|
||||
#include "gmr/field_identifiers.h"
|
||||
#include "gmr/field_identifiers.h"
|
||||
#include "gmr/symbols.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>
|
||||
|
||||
void ast_set_term(t_ast_node *node, t_ast_terminator_kind term)
|
||||
{
|
||||
t_ast_terminator_kind void_storage;
|
||||
t_ast_terminator_kind *ptr;
|
||||
t_ast_node val;
|
||||
|
||||
if (node == NULL)
|
||||
return ;
|
||||
val = *node;
|
||||
ptr = &void_storage;
|
||||
if (val->kind == AST_CASE)
|
||||
ptr = &val->data.case_.term;
|
||||
if (val->kind == AST_CASE_ITEM)
|
||||
ptr = &val->data.case_item.term;
|
||||
if (val->kind == AST_COMMAND)
|
||||
ptr = &val->data.command.term;
|
||||
if (val->kind == AST_COMPOUND_STATEMENT)
|
||||
ptr = &val->data.compound_statement.term;
|
||||
if (val->kind == AST_IF)
|
||||
ptr = &val->data.if_.term;
|
||||
if (val->kind == AST_SUBSHELL)
|
||||
ptr = &val->data.subshell.term;
|
||||
*ptr = term;
|
||||
}
|
||||
|
||||
t_error build_sym_if_statement(\
|
||||
t_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
(void)(self);
|
||||
(void)(input);
|
||||
(void)(out);
|
||||
return (ERROR);
|
||||
}
|
||||
/*
|
||||
t_node child;
|
||||
t_ast_node ret;
|
||||
t_ast_node tmp;
|
||||
t_usize i;
|
||||
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_if_statement)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_IF);
|
||||
i = 0;
|
||||
while (i < ts_node_child_count(self))
|
||||
{
|
||||
child = ts_node_child(self, i);
|
||||
if (!ts_node_is_named(child) && (i++, true))
|
||||
continue ;
|
||||
if (ts_node_field_id_for_child(self, i) == field_cond)
|
||||
{
|
||||
if (ast_from_node(child, input, &tmp))
|
||||
return (ast_free(ret), ERROR);
|
||||
vec_ast_push(&ret->data.if_.condition, tmp);
|
||||
}
|
||||
if (ts_node_field_id_for_child(self, i) == field_body)
|
||||
{
|
||||
if (ast_from_node(child, input, &tmp))
|
||||
return (ast_free(ret), ERROR);
|
||||
vec_ast_push(&ret->data.if_.then, tmp);
|
||||
}
|
||||
if (ts_node_field_id_for_child(self, i) == field_elif)
|
||||
{
|
||||
if (ast_from_node(child, input, &tmp))
|
||||
return (ast_free(ret), ERROR);
|
||||
vec_ast_push(&ret->data.if_.elif_, tmp);
|
||||
}
|
||||
if (ts_node_field_id_for_child(self, i) == field_else)
|
||||
{
|
||||
if (ast_from_node(child, input, &tmp))
|
||||
return (ast_free(ret), ERROR);
|
||||
ret->data.if_.else_ = tmp;
|
||||
}
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
*/
|
||||
|
||||
t_error build_sym_elif_clause(\
|
||||
t_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
(void)(self);
|
||||
(void)(input);
|
||||
(void)(out);
|
||||
return (ERROR);
|
||||
}
|
||||
/*
|
||||
t_ast_node ret;
|
||||
t_ast_node tmp;
|
||||
t_usize i;
|
||||
t_node child;
|
||||
|
||||
(void)(out);
|
||||
(void)(input);
|
||||
(void)(self);
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_elif_clause)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_ELIF);
|
||||
i = 0;
|
||||
while (i < ts_node_child_count(self))
|
||||
{
|
||||
child = ts_node_child(self, i);
|
||||
if (!ts_node_is_named(child) && (i++, true))
|
||||
continue ;
|
||||
if (ts_node_field_id_for_child(self, i) == field_cond)
|
||||
{
|
||||
if (ast_from_node(child, input, &tmp))
|
||||
return (ast_free(ret), ERROR);
|
||||
vec_ast_push(&ret->data.elif.condition, tmp);
|
||||
}
|
||||
if (ts_node_field_id_for_child(self, i) == field_body)
|
||||
{
|
||||
if (ast_from_node(child, input, &tmp))
|
||||
return (ast_free(ret), ERROR);
|
||||
vec_ast_push(&ret->data.elif.then, tmp);
|
||||
}
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
*/
|
||||
|
||||
t_error build_sym_else_clause(\
|
||||
t_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
(void)(self);
|
||||
(void)(input);
|
||||
(void)(out);
|
||||
return (ERROR);
|
||||
}
|
||||
/*
|
||||
t_ast_node ret;
|
||||
t_ast_node tmp;
|
||||
t_usize i;
|
||||
t_node child;
|
||||
|
||||
(void)(out);
|
||||
(void)(input);
|
||||
(void)(self);
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_else_clause)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_ELSE);
|
||||
i = 0;
|
||||
while (i < ts_node_child_count(self))
|
||||
{
|
||||
child = ts_node_child(self, i);
|
||||
if (!ts_node_is_named(child) && (i++, true))
|
||||
continue ;
|
||||
if (ts_node_field_id_for_child(self, i) == field_body)
|
||||
{
|
||||
if (ast_from_node(child, input, &tmp))
|
||||
return (ast_free(ret), ERROR);
|
||||
vec_ast_push(&ret->data.else_.then, tmp);
|
||||
}
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
*/
|
||||
|
|
@ -1,114 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* dev_node.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/09 15:07:10 by rparodi #+# #+# */
|
||||
/* Updated: 2024/09/20 16:38:57 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_negated_command(\
|
||||
t_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
|
||||
(void)(out);
|
||||
(void)(input);
|
||||
(void)(self);
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_negated_command)
|
||||
return (ERROR);
|
||||
if (ts_node_child_count(self) != 1)
|
||||
return (ERROR);
|
||||
if (ast_from_node(ts_node_child(self, 1), input, &ret))
|
||||
return (ERROR);
|
||||
_add_negation(&ret);
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_pipeline(\
|
||||
t_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_ast_node t[2];
|
||||
t_usize i;
|
||||
|
||||
if (out == NULL || ts_node_symbol(self) != sym_pipeline)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_PIPELINE);
|
||||
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, &t[0]))
|
||||
return (ast_free(ret), ERROR);
|
||||
if (t[0]->kind == AST_PIPELINE)
|
||||
{
|
||||
while (!vec_ast_pop_front(&t[0]->data.pipeline.statements, &t[1]))
|
||||
vec_ast_push(&ret->data.pipeline.statements, t[1]);
|
||||
ast_free(t[0]);
|
||||
}
|
||||
else
|
||||
vec_ast_push(&ret->data.pipeline.statements, t[0]);
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_comment(t_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
(void)(out);
|
||||
(void)(input);
|
||||
(void)(self);
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_comment)
|
||||
return (ERROR);
|
||||
*out = ast_alloc(AST_EMPTY);
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_variable_assignment(\
|
||||
t_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_node temp_ast;
|
||||
|
||||
(void)(self);
|
||||
(void)(input);
|
||||
(void)(out);
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_variable_assignment)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_VARIABLE_ASSIGNMENT);
|
||||
if (ts_node_child_count(self) >= 2)
|
||||
{
|
||||
temp_ast = ts_node_child(self, 0);
|
||||
if (ts_node_symbol(temp_ast) != sym_variable_name)
|
||||
return (ast_free(ret), ERROR);
|
||||
ret->data.variable_assignment.name = _extract_str(temp_ast, input);
|
||||
}
|
||||
if (ts_node_child_count(self) > 2)
|
||||
{
|
||||
if (ast_from_node(ts_node_child(\
|
||||
self, 2), input, &ret->data.variable_assignment.value))
|
||||
return (ast_free(ret), ERROR);
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
|
@ -1,127 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* exec_node.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/02 17:33:20 by rparodi #+# #+# */
|
||||
/* Updated: 2024/09/13 15:25:45 by maiboyer ### ########.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>
|
||||
|
||||
/*
|
||||
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
|
||||
*/
|
||||
|
||||
t_error build_sym_compound_statement(\
|
||||
t_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_ast_node tmp;
|
||||
t_usize i;
|
||||
|
||||
if (out == NULL || 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_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);
|
||||
}
|
||||
/*
|
||||
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)));
|
||||
}
|
||||
*/
|
||||
|
||||
t_error build_sym_program(t_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_usize i;
|
||||
t_ast_node temp;
|
||||
|
||||
if (out == NULL || 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);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_command_name(\
|
||||
t_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_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);
|
||||
}
|
||||
|
|
@ -1,134 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* expansion_node.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/06 18:26:15 by rparodi #+# #+# */
|
||||
/* Updated: 2024/09/13 14:56:19 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ast/_from_node.h"
|
||||
#include "ast/ast.h"
|
||||
#include "gmr/field_identifiers.h"
|
||||
#include "gmr/field_identifiers.h"
|
||||
#include "gmr/symbols.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>
|
||||
|
||||
void _build_sym_command_substitution_inner(\
|
||||
t_node self, t_const_str input, t_ast_node ret, t_usize i);
|
||||
void _build_sym_expansion_inner(\
|
||||
t_node self, t_const_str input, t_ast_node ret, t_usize i);
|
||||
|
||||
t_error build_sym_regex(\
|
||||
t_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_regex)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_REGEX);
|
||||
ret->data.regex.pattern = _extract_str(self, input);
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_extglob_pattern(\
|
||||
t_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_extglob_pattern)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_EXTGLOB);
|
||||
ret->data.extglob.pattern = _extract_str(self, input);
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_expansion(\
|
||||
t_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_ast_node tmp;
|
||||
t_usize i;
|
||||
|
||||
if (out == NULL || ts_node_symbol(self) != sym_expansion)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_EXPANSION);
|
||||
ret->data.expansion.kind = E_OP_NONE;
|
||||
i = 0;
|
||||
while (i < ts_node_child_count(self))
|
||||
{
|
||||
if (!ts_node_is_named(ts_node_child(self, i)) && (i++, true))
|
||||
continue ;
|
||||
_build_sym_expansion_inner(self, input, ret, i);
|
||||
if (ts_node_field_id_for_child(self, i) == field_args)
|
||||
{
|
||||
if (ast_from_node(ts_node_child(self, i), input, &tmp))
|
||||
return (ast_free(ret), ERROR);
|
||||
vec_ast_push(&ret->data.expansion.args, tmp);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_simple_expansion(\
|
||||
t_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_usize i;
|
||||
|
||||
if (out == NULL || ts_node_symbol(self) != sym_simple_expansion)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_EXPANSION);
|
||||
ret->data.expansion.kind = E_OP_NONE;
|
||||
i = 0;
|
||||
while (i < ts_node_child_count(self))
|
||||
{
|
||||
if (!ts_node_is_named(ts_node_child(self, i)) && (i++, true))
|
||||
continue ;
|
||||
ret->data.expansion.var_name = \
|
||||
_extract_str(ts_node_child(self, i), input);
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_command_substitution(\
|
||||
t_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_ast_node tmp;
|
||||
t_usize i;
|
||||
|
||||
if ((out == NULL) || 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)
|
||||
_build_sym_command_substitution_inner(self, input, ret, 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);
|
||||
}
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* file_node.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/09 16:25:02 by rparodi #+# #+# */
|
||||
/* Updated: 2024/09/02 11:37:38 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ast/_from_node.h"
|
||||
#include "ast/ast.h"
|
||||
#include "gmr/field_identifiers.h"
|
||||
#include "gmr/field_identifiers.h"
|
||||
#include "gmr/symbols.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_number(\
|
||||
t_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
|
||||
(void)(out);
|
||||
(void)(input);
|
||||
(void)(self);
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_number)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_RAW_STRING);
|
||||
ret->data.raw_string.str = _extract_str(self, input);
|
||||
ret->data.raw_string.len = str_len(ret->data.raw_string.str);
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_file_descriptor(\
|
||||
t_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
|
||||
(void)(out);
|
||||
(void)(input);
|
||||
(void)(self);
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(self) != sym_file_descriptor)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_RAW_STRING);
|
||||
ret->data.raw_string.str = _extract_str(self, input);
|
||||
ret->data.raw_string.len = str_len(ret->data.raw_string.str);
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
|
@ -1,132 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* from_node.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/26 10:55:52 by rparodi #+# #+# */
|
||||
/* Updated: 2024/09/16 13:49:34 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 ast_from_node(t_node node, t_const_str input, t_ast_node *out);
|
||||
|
||||
// if (ts_node_symbol(node) == sym_while_statement)
|
||||
// return (build_sym_while_statement(node, input, out));
|
||||
t_error _from_node_inner3(\
|
||||
t_node node, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
if (ts_node_symbol(node) == sym_pipeline)
|
||||
return (build_sym_pipeline(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_program)
|
||||
return (build_sym_program(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_raw_string)
|
||||
return (build_sym_raw_string(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_redirected_statement)
|
||||
return (build_sym_redirected_statement(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_regex)
|
||||
return (build_sym_regex(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_simple_expansion)
|
||||
return (build_sym_simple_expansion(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_string)
|
||||
return (build_sym_string(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_string_content)
|
||||
return (build_sym_string_content(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_subshell)
|
||||
return (build_sym_subshell(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_variable_assignment)
|
||||
return (build_sym_variable_assignment(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_word)
|
||||
return (build_sym_word(node, input, out));
|
||||
return (ERROR);
|
||||
}
|
||||
|
||||
// if (ts_node_symbol(node) == sym_for_statement)
|
||||
// return (build_sym_for_statement(node, input, out));
|
||||
// if (ts_node_symbol(node) == sym_function_definition)
|
||||
// return (build_sym_function_definition(node, input, out));
|
||||
// if (ts_node_symbol(node) == sym_if_statement)
|
||||
// return (build_sym_if_statement(node, input, out));
|
||||
t_error _from_node_inner2(\
|
||||
t_node node, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
if (ts_node_symbol(node) == sym_extglob_pattern)
|
||||
return (build_sym_extglob_pattern(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_file_descriptor)
|
||||
return (build_sym_file_descriptor(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_file_redirect)
|
||||
return (build_sym_file_redirect(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_heredoc_redirect)
|
||||
return (build_sym_heredoc_redirect(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_list)
|
||||
return (build_sym_list(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_negated_command)
|
||||
return (build_sym_negated_command(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_number)
|
||||
return (build_sym_number(node, input, out));
|
||||
return (_from_node_inner3(node, input, out));
|
||||
}
|
||||
|
||||
// if (ts_node_symbol(node) == sym_do_group)
|
||||
// return (build_sym_do_group(node, input, out));
|
||||
// if (ts_node_symbol(node) == sym_elif_clause)
|
||||
// return (build_sym_elif_clause(node, input, out));
|
||||
// if (ts_node_symbol(node) == sym_else_clause)
|
||||
// return (build_sym_else_clause(node, input, out));
|
||||
t_error _from_node_inner(\
|
||||
t_node node, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
if (ts_node_symbol(node) == sym_command)
|
||||
return (build_sym_command(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_command_name)
|
||||
return (build_sym_command_name(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_command_substitution)
|
||||
return (build_sym_command_substitution(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_comment)
|
||||
return (build_sym_comment(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_compound_statement)
|
||||
return (build_sym_compound_statement(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_concatenation)
|
||||
return (build_sym_concatenation(node, input, out));
|
||||
if (ts_node_symbol(node) == sym_expansion)
|
||||
return (build_sym_expansion(node, input, out));
|
||||
return (_from_node_inner2(node, input, out));
|
||||
}
|
||||
|
||||
// else if (ts_node_symbol(node) == sym_case_item)
|
||||
// return (build_sym_case_item(node, input, out));
|
||||
// else if (ts_node_symbol(node) == sym_case_statement)
|
||||
// return (build_sym_case_statement(node, input, out));
|
||||
t_error ast_from_node(\
|
||||
t_node node, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
if (out == NULL)
|
||||
return (ERROR);
|
||||
if (ts_node_symbol(node) == sym_arithmetic_binary_expression)
|
||||
return (build_sym_arithmetic_binary_expression(node, input, out));
|
||||
else if (ts_node_symbol(node) == sym_arithmetic_expansion)
|
||||
return (build_sym_arithmetic_expansion(node, input, out));
|
||||
else if (ts_node_symbol(node) == sym_arithmetic_literal)
|
||||
return (build_sym_arithmetic_literal(node, input, out));
|
||||
else if (ts_node_symbol(node) == sym_arithmetic_parenthesized_expression)
|
||||
return (build_sym_arithmetic_parenthesized_expression(\
|
||||
node, input, out));
|
||||
else if (ts_node_symbol(node) == sym_arithmetic_postfix_expression)
|
||||
return (build_sym_arithmetic_postfix_expression(node, input, out));
|
||||
else if (ts_node_symbol(node) == sym_arithmetic_ternary_expression)
|
||||
return (build_sym_arithmetic_ternary_expression(node, input, out));
|
||||
else if (ts_node_symbol(node) == sym_arithmetic_unary_expression)
|
||||
return (build_sym_arithmetic_unary_expression(node, input, out));
|
||||
return (_from_node_inner(node, input, out));
|
||||
}
|
||||
|
|
@ -1,112 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* node_utils.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/04 10:55:45 by rparodi #+# #+# */
|
||||
/* Updated: 2024/08/14 18:29:10 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ast/_from_node.h"
|
||||
#include "ast/ast.h"
|
||||
#include "gmr/field_identifiers.h"
|
||||
#include "gmr/field_identifiers.h"
|
||||
#include "gmr/symbols.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_ast_expansion_operator _extract_exp_fix(t_node self)
|
||||
{
|
||||
t_ast_expansion_operator kind;
|
||||
t_symbol symbol;
|
||||
|
||||
kind = E_OP_NONE;
|
||||
symbol = ts_node_grammar_symbol(self);
|
||||
if (symbol == anon_sym_POUND)
|
||||
kind = E_OP_SMALLEST_PREFIX;
|
||||
if (symbol == sym__immediate_double_hash)
|
||||
kind = E_OP_LARGEST_PREFIX;
|
||||
if (symbol == anon_sym_PERCENT)
|
||||
kind = E_OP_SMALLEST_SUFFIX;
|
||||
if (symbol == anon_sym_PERCENT_PERCENT)
|
||||
kind = E_OP_LARGEST_SUFFIX;
|
||||
return (kind);
|
||||
}
|
||||
|
||||
t_ast_expansion_operator _extract_exp_op(t_node self)
|
||||
{
|
||||
t_ast_expansion_operator kind;
|
||||
t_symbol symbol;
|
||||
|
||||
symbol = ts_node_grammar_symbol(self);
|
||||
if (symbol == anon_sym_DASH)
|
||||
kind = E_OP_DEFAULT;
|
||||
else if (symbol == anon_sym_EQ)
|
||||
kind = E_OP_ASSIGN_DEFAULT;
|
||||
else if (symbol == anon_sym_QMARK)
|
||||
kind = E_OP_ERROR;
|
||||
else if (symbol == anon_sym_PLUS)
|
||||
kind = E_OP_ALTERNATE;
|
||||
else if (symbol == anon_sym_COLON_DASH)
|
||||
kind = E_OP_DEFAULT_COLON;
|
||||
else if (symbol == anon_sym_COLON_EQ)
|
||||
kind = E_OP_ASSIGN_DEFAULT_COLON;
|
||||
else if (symbol == anon_sym_COLON_QMARK)
|
||||
kind = E_OP_ERROR_COLON;
|
||||
else if (symbol == anon_sym_COLON_PLUS)
|
||||
kind = E_OP_ALTERNATE_COLON;
|
||||
else
|
||||
kind = _extract_exp_fix(self);
|
||||
return (kind);
|
||||
}
|
||||
|
||||
t_vec_ast *_vec_command(t_ast_command *val, t_usize i)
|
||||
{
|
||||
if (i == 0)
|
||||
return (&val->prefixes);
|
||||
if (i == 1)
|
||||
return (&val->cmd_word);
|
||||
if (i == 2)
|
||||
return (&val->suffixes_redirections);
|
||||
me_abort("invalid index for i in _get_vec_command");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
void _add_negation(t_ast_node *node)
|
||||
{
|
||||
if (node == NULL || *node == NULL)
|
||||
return ;
|
||||
if ((*node)->kind == AST_PIPELINE)
|
||||
(*node)->data.pipeline.bang = true;
|
||||
if ((*node)->kind == AST_COMMAND)
|
||||
(*node)->data.command.bang = true;
|
||||
if ((*node)->kind == AST_SUBSHELL)
|
||||
(*node)->data.subshell.bang = true;
|
||||
if ((*node)->kind == AST_COMPOUND_STATEMENT)
|
||||
(*node)->data.compound_statement.bang = true;
|
||||
if ((*node)->kind == AST_VARIABLE_ASSIGNMENT)
|
||||
(*node)->data.variable_assignment.bang = true;
|
||||
}
|
||||
|
||||
t_ast_redirection_kind _get_redirection_op(t_node self)
|
||||
{
|
||||
t_symbol symbol;
|
||||
|
||||
symbol = ts_node_grammar_symbol(self);
|
||||
if (symbol == anon_sym_LT)
|
||||
return (AST_REDIR_INPUT);
|
||||
if (symbol == anon_sym_GT)
|
||||
return (AST_REDIR_OUTPUT);
|
||||
if (symbol == anon_sym_GT_GT)
|
||||
return (AST_REDIR_APPEND);
|
||||
if (symbol == anon_sym_LT_LT)
|
||||
return (AST_REDIR_HEREDOC);
|
||||
return (me_abort("invalid redirection symbol"), 0);
|
||||
}
|
||||
|
|
@ -1,104 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* node_utils2.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/06 18:27:48 by rparodi #+# #+# */
|
||||
/* Updated: 2024/09/15 20:21:18 by maiboyer ### ########.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>
|
||||
|
||||
// else
|
||||
// *vec = _append_scripting(node);
|
||||
void _append_redirection_single(t_ast_node node, t_vec_ast **vec)
|
||||
{
|
||||
if (node->kind == AST_CASE)
|
||||
*vec = &node->data.case_.suffixes_redirections;
|
||||
else if (node->kind == AST_COMMAND)
|
||||
*vec = &node->data.command.suffixes_redirections;
|
||||
else if (node->kind == AST_COMPOUND_STATEMENT)
|
||||
*vec = &node->data.compound_statement.suffixes_redirections;
|
||||
else if (node->kind == AST_SUBSHELL)
|
||||
*vec = &node->data.subshell.suffixes_redirections;
|
||||
}
|
||||
|
||||
void _append_redirection(t_ast_node node, t_ast_node redirection)
|
||||
{
|
||||
t_vec_ast *vec;
|
||||
|
||||
vec = NULL;
|
||||
if (node == NULL || redirection == NULL || \
|
||||
!(redirection->kind == AST_FILE_REDIRECTION || \
|
||||
redirection->kind == AST_HEREDOC_REDIRECTION))
|
||||
return (ast_free(redirection));
|
||||
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));
|
||||
else
|
||||
_append_redirection_single(node, &vec);
|
||||
if (vec != NULL)
|
||||
vec_ast_push(vec, redirection);
|
||||
else
|
||||
(ast_free(redirection));
|
||||
}
|
||||
|
||||
//// hello I am the SEGV police and I sized this code
|
||||
//
|
||||
// t_symbol symbol;
|
||||
//
|
||||
// symbol = ts_node_grammar_symbol(ts_node_child(node, 0));
|
||||
// if (symbol == anon_sym_SEMI)
|
||||
// return (AST_TERM_SEMI);
|
||||
// if (symbol == anon_sym_SEMI_SEMI)
|
||||
// return (AST_TERM_DOUBLE_SEMI);
|
||||
// printf("unknown term symbol %d\n", symbol);
|
||||
t_ast_terminator_kind _select_term(t_node node)
|
||||
{
|
||||
(void)(node);
|
||||
return (AST_TERM_NONE);
|
||||
}
|
||||
|
||||
t_str _extract_str(t_node self, t_const_str input)
|
||||
{
|
||||
t_usize start;
|
||||
t_usize end;
|
||||
t_str result;
|
||||
|
||||
start = ts_node_start_byte(self);
|
||||
end = ts_node_end_byte(self);
|
||||
result = str_substring(input, start, end - start);
|
||||
return (result);
|
||||
}
|
||||
|
||||
/*
|
||||
E_OP_NONE = 0, // ${var}
|
||||
E_OP_DEFAULT, // ${var-word}
|
||||
E_OP_ASSIGN_DEFAULT, // ${var=word}
|
||||
E_OP_ERROR, // ${var?word}
|
||||
E_OP_ALTERNATE, // ${var+word}
|
||||
E_OP_DEFAULT_COLON, // ${var:-word}
|
||||
E_OP_ASSIGN_DEFAULT_COLON, // ${var:=word}
|
||||
E_OP_ERROR_COLON, // ${var:?word}
|
||||
E_OP_ALTERNATE_COLON, // ${var:+word}
|
||||
E_OP_LENGTH, // ${#var}
|
||||
E_OP_SMALLEST_PREFIX, // ${var#pattern}
|
||||
E_OP_LARGEST_PREFIX, // ${var##pattern}
|
||||
E_OP_SMALLEST_SUFFIX, // ${var%pattern}
|
||||
E_OP_LARGEST_SUFFIX, // ${var%%pattern}
|
||||
*/
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* node_utils3.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/13 14:54:21 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/13 14:57:34 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ast/_from_node.h"
|
||||
#include "ast/ast.h"
|
||||
#include "gmr/field_identifiers.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_ast.h"
|
||||
#include "parser/api.h"
|
||||
|
||||
void _build_sym_expansion_inner(\
|
||||
t_node self, t_const_str input, t_ast_node ret, t_usize i)
|
||||
{
|
||||
if (ts_node_field_id_for_child(self, i) == field_len)
|
||||
ret->data.expansion.len_operator = true;
|
||||
if (ts_node_field_id_for_child(self, i) == field_name)
|
||||
ret->data.expansion.var_name = \
|
||||
_extract_str(ts_node_child(self, i), input);
|
||||
if (ts_node_field_id_for_child(self, i) == field_op)
|
||||
ret->data.expansion.kind = _extract_exp_op(ts_node_child(self, i));
|
||||
}
|
||||
|
||||
void _build_sym_command_substitution_inner(\
|
||||
t_node self, t_const_str input, t_ast_node ret, t_usize i)
|
||||
{
|
||||
(void)(input);
|
||||
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)));
|
||||
}
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* other_node.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/13 15:03:03 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/13 15:26:05 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ast/ast.h"
|
||||
#include "gmr/symbols.h"
|
||||
#include "gmr/field_identifiers.h"
|
||||
#include "parser/api.h"
|
||||
#include "ast/_from_node.h"
|
||||
|
||||
static void _set_op_list(\
|
||||
t_node self, t_ast_node **output, t_ast_node ret, t_usize i)
|
||||
{
|
||||
t_symbol temp;
|
||||
|
||||
temp = ts_node_grammar_symbol(ts_node_child(self, i));
|
||||
if (temp == anon_sym_PIPE_PIPE)
|
||||
ret->data.list.op = AST_LIST_OR;
|
||||
if (temp == anon_sym_AMP_AMP)
|
||||
ret->data.list.op = AST_LIST_AND;
|
||||
*output = &ret->data.list.right;
|
||||
}
|
||||
|
||||
t_error build_sym_list(t_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_ast_node *output;
|
||||
t_usize i;
|
||||
|
||||
if (out == NULL || ts_node_symbol(self) == sym_list)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_LIST);
|
||||
i = 0;
|
||||
output = &ret->data.list.left;
|
||||
while (i < ts_node_child_count(self))
|
||||
{
|
||||
if (ts_node_field_id_for_child(self, i) == field_cmd)
|
||||
{
|
||||
if (ast_from_node(ts_node_child(self, i), input, output))
|
||||
return (ast_free(ret), ERROR);
|
||||
}
|
||||
else if (ts_node_field_id_for_child(self, i) == field_op)
|
||||
_set_op_list(self, &output, ret, i);
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_subshell(\
|
||||
t_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node ret;
|
||||
t_ast_node tmp;
|
||||
t_usize i;
|
||||
|
||||
if (out == NULL || ts_node_symbol(self) != sym_subshell)
|
||||
return (ERROR);
|
||||
ret = ast_alloc(AST_SUBSHELL);
|
||||
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, &tmp))
|
||||
return (ast_free(ret), ERROR);
|
||||
vec_ast_push(&ret->data.subshell.body, tmp);
|
||||
i++;
|
||||
}
|
||||
return (*out = ret, NO_ERROR);
|
||||
}
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* redirect_node.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/06 18:45:21 by rparodi #+# #+# */
|
||||
/* Updated: 2024/09/13 14:37:44 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ast/_from_node.h"
|
||||
#include "ast/ast.h"
|
||||
#include "gmr/field_identifiers.h"
|
||||
#include "gmr/field_identifiers.h"
|
||||
#include "gmr/symbols.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_file_redirect(\
|
||||
t_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node n[2];
|
||||
t_usize i;
|
||||
|
||||
if (out == NULL || ts_node_symbol(self) != sym_file_redirect)
|
||||
return (ERROR);
|
||||
n[0] = ast_alloc(AST_FILE_REDIRECTION);
|
||||
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_op)
|
||||
{
|
||||
n[0]->data.file_redirection.op = \
|
||||
_get_redirection_op(ts_node_child(self, i));
|
||||
}
|
||||
if (ts_node_field_id_for_child(self, i) == field_dest)
|
||||
{
|
||||
if (ast_from_node(ts_node_child(self, i), input, &n[1]))
|
||||
return (ast_free(n[0]), ERROR);
|
||||
n[0]->data.file_redirection.output = n[1];
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (*out = n[0], NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_sym_redirected_statement(\
|
||||
t_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
t_ast_node n[3];
|
||||
t_usize i;
|
||||
|
||||
if (out == NULL || ts_node_symbol(self) != sym_redirected_statement)
|
||||
return (ERROR);
|
||||
i = 0;
|
||||
n[1] = ast_alloc(AST_COMMAND);
|
||||
n[0] = n[1];
|
||||
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)) == sym_file_redirect || \
|
||||
ts_node_symbol(ts_node_child(self, i)) == sym_heredoc_redirect))
|
||||
{
|
||||
if (ast_from_node(ts_node_child(self, i++), input, &n[1]))
|
||||
return (ast_free(n[0]), ERROR);
|
||||
continue ;
|
||||
}
|
||||
if (ast_from_node(ts_node_child(self, i++), input, &n[2]))
|
||||
return ((void)((n[1] != n[0]) \
|
||||
&& (ast_free(n[0]), true)), ast_free(n[1]), ERROR);
|
||||
_append_redirection(n[1], n[2]);
|
||||
}
|
||||
return ((void)(n[1] != n[0] && (ast_free(n[0]), true)), *out = n[1], 0);
|
||||
}
|
||||
|
|
@ -1,194 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* scripting_node.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/06 18:34:12 by rparodi #+# #+# */
|
||||
/* Updated: 2024/09/13 15:10:16 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ast/_from_node.h"
|
||||
#include "ast/ast.h"
|
||||
#include "gmr/field_identifiers.h"
|
||||
#include "gmr/field_identifiers.h"
|
||||
#include "gmr/symbols.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_function_definition(\
|
||||
t_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
(void)(self);
|
||||
(void)(input);
|
||||
(void)(out);
|
||||
return (ERROR);
|
||||
}
|
||||
/*
|
||||
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_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 = \
|
||||
_extract_str(ts_node_child(self, i), input);
|
||||
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_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
(void)(self);
|
||||
(void)(input);
|
||||
(void)(out);
|
||||
return (ERROR);
|
||||
}
|
||||
/*
|
||||
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_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_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
(void)(self);
|
||||
(void)(input);
|
||||
(void)(out);
|
||||
return (ERROR);
|
||||
}
|
||||
/*
|
||||
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_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_node self, t_const_str input, t_ast_node *out)
|
||||
{
|
||||
(void)(self);
|
||||
(void)(input);
|
||||
(void)(out);
|
||||
return (ERROR);
|
||||
}
|
||||
/*
|
||||
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_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);
|
||||
}
|
||||
*/
|
||||
|
|
@ -1,141 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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_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_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_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_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_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);
|
||||
}
|
||||
|
|
@ -6,13 +6,14 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/07 18:04:13 by rparodi #+# #+# */
|
||||
/* Updated: 2024/10/08 15:04:28 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/10/08 15:32:12 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_token.h"
|
||||
#include "parser/token.h"
|
||||
#include "ast/ast.h"
|
||||
#include <stdio.h>
|
||||
|
||||
int _get_precedance(t_token *token)
|
||||
|
|
@ -27,25 +28,28 @@ int _get_precedance(t_token *token)
|
|||
}
|
||||
t_str token_name(t_token *token);
|
||||
|
||||
t_error yarn(t_vec_token ts, t_vec_token *out)
|
||||
t_ast_node ast_from_cmd(t_token tok);
|
||||
t_ast_node ast_from_op(t_token tok, t_vec_ast *out);
|
||||
|
||||
t_error yarn(t_vec_token ts, t_vec_ast *out)
|
||||
{
|
||||
t_token tmp;
|
||||
t_token tmp2;
|
||||
t_vec_token output_queue;
|
||||
t_token op;
|
||||
t_vec_ast output_queue;
|
||||
t_vec_token operator_stack;
|
||||
|
||||
output_queue = vec_token_new(16, token_free);;
|
||||
output_queue = vec_ast_new(16, ast_free);;
|
||||
operator_stack = vec_token_new(16, token_free);;
|
||||
while (!vec_token_pop_front(&ts, &tmp))
|
||||
{
|
||||
if (tmp.type == TOK_CMD)
|
||||
vec_token_push(&output_queue, tmp);
|
||||
vec_ast_push(&output_queue, ast_from_cmd(tmp));
|
||||
else if (tmp.type == TOK_OR || tmp.type == TOK_AND || tmp.type == TOK_PIPE)
|
||||
{
|
||||
while (vec_token_last(&operator_stack) != NULL && vec_token_last(&operator_stack)->type != TOK_LPAREN && _get_precedance(vec_token_last(&operator_stack)) > _get_precedance(&tmp))
|
||||
{
|
||||
vec_token_pop(&operator_stack, &tmp2);
|
||||
vec_token_push(&output_queue, tmp2);
|
||||
vec_token_pop(&operator_stack, &op);
|
||||
vec_ast_push(&output_queue, ast_from_op(op, &output_queue));
|
||||
}
|
||||
vec_token_push(&operator_stack, tmp);
|
||||
}
|
||||
|
|
@ -56,8 +60,8 @@ t_error yarn(t_vec_token ts, t_vec_token *out)
|
|||
token_free(tmp);
|
||||
while (vec_token_last(&operator_stack) != NULL && vec_token_last(&operator_stack)->type != TOK_LPAREN)
|
||||
{
|
||||
vec_token_pop(&operator_stack, &tmp2);
|
||||
vec_token_push(&output_queue, tmp2);
|
||||
vec_token_pop(&operator_stack, &op);
|
||||
vec_ast_push(&output_queue, ast_from_op(op, &output_queue));
|
||||
}
|
||||
if (!(vec_token_last(&operator_stack) != NULL && vec_token_last(&operator_stack)->type == TOK_LPAREN))
|
||||
return (ERROR);
|
||||
|
|
@ -65,11 +69,11 @@ t_error yarn(t_vec_token ts, t_vec_token *out)
|
|||
token_free(tmp);
|
||||
}
|
||||
}
|
||||
while (!vec_token_pop(&operator_stack, &tmp))
|
||||
while (!vec_token_pop(&operator_stack, &op))
|
||||
{
|
||||
if (tmp.type == TOK_LPAREN)
|
||||
if (op.type == TOK_LPAREN)
|
||||
return (token_free(tmp), ERROR);
|
||||
vec_token_push(&output_queue, tmp);
|
||||
vec_ast_push(&output_queue, ast_from_op(op, &output_queue));
|
||||
}
|
||||
vec_token_free(ts);
|
||||
vec_token_free(operator_stack);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue