Started work on implementing the AST builder

This commit is contained in:
Maix0 2024-06-20 23:15:45 +02:00
parent c6e426f235
commit 3b197d82c2
5 changed files with 721 additions and 216 deletions

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/11 14:23:40 by maiboyer #+# #+# */
/* Updated: 2024/06/20 14:23:59 by maiboyer ### ########.fr */
/* Updated: 2024/06/20 18:22:03 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -37,11 +37,9 @@ enum e_ast_node_kind
AST_ELIF = S_AST_NONE | 0x0006,
AST_ELSE = S_AST_NONE | 0x0007,
AST_EMPTY = S_AST_NONE | 0x0008,
AST_LIST = S_AST_NONE | 0x0009,
AST_RAW_STRING = S_AST_NONE | 0x000A,
AST_STRING = S_AST_NONE | 0x000B,
AST_WORD = S_AST_NONE | 0x000C,
AST_FUNCTION_DEFINITION = S_AST_NONE | 0x000D,
AST_VARIABLE_ASSIGNMENT = S_AST_NONE | 0x000E,
AST_FILE_REDIRECTION = S_AST_REDIRECT | 0x000F,
@ -51,6 +49,8 @@ enum e_ast_node_kind
AST_CASE = S_AST_COMPOUND_COMMAND | 0x0012,
AST_COMPOUND_STATEMENT = S_AST_COMPOUND_COMMAND | 0x0013,
AST_IF = S_AST_COMPOUND_COMMAND | 0x0014,
AST_FUNCTION_DEFINITION = S_AST_COMPOUND_COMMAND | 0x000D,
AST_LIST = S_AST_COMPOUND_COMMAND | 0x0009,
AST_PIPELINE = S_AST_COMPOUND_COMMAND | 0x00015,
AST_PROGRAM = S_AST_COMPOUND_COMMAND | 0x0016,
AST_SUBSHELL = S_AST_COMPOUND_COMMAND | 0x00017,
@ -82,6 +82,7 @@ union u_ast_node_data {
t_ast_subshell subshell;
t_ast_until until;
t_ast_variable_assignment variable_assignment;
t_ast_while while_;
t_ast_word word;
};

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/14 17:46:58 by maiboyer #+# #+# */
/* Updated: 2024/06/20 14:29:55 by maiboyer ### ########.fr */
/* Updated: 2024/06/20 22:17:36 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,27 +17,6 @@
#include "me/types.h"
#include "me/vec/vec_ast.h"
/*
ast_statement:
case_statement
command
compound_statement
for_statement
function_definition
if_statement
list
negated_command
pipeline
redirected_statement
subshell
variable_assignment
variable_assignments
while_statement
ast_statement_not_pipeline == ast_statement - pipeline
ast_statement_not_subshell == ast_statement - subshell
*/
enum e_ast_list_kind
{
AST_LIST_AND,
@ -89,44 +68,72 @@ struct s_ast_raw_string
t_usize len;
};
struct s_ast_list
{
t_ast_node left;
t_ast_list_kind op;
t_ast_node right;
};
/// @brief A string that is may be quoted or not
/// @param parts this can be multiple things:
/// - a "raw" string (no processing needed)
/// - a expension (variable, command substitution, artihmetic expansion, etc.)
/// @param parts_len the number of parts in the string
/// @note if the string isn't quoted, it needs to be split into parts using $IFS
struct s_ast_string
{
t_vec_ast parts;
};
struct s_ast_pipeline
{
bool bang;
t_vec_ast statements;
};
struct s_ast_word
{
t_ast_word_kind kind;
t_vec_ast inner;
};
struct s_ast_program
{
t_vec_ast body;
};
/// Pipeline Statemen
/// ```shell
/// cmd1 || cmd2
/// cmd1 && cmd2
/// cmd1 || cmd2 >outfile
/// ```
struct s_ast_list
{
t_ast_node left;
t_ast_list_kind op;
t_ast_node right;
t_ast_terminator_kind term;
t_vec_ast suffixes_redirections;
};
/// Pipeline Statement
/// ```shell
/// cat file | grep stuff | banane | truc
/// echo "$sutff" | if truc; then banane; fi | lololol
/// ```
struct s_ast_pipeline
{
bool bang;
t_vec_ast statements;
t_ast_terminator_kind term;
t_vec_ast suffixes_redirections;
};
/// Command Statement
/// ```shell
/// cmd1 arg1 argN
/// >output yes
/// banane >output
/// VALUE=something echo $VALUE >&1 2>somewhere
/// ```
struct s_ast_command
{
t_vec_ast prefixes;
t_vec_ast cmd_word;
t_vec_ast suffixes;
t_vec_ast suffixes_redirections;
t_ast_terminator_kind term;
};
/// If Statement
/// ```shell
/// if cmd_condition; then
/// cmd $varname;
/// fi
/// ```
/// Closely related to `t_ast_elif` and `t_ast_else`
struct s_ast_if
{
t_vec_ast condition;
@ -134,39 +141,92 @@ struct s_ast_if
t_vec_ast elif_;
t_ast_node else_;
t_ast_terminator_kind term;
t_vec_ast suffixes_redirections;
};
/// Elif Statement
/// ```shell
/// elif cmd_condition; then
/// cmd $varname;
/// fi
/// ```
/// Closely related to `t_ast_if` and `t_ast_else`
struct s_ast_elif
{
t_vec_ast condition;
t_vec_ast then;
};
/// Else Statement
/// ```shell
/// else cmd_condition; then
/// cmd $varname;
/// fi
/// ```
/// Closely related to `t_ast_if` and `t_ast_elif`
struct s_ast_else
{
t_vec_ast then;
};
/// While loop
/// ```shell
/// while cmd_condition; do
/// cmd $varname;
/// done
/// ```
struct s_ast_while
{
t_vec_ast condition;
t_vec_ast do_;
t_ast_terminator_kind term;
t_vec_ast suffixes_redirections;
};
/// For loop
/// ```shell
/// for varname in words truc bidule; do
/// cmd $varname;
/// done
/// ```
struct s_ast_for
{
t_str var_name;
t_vec_ast words;
t_vec_ast do_;
t_ast_terminator_kind term;
t_vec_ast suffixes_redirections;
};
/// Case Statement
/// ```shell
/// case truc; in
/// *pattern)
/// dosmth;
/// *other_pattern | *another)
/// cmd2;
/// *)
/// fallback;
/// esac
/// ```
struct s_ast_case
{
t_ast_node word;
t_vec_ast cases;
t_ast_terminator_kind term;
t_vec_ast suffixes_redirections;
};
/// Case Statement
/// ```shell
/// *pattern)
/// dosmth;
/// *other_pattern | *another)
/// cmd2;
/// *)
/// fallback;
/// ```
/// Closely tied to `t_ast_case`
struct s_ast_case_item
{
t_vec_ast pattern;
@ -174,47 +234,97 @@ struct s_ast_case_item
t_ast_terminator_kind term;
};
/// Until loop
/// ```shell
/// until cmd arg1 arg2 argN; do
/// cmd1;
/// cmd2;
/// truc;
/// done
/// ```
struct s_ast_until
{
t_vec_ast condition;
t_vec_ast do_;
t_ast_terminator_kind term;
t_vec_ast suffixes_redirections;
};
/// Function Definition
/// ```shell
/// function_name() (comand1; command2 truc banane pomme;)
/// function_name() {comand1; command2 truc banane pomme;}
/// ```
struct s_ast_function_definition
{
t_str name;
t_vec_ast body;
};
/// Parenthesis block
/// ```shell
/// (comand1; command2 truc banane pomme;)
/// ```
struct s_ast_subshell
{
t_vec_ast body;
t_ast_terminator_kind term;
t_vec_ast suffixes_redirections;
};
/// Brace block
/// ```shell
/// { command1; command2 truc banane pomme; }
/// ```
struct s_ast_compound_statement
{
t_vec_ast body;
t_ast_terminator_kind term;
t_vec_ast suffixes_redirections;
};
/// Variable Assignment
/// ```shell
/// VARIABLE=something
/// ```
struct s_ast_variable_assignment
{
t_str name;
t_ast_node value;
};
/// File Redirection
/// ```shell
/// <infile
/// >>outfile
/// 2>&1
/// ```
struct s_ast_file_redirection
{
t_ast_node output;
t_ast_node input;
};
/// File Redirection
/// ```shell
/// << EOF
/// TEXT blablabla
/// EOF
/// ```
struct s_ast_heredoc_redirection
{
t_ast_node output;
t_ast_node delimiter;
};
/// Variable Expension
/// ```shell
/// $VARNAME
/// ${VARNAME}
/// ${VARNAME:?truc}
/// ${VARNAME%%trucmuch pattern}
/// $@
/// ```
struct s_ast_expansion
{
t_str var_name;
@ -222,18 +332,25 @@ struct s_ast_expansion
t_vec_ast args;
};
/// Variable Expension
/// ```shell
/// $((VARNAME))
/// $((1 + 2))
/// $((- 1))
/// $((1-1))
/// ```
struct s_ast_arithmetic_expansion
{
t_ast_node expr;
};
/// Command Substitution
/// ```shell
/// $(command)
/// ```
struct s_ast_command_substitution
{
t_ast_node cmd;
};
struct s_ast_program {
t_vec_ast body;
};
#endif /* AST_RAW_STRUCTS_H */

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/17 12:41:56 by maiboyer #+# #+# */
/* Updated: 2024/06/20 14:38:08 by maiboyer ### ########.fr */
/* Updated: 2024/06/20 23:15:26 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,6 +14,7 @@
#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"
@ -71,11 +72,141 @@ sym_while_statement
sym_word
*/
void free_ast(t_ast_node elem)
#undef ERROR
#define ERROR ((void)printf("ERROR HERE: " __FILE__ ":%d in %s\n", __LINE__, __func__), 1)
void ast_free(t_ast_node elem)
{
if (elem == NULL)
return;
if (elem->kind == AST_ARITHMETIC_EXPANSION)
{
ast_free(elem->data.arithmetic_expansion.expr);
}
if (elem->kind == AST_CASE)
{
ast_free(elem->data.case_.word);
vec_ast_free(elem->data.case_.cases);
vec_ast_free(elem->data.case_.suffixes_redirections);
}
if (elem->kind == AST_CASE_ITEM)
{
vec_ast_free(elem->data.case_item.body);
vec_ast_free(elem->data.case_item.pattern);
}
if (elem->kind == AST_COMMAND)
{
vec_ast_free(elem->data.command.cmd_word);
vec_ast_free(elem->data.command.prefixes);
vec_ast_free(elem->data.command.suffixes_redirections);
}
if (elem->kind == AST_COMMAND_SUBSTITUTION)
{
ast_free(elem->data.command_substitution.cmd);
}
if (elem->kind == AST_COMPOUND_STATEMENT)
{
vec_ast_free(elem->data.compound_statement.body);
vec_ast_free(elem->data.compound_statement.suffixes_redirections);
}
if (elem->kind == AST_ELIF)
{
vec_ast_free(elem->data.elif.condition);
vec_ast_free(elem->data.elif.then);
}
if (elem->kind == AST_ELSE)
{
vec_ast_free(elem->data.else_.then);
}
if (elem->kind == AST_EXPANSION)
{
vec_ast_free(elem->data.expansion.args);
mem_free(elem->data.expansion.var_name);
}
if (elem->kind == AST_FILE_REDIRECTION)
{
ast_free(elem->data.file_redirection.input);
ast_free(elem->data.file_redirection.output);
}
if (elem->kind == AST_FOR)
{
mem_free(elem->data.for_.var_name);
vec_ast_free(elem->data.for_.do_);
vec_ast_free(elem->data.for_.suffixes_redirections);
vec_ast_free(elem->data.for_.words);
}
if (elem->kind == AST_FUNCTION_DEFINITION)
{
vec_ast_free(elem->data.function_definition.body);
mem_free(elem->data.function_definition.name);
}
if (elem->kind == AST_HEREDOC_REDIRECTION)
{
ast_free(elem->data.heredoc_redirection.delimiter);
ast_free(elem->data.heredoc_redirection.output);
}
if (elem->kind == AST_IF)
{
ast_free(elem->data.if_.else_);
vec_ast_free(elem->data.if_.condition);
vec_ast_free(elem->data.if_.elif_);
vec_ast_free(elem->data.if_.suffixes_redirections);
vec_ast_free(elem->data.if_.then);
}
if (elem->kind == AST_LIST)
{
ast_free(elem->data.list.left);
ast_free(elem->data.list.right);
vec_ast_free(elem->data.list.suffixes_redirections);
}
if (elem->kind == AST_PIPELINE)
{
vec_ast_free(elem->data.pipeline.statements);
vec_ast_free(elem->data.pipeline.suffixes_redirections);
}
if (elem->kind == AST_PROGRAM)
{
vec_ast_free(elem->data.program.body);
}
if (elem->kind == AST_RAW_STRING)
{
mem_free(elem->data.raw_string.str);
}
if (elem->kind == AST_STRING)
{
vec_ast_free(elem->data.string.parts);
}
if (elem->kind == AST_SUBSHELL)
{
vec_ast_free(elem->data.subshell.body);
vec_ast_free(elem->data.subshell.suffixes_redirections);
}
if (elem->kind == AST_UNTIL)
{
vec_ast_free(elem->data.until.condition);
vec_ast_free(elem->data.until.do_);
vec_ast_free(elem->data.until.suffixes_redirections);
}
if (elem->kind == AST_VARIABLE_ASSIGNMENT)
{
ast_free(elem->data.variable_assignment.value);
mem_free(elem->data.variable_assignment.name);
}
if (elem->kind == AST_WHILE)
{
vec_ast_free(elem->data.while_.condition);
vec_ast_free(elem->data.while_.do_);
vec_ast_free(elem->data.while_.suffixes_redirections);
}
if (elem->kind == AST_WORD)
{
vec_ast_free(elem->data.word.inner);
}
mem_free(elem);
}
t_ast_node alloc_ast(t_ast_node_kind kind)
t_ast_node ast_alloc(t_ast_node_kind kind)
{
t_ast_node ret;
@ -86,147 +217,226 @@ t_ast_node alloc_ast(t_ast_node_kind kind)
{
ret->data.arithmetic_expansion.expr = NULL;
}
else if (kind == AST_CASE)
if (kind == AST_CASE)
{
ret->data.case_.word = NULL;
ret->data.case_.cases = vec_ast_new(16, free_ast);
ret->data.case_.cases = vec_ast_new(16, ast_free);
ret->data.case_.suffixes_redirections = vec_ast_new(16, ast_free);
ret->data.case_.term = AST_TERM_NONE;
ret->data.case_.word = NULL;
}
else if (kind == AST_CASE_ITEM)
if (kind == AST_CASE_ITEM)
{
ret->data.case_item.body = vec_ast_new(16, ast_free);
ret->data.case_item.pattern = vec_ast_new(16, ast_free);
ret->data.case_item.term = AST_TERM_NONE;
ret->data.case_item.pattern = vec_ast_new(16, free_ast);
ret->data.case_item.body = vec_ast_new(16, free_ast);
}
else if (kind == AST_COMMAND)
if (kind == AST_COMMAND)
{
ret->data.command.cmd_word = vec_ast_new(16, ast_free);
ret->data.command.prefixes = vec_ast_new(16, ast_free);
ret->data.command.suffixes_redirections = vec_ast_new(16, ast_free);
ret->data.command.term = AST_TERM_NONE;
ret->data.command.cmd_word = vec_ast_new(16, free_ast);
ret->data.command.prefixes = vec_ast_new(16, free_ast);
ret->data.command.suffixes = vec_ast_new(16, free_ast);
}
else if (kind == AST_COMMAND_SUBSTITUTION)
if (kind == AST_COMMAND_SUBSTITUTION)
{
ret->data.command_substitution.cmd = NULL;
}
else if (kind == AST_COMPOUND_STATEMENT)
if (kind == AST_COMPOUND_STATEMENT)
{
ret->data.compound_statement.body = vec_ast_new(16, ast_free);
ret->data.compound_statement.suffixes_redirections = vec_ast_new(16, ast_free);
ret->data.compound_statement.term = AST_TERM_NONE;
}
else if (kind == AST_ELIF)
if (kind == AST_ELIF)
{
ret->data.elif.condition = vec_ast_new(16, ast_free);
ret->data.elif.then = vec_ast_new(16, ast_free);
}
else if (kind == AST_ELSE)
if (kind == AST_ELSE)
{
ret->data.else_.then = vec_ast_new(16, ast_free);
}
else if (kind == AST_EMPTY)
if (kind == AST_EXPANSION)
{
ret->data.expansion.args = vec_ast_new(16, ast_free);
ret->data.expansion.kind = E_OP_NONE;
ret->data.expansion.var_name = NULL;
}
else if (kind == AST_EXPANSION)
if (kind == AST_FILE_REDIRECTION)
{
ret->data.file_redirection.input = NULL;
ret->data.file_redirection.output = NULL;
}
else if (kind == AST_FILE_REDIRECTION)
if (kind == AST_FOR)
{
ret->data.for_.do_ = vec_ast_new(16, ast_free);
ret->data.for_.suffixes_redirections = vec_ast_new(16, ast_free);
ret->data.for_.term = AST_TERM_NONE;
ret->data.for_.var_name = NULL;
ret->data.for_.words = vec_ast_new(16, ast_free);
}
else if (kind == AST_FOR)
if (kind == AST_FUNCTION_DEFINITION)
{
ret->data.function_definition.body = vec_ast_new(16, ast_free);
ret->data.function_definition.name = NULL;
}
else if (kind == AST_FUNCTION_DEFINITION)
if (kind == AST_HEREDOC_REDIRECTION)
{
ret->data.heredoc_redirection.delimiter = NULL;
ret->data.heredoc_redirection.output = NULL;
}
else if (kind == AST_HEREDOC_REDIRECTION)
if (kind == AST_IF)
{
ret->data.if_.condition = vec_ast_new(16, ast_free);
ret->data.if_.elif_ = vec_ast_new(16, ast_free);
ret->data.if_.else_ = NULL;
ret->data.if_.suffixes_redirections = vec_ast_new(16, ast_free);
ret->data.if_.term = AST_TERM_NONE;
ret->data.if_.then = vec_ast_new(16, ast_free);
}
else if (kind == AST_IF)
if (kind == AST_LIST)
{
ret->data.list.left = NULL;
ret->data.list.op = AST_LIST_OR;
ret->data.list.right = NULL;
ret->data.list.suffixes_redirections = vec_ast_new(16, ast_free);
ret->data.list.term = AST_TERM_NONE;
}
else if (kind == AST_LIST)
if (kind == AST_PIPELINE)
{
ret->data.pipeline.bang = false;
ret->data.pipeline.statements = vec_ast_new(16, ast_free);
ret->data.pipeline.suffixes_redirections = vec_ast_new(16, ast_free);
ret->data.pipeline.term = AST_TERM_NONE;
}
else if (kind == AST_PIPELINE)
if (kind == AST_PROGRAM)
{
ret->data.program.body = vec_ast_new(16, ast_free);
}
else if (kind == AST_PROGRAM)
if (kind == AST_RAW_STRING)
{
ret->data.raw_string.len = 0;
ret->data.raw_string.str = NULL;
}
else if (kind == AST_RAW_STRING)
if (kind == AST_STRING)
{
ret->data.string.parts = vec_ast_new(16, ast_free);
}
else if (kind == AST_STRING)
if (kind == AST_SUBSHELL)
{
ret->data.list.term = AST_TERM_NONE;
ret->data.subshell.body = vec_ast_new(16, ast_free);
ret->data.subshell.suffixes_redirections = vec_ast_new(16, ast_free);
}
else if (kind == AST_SUBSHELL)
if (kind == AST_UNTIL)
{
ret->data.until.condition = vec_ast_new(16, ast_free);
ret->data.until.do_ = vec_ast_new(16, ast_free);
ret->data.until.suffixes_redirections = vec_ast_new(16, ast_free);
ret->data.until.term = AST_TERM_NONE;
}
else if (kind == AST_UNTIL)
if (kind == AST_VARIABLE_ASSIGNMENT)
{
ret->data.variable_assignment.name = NULL;
ret->data.variable_assignment.value = NULL;
}
else if (kind == AST_VARIABLE_ASSIGNMENT)
if (kind == AST_WHILE)
{
ret->data.while_.condition = vec_ast_new(16, ast_free);
ret->data.while_.do_ = vec_ast_new(16, ast_free);
ret->data.while_.suffixes_redirections = vec_ast_new(16, ast_free);
ret->data.while_.term = AST_TERM_NONE;
}
else if (kind == AST_WHILE)
{
}
else if (kind == AST_WORD)
if (kind == AST_WORD)
{
ret->data.word.inner = vec_ast_new(16, ast_free);
ret->data.word.kind = AST_WORD_NO_QUOTE;
}
return (ret);
}
t_error from_node(t_parse_node node, t_ast_node *out);
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;
t_error build_sym_arithmetic_binary_expression(t_parse_node self, t_ast_node *out);
t_error build_sym_arithmetic_expansion(t_parse_node self, t_ast_node *out);
t_error build_sym_arithmetic_literal(t_parse_node self, t_ast_node *out);
t_error build_sym_arithmetic_parenthesized_expression(t_parse_node self, t_ast_node *out);
t_error build_sym_arithmetic_postfix_expression(t_parse_node self, t_ast_node *out);
t_error build_sym_arithmetic_ternary_expression(t_parse_node self, t_ast_node *out);
t_error build_sym_arithmetic_unary_expression(t_parse_node self, t_ast_node *out);
t_error build_sym_case_item(t_parse_node self, t_ast_node *out);
t_error build_sym_case_statement(t_parse_node self, t_ast_node *out);
t_error build_sym_command(t_parse_node self, t_ast_node *out);
t_error build_sym_command_name(t_parse_node self, t_ast_node *out);
t_error build_sym_command_substitution(t_parse_node self, t_ast_node *out);
t_error build_sym_comment(t_parse_node self, t_ast_node *out);
t_error build_sym_compound_statement(t_parse_node self, t_ast_node *out);
t_error build_sym_concatenation(t_parse_node self, t_ast_node *out);
t_error build_sym_do_group(t_parse_node self, t_ast_node *out);
t_error build_sym_elif_clause(t_parse_node self, t_ast_node *out);
t_error build_sym_else_clause(t_parse_node self, t_ast_node *out);
t_error build_sym_expansion(t_parse_node self, t_ast_node *out);
t_error build_sym_expansion_expression(t_parse_node self, t_ast_node *out);
t_error build_sym_expansion_regex(t_parse_node self, t_ast_node *out);
t_error build_sym_extglob_pattern(t_parse_node self, t_ast_node *out);
t_error build_sym_file_descriptor(t_parse_node self, t_ast_node *out);
t_error build_sym_file_redirect(t_parse_node self, t_ast_node *out);
t_error build_sym_for_statement(t_parse_node self, t_ast_node *out);
t_error build_sym_function_definition(t_parse_node self, t_ast_node *out);
t_error build_sym_heredoc_body(t_parse_node self, t_ast_node *out);
t_error build_sym_heredoc_content(t_parse_node self, t_ast_node *out);
t_error build_sym_heredoc_end(t_parse_node self, t_ast_node *out);
t_error build_sym_heredoc_redirect(t_parse_node self, t_ast_node *out);
t_error build_sym_heredoc_start(t_parse_node self, t_ast_node *out);
t_error build_sym_if_statement(t_parse_node self, t_ast_node *out);
t_error build_sym_list(t_parse_node self, t_ast_node *out);
t_error build_sym_negated_command(t_parse_node self, t_ast_node *out);
t_error build_sym_number(t_parse_node self, t_ast_node *out);
t_error build_sym_pipeline(t_parse_node self, t_ast_node *out);
t_error build_sym_program(t_parse_node self, t_ast_node *out);
t_error build_sym_raw_string(t_parse_node self, t_ast_node *out);
t_error build_sym_redirected_statement(t_parse_node self, t_ast_node *out);
t_error build_sym_regex(t_parse_node self, t_ast_node *out);
t_error build_sym_simple_expansion(t_parse_node self, t_ast_node *out);
t_error build_sym_simple_heredoc_body(t_parse_node self, t_ast_node *out);
t_error build_sym_string(t_parse_node self, t_ast_node *out);
t_error build_sym_string_content(t_parse_node self, t_ast_node *out);
t_error build_sym_subshell(t_parse_node self, t_ast_node *out);
t_error build_sym_variable_assignment(t_parse_node self, t_ast_node *out);
t_error build_sym_variable_assignments(t_parse_node self, t_ast_node *out);
t_error build_sym_variable_name(t_parse_node self, t_ast_node *out);
t_error build_sym_while_statement(t_parse_node self, t_ast_node *out);
t_error build_sym_word(t_parse_node self, t_ast_node *out);
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;
t_error build_sym_program(t_parse_node self, t_ast_node *out)
*ptr = term;
(void)(void_storage);
}
t_error ast_from_node(t_parse_node node, t_const_str input, t_ast_node *out);
t_error build_sym_arithmetic_binary_expression(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_arithmetic_expansion(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_arithmetic_literal(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_arithmetic_parenthesized_expression(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_arithmetic_postfix_expression(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_arithmetic_ternary_expression(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_arithmetic_unary_expression(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_case_item(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_case_statement(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_command(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_command_name(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_command_substitution(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_comment(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_compound_statement(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_concatenation(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_do_group(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_elif_clause(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_else_clause(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_expansion(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_expansion_expression(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_expansion_regex(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_extglob_pattern(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_file_descriptor(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_file_redirect(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_for_statement(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_function_definition(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_heredoc_body(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_heredoc_content(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_heredoc_end(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_heredoc_redirect(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_heredoc_start(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_if_statement(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_list(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_negated_command(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_number(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_pipeline(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_program(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_raw_string(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_redirected_statement(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_regex(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_simple_expansion(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_simple_heredoc_body(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_string(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_string_content(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_subshell(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_variable_assignment(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_variable_assignments(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_variable_name(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_while_statement(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_word(t_parse_node self, t_const_str input, t_ast_node *out);
#include <stdio.h>
t_error build_sym_program(t_parse_node self, t_const_str input, t_ast_node *out)
{
t_ast_node ret;
t_usize i;
@ -236,33 +446,206 @@ t_error build_sym_program(t_parse_node self, t_ast_node *out)
return (ERROR);
if (ts_node_grammar_symbol(self) != sym_program)
return (ERROR);
ret = alloc_node(AST_PROGRAM);
ret = ast_alloc(AST_PROGRAM);
i = 0;
ret->kind = AST_COMPOUND_STATEMENT;
while (i < ts_node_named_child_count(self))
{
if (i < ts_node_named_child_count(self))
temp = NULL;
if (i < ts_node_named_child_count(self) && ts_node_field_id_for_child(self, i) == field_stmt)
{
if (from_node(ts_node_named_child(self, i)))
return (free_node(ret), ERROR);
if (ast_from_node(ts_node_named_child(self, i), input, &temp))
return (ast_free(ret), ERROR);
i++;
}
if (i < ts_node_named_child_count(self) && ts_node_field_id_for_child(self, i) == field_terminator)
{
printf("%s\n", (ts_node_grammar_type(ts_node_named_child(self, i))));
i++;
}
if (temp == NULL)
break;
vec_ast_push(&ret->data.program.body, temp);
}
return (*out = ret, NO_ERROR);
return (mem_free(ret), ERROR);
}
t_error from_node(t_parse_node node, t_ast_node *out)
t_error build_sym_command_name(t_parse_node self, t_const_str input, t_ast_node *out)
{
if (out == NULL)
return (ERROR);
return (build_sym_word(node, out));
return (NO_ERROR);
if (ts_node_grammar_symbol(self) != sym_command_name)
return (ERROR);
return (ast_from_node(ts_node_named_child(self, 0), input, out));
}
static inline 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);
}
static inline void _append_redirection(t_ast_command *val, t_ast_node redirection)
{
(void)(val);
(void)(redirection);
}
t_error build_sym_word(t_parse_node self, t_const_str input, t_ast_node *out)
{
t_ast_node ret;
t_str temp_str;
t_ast_node temp;
if (out == NULL)
return (ERROR);
if (ts_node_grammar_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 = str_substring(input, ts_node_start_byte(self), ts_node_end_byte(self) - ts_node_start_byte(self));
temp->data.raw_string.str = temp_str;
temp->data.raw_string.len = str_len(temp_str);
vec_ast_push(&ret->data.word.inner, temp);
return (*out = ret, NO_ERROR);
}
t_error build_sym_command(t_parse_node self, t_const_str input, t_ast_node *out)
{
t_ast_node ret;
t_usize i;
t_usize vec_idx;
t_ast_node temp;
if (out == NULL)
return (ERROR);
if (ts_node_grammar_symbol(self) != sym_command)
return (ERROR);
ret = ast_alloc(AST_COMMAND);
i = 0;
vec_idx = 0;
while (i < ts_node_named_child_count(self))
{
temp = NULL;
if (ts_node_field_id_for_child(self, i) == field_name)
vec_idx++;
if (ast_from_node(ts_node_named_child(self, i), input, &temp))
return (ast_free(ret), ERROR);
vec_ast_push(_vec_command(&ret->data.command, vec_idx), temp);
i++;
}
return (*out = ret, NO_ERROR);
}
t_error ast_from_node(t_parse_node node, t_const_str input, t_ast_node *out)
{
if (out == NULL)
return (ERROR);
if (ts_node_grammar_symbol(node) == sym_arithmetic_binary_expression)
return (build_sym_arithmetic_binary_expression(node, input, out));
if (ts_node_grammar_symbol(node) == sym_arithmetic_expansion)
return (build_sym_arithmetic_expansion(node, input, out));
if (ts_node_grammar_symbol(node) == sym_arithmetic_literal)
return (build_sym_arithmetic_literal(node, input, out));
if (ts_node_grammar_symbol(node) == sym_arithmetic_parenthesized_expression)
return (build_sym_arithmetic_parenthesized_expression(node, input, out));
if (ts_node_grammar_symbol(node) == sym_arithmetic_postfix_expression)
return (build_sym_arithmetic_postfix_expression(node, input, out));
if (ts_node_grammar_symbol(node) == sym_arithmetic_ternary_expression)
return (build_sym_arithmetic_ternary_expression(node, input, out));
if (ts_node_grammar_symbol(node) == sym_arithmetic_unary_expression)
return (build_sym_arithmetic_unary_expression(node, input, out));
if (ts_node_grammar_symbol(node) == sym_case_item)
return (build_sym_case_item(node, input, out));
if (ts_node_grammar_symbol(node) == sym_case_statement)
return (build_sym_case_statement(node, input, out));
if (ts_node_grammar_symbol(node) == sym_command)
return (build_sym_command(node, input, out));
if (ts_node_grammar_symbol(node) == sym_command_name)
return (build_sym_command_name(node, input, out));
if (ts_node_grammar_symbol(node) == sym_command_substitution)
return (build_sym_command_substitution(node, input, out));
if (ts_node_grammar_symbol(node) == sym_comment)
return (build_sym_comment(node, input, out));
if (ts_node_grammar_symbol(node) == sym_compound_statement)
return (build_sym_compound_statement(node, input, out));
if (ts_node_grammar_symbol(node) == sym_concatenation)
return (build_sym_concatenation(node, input, out));
if (ts_node_grammar_symbol(node) == sym_do_group)
return (build_sym_do_group(node, input, out));
if (ts_node_grammar_symbol(node) == sym_elif_clause)
return (build_sym_elif_clause(node, input, out));
if (ts_node_grammar_symbol(node) == sym_else_clause)
return (build_sym_else_clause(node, input, out));
if (ts_node_grammar_symbol(node) == sym_expansion)
return (build_sym_expansion(node, input, out));
if (ts_node_grammar_symbol(node) == sym_expansion_expression)
return (build_sym_expansion_expression(node, input, out));
if (ts_node_grammar_symbol(node) == sym_expansion_regex)
return (build_sym_expansion_regex(node, input, out));
if (ts_node_grammar_symbol(node) == sym_extglob_pattern)
return (build_sym_extglob_pattern(node, input, out));
if (ts_node_grammar_symbol(node) == sym_file_descriptor)
return (build_sym_file_descriptor(node, input, out));
if (ts_node_grammar_symbol(node) == sym_file_redirect)
return (build_sym_file_redirect(node, input, out));
if (ts_node_grammar_symbol(node) == sym_for_statement)
return (build_sym_for_statement(node, input, out));
if (ts_node_grammar_symbol(node) == sym_function_definition)
return (build_sym_function_definition(node, input, out));
if (ts_node_grammar_symbol(node) == sym_heredoc_body)
return (build_sym_heredoc_body(node, input, out));
if (ts_node_grammar_symbol(node) == sym_heredoc_content)
return (build_sym_heredoc_content(node, input, out));
if (ts_node_grammar_symbol(node) == sym_heredoc_end)
return (build_sym_heredoc_end(node, input, out));
if (ts_node_grammar_symbol(node) == sym_heredoc_redirect)
return (build_sym_heredoc_redirect(node, input, out));
if (ts_node_grammar_symbol(node) == sym_heredoc_start)
return (build_sym_heredoc_start(node, input, out));
if (ts_node_grammar_symbol(node) == sym_if_statement)
return (build_sym_if_statement(node, input, out));
if (ts_node_grammar_symbol(node) == sym_list)
return (build_sym_list(node, input, out));
if (ts_node_grammar_symbol(node) == sym_negated_command)
return (build_sym_negated_command(node, input, out));
if (ts_node_grammar_symbol(node) == sym_number)
return (build_sym_number(node, input, out));
if (ts_node_grammar_symbol(node) == sym_pipeline)
return (build_sym_pipeline(node, input, out));
if (ts_node_grammar_symbol(node) == sym_program)
return (build_sym_program(node, input, out));
if (ts_node_grammar_symbol(node) == sym_raw_string)
return (build_sym_raw_string(node, input, out));
if (ts_node_grammar_symbol(node) == sym_redirected_statement)
return (build_sym_redirected_statement(node, input, out));
if (ts_node_grammar_symbol(node) == sym_regex)
return (build_sym_regex(node, input, out));
if (ts_node_grammar_symbol(node) == sym_simple_expansion)
return (build_sym_simple_expansion(node, input, out));
if (ts_node_grammar_symbol(node) == sym_simple_heredoc_body)
return (build_sym_simple_heredoc_body(node, input, out));
if (ts_node_grammar_symbol(node) == sym_string)
return (build_sym_string(node, input, out));
if (ts_node_grammar_symbol(node) == sym_string_content)
return (build_sym_string_content(node, input, out));
if (ts_node_grammar_symbol(node) == sym_subshell)
return (build_sym_subshell(node, input, out));
if (ts_node_grammar_symbol(node) == sym_variable_assignment)
return (build_sym_variable_assignment(node, input, out));
if (ts_node_grammar_symbol(node) == sym_variable_assignments)
return (build_sym_variable_assignments(node, input, out));
if (ts_node_grammar_symbol(node) == sym_variable_name)
return (build_sym_variable_name(node, input, out));
if (ts_node_grammar_symbol(node) == sym_while_statement)
return (build_sym_while_statement(node, input, out));
if (ts_node_grammar_symbol(node) == sym_word)
return (build_sym_word(node, input, out));
return (ERROR);
}

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/17 13:04:32 by maiboyer #+# #+# */
/* Updated: 2024/06/20 14:11:07 by maiboyer ### ########.fr */
/* Updated: 2024/06/20 22:36:33 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,61 +16,62 @@
#include "me/types.h"
#include <stdio.h>
t_error _build_not_finished(t_parse_node node, t_ast_node *out)
t_error _build_not_finished(t_parse_node self, t_const_str input, t_ast_node *out)
{
(void)(node);
(void)(self);
(void)(out);
printf("building undefined symbol '%s'\n", ts_node_grammar_type(node));
(void)(input);
printf("building undefined symbol '%s'\n", ts_node_grammar_type(self));
return (ERROR);
}
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_arithmetic_binary_expression(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_arithmetic_expansion(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_arithmetic_literal(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_arithmetic_parenthesized_expression(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_arithmetic_postfix_expression(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_arithmetic_ternary_expression(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_arithmetic_unary_expression(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_case_item(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_case_statement(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_command(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_command_name(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_command_substitution(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_comment(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_compound_statement(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_concatenation(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_do_group(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_elif_clause(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_else_clause(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_expansion(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_expansion_expression(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_expansion_regex(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_extglob_pattern(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_file_descriptor(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_file_redirect(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_for_statement(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_function_definition(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_heredoc_body(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_heredoc_content(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_heredoc_end(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_heredoc_redirect(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_heredoc_start(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_if_statement(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_list(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_negated_command(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_number(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_pipeline(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_program(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_raw_string(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_redirected_statement(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_regex(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_simple_expansion(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_simple_heredoc_body(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_string(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_string_content(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_subshell(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_variable_assignment(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_variable_assignments(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_variable_name(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_while_statement(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_word(t_parse_node self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_arithmetic_binary_expression(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_arithmetic_expansion(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_arithmetic_literal(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_arithmetic_parenthesized_expression(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_arithmetic_postfix_expression(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_arithmetic_ternary_expression(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_arithmetic_unary_expression(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_case_item(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_case_statement(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_command(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_command_name(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_command_substitution(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_comment(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_compound_statement(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_concatenation(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_do_group(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_elif_clause(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_else_clause(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_expansion(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_expansion_expression(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_expansion_regex(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_extglob_pattern(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_file_descriptor(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_file_redirect(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_for_statement(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_function_definition(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_heredoc_body(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_heredoc_content(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_heredoc_end(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_heredoc_redirect(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_heredoc_start(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_if_statement(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_list(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_negated_command(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_number(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_pipeline(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_program(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_raw_string(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_redirected_statement(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_regex(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_simple_expansion(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_simple_heredoc_body(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_string(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_string_content(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_subshell(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_variable_assignment(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_variable_assignments(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_variable_name(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_while_statement(t_parse_node self, t_const_str input, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_word(t_parse_node self, t_const_str input, t_ast_node *out);

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */
/* Updated: 2024/06/19 13:45:53 by maiboyer ### ########.fr */
/* Updated: 2024/06/20 23:04:03 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -30,7 +30,7 @@
#include "ast/ast.h"
t_error from_node(t_parse_node *node, t_ast_node *out);
t_error ast_from_node(t_parse_node node, t_str input, t_ast_node *out);
// Foutre envp dans env
// Chaque elemenet d'envp split au premier =
@ -108,6 +108,8 @@ void print_node_data(t_node *t, t_usize depth)
t_node parse_to_nodes(t_first_parser *parser, t_const_str input)
{
void ast_free(t_ast_node node);
t_first_tree *tree;
t_parse_node node;
t_node ret;
@ -115,9 +117,10 @@ t_node parse_to_nodes(t_first_parser *parser, t_const_str input)
tree = ts_parser_parse_string(parser, NULL, input, str_len(input));
node = ts_tree_root_node(tree);
if (from_node(&node, &out))
if (ast_from_node(node, (t_str)input, &out))
printf("Error when building node\n");
(void)(out);
else
ast_free(out);
ret = build_node(node, input);
ts_tree_delete(tree);
return (ret);