aboutsummaryrefslogtreecommitdiff
path: root/include/lexer.h
blob: 27910a524649677598ffdae718bc89b17448f033 (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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   lexer.h                                            :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: nahaddac <nahaddac@student.42.fr>          +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/06/19 10:51:26 by nahaddac          #+#    #+#             */
/*   Updated: 2020/08/19 13:41:08 by charles          ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#ifndef LEXER_H
# define LEXER_H

# include <stdlib.h>
# include "libft_lst.h"
# include "libft_str.h"
# include "minishell.h"

enum                    e_token_tag
{
	TAG_AND          = 1 << 0,
	TAG_END          = 1 << 1,
	TAG_OR           = 1 << 2,
	TAG_PIPE         = 1 << 3,
	TAG_REDIR_IN     = 1 << 4,
	TAG_REDIR_OUT    = 1 << 5,
	TAG_REDIR_APPEND = 1 << 6,
	TAG_PARENT_OPEN  = 1 << 7,
	TAG_PARENT_CLOSE = 1 << 8,
	TAG_STR          = 1 << 9,
	TAG_STR_DOUBLE   = 1 << 10,
	TAG_STR_SINGLE   = 1 << 11,
	TAG_STICK        = 1 << 12,

	TAG_IS_STR       = TAG_STR | TAG_STR_SINGLE | TAG_STR_DOUBLE,
    TAG_IS_REDIR     = TAG_REDIR_IN | TAG_REDIR_OUT | TAG_REDIR_APPEND,
    TAG_IS_SEP       = TAG_AND | TAG_END | TAG_OR | TAG_PIPE,
};

typedef struct
{
    enum e_token_tag    tag;
    char                *content;
}                       t_token;

t_ftlst                 *lexer(char *input);
enum e_token_tag        ret_token(char *input, int  i);
enum e_token_tag        ret_token_sep_redir_append(char *input, int i);

int                     lexer_sep(char input);
int                     lexer_verif_entre_cote(char *input, int i);
int                     lexe_space(char *input);


t_token					*push_token_enum(t_token *lst_token);

t_ftlst             	*lexe_trim_out(t_ftlst *lst);

/*
** token.c
*/

t_token					*token_new(enum e_token_tag tag, char *content);
t_token					*token_new_until(enum e_token_tag tag, char *content, int n);
void					token_destroy(t_token *token);
void					token_destroy_lst(t_ftlst *tokens);
void					token_destroy_lst2(t_ftlst *tokens1, t_ftlst *tokens2);
enum e_token_tag		token_tag(t_ftlst *token_lst);
void					token_set_tag(t_ftlst *token_lst, enum e_token_tag tag);
char					*token_content(t_ftlst *token_lst);
void					token_set_content(t_ftlst *token_lst, char *content);
void					token_set_contentf(t_ftlst *token_lst, char *content);

#endif