]> git.lizzy.rs Git - plan9front.git/blob - sys/src/libregexp/regimpl.h
libregexp: simplify regular expression vm implementation
[plan9front.git] / sys / src / libregexp / regimpl.h
1 enum {
2         LANY = 0,
3         LBOL,
4         LCLASS,
5         LEND,
6         LEOL,
7         LLPAR,
8         LOR,
9         LREP,
10         LRPAR,
11         LRUNE,
12
13         TANY = 0,
14         TBOL,
15         TCAT,
16         TCLASS,
17         TEOL,
18         TNOTNL,
19         TOR,
20         TPLUS,
21         TQUES,
22         TRUNE,
23         TSTAR,
24         TSUB,
25
26         NSUBEXPM = 32
27 };
28
29 typedef struct Parselex Parselex;
30 typedef struct Renode Renode;
31
32 struct Parselex {
33         /* Parse */
34         Renode *next;
35         Renode *nodes;
36         int sub;
37         int instrs;
38         jmp_buf exitenv;
39         /* Lex */
40         void (*getnextr)(Parselex*);
41         char *rawexp;
42         char *orig;
43         Rune rune;
44         Rune peek;
45         int peeklex;
46         int done;
47         int literal;
48         Rune cpairs[400+2];
49         int nc;
50 };
51
52 struct Renode {
53         int op;
54         Renode *left;
55         Rune r;
56         union
57         {
58                 Rune r1;
59                 int sub;
60                 Renode *right;
61         };
62         int nclass;
63 };
64
65 struct Rethread {
66         Reinst *i;
67         Resub sem[NSUBEXPM];
68         Rethread *next;
69         int gen;
70 };
71
72 struct Reinst {
73         char op;
74         int gen;
75         Reinst *a;
76         union
77         {
78                 Rune r;
79                 int sub;
80         };
81         union
82         {
83                 Rune r1;
84                 Reinst *b;
85         };
86 };
87
88 static int lex(Parselex*);
89 static void getnextr(Parselex*);
90 static void getnextrlit(Parselex*);
91 static void getclass(Parselex*);
92 static Renode *e0(Parselex*);
93 static Renode *e1(Parselex*);
94 static Renode *e2(Parselex*);
95 static Renode *e3(Parselex*);
96 static Renode *buildclass(Parselex*);
97 static Renode *buildclassn(Parselex*);
98 static int pcmp(void*, void*);
99 static Reprog *regcomp1(char*, int, int);
100 static Reinst *compile(Renode*, Reprog*, int);
101 static Reinst *compile1(Renode*, Reinst*, int*, int);
102 static void prtree(Renode*, int, int);