-
Notifications
You must be signed in to change notification settings - Fork 0
/
libparse.h
85 lines (71 loc) · 2.28 KB
/
libparse.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
78
79
80
81
82
83
84
85
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* libparse.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qle-guen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/10/19 11:28:35 by qle-guen #+# #+# */
/* Updated: 2016/10/19 15:47:20 by qle-guen ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef LIBPARSE_H
# define LIBPARSE_H
# include <stdlib.h>
typedef struct s_range
{
int a;
int b;
} t_range;
typedef union u_parg
{
char c;
char *s;
int (*f)(char);
t_range r;
} t_parg;
typedef union u_pfun_t t_pfun_t;
typedef struct s_pfun
{
t_pfun_t *t;
int type;
} t_pfun;
typedef struct s_cons
{
char *(*f)(t_parg, char *);
t_parg arg;
} t_cons;
# define CONS 1 << 0
# define RUNCONS(x, i) x.t->cons.f(x.t->cons.arg, i)
typedef struct s_comb
{
char *(*f)(t_pfun, t_pfun, char *inp);
t_pfun p1;
t_pfun p2;
} t_comb;
# define COMB 1 << 1
# define RUNCOMB(x, i) x.t->comb.f(x.t->comb.p1, x.t->comb.p2, i)
typedef struct s_uni
{
char *(*f)(t_parg, t_pfun, char *inp);
t_parg arg;
t_pfun p;
} t_uni;
# define UNI 1 << 2
# define RUNUNI(x, i) x.t->uni.f(x.t->uni.arg, x.t->uni.p, i)
typedef union u_pfun_t
{
t_cons cons;
t_comb comb;
t_uni uni;
} t_pfun_t;
char *run_pfun(t_pfun p, char *inp);
char *comb_and(t_pfun p1, t_pfun p2, char *inp);
char *space(t_parg arg, char *inp);
char *satisfy(t_parg arg, char *inp);
t_pfun uni(char *(*f)(t_parg, t_pfun, char *), t_pfun pfun, t_parg arg);
t_pfun cons(char *(*f)(t_parg, char *), t_parg arg);
t_parg parg_range(int a, int b);
char *uni_manyrange(t_parg arg, t_pfun p, char *inp);
char *run_parser(char *fmt, char *inp);
#endif