starting the norm of the ast

This commit is contained in:
EniumRaphael 2024-07-11 14:53:15 +02:00
parent 0e18e20181
commit 0da9510ec6
5 changed files with 253 additions and 208 deletions

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/11 14:23:40 by maiboyer #+# #+# */
/* Updated: 2024/07/03 22:33:51 by maiboyer ### ########.fr */
/* Updated: 2024/07/11 14:05:20 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,19 +20,15 @@ enum e_ast_node_kind
{
S_AST_CATEGORY_MASK = 0xFFFF0000,
S_AST_NODETYPE_MASK = 0x0000FFFF,
S_AST_NONE = 0,
S_AST_COMPOUND_COMMAND = 1 << 16,
S_AST_COMMAND = 1 << 17,
S_AST_REDIRECT = 1 << 18,
S_AST_EXPANSION = 1 << 19,
AST_ARITHMETIC_EXPANSION = S_AST_EXPANSION | 0x0001,
AST_COMMAND_SUBSTITUTION = S_AST_EXPANSION | 0x0002,
AST_EXPANSION = S_AST_EXPANSION | 0x0003,
AST_COMMAND = S_AST_COMMAND | 0x0004,
AST_CASE_ITEM = S_AST_NONE | 0x0005,
AST_ELIF = S_AST_NONE | 0x0006,
AST_ELSE = S_AST_NONE | 0x0007,
@ -42,10 +38,8 @@ enum e_ast_node_kind
AST_VARIABLE_ASSIGNMENT = S_AST_NONE | 0x000E,
AST_EXTGLOB = S_AST_NONE | 0x001A,
AST_REGEX = S_AST_NONE | 0x001B,
AST_FILE_REDIRECTION = S_AST_REDIRECT | 0x000F,
AST_HEREDOC_REDIRECTION = S_AST_REDIRECT | 0x0010,
AST_FOR = S_AST_COMPOUND_COMMAND | 0x0011,
AST_CASE = S_AST_COMPOUND_COMMAND | 0x0012,
AST_COMPOUND_STATEMENT = S_AST_COMPOUND_COMMAND | 0x0013,
@ -59,7 +53,8 @@ enum e_ast_node_kind
AST_WHILE = S_AST_COMPOUND_COMMAND | 0x0019,
};
union u_ast_node_data {
union u_ast_node_data
{
t_ast_arithmetic_expansion arithmetic_expansion;
t_ast_case case_;
t_ast_case_item case_item;

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/11 14:24:24 by maiboyer #+# #+# */
/* Updated: 2024/07/03 22:30:23 by maiboyer ### ########.fr */
/* Updated: 2024/07/11 14:04:34 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,7 +19,6 @@ typedef enum e_ast_list_kind t_ast_list_kind;
typedef enum e_ast_expansion_operator t_ast_expansion_operator;
typedef enum e_ast_terminator_kind t_ast_terminator_kind;
typedef enum e_ast_redirection_kind t_ast_redirection_kind;
typedef union u_ast_node_data t_ast_node_data;
typedef struct s_ast_node *t_ast_node;

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/14 17:46:58 by maiboyer #+# #+# */
/* Updated: 2024/07/03 22:30:01 by maiboyer ### ########.fr */
/* Updated: 2024/07/11 14:48:53 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
@ -39,37 +39,66 @@ enum e_ast_terminator_kind
AST_TERM_FORK,
};
/*
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_SMALLEST_PREFIX, = ${var#pattern}
E_OP_LARGEST_PREFIX, = ${var##pattern}
E_OP_SMALLEST_SUFFIX, = ${var%pattern}
E_OP_LARGEST_SUFFIX, = ${var%%pattern}
*/
enum e_ast_expansion_operator
{
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_SMALLEST_PREFIX, // ${var#pattern}
E_OP_LARGEST_PREFIX, // ${var##pattern}
E_OP_SMALLEST_SUFFIX, // ${var%pattern}
E_OP_LARGEST_SUFFIX, // ${var%%pattern}
E_OP_NONE = 0,
E_OP_DEFAULT,
E_OP_ASSIGN_DEFAULT,
E_OP_ERROR,
E_OP_ALTERNATE,
E_OP_DEFAULT_COLON,
E_OP_ASSIGN_DEFAULT_COLON,
E_OP_ERROR_COLON,
E_OP_ALTERNATE_COLON,
E_OP_SMALLEST_PREFIX,
E_OP_LARGEST_PREFIX,
E_OP_SMALLEST_SUFFIX,
E_OP_LARGEST_SUFFIX,
};
/*
AST_REDIR_INPUT, = <
AST_REDIR_OUTPUT, = >
AST_REDIR_APPEND, = >>
AST_REDIR_HEREDOC, = <<
AST_REDIR_HEREDOC_INDENT, = <<-
AST_REDIR_DUP_INPUT, = <&
AST_REDIR_DUP_OUTPUT, = >&
AST_REDIR_OUTPUT_CLOBBER, = >|
AST_REDIR_INPUT_OUTPUT, = <>
AST_REDIR_CLOSE_INPUT, = <&
AST_REDIR_CLOSE_OUTPUT, = >&
*/
enum e_ast_redirection_kind
{
AST_REDIR_INPUT, // <
AST_REDIR_OUTPUT, // >
AST_REDIR_APPEND, // >>
AST_REDIR_HEREDOC, // <<
AST_REDIR_HEREDOC_INDENT, // <<-
AST_REDIR_DUP_INPUT, // <&
AST_REDIR_DUP_OUTPUT, // >&
AST_REDIR_OUTPUT_CLOBBER, // >|
AST_REDIR_INPUT_OUTPUT, // <>
AST_REDIR_CLOSE_INPUT, // <&
AST_REDIR_CLOSE_OUTPUT, // >&
AST_REDIR_INPUT,
AST_REDIR_OUTPUT,
AST_REDIR_APPEND,
AST_REDIR_HEREDOC,
AST_REDIR_HEREDOC_INDENT,
AST_REDIR_DUP_INPUT,
AST_REDIR_DUP_OUTPUT,
AST_REDIR_OUTPUT_CLOBBER,
AST_REDIR_INPUT_OUTPUT,
AST_REDIR_CLOSE_INPUT,
AST_REDIR_CLOSE_OUTPUT,
};
struct s_ast_empty
@ -99,6 +128,7 @@ struct s_ast_program
/// cmd1 && cmd2
/// cmd1 || cmd2 >outfile
/// ```
struct s_ast_list
{
t_ast_node left;
@ -113,6 +143,7 @@ struct s_ast_list
/// cat file | grep stuff | banane | truc
/// echo "$sutff" | if truc; then banane; fi | lololol
/// ```
struct s_ast_pipeline
{
bool bang;
@ -128,6 +159,7 @@ struct s_ast_pipeline
/// banane >output
/// VALUE=something echo $VALUE >&1 2>somewhere
/// ```
struct s_ast_command
{
t_vec_ast prefixes;
@ -144,6 +176,7 @@ struct s_ast_command
/// fi
/// ```
/// Closely related to `t_ast_elif` and `t_ast_else`
struct s_ast_if
{
t_vec_ast condition;
@ -161,6 +194,7 @@ struct s_ast_if
/// fi
/// ```
/// Closely related to `t_ast_if` and `t_ast_else`
struct s_ast_elif
{
t_vec_ast condition;
@ -174,6 +208,7 @@ struct s_ast_elif
/// fi
/// ```
/// Closely related to `t_ast_if` and `t_ast_elif`
struct s_ast_else
{
t_vec_ast then;
@ -185,6 +220,7 @@ struct s_ast_else
/// cmd $varname;
/// done
/// ```
struct s_ast_while
{
t_vec_ast condition;
@ -199,6 +235,7 @@ struct s_ast_while
/// cmd $varname;
/// done
/// ```
struct s_ast_for
{
t_str var_name;
@ -219,6 +256,7 @@ struct s_ast_for
/// fallback;
/// esac
/// ```
struct s_ast_case
{
t_ast_node word;
@ -237,6 +275,7 @@ struct s_ast_case
/// fallback;
/// ```
/// Closely tied to `t_ast_case`
struct s_ast_case_item
{
t_vec_ast pattern;
@ -252,6 +291,7 @@ struct s_ast_case_item
/// truc;
/// done
/// ```
struct s_ast_until
{
t_vec_ast condition;
@ -265,6 +305,7 @@ struct s_ast_until
/// function_name() (comand1; command2 truc banane pomme;)
/// function_name() {comand1; command2 truc banane pomme;}
/// ```
struct s_ast_function_definition
{
t_str name;
@ -275,6 +316,7 @@ struct s_ast_function_definition
/// ```shell
/// (comand1; command2 truc banane pomme;)
/// ```
struct s_ast_subshell
{
t_vec_ast body;
@ -287,6 +329,7 @@ struct s_ast_subshell
/// ```shell
/// { command1; command2 truc banane pomme; }
/// ```
struct s_ast_compound_statement
{
t_vec_ast body;
@ -299,6 +342,7 @@ struct s_ast_compound_statement
/// ```shell
/// VARIABLE=something
/// ```
struct s_ast_variable_assignment
{
t_str name;
@ -312,6 +356,7 @@ struct s_ast_variable_assignment
/// >>outfile
/// 2>&1
/// ```
struct s_ast_file_redirection
{
t_ast_node output;
@ -325,6 +370,7 @@ struct s_ast_file_redirection
/// TEXT blablabla
/// EOF
/// ```
struct s_ast_heredoc_redirection
{
t_ast_node output;
@ -340,6 +386,7 @@ struct s_ast_heredoc_redirection
/// ${VARNAME%%trucmuch pattern}
/// $@
/// ```
struct s_ast_expansion
{
t_str var_name;
@ -355,6 +402,7 @@ struct s_ast_expansion
/// $((- 1))
/// $((1-1))
/// ```
struct s_ast_arithmetic_expansion
{
t_ast_node expr;
@ -364,6 +412,7 @@ struct s_ast_arithmetic_expansion
/// ```shell
/// $(command)
/// ```
struct s_ast_command_substitution
{
t_vec_ast body;
@ -377,6 +426,7 @@ struct s_ast_command_substitution
/// +(pattern)
/// @(pattern)
/// ```
struct s_ast_extglob
{
t_str pattern;
@ -386,6 +436,7 @@ struct s_ast_extglob
/// ```shell
/// ~pattern
/// ```
struct s_ast_regex
{
t_str pattern;

View file

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/03 20:38:29 by maiboyer #+# #+# */
/* Updated: 2024/07/03 22:44:59 by maiboyer ### ########.fr */
/* Updated: 2024/07/11 14:50:03 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */