-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathast.h
77 lines (63 loc) · 1.79 KB
/
ast.h
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
#ifndef AST_H_SENTRY
#define AST_H_SENTRY
#include <stdbool.h>
#include "dynamic_array.h"
struct ast_data_script {
struct dynamic_array *expressions;
};
struct ast_data_command {
struct dynamic_array *words;
struct dynamic_array *redirects;
};
struct ast_data_pipeline {
struct dynamic_array *expressions;
};
enum ast_data_expression_redirect_type {
AST_DATA_EXPRESSION_REDIRECT_TYPE_INPUT,
AST_DATA_EXPRESSION_REDIRECT_TYPE_OUTPUT,
AST_DATA_EXPRESSION_REDIRECT_TYPE_OUTPUT_APPEND
};
struct ast_data_expression_redirect {
enum ast_data_expression_redirect_type type;
char *file;
};
enum ast_data_logical_expression_type {
AST_DATA_LOGICAL_EXPRESSION_TYPE_AND,
AST_DATA_LOGICAL_EXPRESSION_TYPE_OR
};
struct ast_data_logical_expression {
enum ast_data_logical_expression_type type;
struct ast *left;
struct ast *right;
};
struct ast_data_subshell {
struct ast *script;
struct dynamic_array *redirects;
};
union ast_data {
struct ast_data_script script;
struct ast_data_command command;
struct ast_data_pipeline pipeline;
struct ast_data_logical_expression logical_expression;
struct ast_data_subshell subshell;
};
enum ast_type {
AST_TYPE_SCRIPT,
AST_TYPE_COMMAND,
AST_TYPE_PIPELINE,
AST_TYPE_LOGICAL_EXPRESSION,
AST_TYPE_SUBSHELL
};
struct ast {
enum ast_type type;
union ast_data data;
bool async;
};
struct ast *ast_create_script();
struct ast *ast_create_command();
struct ast *ast_create_pipeline();
struct ast *ast_create_logical_expression(enum ast_data_logical_expression_type type);
struct ast *ast_create_subshell();
struct ast_data_expression_redirect *ast_data_expression_redirect_create(enum ast_data_expression_redirect_type type, char *file);
void ast_destroy(struct ast *ast);
#endif