aboutsummaryrefslogtreecommitdiff
path: root/include/ms_parse.h
blob: 0810ec2a8770a10a2c67ad234317281bae5d280d (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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ms_parse.h                                         :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: cacharle <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/28 09:00:00 by cacharle          #+#    #+#             */
/*   Updated: 2020/02/28 14:57:58 by cacharle         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#ifndef MS_PARSE_H
# define MS_PARSE_H

# include "minishell.h"

/**
** \file   ms_parse.h
** \brief  Input parsing and AST manipulation
**
** Context free grammar:
** ```
** redir_in     ::= '<' <string>
** redir_out    ::= '>' <string>
** redir_append ::= '>>' <string>
** string       ::= '\'' .+ '\'' | '"' .+ '"' | [^ ]+
** sep          ::= '&&' | '||' | '|' | ';'
** expr         ::= <redir_in> | <redir_out> | <redir_append> | <string>
** cmd          ::= <expr>+
** line         ::= <cmd> <sep> <line> | <cmd>
** ```
*/

/**
** \brief                  AST node tag
** \param TAG_STRING       string
** \param TAG_SEP          `;` | `|` | `&&` | `||`
** \param TAG_REDIR_OUT    `>`
** \param TAG_REDIR_IN     `<`
** \param TAG_REDIR_APPEND `>>`
*/

typedef enum
{
    TAG_STRING,
    TAG_SEP,
    TAG_REDIR_OUT,
    TAG_REDIR_IN,
    TAG_REDIR_APPEND,
	TAG_CMD,
	TAG_LINE,
}   t_tag;

/**
** \brief               AST (Abstract Syntax Tree)
** \param tag           tag (type) of node
** \param content       substring of the parsed string which corespond to tag
** \param children_num  number of children
** \param children      children nodes
*/

typedef struct		s_ast
{
    t_tag			tag;
    char*			content;
    int				children_num;
    struct s_ast**	children;
}					t_ast;


/*
** lexer.c
*/

char				**ms_lexer(char *input);

/*
** parse.c
*/

t_ast				*ms_parse(char *input);

/*
** ast.c
*/

t_ast				*ms_ast_new(t_tag tag);
void				ms_ast_destroy(t_ast *ast);
void				ms_ast_iter(t_ast *ast, void (*f)(void *f_arg, t_ast *children), void *arg);

#endif