-
Notifications
You must be signed in to change notification settings - Fork 0
/
pat.ih
82 lines (70 loc) · 1.62 KB
/
pat.ih
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
#ifndef _lib_pat_ih_
#define _lib_pat_ih_
#include <stdint.h>
#include <pat.h>
enum type {
type_nil,
type_alt,
type_cat,
type_cls,
type_lit,
type_opt,
type_rep,
type_kln,
type_sub,
type_reg,
type_nop,
};
struct context;
struct ins;
struct thread;
struct token;
struct context {
char const *str;
size_t len;
size_t pos;
struct thread *res;
struct thread *thr;
struct thread *que[2];
struct thread *frl[2];
};
struct thread {
struct thread *next;
struct ins *ip;
size_t nmat;
struct patmatch mat[10];
};
struct token {
struct token *up;
uint16_t len;
uint16_t siz;
uint8_t ch;
uint8_t id;
};
struct ins {
int (*op)(struct context *, char const *);
int16_t arg;
};
/* pat-exec.c */
int pat_match(struct pattern *, struct context *);
int do_char(struct context *, char const *);
int do_clss(struct context *, char const *);
int do_fork(struct context *, char const *);
int do_halt(struct context *, char const *);
int do_jump(struct context *, char const *);
int do_mark(struct context *, char const *);
int do_save(struct context *, char const *);
/* pat-thr.c */
int thr_alloc(struct thread *[static 2]);
int thr_cmp( struct thread *, struct thread *);
int thr_init( struct thread *, struct ins *);
void thr_fork( struct thread *, struct thread *);
void thr_free( struct thread *);
void thr_mv( struct thread *[static 2], struct thread **);
/* pat-comp.c */
int pat_marshal(struct pattern *, struct token *);
size_t type_len(enum type);
/* pat_parse.c */
int pat_parse(struct token **, char const *);
void tok_free(struct token *);
#endif