Updated to support heredocs
This commit is contained in:
parent
92823aff80
commit
980cae5597
5 changed files with 42 additions and 202 deletions
|
|
@ -11,67 +11,34 @@
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "app/node.h"
|
#include "app/node.h"
|
||||||
|
#include "ast/_from_node.h"
|
||||||
#include "ast/ast.h"
|
#include "ast/ast.h"
|
||||||
#include "gmr/symbols.h"
|
#include "gmr/symbols.h"
|
||||||
|
#include "gmr/field_identifiers.h"
|
||||||
|
#include "me/str/str.h"
|
||||||
#include "me/types.h"
|
#include "me/types.h"
|
||||||
|
#include "parser/api.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
t_error build_sym_heredoc_body(t_parse_node self, t_const_str input, \
|
|
||||||
t_ast_node *out)
|
|
||||||
{
|
|
||||||
printf("This function is not done '%s'", __func__);
|
|
||||||
(void)(self);
|
|
||||||
(void)(input);
|
|
||||||
(void)(out);
|
|
||||||
return (ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
t_error build_sym_heredoc_content(t_parse_node self, t_const_str input, \
|
|
||||||
t_ast_node *out)
|
|
||||||
{
|
|
||||||
printf("This function is not done '%s'", __func__);
|
|
||||||
(void)(self);
|
|
||||||
(void)(input);
|
|
||||||
(void)(out);
|
|
||||||
return (ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
t_error build_sym_heredoc_end(t_parse_node self, t_const_str input, \
|
|
||||||
t_ast_node *out)
|
|
||||||
{
|
|
||||||
printf("This function is not done '%s'", __func__);
|
|
||||||
(void)(self);
|
|
||||||
(void)(input);
|
|
||||||
(void)(out);
|
|
||||||
return (ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
t_error build_sym_heredoc_redirect(t_parse_node self, t_const_str input, \
|
t_error build_sym_heredoc_redirect(t_parse_node self, t_const_str input, \
|
||||||
t_ast_node *out)
|
t_ast_node *out)
|
||||||
{
|
{
|
||||||
printf("This function is not done '%s'", __func__);
|
t_ast_node ret;
|
||||||
(void)(self);
|
t_usize i;
|
||||||
(void)(input);
|
|
||||||
(void)(out);
|
|
||||||
return (ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
t_error build_sym_heredoc_start(t_parse_node self, t_const_str input, \
|
if (ts_node_symbol(self) != sym_heredoc_redirect || input == NULL || out == NULL)
|
||||||
t_ast_node *out)
|
|
||||||
{
|
|
||||||
printf("This function is not done '%s'", __func__);
|
|
||||||
(void)(self);
|
|
||||||
(void)(input);
|
|
||||||
(void)(out);
|
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
}
|
ret = ast_alloc(AST_HEREDOC_REDIRECTION);
|
||||||
|
i = 0;
|
||||||
t_error build_sym_simple_heredoc_body(t_parse_node self, t_const_str input, \
|
while (i < ts_node_child_count(self))
|
||||||
t_ast_node *out)
|
|
||||||
{
|
{
|
||||||
printf("This function is not done '%s'", __func__);
|
if (ts_node_field_id_for_child(self, i) == field_op)
|
||||||
(void)(self);
|
ret->data.heredoc_redirection.op = _get_redirection_op(ts_node_child(self, i));
|
||||||
(void)(input);
|
else if (ts_node_symbol(ts_node_child(self, i)) == sym_heredoc_start)
|
||||||
(void)(out);
|
ret->data.heredoc_redirection.delimiter = _extract_str(ts_node_child(self, i), input);
|
||||||
return (ERROR);
|
else if (ts_node_symbol(ts_node_child(self, i)) == sym_heredoc_body)
|
||||||
|
ret->data.heredoc_redirection.content = _extract_str(ts_node_child(self, i), input);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (*out = ret, NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
@ -29,7 +29,7 @@ void ast_set_term(t_ast_node *node, t_ast_terminator_kind term)
|
||||||
t_ast_node val;
|
t_ast_node val;
|
||||||
|
|
||||||
if (node == NULL)
|
if (node == NULL)
|
||||||
return ((void)printf("node == NULL\n"));
|
return ;
|
||||||
val = *node;
|
val = *node;
|
||||||
ptr = &void_storage;
|
ptr = &void_storage;
|
||||||
if (val->kind == AST_CASE)
|
if (val->kind == AST_CASE)
|
||||||
|
|
@ -45,9 +45,6 @@ void ast_set_term(t_ast_node *node, t_ast_terminator_kind term)
|
||||||
if (val->kind == AST_SUBSHELL)
|
if (val->kind == AST_SUBSHELL)
|
||||||
ptr = &val->data.subshell.term;
|
ptr = &val->data.subshell.term;
|
||||||
*ptr = term;
|
*ptr = term;
|
||||||
if (ptr == &void_storage)
|
|
||||||
printf("node wasn't a term capable node\n");
|
|
||||||
(void)(void_storage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
t_error build_sym_if_statement(\
|
t_error build_sym_if_statement(\
|
||||||
|
|
|
||||||
|
|
@ -19,58 +19,6 @@
|
||||||
#include "me/vec/vec_ast.h"
|
#include "me/vec/vec_ast.h"
|
||||||
#include "parser/api.h"
|
#include "parser/api.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
/*
|
|
||||||
sym_arithmetic_binary_expression
|
|
||||||
sym_arithmetic_expansion
|
|
||||||
sym_arithmetic_literal
|
|
||||||
sym_arithmetic_parenthesized_expression
|
|
||||||
sym_arithmetic_postfix_expression
|
|
||||||
sym_arithmetic_ternary_expression
|
|
||||||
sym_arithmetic_unary_expression
|
|
||||||
sym_case_item
|
|
||||||
sym_case_statement
|
|
||||||
sym_command
|
|
||||||
sym_command_name
|
|
||||||
sym_command_substitution
|
|
||||||
sym_comment
|
|
||||||
sym_compound_statement
|
|
||||||
sym_concatenation
|
|
||||||
sym_do_group
|
|
||||||
sym_elif_clause
|
|
||||||
sym_else_clause
|
|
||||||
sym_expansion
|
|
||||||
sym_expansion_expression
|
|
||||||
sym_expansion_regex
|
|
||||||
sym_extglob_pattern
|
|
||||||
sym_file_descriptor
|
|
||||||
sym_file_redirect
|
|
||||||
sym_for_statement
|
|
||||||
sym_function_definition
|
|
||||||
sym_heredoc_body
|
|
||||||
sym_heredoc_content
|
|
||||||
sym_heredoc_end
|
|
||||||
sym_heredoc_redirect
|
|
||||||
sym_heredoc_start
|
|
||||||
sym_if_statement
|
|
||||||
sym_list
|
|
||||||
sym_negated_command
|
|
||||||
sym_number
|
|
||||||
sym_pipeline
|
|
||||||
sym_program
|
|
||||||
sym_raw_string
|
|
||||||
sym_redirected_statement
|
|
||||||
sym_regex
|
|
||||||
sym_simplex _expansion
|
|
||||||
sym_simple_heredoc_body
|
|
||||||
sym_string
|
|
||||||
sym_string_content
|
|
||||||
sym_subshell
|
|
||||||
sym_variable_assignment
|
|
||||||
sym_variable_assignments
|
|
||||||
sym_variable_name
|
|
||||||
sym_while_statement
|
|
||||||
sym_word
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
E_OP_NONE = 0, // ${var}
|
E_OP_NONE = 0, // ${var}
|
||||||
|
|
@ -193,79 +141,6 @@ t_error build_sym_list(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||||
return (*out = ret, NO_ERROR);
|
return (*out = ret, NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
alias_sym_statements
|
|
||||||
alias_sym_terminator
|
|
||||||
sym___error_recovery
|
|
||||||
sym__arithmetic_expression
|
|
||||||
sym__bare_dollar
|
|
||||||
sym__case_item_last
|
|
||||||
sym__comment_word
|
|
||||||
sym__concat
|
|
||||||
sym__concatenation_in_expansion
|
|
||||||
sym__empty_value
|
|
||||||
sym__expansion_body
|
|
||||||
sym__expansion_word
|
|
||||||
sym__extglob_blob
|
|
||||||
sym__heredoc_body
|
|
||||||
sym__heredoc_body_beginning
|
|
||||||
sym__heredoc_expression
|
|
||||||
sym__heredoc_pipeline
|
|
||||||
sym__immediate_double_hash
|
|
||||||
sym__simple_heredoc_body
|
|
||||||
sym__statement_not_pipeline
|
|
||||||
sym__statements
|
|
||||||
sym_arithmetic_binary_expression
|
|
||||||
sym_arithmetic_expansion
|
|
||||||
sym_arithmetic_literal
|
|
||||||
sym_arithmetic_parenthesized_expression
|
|
||||||
sym_arithmetic_postfix_expression
|
|
||||||
sym_arithmetic_ternary_expression
|
|
||||||
sym_arithmetic_unary_expression
|
|
||||||
sym_case_item
|
|
||||||
sym_case_statement
|
|
||||||
sym_command
|
|
||||||
sym_command_name
|
|
||||||
sym_command_substitution
|
|
||||||
sym_comment
|
|
||||||
sym_compound_statement
|
|
||||||
sym_concatenation
|
|
||||||
sym_do_group
|
|
||||||
sym_elif_clause
|
|
||||||
sym_else_clause
|
|
||||||
sym_expansion
|
|
||||||
sym_expansion_expression
|
|
||||||
sym_expansion_regex
|
|
||||||
sym_extglob_pattern
|
|
||||||
sym_file_descriptor
|
|
||||||
sym_file_redirect
|
|
||||||
sym_for_statement
|
|
||||||
sym_function_definition
|
|
||||||
sym_heredoc_body
|
|
||||||
sym_heredoc_content
|
|
||||||
sym_heredoc_end
|
|
||||||
sym_heredoc_redirect
|
|
||||||
sym_heredoc_start
|
|
||||||
sym_if_statement
|
|
||||||
sym_list
|
|
||||||
sym_negated_command
|
|
||||||
sym_number
|
|
||||||
sym_pipeline
|
|
||||||
sym_program
|
|
||||||
sym_raw_string
|
|
||||||
sym_redirected_statement
|
|
||||||
sym_regex
|
|
||||||
sym_simple_expansion
|
|
||||||
sym_simple_heredoc_body
|
|
||||||
sym_string
|
|
||||||
sym_string_content
|
|
||||||
sym_subshell
|
|
||||||
sym_variable_assignment
|
|
||||||
sym_variable_assignments
|
|
||||||
sym_variable_name
|
|
||||||
sym_while_statement
|
|
||||||
sym_word
|
|
||||||
*/
|
|
||||||
|
|
||||||
t_error ast_from_node(\
|
t_error ast_from_node(\
|
||||||
t_parse_node node, t_const_str input, t_ast_node *out)
|
t_parse_node node, t_const_str input, t_ast_node *out)
|
||||||
|
|
@ -321,16 +196,8 @@ t_error ast_from_node(\
|
||||||
return (build_sym_for_statement(node, input, out));
|
return (build_sym_for_statement(node, input, out));
|
||||||
if (ts_node_symbol(node) == sym_function_definition)
|
if (ts_node_symbol(node) == sym_function_definition)
|
||||||
return (build_sym_function_definition(node, input, out));
|
return (build_sym_function_definition(node, input, out));
|
||||||
if (ts_node_symbol(node) == sym_heredoc_body)
|
|
||||||
return (build_sym_heredoc_body(node, input, out));
|
|
||||||
if (ts_node_symbol(node) == sym_heredoc_content)
|
|
||||||
return (build_sym_heredoc_content(node, input, out));
|
|
||||||
if (ts_node_symbol(node) == sym_heredoc_end)
|
|
||||||
return (build_sym_heredoc_end(node, input, out));
|
|
||||||
if (ts_node_symbol(node) == sym_heredoc_redirect)
|
if (ts_node_symbol(node) == sym_heredoc_redirect)
|
||||||
return (build_sym_heredoc_redirect(node, input, out));
|
return (build_sym_heredoc_redirect(node, input, out));
|
||||||
if (ts_node_symbol(node) == sym_heredoc_start)
|
|
||||||
return (build_sym_heredoc_start(node, input, out));
|
|
||||||
if (ts_node_symbol(node) == sym_if_statement)
|
if (ts_node_symbol(node) == sym_if_statement)
|
||||||
return (build_sym_if_statement(node, input, out));
|
return (build_sym_if_statement(node, input, out));
|
||||||
if (ts_node_symbol(node) == sym_list)
|
if (ts_node_symbol(node) == sym_list)
|
||||||
|
|
@ -351,8 +218,6 @@ t_error ast_from_node(\
|
||||||
return (build_sym_regex(node, input, out));
|
return (build_sym_regex(node, input, out));
|
||||||
if (ts_node_symbol(node) == sym_simple_expansion)
|
if (ts_node_symbol(node) == sym_simple_expansion)
|
||||||
return (build_sym_simple_expansion(node, input, out));
|
return (build_sym_simple_expansion(node, input, out));
|
||||||
if (ts_node_symbol(node) == sym_simple_heredoc_body)
|
|
||||||
return (build_sym_simple_heredoc_body(node, input, out));
|
|
||||||
if (ts_node_symbol(node) == sym_string)
|
if (ts_node_symbol(node) == sym_string)
|
||||||
return (build_sym_string(node, input, out));
|
return (build_sym_string(node, input, out));
|
||||||
if (ts_node_symbol(node) == sym_string_content)
|
if (ts_node_symbol(node) == sym_string_content)
|
||||||
|
|
|
||||||
|
|
@ -52,16 +52,19 @@ void _append_redirection(t_ast_node node, t_ast_node redirection)
|
||||||
(ast_free(redirection));
|
(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_parse_node node)
|
t_ast_terminator_kind _select_term(t_parse_node node)
|
||||||
{
|
{
|
||||||
t_symbol symbol;
|
(void)(node);
|
||||||
|
|
||||||
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);
|
|
||||||
return (AST_TERM_NONE);
|
return (AST_TERM_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
8
test_heredoc.sh
Executable file
8
test_heredoc.sh
Executable file
|
|
@ -0,0 +1,8 @@
|
||||||
|
make
|
||||||
|
valgrind --leak-check=full --show-leak-kinds=none --track-origins=yes --track-fds=yes --trace-children=yes ./minishell <<<'cat <<EOF
|
||||||
|
bonjour je suis un heredoc
|
||||||
|
le saviez tu je dois finir par EOF mais qui est sur la ligne
|
||||||
|
donc par example si j ai cette ligne qui fini avec EOF
|
||||||
|
rien ne se passe
|
||||||
|
mais la ligne d en dessous fini le heredoc :D
|
||||||
|
EOF'
|
||||||
Loading…
Add table
Add a link
Reference in a new issue