apc init
[henge/apc.git] / lexer_fsm.c
1
2 #line 1 "lexer_fsm.rl"
3 #include <stdio.h>
4 #include <stdint.h>
5 #include <apc/parser.tab.h>
6 #include <unistdio.h>
7 #include <unistr.h>
8
9 extern void lexer_pushtok(int, YYSTYPE);
10 extern int lexer_lexmapfile(int, int);
11 extern int ipower(int, int);
12 extern int ttov(uint8_t*, int);
13 extern uint8_t* ttos(const uint8_t*, int);
14
15 int lexer_setdirection(uint8_t*, int);
16 int lexer_lexstring(uint8_t*, int);
17 int lexer_setstr(uint8_t*, int);
18
19 #define $($)#$
20 #define PUSHTOK(TOK,LFUNC,UTYPE) \
21 do { \
22 printf("Lexer_lexstring:: PUSHTOK(" $(TOK) $(LFUNC) $(UTYPE) ")\n"); \
23 tok_t = TOK; \
24 yylval.UTYPE = LFUNC(ts, p-ts); \
25 lexer_pushtok(tok_t, yylval); \
26 ++ntok; \
27 } while (0);
28
29
30 #line 31 "lexer_fsm.c"
31 static const char _lexstring_actions[] = {
32 0, 1, 0, 1, 1, 1, 2, 1,
33 3, 1, 4, 1, 5, 1, 13, 1,
34 14, 1, 15, 2, 0, 14, 2, 2,
35 6, 2, 2, 7, 2, 2, 8, 2,
36 2, 9, 2, 2, 10, 2, 2, 11,
37 2, 2, 12
38 };
39
40 static const short _lexstring_key_offsets[] = {
41 0, 0, 12, 17, 22, 24, 28, 34,
42 40, 48, 54, 63, 69, 75, 76, 82,
43 83, 89, 95, 103, 111, 123, 135, 147,
44 159, 171, 183, 195, 207, 219, 231, 243,
45 255, 267, 279
46 };
47
48 static const char _lexstring_trans_keys[] = {
49 48, 69, 78, 83, 87, 126, 49, 57,
50 65, 90, 97, 122, 0, 95, 120, 48,
51 57, 0, 95, 120, 48, 57, 48, 57,
52 0, 95, 48, 57, 0, 95, 65, 90,
53 97, 122, 0, 95, 65, 90, 97, 122,
54 0, 69, 87, 95, 65, 90, 97, 122,
55 0, 95, 65, 90, 97, 122, 0, 69,
56 83, 87, 95, 65, 90, 97, 122, 0,
57 95, 65, 90, 97, 122, 0, 95, 65,
58 90, 97, 122, 95, 35, 95, 65, 90,
59 97, 122, 95, 0, 95, 65, 90, 97,
60 122, 48, 57, 65, 90, 97, 122, 0,
61 95, 48, 57, 65, 90, 97, 122, 0,
62 95, 48, 57, 65, 90, 97, 122, 48,
63 69, 78, 83, 87, 126, 49, 57, 65,
64 90, 97, 122, 48, 69, 78, 83, 87,
65 126, 49, 57, 65, 90, 97, 122, 48,
66 69, 78, 83, 87, 126, 49, 57, 65,
67 90, 97, 122, 48, 69, 78, 83, 87,
68 126, 49, 57, 65, 90, 97, 122, 48,
69 69, 78, 83, 87, 126, 49, 57, 65,
70 90, 97, 122, 48, 69, 78, 83, 87,
71 126, 49, 57, 65, 90, 97, 122, 48,
72 69, 78, 83, 87, 126, 49, 57, 65,
73 90, 97, 122, 48, 69, 78, 83, 87,
74 126, 49, 57, 65, 90, 97, 122, 48,
75 69, 78, 83, 87, 126, 49, 57, 65,
76 90, 97, 122, 48, 69, 78, 83, 87,
77 126, 49, 57, 65, 90, 97, 122, 48,
78 69, 78, 83, 87, 126, 49, 57, 65,
79 90, 97, 122, 48, 69, 78, 83, 87,
80 126, 49, 57, 65, 90, 97, 122, 48,
81 69, 78, 83, 87, 126, 49, 57, 65,
82 90, 97, 122, 48, 69, 78, 83, 87,
83 126, 49, 57, 65, 90, 97, 122, 48,
84 69, 78, 83, 87, 126, 49, 57, 65,
85 90, 97, 122, 0
86 };
87
88 static const char _lexstring_single_lengths[] = {
89 0, 6, 3, 3, 0, 2, 2, 2,
90 4, 2, 5, 2, 2, 1, 2, 1,
91 2, 0, 2, 2, 6, 6, 6, 6,
92 6, 6, 6, 6, 6, 6, 6, 6,
93 6, 6, 6
94 };
95
96 static const char _lexstring_range_lengths[] = {
97 0, 3, 1, 1, 1, 1, 2, 2,
98 2, 2, 2, 2, 2, 0, 2, 0,
99 2, 3, 3, 3, 3, 3, 3, 3,
100 3, 3, 3, 3, 3, 3, 3, 3,
101 3, 3, 3
102 };
103
104 static const short _lexstring_index_offsets[] = {
105 0, 0, 10, 15, 20, 22, 26, 31,
106 36, 43, 48, 56, 61, 66, 68, 73,
107 75, 80, 84, 90, 96, 106, 116, 126,
108 136, 146, 156, 166, 176, 186, 196, 206,
109 216, 226, 236
110 };
111
112 static const char _lexstring_indicies[] = {
113 0, 4, 5, 6, 7, 8, 2, 3,
114 3, 1, 9, 9, 11, 10, 1, 9,
115 9, 12, 10, 1, 13, 1, 14, 14,
116 15, 1, 16, 16, 17, 17, 1, 16,
117 18, 17, 17, 1, 16, 19, 19, 20,
118 17, 17, 1, 16, 21, 17, 17, 1,
119 16, 22, 23, 24, 25, 17, 17, 1,
120 16, 26, 17, 17, 1, 16, 27, 17,
121 17, 1, 28, 1, 29, 30, 17, 17,
122 1, 31, 1, 16, 32, 17, 17, 1,
123 33, 34, 34, 1, 35, 35, 36, 34,
124 34, 1, 37, 37, 34, 34, 34, 1,
125 0, 4, 5, 6, 7, 8, 2, 3,
126 3, 1, 0, 4, 5, 6, 7, 8,
127 2, 3, 3, 1, 0, 4, 5, 6,
128 7, 8, 2, 3, 3, 1, 0, 4,
129 5, 6, 7, 8, 2, 3, 3, 1,
130 0, 4, 5, 6, 7, 8, 2, 3,
131 3, 1, 0, 4, 5, 6, 7, 8,
132 2, 3, 3, 1, 0, 4, 5, 6,
133 7, 8, 2, 3, 3, 1, 0, 4,
134 5, 6, 7, 8, 2, 3, 3, 1,
135 0, 4, 5, 6, 7, 8, 2, 3,
136 3, 1, 0, 4, 5, 6, 7, 8,
137 2, 3, 3, 1, 0, 4, 5, 6,
138 7, 8, 2, 3, 3, 1, 0, 4,
139 5, 6, 7, 8, 2, 3, 3, 1,
140 0, 4, 5, 6, 7, 8, 2, 3,
141 3, 1, 0, 4, 5, 6, 7, 8,
142 2, 3, 3, 1, 0, 4, 5, 6,
143 7, 8, 2, 3, 3, 1, 0
144 };
145
146 static const char _lexstring_trans_targs[] = {
147 2, 0, 3, 6, 7, 8, 10, 12,
148 13, 20, 3, 17, 4, 5, 21, 5,
149 22, 6, 23, 9, 32, 24, 11, 14,
150 16, 31, 25, 26, 27, 15, 29, 28,
151 30, 18, 19, 33, 18, 34
152 };
153
154 static const char _lexstring_trans_actions[] = {
155 9, 0, 9, 9, 9, 9, 9, 9,
156 0, 0, 0, 13, 13, 9, 0, 0,
157 0, 0, 0, 0, 0, 0, 0, 0,
158 0, 0, 0, 0, 0, 11, 0, 0,
159 0, 9, 0, 0, 0, 0
160 };
161
162 static const char _lexstring_to_state_actions[] = {
163 0, 0, 0, 0, 0, 0, 0, 0,
164 0, 0, 0, 0, 0, 0, 0, 17,
165 0, 0, 0, 0, 3, 15, 5, 37,
166 31, 40, 28, 7, 0, 11, 25, 22,
167 34, 19, 1
168 };
169
170 static const int lexstring_start = 1;
171 static const int lexstring_first_final = 20;
172 static const int lexstring_error = 0;
173
174 static const int lexstring_en_tok_lexer = 1;
175
176
177 #line 114 "lexer_fsm.rl"
178
179
180 int
181 lexer_lexstring
182 (uint8_t* str, int size)
183 { uint8_t *p;
184 uint8_t *ts, *pe, *eof;
185 int cs, ntok, tok_t, direction;
186
187 ntok = direction = 0;
188 p = ts = str;
189 pe = p + size +1;
190
191 printf("|---Begin lexstring on p = %s, pe = %s.\n",p, pe);
192
193
194 #line 195 "lexer_fsm.c"
195 {
196 cs = lexstring_start;
197 }
198
199 #line 130 "lexer_fsm.rl"
200
201 #line 202 "lexer_fsm.c"
202 {
203 int _klen;
204 unsigned int _trans;
205 const char *_acts;
206 unsigned int _nacts;
207 const char *_keys;
208
209 if ( p == pe )
210 goto _test_eof;
211 if ( cs == 0 )
212 goto _out;
213 _resume:
214 _keys = _lexstring_trans_keys + _lexstring_key_offsets[cs];
215 _trans = _lexstring_index_offsets[cs];
216
217 _klen = _lexstring_single_lengths[cs];
218 if ( _klen > 0 ) {
219 const char *_lower = _keys;
220 const char *_mid;
221 const char *_upper = _keys + _klen - 1;
222 while (1) {
223 if ( _upper < _lower )
224 break;
225
226 _mid = _lower + ((_upper-_lower) >> 1);
227 if ( (*p) < *_mid )
228 _upper = _mid - 1;
229 else if ( (*p) > *_mid )
230 _lower = _mid + 1;
231 else {
232 _trans += (unsigned int)(_mid - _keys);
233 goto _match;
234 }
235 }
236 _keys += _klen;
237 _trans += _klen;
238 }
239
240 _klen = _lexstring_range_lengths[cs];
241 if ( _klen > 0 ) {
242 const char *_lower = _keys;
243 const char *_mid;
244 const char *_upper = _keys + (_klen<<1) - 2;
245 while (1) {
246 if ( _upper < _lower )
247 break;
248
249 _mid = _lower + (((_upper-_lower) >> 1) & ~1);
250 if ( (*p) < _mid[0] )
251 _upper = _mid - 2;
252 else if ( (*p) > _mid[1] )
253 _lower = _mid + 2;
254 else {
255 _trans += (unsigned int)((_mid - _keys)>>1);
256 goto _match;
257 }
258 }
259 _trans += _klen;
260 }
261
262 _match:
263 _trans = _lexstring_indicies[_trans];
264 cs = _lexstring_trans_targs[_trans];
265
266 if ( _lexstring_trans_actions[_trans] == 0 )
267 goto _again;
268
269 _acts = _lexstring_actions + _lexstring_trans_actions[_trans];
270 _nacts = (unsigned int) *_acts++;
271 while ( _nacts-- > 0 )
272 {
273 switch ( *_acts++ )
274 {
275 case 4:
276 #line 41 "lexer_fsm.rl"
277 { printf("Lexer_lexstring:: action:set_ts. ts = %s\n", p); ts = p; }
278 break;
279 case 5:
280 #line 42 "lexer_fsm.rl"
281 { printf("Lexer_lexstring:: action:push_SS. p = %s\n",p);
282 yylval.str = (uint8_t*) "SS";
283 lexer_pushtok(SS, yylval);
284 ntok++;
285 }
286 break;
287 case 13:
288 #line 79 "lexer_fsm.rl"
289 { printf("Lexer_lexstring:: action:push_height p = %s\n", p);
290 PUSHTOK(HEIGHT, ttov, val);
291 }
292 break;
293 #line 294 "lexer_fsm.c"
294 }
295 }
296
297 _again:
298 _acts = _lexstring_actions + _lexstring_to_state_actions[cs];
299 _nacts = (unsigned int) *_acts++;
300 while ( _nacts-- > 0 ) {
301 switch ( *_acts++ ) {
302 case 0:
303 #line 31 "lexer_fsm.rl"
304 { PUSHTOK(REF, ttov, ref); }
305 break;
306 case 1:
307 #line 32 "lexer_fsm.rl"
308 { PUSHTOK(NUM, ttov, val); }
309 break;
310 case 2:
311 #line 33 "lexer_fsm.rl"
312 { printf("Lexer_lexstring:: action:push_name: from %s to %s\n", ts, p);
313 PUSHTOK(NAME, ttos, str);
314 }
315 break;
316 case 3:
317 #line 36 "lexer_fsm.rl"
318 { printf("Lexer_lexstring:: action:push_map: pushing '~'\n");
319 yylval.str = (uint8_t*) '~';
320 lexer_pushtok(MOPEN, yylval);
321 ntok++;
322 }
323 break;
324 case 5:
325 #line 42 "lexer_fsm.rl"
326 { printf("Lexer_lexstring:: action:push_SS. p = %s\n",p);
327 yylval.str = (uint8_t*) "SS";
328 lexer_pushtok(SS, yylval);
329 ntok++;
330 }
331 break;
332 case 6:
333 #line 47 "lexer_fsm.rl"
334 { printf("Lexer_lexstring:: action:push_S. p = %s\n", p);
335 yylval.val = 0;
336 lexer_pushtok(D, yylval);
337 }
338 break;
339 case 7:
340 #line 51 "lexer_fsm.rl"
341 { printf("Lexer_lexstring:: action:push_SW. p = %s\n", p);
342 yylval.val = 1;
343 lexer_pushtok(D, yylval);
344 }
345 break;
346 case 8:
347 #line 55 "lexer_fsm.rl"
348 { printf("Lexer_lexstring:: action:push_W. p = %s\n", p);
349 yylval.val = 2;
350 lexer_pushtok(D, yylval);
351 }
352 break;
353 case 9:
354 #line 59 "lexer_fsm.rl"
355 { printf("Lexer_lexstring:: action:push_NW. p = %s\n", p);
356 yylval.val = 3;
357 lexer_pushtok(D, yylval);
358 }
359 break;
360 case 10:
361 #line 63 "lexer_fsm.rl"
362 { printf("Lexer_lexstring:: action:push_N. p = %s\n", p);
363 yylval.val = 4;
364 lexer_pushtok(D, yylval);
365 }
366 break;
367 case 11:
368 #line 71 "lexer_fsm.rl"
369 { printf("Lexer_lexstring:: action:push_N. p = %s\n", p);
370 yylval.val = 6;
371 lexer_pushtok(D, yylval);
372 }
373 break;
374 case 12:
375 #line 75 "lexer_fsm.rl"
376 { printf("Lexer_lexstring:: action:push_N. p = %s\n", p);
377 yylval.val = 7;
378 lexer_pushtok(D, yylval);
379 }
380 break;
381 case 14:
382 #line 82 "lexer_fsm.rl"
383 { printf("Lexer_lexstring:: action:push_height p = %s\n", p);
384 PUSHTOK(WIDTH, ttov, val);
385 }
386 break;
387 case 15:
388 #line 85 "lexer_fsm.rl"
389 {yylval.str = (uint8_t*) '#'; lexer_pushtok(LINK),yylval); }
390 break;
391 #line 392 "lexer_fsm.c"
392 }
393 }
394
395 if ( cs == 0 )
396 goto _out;
397 if ( ++p != pe )
398 goto _resume;
399 _test_eof: {}
400 _out: {}
401 }
402
403 #line 131 "lexer_fsm.rl"
404
405 printf("Ending lexstring of file %s, pushed %d tokens.\n",str, ntok);
406
407 return ntok;
408 }
409
410
411
412 #line 413 "lexer_fsm.c"
413 static const char _setdirection_actions[] = {
414 0, 1, 0, 1, 1, 1, 2, 1,
415 3, 1, 4, 1, 5, 1, 6, 1,
416 7
417 };
418
419 static const char _setdirection_key_offsets[] = {
420 0, 0, 6, 8, 12, 14, 16, 20,
421 22, 24, 26, 26, 26, 26, 26, 26,
422 26, 26
423 };
424
425 static const char _setdirection_trans_keys[] = {
426 0, 69, 78, 83, 87, 95, 0, 95,
427 0, 69, 87, 95, 0, 95, 0, 95,
428 0, 69, 87, 95, 0, 95, 0, 95,
429 0, 95, 0
430 };
431
432 static const char _setdirection_single_lengths[] = {
433 0, 6, 2, 4, 2, 2, 4, 2,
434 2, 2, 0, 0, 0, 0, 0, 0,
435 0, 0
436 };
437
438 static const char _setdirection_range_lengths[] = {
439 0, 0, 0, 0, 0, 0, 0, 0,
440 0, 0, 0, 0, 0, 0, 0, 0,
441 0, 0
442 };
443
444 static const char _setdirection_index_offsets[] = {
445 0, 0, 7, 10, 15, 18, 21, 26,
446 29, 32, 35, 36, 37, 38, 39, 40,
447 41, 42
448 };
449
450 static const char _setdirection_indicies[] = {
451 0, 2, 3, 4, 5, 0, 1, 6,
452 6, 1, 7, 8, 9, 7, 1, 10,
453 10, 1, 11, 11, 1, 0, 12, 13,
454 0, 1, 14, 14, 1, 15, 15, 1,
455 16, 16, 1, 1, 1, 1, 1, 1,
456 1, 1, 1, 0
457 };
458
459 static const char _setdirection_trans_targs[] = {
460 10, 0, 2, 3, 6, 9, 11, 12,
461 4, 5, 13, 14, 7, 8, 15, 16,
462 17
463 };
464
465 static const char _setdirection_trans_actions[] = {
466 0, 0, 0, 0, 0, 0, 0, 0,
467 0, 0, 0, 0, 0, 0, 0, 0,
468 0
469 };
470
471 static const char _setdirection_to_state_actions[] = {
472 0, 0, 0, 0, 0, 0, 0, 0,
473 0, 0, 7, 5, 1, 9, 11, 13,
474 15, 3
475 };
476
477 static const int setdirection_start = 1;
478 static const int setdirection_first_final = 10;
479 static const int setdirection_error = 0;
480
481 static const int setdirection_en_main = 1;
482
483
484 #line 166 "lexer_fsm.rl"
485
486
487 int
488 lexer_setdirection
489 (uint8_t* str, int size)
490 { uint8_t *p, *pe, *eof;
491 int cs;
492
493
494 p = str;
495 pe = str + size + 1;
496
497 printf("|--- Begin lexer_setdirection str = %s, p = %s, pe = %s ---|\n", str,p, pe);
498
499
500 #line 501 "lexer_fsm.c"
501 {
502 cs = setdirection_start;
503 }
504
505 #line 181 "lexer_fsm.rl"
506
507 #line 508 "lexer_fsm.c"
508 {
509 int _klen;
510 unsigned int _trans;
511 const char *_acts;
512 unsigned int _nacts;
513 const char *_keys;
514
515 if ( cs == 0 )
516 goto _out;
517 _resume:
518 _keys = _setdirection_trans_keys + _setdirection_key_offsets[cs];
519 _trans = _setdirection_index_offsets[cs];
520
521 _klen = _setdirection_single_lengths[cs];
522 if ( _klen > 0 ) {
523 const char *_lower = _keys;
524 const char *_mid;
525 const char *_upper = _keys + _klen - 1;
526 while (1) {
527 if ( _upper < _lower )
528 break;
529
530 _mid = _lower + ((_upper-_lower) >> 1);
531 if ( (*p) < *_mid )
532 _upper = _mid - 1;
533 else if ( (*p) > *_mid )
534 _lower = _mid + 1;
535 else {
536 _trans += (unsigned int)(_mid - _keys);
537 goto _match;
538 }
539 }
540 _keys += _klen;
541 _trans += _klen;
542 }
543
544 _klen = _setdirection_range_lengths[cs];
545 if ( _klen > 0 ) {
546 const char *_lower = _keys;
547 const char *_mid;
548 const char *_upper = _keys + (_klen<<1) - 2;
549 while (1) {
550 if ( _upper < _lower )
551 break;
552
553 _mid = _lower + (((_upper-_lower) >> 1) & ~1);
554 if ( (*p) < _mid[0] )
555 _upper = _mid - 2;
556 else if ( (*p) > _mid[1] )
557 _lower = _mid + 2;
558 else {
559 _trans += (unsigned int)((_mid - _keys)>>1);
560 goto _match;
561 }
562 }
563 _trans += _klen;
564 }
565
566 _match:
567 _trans = _setdirection_indicies[_trans];
568 cs = _setdirection_trans_targs[_trans];
569
570 _acts = _setdirection_actions + _setdirection_to_state_actions[cs];
571 _nacts = (unsigned int) *_acts++;
572 while ( _nacts-- > 0 ) {
573 switch ( *_acts++ ) {
574 case 0:
575 #line 141 "lexer_fsm.rl"
576 {printf("Lexer_setdirection:: direction is north, returning 4\n"); return 4;; }
577 break;
578 case 1:
579 #line 142 "lexer_fsm.rl"
580 { printf("Lexer_setdirection:: direction is west, returning 2\n");return 2;}
581 break;
582 case 2:
583 #line 143 "lexer_fsm.rl"
584 { printf("Lexer_setdirection:: direction is east, returning 6\n");return 6;}
585 break;
586 case 3:
587 #line 144 "lexer_fsm.rl"
588 { printf("Lexer_setdirection:: direction is south, returning 0\n");return 0;}
589 break;
590 case 4:
591 #line 145 "lexer_fsm.rl"
592 { printf("Lexer_setdirection:: direction is northeast, returning 5\n");return 5 ;}
593 break;
594 case 5:
595 #line 146 "lexer_fsm.rl"
596 { printf("Lexer_setdirection:: direction is northwest, returning 3\n");return 3;}
597 break;
598 case 6:
599 #line 147 "lexer_fsm.rl"
600 { printf("Lexer_setdirection:: direction is southeast, returning 7\n");return 7;}
601 break;
602 case 7:
603 #line 148 "lexer_fsm.rl"
604 { printf("Lexer_setdirection:: direction is southwest, returning 1\n");return 1;}
605 break;
606 #line 607 "lexer_fsm.c"
607 }
608 }
609
610 if ( cs == 0 )
611 goto _out;
612 p += 1;
613 goto _resume;
614 _out: {}
615 }
616
617 #line 182 "lexer_fsm.rl"
618
619 printf("|--- Error in: lexer_setdirection ---|\n");
620
621 return -1;
622 }
623
624
625
626 /**************************/
627 /****Abandon All Hope******/
628 /**************************/
629 /*** ***/
630 /*** ***/
631 /*** ***/
632 /*** ***/
633
634
635 #if 0
636
637 #line 638 "lexer_fsm.c"
638 static const char _setstr_actions[] = {
639 0, 1, 0, 1, 1, 1, 2, 1,
640 3, 1, 4, 1, 5, 1, 6, 1,
641 7, 1, 8
642 };
643
644 static const unsigned char _setstr_key_offsets[] = {
645 0, 0, 6, 7, 13, 20, 25, 33,
646 34, 35, 36, 42, 50, 55, 60, 66,
647 75, 79, 85, 86, 92, 99, 106, 111,
648 115, 116, 117, 118, 124, 132, 137, 142,
649 148, 157, 161, 167, 168, 174, 181, 184,
650 185, 191, 195, 201, 202, 203, 209, 216,
651 222, 231, 235, 241, 241, 241, 241, 241,
652 241, 250, 251
653 };
654
655 static const char _setstr_trans_keys[] = {
656 48, 83, 65, 90, 97, 122, 120, 48,
657 57, 65, 90, 97, 122, 0, 48, 57,
658 65, 90, 97, 122, 95, 65, 90, 97,
659 122, 35, 48, 83, 126, 65, 90, 97,
660 122, 95, 48, 120, 48, 57, 65, 90,
661 97, 122, 0, 95, 48, 57, 65, 90,
662 97, 122, 83, 65, 90, 97, 122, 0,
663 65, 90, 97, 122, 0, 83, 65, 90,
664 97, 122, 0, 69, 78, 83, 87, 65,
665 90, 97, 122, 65, 90, 97, 122, 69,
666 87, 65, 90, 97, 122, 120, 48, 57,
667 65, 90, 97, 122, 95, 48, 57, 65,
668 90, 97, 122, 35, 83, 126, 65, 90,
669 97, 122, 95, 65, 90, 97, 122, 35,
670 48, 83, 126, 95, 48, 120, 48, 57,
671 65, 90, 97, 122, 0, 95, 48, 57,
672 65, 90, 97, 122, 83, 65, 90, 97,
673 122, 0, 65, 90, 97, 122, 0, 83,
674 65, 90, 97, 122, 0, 69, 78, 83,
675 87, 65, 90, 97, 122, 65, 90, 97,
676 122, 69, 87, 65, 90, 97, 122, 120,
677 48, 57, 65, 90, 97, 122, 95, 48,
678 57, 65, 90, 97, 122, 35, 83, 126,
679 83, 83, 95, 65, 90, 97, 122, 65,
680 90, 97, 122, 69, 87, 65, 90, 97,
681 122, 48, 120, 48, 57, 65, 90, 97,
682 122, 0, 48, 57, 65, 90, 97, 122,
683 83, 95, 65, 90, 97, 122, 69, 78,
684 83, 87, 95, 65, 90, 97, 122, 65,
685 90, 97, 122, 69, 87, 65, 90, 97,
686 122, 69, 78, 83, 87, 95, 65, 90,
687 97, 122, 95, 0
688 };
689
690 static const char _setstr_single_lengths[] = {
691 0, 2, 1, 0, 1, 1, 4, 1,
692 1, 1, 0, 2, 1, 1, 2, 5,
693 0, 2, 1, 0, 1, 3, 1, 4,
694 1, 1, 1, 0, 2, 1, 1, 2,
695 5, 0, 2, 1, 0, 1, 3, 1,
696 2, 0, 2, 1, 1, 0, 1, 2,
697 5, 0, 2, 0, 0, 0, 0, 0,
698 5, 1, 0
699 };
700
701 static const char _setstr_range_lengths[] = {
702 0, 2, 0, 3, 3, 2, 2, 0,
703 0, 0, 3, 3, 2, 2, 2, 2,
704 2, 2, 0, 3, 3, 2, 2, 0,
705 0, 0, 0, 3, 3, 2, 2, 2,
706 2, 2, 2, 0, 3, 3, 0, 0,
707 2, 2, 2, 0, 0, 3, 3, 2,
708 2, 2, 2, 0, 0, 0, 0, 0,
709 2, 0, 0
710 };
711
712 static const short _setstr_index_offsets[] = {
713 0, 0, 5, 7, 11, 16, 20, 27,
714 29, 31, 33, 37, 43, 47, 51, 56,
715 64, 67, 72, 74, 78, 83, 89, 93,
716 98, 100, 102, 104, 108, 114, 118, 122,
717 127, 135, 138, 143, 145, 149, 154, 158,
718 160, 165, 168, 173, 175, 177, 181, 186,
719 191, 199, 202, 207, 208, 209, 210, 211,
720 212, 220, 222
721 };
722
723 static const char _setstr_indicies[] = {
724 0, 3, 2, 2, 1, 4, 1, 5,
725 5, 5, 1, 6, 5, 5, 5, 1,
726 7, 2, 2, 1, 8, 9, 11, 12,
727 10, 10, 1, 13, 1, 14, 1, 15,
728 1, 16, 16, 16, 1, 17, 18, 16,
729 16, 16, 1, 20, 19, 19, 1, 17,
730 19, 19, 1, 17, 21, 19, 19, 1,
731 17, 22, 23, 23, 22, 19, 19, 1,
732 19, 19, 1, 22, 22, 19, 19, 1,
733 24, 1, 25, 25, 25, 1, 26, 25,
734 25, 25, 1, 8, 11, 12, 10, 10,
735 1, 27, 10, 10, 1, 28, 29, 30,
736 31, 1, 32, 1, 33, 1, 34, 1,
737 35, 35, 35, 1, 36, 37, 35, 35,
738 35, 1, 39, 38, 38, 1, 36, 38,
739 38, 1, 36, 40, 38, 38, 1, 36,
740 41, 42, 42, 41, 38, 38, 1, 38,
741 38, 1, 41, 41, 38, 38, 1, 43,
742 1, 44, 44, 44, 1, 45, 44, 44,
743 44, 1, 28, 30, 31, 1, 46, 1,
744 47, 27, 10, 10, 1, 10, 10, 1,
745 48, 48, 10, 10, 1, 49, 1, 50,
746 1, 51, 51, 51, 1, 52, 51, 51,
747 51, 1, 53, 7, 2, 2, 1, 54,
748 55, 55, 54, 7, 2, 2, 1, 2,
749 2, 1, 54, 54, 2, 2, 1, 1,
750 1, 1, 1, 1, 48, 56, 56, 48,
751 27, 10, 10, 1, 57, 1, 1, 0
752 };
753
754 static const char _setstr_trans_targs[] = {
755 2, 0, 5, 47, 3, 4, 51, 6,
756 7, 18, 22, 40, 57, 8, 9, 10,
757 11, 52, 12, 13, 14, 15, 16, 17,
758 19, 20, 21, 23, 24, 35, 39, 55,
759 25, 26, 27, 28, 53, 29, 30, 31,
760 32, 33, 34, 36, 37, 38, 54, 56,
761 41, 44, 45, 46, 58, 48, 49, 50,
762 42, 43
763 };
764
765 static const char _setstr_trans_actions[] = {
766 17, 0, 17, 17, 17, 17, 0, 0,
767 0, 17, 17, 17, 0, 0, 17, 17,
768 17, 0, 0, 17, 17, 17, 17, 17,
769 17, 17, 0, 0, 0, 17, 0, 0,
770 0, 17, 17, 17, 0, 0, 17, 17,
771 17, 17, 17, 17, 17, 0, 0, 17,
772 17, 17, 17, 17, 0, 17, 17, 17,
773 17, 0
774 };
775
776 static const char _setstr_to_state_actions[] = {
777 0, 0, 0, 0, 13, 0, 0, 0,
778 0, 0, 0, 0, 0, 0, 0, 0,
779 0, 0, 0, 0, 0, 0, 0, 0,
780 0, 0, 0, 0, 0, 0, 0, 0,
781 0, 0, 0, 0, 0, 0, 0, 0,
782 0, 0, 0, 0, 0, 0, 0, 0,
783 0, 0, 0, 0, 1, 3, 9, 11,
784 5, 7, 15
785 };
786
787 static const int setstr_start = 1;
788 static const int setstr_first_final = 51;
789 static const int setstr_error = 0;
790
791 static const int setstr_en_main = 1;
792
793
794 #line 260 "lexer_fsm.rl"
795
796
797 int
798 lexer_setstr
799 (uint8_t* str, int size)
800 { uint8_t *p, *pe, *eof;
801 int cs, type, newstrt;
802
803 type = newstrt = 0;
804
805 p = str;
806 pe = str + size + 1;
807
808 printf("|--- Begin lexer_setstr with str = %s, p = %s, pe = %s ---|\n", str,p, pe);
809
810
811 #line 812 "lexer_fsm.c"
812 {
813 cs = setstr_start;
814 }
815
816 #line 276 "lexer_fsm.rl"
817
818 #line 819 "lexer_fsm.c"
819 {
820 int _klen;
821 unsigned int _trans;
822 const char *_acts;
823 unsigned int _nacts;
824 const char *_keys;
825
826 if ( cs == 0 )
827 goto _out;
828 _resume:
829 _keys = _setstr_trans_keys + _setstr_key_offsets[cs];
830 _trans = _setstr_index_offsets[cs];
831
832 _klen = _setstr_single_lengths[cs];
833 if ( _klen > 0 ) {
834 const char *_lower = _keys;
835 const char *_mid;
836 const char *_upper = _keys + _klen - 1;
837 while (1) {
838 if ( _upper < _lower )
839 break;
840
841 _mid = _lower + ((_upper-_lower) >> 1);
842 if ( (*p) < *_mid )
843 _upper = _mid - 1;
844 else if ( (*p) > *_mid )
845 _lower = _mid + 1;
846 else {
847 _trans += (unsigned int)(_mid - _keys);
848 goto _match;
849 }
850 }
851 _keys += _klen;
852 _trans += _klen;
853 }
854
855 _klen = _setstr_range_lengths[cs];
856 if ( _klen > 0 ) {
857 const char *_lower = _keys;
858 const char *_mid;
859 const char *_upper = _keys + (_klen<<1) - 2;
860 while (1) {
861 if ( _upper < _lower )
862 break;
863
864 _mid = _lower + (((_upper-_lower) >> 1) & ~1);
865 if ( (*p) < _mid[0] )
866 _upper = _mid - 2;
867 else if ( (*p) > _mid[1] )
868 _lower = _mid + 2;
869 else {
870 _trans += (unsigned int)((_mid - _keys)>>1);
871 goto _match;
872 }
873 }
874 _trans += _klen;
875 }
876
877 _match:
878 _trans = _setstr_indicies[_trans];
879 cs = _setstr_trans_targs[_trans];
880
881 if ( _setstr_trans_actions[_trans] == 0 )
882 goto _again;
883
884 _acts = _setstr_actions + _setstr_trans_actions[_trans];
885 _nacts = (unsigned int) *_acts++;
886 while ( _nacts-- > 0 )
887 {
888 switch ( *_acts++ )
889 {
890 case 8:
891 #line 212 "lexer_fsm.rl"
892 {printf("p = %s \n",p);}
893 break;
894 #line 895 "lexer_fsm.c"
895 }
896 }
897
898 _again:
899 _acts = _setstr_actions + _setstr_to_state_actions[cs];
900 _nacts = (unsigned int) *_acts++;
901 while ( _nacts-- > 0 ) {
902 switch ( *_acts++ ) {
903 case 0:
904 #line 204 "lexer_fsm.rl"
905 {printf("Lexer_setstr:: Returning setvlink filetype for %s\n", str); type = 5; newstrt = lexer_lexsetvlink(str); {p++; goto _out; }}
906 break;
907 case 1:
908 #line 205 "lexer_fsm.rl"
909 {printf("Lexer_setstr:: Returning elevlink filetype for %s\n", str); type = 6; newstrt = lexer_lexelevlink(str); {p++; goto _out; }}
910 break;
911 case 2:
912 #line 206 "lexer_fsm.rl"
913 {printf("Lexer_setstr:: Returning setmodel filetype\n"); newstrt = lexer_lexsetmodel(str); type = 1; {p++; goto _out; }}
914 break;
915 case 3:
916 #line 207 "lexer_fsm.rl"
917 {printf("Lexer_setstr:: Returning setmap filetype\n"); newstrt = lexer_lexsetmap(str); type = 2; {p++; goto _out; }}
918 break;
919 case 4:
920 #line 208 "lexer_fsm.rl"
921 {printf("Lexer_setstr:: Returning elemodel filetype for %s\n", str); newstrt = lexer_lexelemodel(str); type = 3; {p++; goto _out; }}
922 break;
923 case 5:
924 #line 209 "lexer_fsm.rl"
925 {printf("Lexer_setstr:: Returning elemap filetype for %s\n", str); newstrt = lexer_lexelemap(str); type = 4; {p++; goto _out; }}
926 break;
927 case 6:
928 #line 210 "lexer_fsm.rl"
929 { printf("Lexer_setstr:: Returning setolink filetype\n"); type = 8; newstrt = lexer_lexsetolink(str); {p++; goto _out; }}
930 break;
931 case 7:
932 #line 211 "lexer_fsm.rl"
933 { printf("Lexer_setstr:: Returning eleolink filetype\n"); type = 7; newstrt = lexer_lexeleolink(str); {p++; goto _out; }}
934 break;
935 #line 936 "lexer_fsm.c"
936 }
937 }
938
939 if ( cs == 0 )
940 goto _out;
941 p += 1;
942 goto _resume;
943 _out: {}
944 }
945
946 #line 277 "lexer_fsm.rl"
947
948 printf("|--- End lexer_setstr. Incrementing str by %d, type is %d ---|\n", newstrt, type);
949
950 return newstrt;
951 }
952
953 #endif
954
955
956 /* %%{ */
957 /* machine file_matcher; */
958
959 /* action call_ml { ts = p; fgoto set_hw ;} */
960 /* action call_tl { return 0;} */
961 /* action set_height {height = ttov(p, p-ts+1); ts = p;} */
962 /* action set_width { width = ttov(p, p-ts+1);} */
963 /* action call_lmf {lexer_lexmapfile(height, width); } */
964 /* action lex_error {printf("input error: character %c in filename %s is invalid\n = %s\n", fc, str, p);} */
965
966 /* #This machine determines the type of file we are lexing */
967 /* #and calls the appropriate machine to handle it. */
968
969 /* #TODO add mapping name */
970 /* width = digit+ %set_width; */
971 /* height = digit+ %set_height; */
972
973 /* set_hw := height . '_' . width [\0] %to(call_lmf); */
974
975 /* tok_segment = alnum; */
976 /* map_end = 'm' . '_' %to(call_ml); */
977 /* tok_end = alnum+ . [\0] %to(call_tl); */
978
979 /* file_matcher := (tok_segment+ . '_' )+ ( map_end | tok_end ); */
980
981 /* write data; */
982 /* }%% */
983
984 /* int */
985 /* lexer_matchfile */
986 /* (char* str, int size) */
987 /* { *p, *pe; */
988 /* char* ts; */
989 /* int cs, ntok, height, width; */
990
991 /* p = str; */
992 /* pe = p + size; */
993 /* height = width = 0; */
994
995 /* printf("Checking if filename is a map file:: filename = %s, p = %c, pe = %c\n", str, *p, *pe); */
996
997 /* %%write init; */
998 /* %%write exec noend; */
999
1000 /* printf("Ending lexer_ismapfile on %s\n", str); */
1001
1002 /* return ntok; */
1003 /* } */
1004
1005 /* %%{ */
1006 /* machine vartype; */
1007
1008 /* action isele {return 0;} */
1009 /* action ismodel {return 1;} */
1010
1011 /* set_name = alpha+; */
1012 /* ele_name = alpha+; */
1013 /* model_name = alpha+; */
1014
1015 /* ele = set_name '_' model_name '_' ele_name %isele; */
1016 /* model = set_name '_' model_name [\0] %ismodel; */
1017
1018
1019 /* ismodel := (ele | model); */
1020
1021 /* write data; */
1022
1023 /* }%% */
1024
1025 /* int */
1026 /* lexer_ismodel */
1027 /* (uint8_t* str, int size) */
1028 /* { uint8_t *p, *pe, *eof; */
1029 /* int cs; */
1030
1031 /* p = str; */
1032 /* pe = p + size + 1; */
1033
1034 /* %%write init; */
1035 /* %%write exec; */
1036
1037
1038 /* } */