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.
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.
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/>.
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 //----------------------------------------------------------------------//
22 #include "wikitext_ragel.h"
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))
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,
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
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,
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
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
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
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,
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
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
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
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
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
260 static const int wikitext_start = 38;
261 static const int wikitext_first_final = 38;
262 static const int wikitext_error = 0;
264 static const int wikitext_en_main = 38;
266 #line 348 "wikitext_ragel.rl"
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)
276 int last_token_type = NO_TOKEN;
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;
287 out->column_start = 1;
289 out->column_stop = 1;
291 out->type = NO_TOKEN;
296 // all done, have reached end of input
298 out->type = END_OF_FILE;
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)
309 #line 310 "wikitext_ragel.c"
316 #line 390 "wikitext_ragel.rl"
318 #line 319 "wikitext_ragel.c"
331 _acts = _wikitext_actions + _wikitext_from_state_actions[cs];
332 _nacts = (unsigned int) *_acts++;
333 while ( _nacts-- > 0 ) {
334 switch ( *_acts++ ) {
336 #line 1 "wikitext_ragel.rl"
339 #line 340 "wikitext_ragel.c"
343 _keys = _wikitext_trans_keys + _wikitext_key_offsets[cs];
344 _trans = _wikitext_index_offsets[cs];
346 _klen = _wikitext_single_lengths[cs];
348 const char *_lower = _keys;
350 const char *_upper = _keys + _klen - 1;
352 if ( _upper < _lower )
355 _mid = _lower + ((_upper-_lower) >> 1);
358 else if ( (*p) > *_mid )
361 _trans += (_mid - _keys);
369 _klen = _wikitext_range_lengths[cs];
371 const char *_lower = _keys;
373 const char *_upper = _keys + (_klen<<1) - 2;
375 if ( _upper < _lower )
378 _mid = _lower + (((_upper-_lower) >> 1) & ~1);
379 if ( (*p) < _mid[0] )
381 else if ( (*p) > _mid[1] )
384 _trans += ((_mid - _keys)>>1);
392 _trans = _wikitext_indicies[_trans];
394 cs = _wikitext_trans_targs_wi[_trans];
396 if ( _wikitext_trans_actions_wi[_trans] == 0 )
399 _acts = _wikitext_actions + _wikitext_trans_actions_wi[_trans];
400 _nacts = (unsigned int) *_acts++;
401 while ( _nacts-- > 0 )
406 #line 36 "wikitext_ragel.rl"
412 #line 41 "wikitext_ragel.rl"
414 out->code_point = *p & 0x7f;
418 #line 46 "wikitext_ragel.rl"
420 out->code_point = ((uint32_t)(*(p - 1)) & 0x1f) << 6 |
425 #line 52 "wikitext_ragel.rl"
427 out->code_point = ((uint32_t)(*(p - 2)) & 0x0f) << 12 |
428 ((uint32_t)(*(p - 1)) & 0x3f) << 6 |
433 #line 59 "wikitext_ragel.rl"
435 out->code_point = ((uint32_t)(*(p - 3)) & 0x07) << 18 |
436 ((uint32_t)(*(p - 2)) & 0x3f) << 12 |
437 ((uint32_t)(*(p - 1)) & 0x3f) << 6 |
442 #line 1 "wikitext_ragel.rl"
446 #line 148 "wikitext_ragel.rl"
450 #line 157 "wikitext_ragel.rl"
454 #line 218 "wikitext_ragel.rl"
458 #line 319 "wikitext_ragel.rl"
462 #line 73 "wikitext_ragel.rl"
469 #line 79 "wikitext_ragel.rl"
476 #line 85 "wikitext_ragel.rl"
480 else if (DISTANCE() == 4)
485 else if (DISTANCE() == 3)
487 else if (DISTANCE() == 2)
495 #line 103 "wikitext_ragel.rl"
502 #line 109 "wikitext_ragel.rl"
509 #line 115 "wikitext_ragel.rl"
516 #line 122 "wikitext_ragel.rl"
518 if (out->column_start == 1 || last_token_type == BLOCKQUOTE)
529 #line 224 "wikitext_ragel.rl"
536 #line 230 "wikitext_ragel.rl"
543 #line 236 "wikitext_ragel.rl"
550 #line 254 "wikitext_ragel.rl"
557 #line 260 "wikitext_ragel.rl"
564 #line 266 "wikitext_ragel.rl"
571 #line 272 "wikitext_ragel.rl"
578 #line 278 "wikitext_ragel.rl"
580 EMIT(DECIMAL_ENTITY);
585 #line 284 "wikitext_ragel.rl"
592 #line 308 "wikitext_ragel.rl"
595 out->column_stop = 1;
601 #line 339 "wikitext_ragel.rl"
604 out->column_stop = out->column_start + 1;
609 #line 85 "wikitext_ragel.rl"
613 else if (DISTANCE() == 4)
618 else if (DISTANCE() == 3)
620 else if (DISTANCE() == 2)
628 #line 122 "wikitext_ragel.rl"
630 if (out->column_start == 1 || last_token_type == BLOCKQUOTE)
641 #line 136 "wikitext_ragel.rl"
643 if (out->column_start == 1 || last_token_type == BLOCKQUOTE)
654 #line 166 "wikitext_ragel.rl"
656 if (out->column_start == 1 || last_token_type == BLOCKQUOTE)
661 else if (DISTANCE() == 2)
663 else if (DISTANCE() == 3)
665 else if (DISTANCE() == 4)
667 else if (DISTANCE() == 5)
669 else if (DISTANCE() == 6)
671 else if (DISTANCE() > 6)
677 else if (AT_END() || NEXT_CHAR() == '\n' || NEXT_CHAR() == '\r')
682 else if (DISTANCE() == 2)
684 else if (DISTANCE() == 3)
686 else if (DISTANCE() == 4)
688 else if (DISTANCE() == 5)
690 else if (DISTANCE() == 6)
692 else if (DISTANCE() > 6)
694 p -= 6; // will scan the H6 on the next scan
707 #line 218 "wikitext_ragel.rl"
714 #line 242 "wikitext_ragel.rl"
716 EMIT(EXT_LINK_START);
721 #line 248 "wikitext_ragel.rl"
728 #line 290 "wikitext_ragel.rl"
735 #line 296 "wikitext_ragel.rl"
742 #line 308 "wikitext_ragel.rl"
745 out->column_stop = 1;
751 #line 319 "wikitext_ragel.rl"
758 #line 218 "wikitext_ragel.rl"
765 #line 290 "wikitext_ragel.rl"
772 #line 296 "wikitext_ragel.rl"
779 #line 1 "wikitext_ragel.rl"
783 if (out->column_start == 1 || last_token_type == OL || last_token_type == UL || last_token_type == BLOCKQUOTE)
792 if (out->column_start == 1 || last_token_type == OL || last_token_type == UL || last_token_type == BLOCKQUOTE)
815 #line 816 "wikitext_ragel.c"
820 _acts = _wikitext_actions + _wikitext_to_state_actions[cs];
821 _nacts = (unsigned int) *_acts++;
822 while ( _nacts-- > 0 ) {
823 switch ( *_acts++ ) {
825 #line 1 "wikitext_ragel.rl"
828 #line 829 "wikitext_ragel.c"
839 if ( _wikitext_eof_trans[cs] > 0 ) {
840 _trans = _wikitext_eof_trans[cs] - 1;
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");