blob: 6470a178fa4cfc36c1fd34dc910a6b29f7a63c27 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ast.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/01 17:05:38 by charles #+# #+# */
/* Updated: 2020/04/02 13:27:59 by charles ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef AST_H
# define AST_H
/*
** \file ast.h
** \brief AST structs
*/
# include <stdlib.h>
# include <stdbool.h>
# include "libft_mem.h"
# include "libft_util.h"
/*
** \brief Separator type
** \param SEP_END Regular command end `;`
** \param SEP_PIPE Pipe output of left to right `|`
** \param SEP_AND Execute right if left status == 0 `&&`
** \param SEP_OR Execute right if left status != 0 `||`
*/
typedef enum e_sep
{
SEP_END,
SEP_PIPE,
SEP_AND,
SEP_OR,
} t_sep;
struct s_ast;
/*
** \brief Line struct
** \param left AST to the left of separator
** \param right AST to the right of separator
** \param sep Type of separator
*/
typedef struct s_line
{
struct s_ast *left;
struct s_ast *right;
t_sep sep;
} t_line;
/*
** \brief Command struct
** \param argv Array of string,
** all arguments beginning with executable name
** \param in STDIN redirection filename
** \param out STDOUT redirection filename
** \param is_append True if out redirection is append to file
*/
typedef struct s_cmd
{
char **argv;
char *in;
char *out;
bool is_append;
} t_cmd;
/*
** \brief AST node tag (type)
** \param TAG_CMD Command AST node
** \param TAG_LINE Line AST node
** \param TAG_ROOT Root line AST node
*/
typedef enum e_ast_tag
{
TAG_CMD,
TAG_LINE,
TAG_ROOT,
} t_ast_tag;
/*
** \brief AST node struct
** \param tag Node tag
** \param data Union containning possible node data
** \param data::cmd Command struct
** \param data::line Line struct
*/
typedef struct s_ast
{
t_ast_tag tag;
union
{
t_line line;
t_cmd cmd;
} data;
} t_ast;
t_ast *ast_new(t_ast_tag tag, void *data);
void ast_destroy(t_ast *ast);
#endif
|