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