2004-03-17 Francois Beauchemin <beauche@softhome.net>
[mono.git] / mcs / class / System / System.Text.RegularExpressions / arch.cs
1 //\r
2 // assembly:    System\r
3 // namespace:   System.Text.RegularExpressions\r
4 // file:        arch.cs\r
5 //\r
6 // author:      Dan Lewis (dlewis@gmx.co.uk)\r
7 //              (c) 2002\r
8 \r
9 using System;\r
10 using System.Collections;\r
11 \r
12 namespace System.Text.RegularExpressions {\r
13 \r
14         enum OpCode : ushort {\r
15                 False           = 0,    // always fails\r
16                 True,                   // always succeeds\r
17 \r
18                 // matching\r
19 \r
20                 Position,               // zero-width position assertion\r
21                 String,                 // match string literal\r
22                 Reference,              // back reference\r
23 \r
24                 // character matching\r
25 \r
26                 Character,              // match character exactly\r
27                 Category,               // match character from category\r
28                 Range,                  // match character from range\r
29                 Set,                    // match character from set\r
30                 In,                     // match character from group of tests\r
31 \r
32                 // capturing\r
33 \r
34                 Open,                   // open group\r
35                 Close,                  // close group\r
36                 Balance,                // balance groups\r
37 \r
38                 // control flow\r
39 \r
40                 IfDefined,              // conditional on capture\r
41                 Sub,                    // non-backtracking subexpression\r
42                 Test,                   // non-backtracking lookahead/behind\r
43                 Branch,                 // alternative expression\r
44                 Jump,                   // unconditional goto\r
45                 Repeat,                 // new repeat context\r
46                 Until,                  // repeat subexpression within context\r
47                 FastRepeat,             // repeat simple subexpression\r
48                 Anchor,                 // anchoring expression\r
49 \r
50                 // miscellaneous\r
51                 \r
52                 Info                    // pattern information\r
53         }\r
54 \r
55         [Flags]\r
56         enum OpFlags : ushort {\r
57                 None            = 0x000,\r
58                 Negate          = 0x100,        // succeed on mismatch\r
59                 IgnoreCase      = 0x200,        // case insensitive matching\r
60                 RightToLeft     = 0x400,        // right-to-left matching\r
61                 Lazy            = 0x800         // minimizing repeat\r
62         }\r
63 \r
64         enum Position : ushort {\r
65                 Any,                    // anywhere\r
66                 Start,                  // start of string                      \A\r
67                 StartOfString,          // start of string                      \A\r
68                 StartOfLine,            // start of line                        ^\r
69                 StartOfScan,            // start of scan                        \G\r
70                 End,                    // end or before newline at end         \Z\r
71                 EndOfString,            // end of string                        \z\r
72                 EndOfLine,              // end of line                          $\r
73                 Boundary,               // word boundary                        \b\r
74                 NonBoundary             // not word boundary                    \B\r
75         };\r
76         \r
77         // see category.cs for Category enum\r
78 \r
79         interface IMachine {\r
80                 Match Scan (Regex regex, string text, int start, int end);\r
81         }\r
82 \r
83         interface IMachineFactory {\r
84                 IMachine NewInstance ();\r
85                 IDictionary Mapping { get; set; }\r
86                 int GroupCount { get; }\r
87         }\r
88 \r
89         // Anchor SKIP OFFSET\r
90         //\r
91         // Flags:       [RightToLeft] ??\r
92         // SKIP:        relative address of tail expression\r
93         // OFFSET:      offset of anchor from start of pattern\r
94         //\r
95         // Usage:\r
96         //\r
97         //      Anchor :1 OFFSET\r
98         //              <expr>\r
99         //              True\r
100         // 1:   <tail>\r
101         //\r
102         // Notes:\r
103         //\r
104         // In practice, the anchoring expression is only going to be\r
105         // Position (StartOfString, StartOfLine, StartOfScan) or String.\r
106         // This is because the optimizer looks for position anchors at the\r
107         // start of the expression, and if that fails it looks for the\r
108         // longest substring. If an expression has neither a position\r
109         // anchor or a longest substring anchor, then the anchoring expression\r
110         // is left empty. Since an empty expression will anchor at any\r
111         // position in any string, the entire input string will be scanned.\r
112 \r
113         // String LEN STR...\r
114         //\r
115         // Flags:       [RightToLeft, IgnoreCase]\r
116         // LEN:         length of string\r
117         // STR:         string characters\r
118 \r
119         // Branch SKIP\r
120         //\r
121         // SKIP:        relative address of next branch\r
122         //\r
123         //      Branch :1\r
124         //              <alt expr 1>\r
125         //              Jump :4\r
126         // 1:   Branch :2\r
127         //              <alt expr 2>\r
128         //              Jump :4\r
129         // 2:   Branch :3\r
130         //              <alt expr 3>\r
131         //              Jump :4\r
132         // 3:   False\r
133         // 4:   <tail>\r
134 \r
135         // Repeat SKIP MIN MAX\r
136         //\r
137         // Flags:       [Lazy]\r
138         // SKIP:        relative address of Until instruction\r
139         // MIN:         minimum iterations\r
140         // MAX:         maximum iterations (0xffff is infinity)\r
141         //\r
142         //      Repeat :1 MIN MAX\r
143         //              <expr>\r
144         //              Until\r
145         // 1:   <tail>\r
146 \r
147         // FastRepeat SKIP MIN MAX\r
148         //\r
149         // Flags:       [Lazy]\r
150         // SKIP:        relative address of tail expression\r
151         // MIN:         minimum iterations\r
152         // MAX:         maximum iterations (0xffff is infinity)\r
153         //\r
154         //      FastRepeat :1 MIN MAX\r
155         //              <expr>\r
156         //              True\r
157         // 1:   <tail>\r
158         //\r
159         // Notes:\r
160         //\r
161         // The subexpression of a FastRepeat construct must not contain any\r
162         // complex operators. These include: Open, Close, Balance, Repeat,\r
163         // FastRepeat, Sub, Test. In addition, the subexpression must have\r
164         // been determined to have a fixed width.\r
165         \r
166         // Sub SKIP\r
167         //\r
168         // SKIP:        relative address of tail expression\r
169         //\r
170         //      Sub :1\r
171         //              <expr>\r
172         // 1:   <tail>\r
173         //\r
174         // Notes:\r
175         //\r
176         // The Sub operator invokes an independent subexpression. This means\r
177         // that the subexpression will match only once and so will not\r
178         // participate in any backtracking.\r
179 \r
180         // Test TSKIP FSKIP\r
181         //\r
182         // TSKIP:       relative address of true expression\r
183         // FSKIP:       relative address of false expression\r
184         //\r
185         // Usage:       (?(?=test)true|false)\r
186         //\r
187         //      Test :1 :2\r
188         //              <test expr>\r
189         // 1:           <true expr>\r
190         //              Jump\r
191         // 2:           <false epxr>\r
192         //      <tail>\r
193         //\r
194         // Usage:       (?(?=test)true)\r
195         //\r
196         //      Test :1 :2\r
197         //              <test expr>\r
198         // 1:           <true expr>\r
199         // 2:   <tail>\r
200         //\r
201         // Usage:       (?=test)\r
202         //\r
203         //      Test :1 :2\r
204         //              <test expr>\r
205         // 1:           <true expr>\r
206         //              Jump 3:\r
207         // 2:           False\r
208         // 3:           <tail>\r
209         //\r
210         // Notes:\r
211         //\r
212         // For negative lookaheads, just swap the values of TSKIP and\r
213         // FSKIP. For lookbehinds, the test expression must be compiled\r
214         // in reverse. The test expression is always executed as an\r
215         // independent subexpression, so its behaviour is non-backtracking\r
216         // (like a Sub clause.)\r
217 \r
218         // IfDefined SKIP GID\r
219         //\r
220         // SKIP:        relative address of else expression\r
221         // GID:         number of group to check\r
222         //\r
223         // Usage:       (?(gid)true)\r
224         //\r
225         //      IfDefined :1\r
226         //              <true expr>\r
227         // 1:   <tail>\r
228         //\r
229         // Usage:       (?(gid)true|false)\r
230         //\r
231         //      IfDefined :1\r
232         //              <true expr>\r
233         //              Jump :2\r
234         // 1:           <false expr>\r
235         // 2:   <tail>\r
236 \r
237         // Jump SKIP\r
238         //\r
239         // SKIP:        relative address of target expression\r
240         //\r
241         //      Jump :1\r
242         //      ...\r
243         // :1   <target expr>\r
244 \r
245         // Character CHAR\r
246         //\r
247         // Flags:       [Negate, IgnoreCase, RightToLeft]\r
248         // CHAR:        exact character to match\r
249 \r
250         // Category CAT\r
251         //\r
252         // Flags:       [Negate, RightToLeft]\r
253         // CAT:         category to match (see Category enum)\r
254 \r
255         // Range LO HI\r
256         //\r
257         // Flags:       [Negate, IgnoreCase, RightToLeft]\r
258         // LO:          lowest character in range\r
259         // HI:          higest character in range\r
260 \r
261         // Set LO LEN SET...\r
262         //\r
263         // Flags:       [Negate, IgnoreCase, RightToLeft]\r
264         // LO:          lowest character in set\r
265         // LEN:         number of words in set\r
266         // SET:         bit array representing characters in set\r
267         //\r
268         // Notes:\r
269         //\r
270         // Each word in the set represents 16 characters, so the first word\r
271         // defines membership for characters LO to LO + 15, the second for\r
272         // LO + 16 to LO + 31, and so on up to LO + (LEN * 16 - 1). It is\r
273         // up to the compiler to provide a compact representation for sparse\r
274         // unicode sets. The simple way is to use Set 0 4096. Other methods\r
275         // involve paritioning the set and placing the components into an\r
276         // In block.\r
277 \r
278         // In SKIP\r
279         //\r
280         // SKIP:        relative address of tail expression\r
281         //\r
282         // Usage:       [expr]\r
283         //\r
284         //      In :1\r
285         //              <expr>\r
286         //              True\r
287         // :1   <tail>\r
288         //\r
289         // Usage:       [^expr]\r
290         //\r
291         //      In :1\r
292         //              <expr>\r
293         //              False\r
294         // :1   <tail>\r
295         //\r
296         // Notes:\r
297         //\r
298         // The In instruction consumes a single character, using the flags\r
299         // of the first instruction in the subexpression to determine its\r
300         // IgnoreCase and RightToLeft properties. The subexpression is then\r
301         // applied to the single character as a disjunction. If any instruction\r
302         // in the subexpression succeeds, the entire In construct succeeds\r
303         // and matching continues with the tail.\r
304 \r
305         // Position POS\r
306         //\r
307         // POS:         position to match (see Position enum)\r
308 \r
309         // Open GID\r
310         //\r
311         // GID:         number of group to open\r
312 \r
313         // Close GID\r
314         //\r
315         // GID:         number of group to close\r
316         \r
317         // Balance GID BAL\r
318         //\r
319         // GID:         number of capturing group (0 if none)\r
320         // BAL:         number of group to undefine\r
321 \r
322         // Info GROUPS MIN MAX\r
323         //\r
324         // GROUPS:      number of capturing groups\r
325         // MIN:         minimum width of pattern\r
326         // MAX:         maximum width of pattern (0xffff means undefined)\r
327 \r
328         // False\r
329 \r
330         // True\r
331 \r
332         // Reference GID\r
333         //\r
334         // Flags:       [IgnoreCase, RightToLeft]\r
335         // GID:         number of group to reference\r
336 }\r