]> git.wincent.com - wikitext.git/blob - ext/wikitext_ragel.c
Fix PRE tokenization inside blockquotes
[wikitext.git] / ext / wikitext_ragel.c
1 #line 1 "wikitext_ragel.rl"
2 // Copyright 2008 Wincent Colaiuta
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16 //----------------------------------------------------------------------//
17 // NOTE: wikitext_ragel.c is generated from wikitext_ragel.rl, so       //
18 //       if you make changes to the former they will be overwritten.    //
19 //       You should perform all your edits in wikitext_ragel.rl.        //
20 //----------------------------------------------------------------------//
21
22 #include "wikitext_ragel.h"
23 #include "wikitext.h"
24 #include <stdio.h>
25
26 #define EMIT(t)     do { out->type = t; out->stop = p + 1; out->column_stop += (out->stop - out->start); } while (0)
27 #define MARK()      do { mark = p; } while (0)
28 #define REWIND()    do { p = mark; } while (0)
29 #define AT_END()    (p + 1 == pe)
30 #define DISTANCE()  (p + 1 - ts)
31 #define NEXT_CHAR() (*(p + 1))
32
33
34 #line 35 "wikitext_ragel.c"
35 static const char _wikitext_actions[] = {
36         0, 1, 0, 1, 1, 1, 5, 1, 
37         6, 1, 7, 1, 12, 1, 13, 1, 
38         14, 1, 15, 1, 16, 1, 17, 1, 
39         18, 1, 19, 1, 20, 1, 21, 1, 
40         22, 1, 23, 1, 24, 1, 25, 1, 
41         26, 1, 27, 1, 28, 1, 30, 1, 
42         31, 1, 32, 1, 33, 1, 34, 1, 
43         35, 1, 36, 1, 37, 1, 38, 1, 
44         39, 1, 40, 1, 41, 1, 42, 1, 
45         43, 1, 44, 2, 1, 29, 2, 2, 
46         29, 2, 3, 29, 2, 4, 29, 2, 
47         7, 8, 2, 7, 9, 2, 7, 10, 
48         2, 7, 11, 2, 28, 1
49 };
50
51 static const short _wikitext_key_offsets[] = {
52         0, 0, 2, 4, 6, 8, 10, 12, 
53         16, 19, 25, 32, 39, 42, 50, 58, 
54         65, 73, 81, 89, 96, 100, 102, 104, 
55         106, 108, 110, 111, 113, 114, 116, 118, 
56         120, 122, 124, 125, 127, 128, 144, 177, 
57         178, 179, 192, 199, 200, 201, 202, 203, 
58         208, 210, 211, 212, 227, 242, 256, 270, 
59         284, 307, 330, 346, 361, 376, 391, 392
60 };
61
62 static const char _wikitext_trans_keys[] = {
63         -128, -65, -128, -65, -128, -65, -128, -65, 
64         -128, -65, -128, -65, 88, 120, 48, 57, 
65         59, 48, 57, 48, 57, 65, 70, 97, 
66         102, 59, 48, 57, 65, 70, 97, 102, 
67         59, 48, 57, 65, 90, 97, 122, 59, 
68         48, 57, 59, 109, 48, 57, 65, 90, 
69         97, 122, 59, 112, 48, 57, 65, 90, 
70         97, 122, 59, 48, 57, 65, 90, 97, 
71         122, 59, 117, 48, 57, 65, 90, 97, 
72         122, 59, 111, 48, 57, 65, 90, 97, 
73         122, 59, 116, 48, 57, 65, 90, 97, 
74         122, 59, 48, 57, 65, 90, 97, 122, 
75         78, 84, 110, 116, 79, 111, 87, 119, 
76         73, 105, 75, 107, 73, 105, 62, 84, 
77         116, 62, 79, 111, 87, 119, 73, 105, 
78         75, 107, 73, 105, 62, 84, 116, 62, 
79         33, 41, 44, 46, 61, 63, 95, 126, 
80         35, 57, 58, 59, 64, 90, 97, 122, 
81         10, 13, 32, 34, 35, 38, 39, 42, 
82         60, 61, 62, 70, 72, 83, 91, 93, 
83         96, 102, 104, 115, 124, 126, 127, -62, 
84         -33, -32, -17, -16, -12, 1, 31, 33, 
85         123, 10, 32, 33, 92, 126, 35, 37, 
86         40, 59, 63, 90, 94, 95, 97, 123, 
87         35, 97, 113, 65, 90, 98, 122, 39, 
88         39, 39, 39, 47, 78, 84, 110, 116, 
89         32, 61, 32, 32, 33, 84, 92, 116, 
90         126, 35, 37, 40, 59, 63, 90, 94, 
91         95, 97, 123, 33, 80, 92, 112, 126, 
92         35, 37, 40, 59, 63, 90, 94, 95, 
93         97, 123, 33, 58, 92, 126, 35, 37, 
94         40, 59, 63, 90, 94, 95, 97, 123, 
95         33, 47, 92, 126, 35, 37, 40, 59, 
96         63, 90, 94, 95, 97, 123, 33, 47, 
97         92, 126, 35, 37, 40, 59, 63, 90, 
98         94, 95, 97, 123, 33, 41, 44, 46, 
99         61, 63, 92, 94, 95, 123, 126, 35, 
100         37, 38, 39, 40, 57, 58, 59, 64, 
101         90, 97, 122, 33, 41, 44, 46, 61, 
102         63, 92, 94, 95, 123, 126, 35, 37, 
103         38, 39, 40, 57, 58, 59, 64, 90, 
104         97, 122, 33, 41, 44, 46, 61, 63, 
105         95, 126, 35, 57, 58, 59, 64, 90, 
106         97, 122, 33, 84, 92, 116, 126, 35, 
107         37, 40, 59, 63, 90, 94, 95, 97, 
108         123, 33, 86, 92, 118, 126, 35, 37, 
109         40, 59, 63, 90, 94, 95, 97, 123, 
110         33, 78, 92, 110, 126, 35, 37, 40, 
111         59, 63, 90, 94, 95, 97, 123, 91, 
112         93, 0
113 };
114
115 static const char _wikitext_single_lengths[] = {
116         0, 0, 0, 0, 0, 0, 0, 2, 
117         1, 0, 1, 1, 1, 2, 2, 1, 
118         2, 2, 2, 1, 4, 2, 2, 2, 
119         2, 2, 1, 2, 1, 2, 2, 2, 
120         2, 2, 1, 2, 1, 8, 23, 1, 
121         1, 3, 3, 1, 1, 1, 1, 5, 
122         2, 1, 1, 5, 5, 4, 4, 4, 
123         11, 11, 8, 5, 5, 5, 1, 1
124 };
125
126 static const char _wikitext_range_lengths[] = {
127         0, 1, 1, 1, 1, 1, 1, 1, 
128         1, 3, 3, 3, 1, 3, 3, 3, 
129         3, 3, 3, 3, 0, 0, 0, 0, 
130         0, 0, 0, 0, 0, 0, 0, 0, 
131         0, 0, 0, 0, 0, 4, 5, 0, 
132         0, 5, 2, 0, 0, 0, 0, 0, 
133         0, 0, 0, 5, 5, 5, 5, 5, 
134         6, 6, 4, 5, 5, 5, 0, 0
135 };
136
137 static const short _wikitext_index_offsets[] = {
138         0, 0, 2, 4, 6, 8, 10, 12, 
139         16, 19, 23, 28, 33, 36, 42, 48, 
140         53, 59, 65, 71, 76, 81, 84, 87, 
141         90, 93, 96, 98, 101, 103, 106, 109, 
142         112, 115, 118, 120, 123, 125, 138, 167, 
143         169, 171, 180, 186, 188, 190, 192, 194, 
144         200, 203, 205, 207, 218, 229, 239, 249, 
145         259, 277, 295, 308, 319, 330, 341, 343
146 };
147
148 static const char _wikitext_indicies[] = {
149         0, 1, 2, 1, 3, 1, 4, 1, 
150         5, 1, 6, 1, 9, 9, 8, 7, 
151         10, 8, 7, 11, 11, 11, 7, 12, 
152         11, 11, 11, 7, 14, 13, 15, 15, 
153         7, 14, 13, 7, 14, 16, 13, 15, 
154         15, 7, 14, 17, 13, 15, 15, 7, 
155         18, 13, 15, 15, 7, 14, 19, 13, 
156         15, 15, 7, 14, 20, 13, 15, 15, 
157         7, 14, 21, 13, 15, 15, 7, 22, 
158         13, 15, 15, 7, 24, 25, 24, 25, 
159         23, 26, 26, 23, 27, 27, 23, 28, 
160         28, 23, 29, 29, 23, 30, 30, 23, 
161         31, 23, 32, 32, 23, 33, 23, 34, 
162         34, 23, 35, 35, 23, 36, 36, 23, 
163         37, 37, 23, 38, 38, 23, 39, 23, 
164         40, 40, 23, 41, 23, 43, 43, 43, 
165         43, 44, 43, 44, 44, 44, 43, 44, 
166         44, 42, 49, 50, 51, 53, 54, 55, 
167         56, 57, 58, 59, 60, 61, 62, 63, 
168         64, 65, 66, 61, 62, 63, 67, 52, 
169         48, 45, 46, 47, 48, 52, 1, 69, 
170         68, 71, 70, 52, 52, 52, 52, 52, 
171         52, 52, 52, 72, 74, 75, 76, 15, 
172         15, 73, 78, 77, 79, 77, 80, 77, 
173         81, 77, 83, 84, 85, 84, 85, 82, 
174         87, 59, 86, 87, 86, 89, 88, 52, 
175         91, 52, 91, 52, 52, 52, 52, 52, 
176         52, 90, 52, 92, 52, 92, 52, 52, 
177         52, 52, 52, 52, 90, 52, 93, 52, 
178         52, 52, 52, 52, 52, 52, 90, 52, 
179         94, 52, 52, 52, 52, 52, 52, 52, 
180         90, 52, 95, 52, 52, 52, 52, 52, 
181         52, 52, 90, 52, 52, 52, 52, 44, 
182         52, 52, 52, 96, 52, 96, 96, 44, 
183         96, 52, 96, 96, 90, 97, 97, 97, 
184         97, 44, 97, 52, 52, 96, 52, 96, 
185         96, 44, 96, 97, 96, 96, 72, 43, 
186         43, 43, 43, 44, 43, 44, 44, 44, 
187         43, 44, 44, 98, 52, 61, 52, 61, 
188         52, 52, 52, 52, 52, 52, 90, 52, 
189         99, 52, 99, 52, 52, 52, 52, 52, 
190         52, 90, 52, 92, 52, 92, 52, 52, 
191         52, 52, 52, 52, 90, 101, 100, 103, 
192         102, 0
193 };
194
195 static const char _wikitext_trans_targs_wi[] = {
196         38, 0, 3, 38, 5, 6, 38, 38, 
197         8, 9, 38, 10, 38, 12, 38, 11, 
198         14, 15, 38, 17, 18, 19, 38, 38, 
199         21, 27, 22, 23, 24, 25, 26, 38, 
200         28, 38, 30, 31, 32, 33, 34, 38, 
201         36, 38, 38, 37, 58, 1, 2, 4, 
202         38, 38, 39, 40, 41, 38, 41, 42, 
203         43, 41, 47, 48, 50, 51, 59, 60, 
204         62, 63, 38, 38, 38, 38, 38, 40, 
205         38, 38, 7, 13, 16, 38, 44, 45, 
206         46, 38, 38, 20, 29, 35, 38, 49, 
207         38, 38, 38, 52, 53, 54, 55, 56, 
208         57, 57, 38, 61, 38, 38, 38, 38
209 };
210
211 static const char _wikitext_trans_actions_wi[] = {
212         78, 0, 0, 81, 0, 0, 84, 69, 
213         0, 0, 39, 0, 37, 0, 35, 0, 
214         0, 0, 33, 0, 0, 0, 31, 71, 
215         0, 0, 0, 0, 0, 0, 0, 13, 
216         0, 21, 0, 0, 0, 0, 0, 11, 
217         0, 19, 67, 0, 9, 0, 0, 0, 
218         75, 99, 3, 1, 96, 41, 87, 9, 
219         0, 90, 9, 1, 1, 0, 0, 0, 
220         0, 0, 17, 29, 63, 43, 49, 0, 
221         73, 59, 0, 0, 0, 45, 0, 0, 
222         0, 15, 61, 0, 0, 0, 51, 0, 
223         47, 23, 65, 0, 0, 0, 0, 0, 
224         93, 96, 53, 0, 55, 25, 57, 27
225 };
226
227 static const char _wikitext_to_state_actions[] = {
228         0, 0, 0, 0, 0, 0, 0, 0, 
229         0, 0, 0, 0, 0, 0, 0, 0, 
230         0, 0, 0, 0, 0, 0, 0, 0, 
231         0, 0, 0, 0, 0, 0, 0, 0, 
232         0, 0, 0, 0, 0, 0, 5, 0, 
233         0, 0, 0, 0, 0, 0, 0, 0, 
234         0, 0, 0, 0, 0, 0, 0, 0, 
235         0, 0, 0, 0, 0, 0, 0, 0
236 };
237
238 static const char _wikitext_from_state_actions[] = {
239         0, 0, 0, 0, 0, 0, 0, 0, 
240         0, 0, 0, 0, 0, 0, 0, 0, 
241         0, 0, 0, 0, 0, 0, 0, 0, 
242         0, 0, 0, 0, 0, 0, 0, 0, 
243         0, 0, 0, 0, 0, 0, 7, 0, 
244         0, 0, 0, 0, 0, 0, 0, 0, 
245         0, 0, 0, 0, 0, 0, 0, 0, 
246         0, 0, 0, 0, 0, 0, 0, 0
247 };
248
249 static const char _wikitext_eof_trans[] = {
250         0, 0, 0, 0, 0, 0, 0, 8, 
251         8, 8, 8, 8, 8, 8, 8, 8, 
252         8, 8, 8, 8, 24, 24, 24, 24, 
253         24, 24, 24, 24, 24, 24, 24, 24, 
254         24, 24, 24, 24, 24, 43, 0, 69, 
255         71, 73, 74, 78, 78, 78, 78, 83, 
256         87, 87, 89, 91, 91, 91, 91, 91, 
257         91, 73, 99, 91, 91, 91, 101, 103
258 };
259
260 static const int wikitext_start = 38;
261 static const int wikitext_first_final = 38;
262 static const int wikitext_error = 0;
263
264 static const int wikitext_en_main = 38;
265
266 #line 348 "wikitext_ragel.rl"
267
268
269 // for now we use the scanner as a tokenizer that returns one token at a time, just like ANTLR
270 // ultimately we could look at embedding all of the transformation inside the scanner itself (combined scanner/parser)
271 // pass in the last token because that's useful for the scanner to know
272 // p data pointer (required by Ragel machine); overriden with contents of last_token if supplied
273 // pe data end pointer (required by Ragel machine)
274 void next_token(token_t *out, token_t *last_token, char *p, char *pe)
275 {
276     int last_token_type = NO_TOKEN;
277     if (last_token)
278     {
279         last_token_type     = last_token->type;
280         p = last_token->stop;
281         out->line_start     = out->line_stop    = last_token->line_stop;
282         out->column_start   = out->column_stop  = last_token->column_stop;
283     }
284     else
285     {
286         out->line_start     = 1;
287         out->column_start   = 1;
288         out->line_stop      = 1;
289         out->column_stop    = 1;
290     }
291     out->type       = NO_TOKEN;
292     out->code_point = 0;
293     out->start      = p;
294     if (p == pe)
295     {
296         // all done, have reached end of input
297         out->stop  = p;
298         out->type  = END_OF_FILE;
299         return;
300     }
301
302     char    *mark;      // for manual backtracking
303     char    *eof = pe;  // required for backtracking (longest match determination)
304     int     cs;         // current state (standard Ragel)
305     char    *ts;        // token start (scanner)
306     char    *te;        // token end (scanner)
307     int     act;        // identity of last patterned matched (scanner)
308     
309 #line 310 "wikitext_ragel.c"
310         {
311         cs = wikitext_start;
312         ts = 0;
313         te = 0;
314         act = 0;
315         }
316 #line 390 "wikitext_ragel.rl"
317     
318 #line 319 "wikitext_ragel.c"
319         {
320         int _klen;
321         unsigned int _trans;
322         const char *_acts;
323         unsigned int _nacts;
324         const char *_keys;
325
326         if ( p == pe )
327                 goto _test_eof;
328         if ( cs == 0 )
329                 goto _out;
330 _resume:
331         _acts = _wikitext_actions + _wikitext_from_state_actions[cs];
332         _nacts = (unsigned int) *_acts++;
333         while ( _nacts-- > 0 ) {
334                 switch ( *_acts++ ) {
335         case 6:
336 #line 1 "wikitext_ragel.rl"
337         {ts = p;}
338         break;
339 #line 340 "wikitext_ragel.c"
340                 }
341         }
342
343         _keys = _wikitext_trans_keys + _wikitext_key_offsets[cs];
344         _trans = _wikitext_index_offsets[cs];
345
346         _klen = _wikitext_single_lengths[cs];
347         if ( _klen > 0 ) {
348                 const char *_lower = _keys;
349                 const char *_mid;
350                 const char *_upper = _keys + _klen - 1;
351                 while (1) {
352                         if ( _upper < _lower )
353                                 break;
354
355                         _mid = _lower + ((_upper-_lower) >> 1);
356                         if ( (*p) < *_mid )
357                                 _upper = _mid - 1;
358                         else if ( (*p) > *_mid )
359                                 _lower = _mid + 1;
360                         else {
361                                 _trans += (_mid - _keys);
362                                 goto _match;
363                         }
364                 }
365                 _keys += _klen;
366                 _trans += _klen;
367         }
368
369         _klen = _wikitext_range_lengths[cs];
370         if ( _klen > 0 ) {
371                 const char *_lower = _keys;
372                 const char *_mid;
373                 const char *_upper = _keys + (_klen<<1) - 2;
374                 while (1) {
375                         if ( _upper < _lower )
376                                 break;
377
378                         _mid = _lower + (((_upper-_lower) >> 1) & ~1);
379                         if ( (*p) < _mid[0] )
380                                 _upper = _mid - 2;
381                         else if ( (*p) > _mid[1] )
382                                 _lower = _mid + 2;
383                         else {
384                                 _trans += ((_mid - _keys)>>1);
385                                 goto _match;
386                         }
387                 }
388                 _trans += _klen;
389         }
390
391 _match:
392         _trans = _wikitext_indicies[_trans];
393 _eof_trans:
394         cs = _wikitext_trans_targs_wi[_trans];
395
396         if ( _wikitext_trans_actions_wi[_trans] == 0 )
397                 goto _again;
398
399         _acts = _wikitext_actions + _wikitext_trans_actions_wi[_trans];
400         _nacts = (unsigned int) *_acts++;
401         while ( _nacts-- > 0 )
402         {
403                 switch ( *_acts++ )
404                 {
405         case 0:
406 #line 36 "wikitext_ragel.rl"
407         {
408         MARK();
409     }
410         break;
411         case 1:
412 #line 41 "wikitext_ragel.rl"
413         {
414         out->code_point = *p & 0x7f;
415     }
416         break;
417         case 2:
418 #line 46 "wikitext_ragel.rl"
419         {
420         out->code_point = ((uint32_t)(*(p - 1)) & 0x1f) << 6 |
421             (*p & 0x3f);
422     }
423         break;
424         case 3:
425 #line 52 "wikitext_ragel.rl"
426         {
427         out->code_point = ((uint32_t)(*(p - 2)) & 0x0f) << 12 |
428             ((uint32_t)(*(p - 1)) & 0x3f) << 6 |
429             (*p & 0x3f);
430     }
431         break;
432         case 4:
433 #line 59 "wikitext_ragel.rl"
434         {
435         out->code_point = ((uint32_t)(*(p - 3)) & 0x07) << 18 |
436             ((uint32_t)(*(p - 2)) & 0x3f) << 12 |
437             ((uint32_t)(*(p - 1)) & 0x3f) << 6 |
438             (*p & 0x3f);
439     }
440         break;
441         case 7:
442 #line 1 "wikitext_ragel.rl"
443         {te = p+1;}
444         break;
445         case 8:
446 #line 148 "wikitext_ragel.rl"
447         {act = 9;}
448         break;
449         case 9:
450 #line 157 "wikitext_ragel.rl"
451         {act = 10;}
452         break;
453         case 10:
454 #line 218 "wikitext_ragel.rl"
455         {act = 12;}
456         break;
457         case 11:
458 #line 319 "wikitext_ragel.rl"
459         {act = 28;}
460         break;
461         case 12:
462 #line 73 "wikitext_ragel.rl"
463         {te = p+1;{
464             EMIT(NO_WIKI_START);
465             {p++; goto _out; }
466         }}
467         break;
468         case 13:
469 #line 79 "wikitext_ragel.rl"
470         {te = p+1;{
471             EMIT(NO_WIKI_END);
472             {p++; goto _out; }
473         }}
474         break;
475         case 14:
476 #line 85 "wikitext_ragel.rl"
477         {te = p+1;{
478             if (DISTANCE() == 5)
479                 EMIT(STRONG_EM);
480             else if (DISTANCE() == 4)
481             {
482                 p--;
483                 EMIT(STRONG_EM);
484             }
485             else if (DISTANCE() == 3)
486                 EMIT(STRONG);
487             else if (DISTANCE() == 2)
488                 EMIT(EM);
489             else
490                 EMIT(PRINTABLE);
491             {p++; goto _out; }
492         }}
493         break;
494         case 15:
495 #line 103 "wikitext_ragel.rl"
496         {te = p+1;{
497             EMIT(TT);
498             {p++; goto _out; }
499         }}
500         break;
501         case 16:
502 #line 109 "wikitext_ragel.rl"
503         {te = p+1;{
504             EMIT(TT_START);
505             {p++; goto _out; }
506         }}
507         break;
508         case 17:
509 #line 115 "wikitext_ragel.rl"
510         {te = p+1;{
511             EMIT(TT_END);
512             {p++; goto _out; }
513         }}
514         break;
515         case 18:
516 #line 122 "wikitext_ragel.rl"
517         {te = p+1;{
518             if (out->column_start == 1 || last_token_type == BLOCKQUOTE)
519                 EMIT(BLOCKQUOTE);
520             else
521             {
522                 REWIND();
523                 EMIT(GREATER);
524             }
525             {p++; goto _out; }
526         }}
527         break;
528         case 19:
529 #line 224 "wikitext_ragel.rl"
530         {te = p+1;{
531             EMIT(LINK_START);
532             {p++; goto _out; }
533         }}
534         break;
535         case 20:
536 #line 230 "wikitext_ragel.rl"
537         {te = p+1;{
538             EMIT(LINK_END);
539             {p++; goto _out; }
540         }}
541         break;
542         case 21:
543 #line 236 "wikitext_ragel.rl"
544         {te = p+1;{
545             EMIT(SEPARATOR);
546             {p++; goto _out; }
547         }}
548         break;
549         case 22:
550 #line 254 "wikitext_ragel.rl"
551         {te = p+1;{
552             EMIT(QUOT_ENTITY);
553             {p++; goto _out; }
554         }}
555         break;
556         case 23:
557 #line 260 "wikitext_ragel.rl"
558         {te = p+1;{
559             EMIT(AMP_ENTITY);
560             {p++; goto _out; }
561         }}
562         break;
563         case 24:
564 #line 266 "wikitext_ragel.rl"
565         {te = p+1;{
566             EMIT(NAMED_ENTITY);
567             {p++; goto _out; }
568         }}
569         break;
570         case 25:
571 #line 272 "wikitext_ragel.rl"
572         {te = p+1;{
573             EMIT(HEX_ENTITY);
574             {p++; goto _out; }
575         }}
576         break;
577         case 26:
578 #line 278 "wikitext_ragel.rl"
579         {te = p+1;{
580             EMIT(DECIMAL_ENTITY);
581             {p++; goto _out; }
582         }}
583         break;
584         case 27:
585 #line 284 "wikitext_ragel.rl"
586         {te = p+1;{
587             EMIT(QUOT);
588             {p++; goto _out; }
589         }}
590         break;
591         case 28:
592 #line 308 "wikitext_ragel.rl"
593         {te = p+1;{
594             EMIT(CRLF);
595             out->column_stop = 1;
596             out->line_stop++;
597             {p++; goto _out; }
598         }}
599         break;
600         case 29:
601 #line 339 "wikitext_ragel.rl"
602         {te = p+1;{
603             EMIT(DEFAULT);
604             out->column_stop = out->column_start + 1;
605             {p++; goto _out; }
606         }}
607         break;
608         case 30:
609 #line 85 "wikitext_ragel.rl"
610         {te = p;p--;{
611             if (DISTANCE() == 5)
612                 EMIT(STRONG_EM);
613             else if (DISTANCE() == 4)
614             {
615                 p--;
616                 EMIT(STRONG_EM);
617             }
618             else if (DISTANCE() == 3)
619                 EMIT(STRONG);
620             else if (DISTANCE() == 2)
621                 EMIT(EM);
622             else
623                 EMIT(PRINTABLE);
624             {p++; goto _out; }
625         }}
626         break;
627         case 31:
628 #line 122 "wikitext_ragel.rl"
629         {te = p;p--;{
630             if (out->column_start == 1 || last_token_type == BLOCKQUOTE)
631                 EMIT(BLOCKQUOTE);
632             else
633             {
634                 REWIND();
635                 EMIT(GREATER);
636             }
637             {p++; goto _out; }
638         }}
639         break;
640         case 32:
641 #line 136 "wikitext_ragel.rl"
642         {te = p;p--;{
643             if (out->column_start == 1 || last_token_type == BLOCKQUOTE)
644             {
645                 REWIND();
646                 EMIT(PRE);
647             }
648             else
649                 EMIT(SPACE);
650             {p++; goto _out; }
651         }}
652         break;
653         case 33:
654 #line 166 "wikitext_ragel.rl"
655         {te = p;p--;{
656             if (out->column_start == 1 || last_token_type == BLOCKQUOTE)
657             {
658                 REWIND();
659                 if (DISTANCE() == 1)
660                     EMIT(H1_START);
661                 else if (DISTANCE() == 2)
662                     EMIT(H2_START);
663                 else if (DISTANCE() == 3)
664                     EMIT(H3_START);
665                 else if (DISTANCE() == 4)
666                     EMIT(H4_START);
667                 else if (DISTANCE() == 5)
668                     EMIT(H5_START);
669                 else if (DISTANCE() == 6)
670                     EMIT(H6_START);
671                 else if (DISTANCE() > 6)
672                 {
673                     p = ts + 6;
674                     EMIT(H6_START);
675                 }
676             }
677             else if (AT_END() || NEXT_CHAR() == '\n' || NEXT_CHAR() == '\r')
678             {
679                 REWIND();
680                 if (DISTANCE() == 1)
681                     EMIT(H1_END);
682                 else if (DISTANCE() == 2)
683                     EMIT(H2_END);
684                 else if (DISTANCE() == 3)
685                     EMIT(H3_END);
686                 else if (DISTANCE() == 4)
687                     EMIT(H4_END);
688                 else if (DISTANCE() == 5)
689                     EMIT(H5_END);
690                 else if (DISTANCE() == 6)
691                     EMIT(H6_END);
692                 else if (DISTANCE() > 6)
693                 {
694                     p -= 6; // will scan the H6 on the next scan
695                     EMIT(PRINTABLE);
696                 }
697             }
698             else
699             {
700                 REWIND();
701                 EMIT(PRINTABLE);
702             }
703             {p++; goto _out; }
704         }}
705         break;
706         case 34:
707 #line 218 "wikitext_ragel.rl"
708         {te = p;p--;{
709             EMIT(URI);
710             {p++; goto _out; }
711         }}
712         break;
713         case 35:
714 #line 242 "wikitext_ragel.rl"
715         {te = p;p--;{
716             EMIT(EXT_LINK_START);
717             {p++; goto _out; }
718         }}
719         break;
720         case 36:
721 #line 248 "wikitext_ragel.rl"
722         {te = p;p--;{
723             EMIT(EXT_LINK_END);
724             {p++; goto _out; }
725         }}
726         break;
727         case 37:
728 #line 290 "wikitext_ragel.rl"
729         {te = p;p--;{
730             EMIT(AMP);
731             {p++; goto _out; }
732         }}
733         break;
734         case 38:
735 #line 296 "wikitext_ragel.rl"
736         {te = p;p--;{
737             EMIT(LESS);
738             {p++; goto _out; }
739         }}
740         break;
741         case 39:
742 #line 308 "wikitext_ragel.rl"
743         {te = p;p--;{
744             EMIT(CRLF);
745             out->column_stop = 1;
746             out->line_stop++;
747             {p++; goto _out; }
748         }}
749         break;
750         case 40:
751 #line 319 "wikitext_ragel.rl"
752         {te = p;p--;{
753             EMIT(PRINTABLE);
754             {p++; goto _out; }
755         }}
756         break;
757         case 41:
758 #line 218 "wikitext_ragel.rl"
759         {{p = ((te))-1;}{
760             EMIT(URI);
761             {p++; goto _out; }
762         }}
763         break;
764         case 42:
765 #line 290 "wikitext_ragel.rl"
766         {{p = ((te))-1;}{
767             EMIT(AMP);
768             {p++; goto _out; }
769         }}
770         break;
771         case 43:
772 #line 296 "wikitext_ragel.rl"
773         {{p = ((te))-1;}{
774             EMIT(LESS);
775             {p++; goto _out; }
776         }}
777         break;
778         case 44:
779 #line 1 "wikitext_ragel.rl"
780         {       switch( act ) {
781         case 9:
782         {{p = ((te))-1;}
783             if (out->column_start == 1 || last_token_type == OL || last_token_type == UL || last_token_type == BLOCKQUOTE)
784                 EMIT(OL);
785             else
786                 EMIT(PRINTABLE);
787             {p++; goto _out; }
788         }
789         break;
790         case 10:
791         {{p = ((te))-1;}
792             if (out->column_start == 1 || last_token_type == OL || last_token_type == UL || last_token_type == BLOCKQUOTE)
793                 EMIT(UL);
794             else
795                 EMIT(PRINTABLE);
796             {p++; goto _out; }
797         }
798         break;
799         case 12:
800         {{p = ((te))-1;}
801             EMIT(URI);
802             {p++; goto _out; }
803         }
804         break;
805         case 28:
806         {{p = ((te))-1;}
807             EMIT(PRINTABLE);
808             {p++; goto _out; }
809         }
810         break;
811         default: break;
812         }
813         }
814         break;
815 #line 816 "wikitext_ragel.c"
816                 }
817         }
818
819 _again:
820         _acts = _wikitext_actions + _wikitext_to_state_actions[cs];
821         _nacts = (unsigned int) *_acts++;
822         while ( _nacts-- > 0 ) {
823                 switch ( *_acts++ ) {
824         case 5:
825 #line 1 "wikitext_ragel.rl"
826         {ts = 0;}
827         break;
828 #line 829 "wikitext_ragel.c"
829                 }
830         }
831
832         if ( cs == 0 )
833                 goto _out;
834         if ( ++p != pe )
835                 goto _resume;
836         _test_eof: {}
837         if ( p == eof )
838         {
839         if ( _wikitext_eof_trans[cs] > 0 ) {
840                 _trans = _wikitext_eof_trans[cs] - 1;
841                 goto _eof_trans;
842         }
843         }
844
845         _out: {}
846         }
847 #line 391 "wikitext_ragel.rl"
848     if (cs == wikitext_error)
849         rb_raise(eWikitextParserError, "failed before finding a token");
850     else if (out->type == NO_TOKEN)
851         rb_raise(eWikitextParserError, "failed to produce a token");
852 }