A fix to the documentation makefile from John D. Mitchell.
[ragel.git] / test / builtin.rl
blob816b441996cbcacc9af6a9f40e772870b01a6de6
1 /*
2  * @LANG: c
3  */
5 #include <stdio.h>
7 void alph(const char *type)
9         printf("%s\n", type);
12 struct builtin
14         int cs;
17 %%{
18         machine builtin;
19         alphtype unsigned int;
20         variable cs fsm->cs;
22         main := (
23                 any    @{alph("any");} |
24                 ascii  @{alph("ascii");} |
25                 extend @{alph("extend");} |
26                 alpha  @{alph("alpha");} |
27                 digit  @{alph("digit");} |
28                 alnum  @{alph("alnum");} |
29                 lower  @{alph("lower");} |
30                 upper  @{alph("upper");} |
31                 cntrl  @{alph("cntrl");} |
32                 graph  @{alph("graph");} |
33                 print  @{alph("print");} |
34                 punct  @{alph("punct");} |
35                 space  @{alph("space");} |
36                 xdigit @{alph("xdigit");}
37         )*;
38 }%%
40 %% write data;
42 void builtin_init( struct builtin *fsm )
44         %% write init;
47 void builtin_execute( struct builtin *fsm, const unsigned int *data, int len )
49         const unsigned int *p = data;
50         const unsigned int *pe = data+len;
51         %% write exec;
54 int builtin_finish( struct builtin *fsm )
56         if ( fsm->cs == builtin_error )
57                 return -1;
58         else if ( fsm->cs >= builtin_first_final )
59                 return 1;
60         return 0;
63 #include <stdio.h>
64 #define BUFSIZE 2048
66 struct builtin fsm;
67 char buf[BUFSIZE];
68 unsigned int i;
70 int test( const unsigned int *data, int len )
72         builtin_init( &fsm );
73         builtin_execute( &fsm, data, len );
74         if ( builtin_finish( &fsm ) > 0 )
75                 printf("ACCEPT\n");
76         else
77                 printf("FAIL\n");
78         return 0;
81 #define DLEN 258
82 unsigned int data[DLEN] = {
83         -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
84         20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
85         39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
86         58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
87         77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
88         96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
89         112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
90         127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141,
91         142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156,
92         157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171,
93         172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186,
94         187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201,
95         202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216,
96         217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231,
97         232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246,
98         247, 248, 249, 250, 251, 252, 253, 254, 255, 256
101 int main()
103         test( data, DLEN );
104         return 0;
107 #ifdef _____OUTPUT_____
110 ascii
111 extend
112 cntrl
114 ascii
115 extend
116 cntrl
118 ascii
119 extend
120 cntrl
122 ascii
123 extend
124 cntrl
126 ascii
127 extend
128 cntrl
130 ascii
131 extend
132 cntrl
134 ascii
135 extend
136 cntrl
138 ascii
139 extend
140 cntrl
142 ascii
143 extend
144 cntrl
146 ascii
147 extend
148 cntrl
149 space
151 ascii
152 extend
153 cntrl
154 space
156 ascii
157 extend
158 cntrl
159 space
161 ascii
162 extend
163 cntrl
164 space
166 ascii
167 extend
168 cntrl
169 space
171 ascii
172 extend
173 cntrl
175 ascii
176 extend
177 cntrl
179 ascii
180 extend
181 cntrl
183 ascii
184 extend
185 cntrl
187 ascii
188 extend
189 cntrl
191 ascii
192 extend
193 cntrl
195 ascii
196 extend
197 cntrl
199 ascii
200 extend
201 cntrl
203 ascii
204 extend
205 cntrl
207 ascii
208 extend
209 cntrl
211 ascii
212 extend
213 cntrl
215 ascii
216 extend
217 cntrl
219 ascii
220 extend
221 cntrl
223 ascii
224 extend
225 cntrl
227 ascii
228 extend
229 cntrl
231 ascii
232 extend
233 cntrl
235 ascii
236 extend
237 cntrl
239 ascii
240 extend
241 cntrl
243 ascii
244 extend
245 print
246 space
248 ascii
249 extend
250 graph
251 print
252 punct
254 ascii
255 extend
256 graph
257 print
258 punct
260 ascii
261 extend
262 graph
263 print
264 punct
266 ascii
267 extend
268 graph
269 print
270 punct
272 ascii
273 extend
274 graph
275 print
276 punct
278 ascii
279 extend
280 graph
281 print
282 punct
284 ascii
285 extend
286 graph
287 print
288 punct
290 ascii
291 extend
292 graph
293 print
294 punct
296 ascii
297 extend
298 graph
299 print
300 punct
302 ascii
303 extend
304 graph
305 print
306 punct
308 ascii
309 extend
310 graph
311 print
312 punct
314 ascii
315 extend
316 graph
317 print
318 punct
320 ascii
321 extend
322 graph
323 print
324 punct
326 ascii
327 extend
328 graph
329 print
330 punct
332 ascii
333 extend
334 graph
335 print
336 punct
338 ascii
339 extend
340 digit
341 alnum
342 graph
343 print
344 xdigit
346 ascii
347 extend
348 digit
349 alnum
350 graph
351 print
352 xdigit
354 ascii
355 extend
356 digit
357 alnum
358 graph
359 print
360 xdigit
362 ascii
363 extend
364 digit
365 alnum
366 graph
367 print
368 xdigit
370 ascii
371 extend
372 digit
373 alnum
374 graph
375 print
376 xdigit
378 ascii
379 extend
380 digit
381 alnum
382 graph
383 print
384 xdigit
386 ascii
387 extend
388 digit
389 alnum
390 graph
391 print
392 xdigit
394 ascii
395 extend
396 digit
397 alnum
398 graph
399 print
400 xdigit
402 ascii
403 extend
404 digit
405 alnum
406 graph
407 print
408 xdigit
410 ascii
411 extend
412 digit
413 alnum
414 graph
415 print
416 xdigit
418 ascii
419 extend
420 graph
421 print
422 punct
424 ascii
425 extend
426 graph
427 print
428 punct
430 ascii
431 extend
432 graph
433 print
434 punct
436 ascii
437 extend
438 graph
439 print
440 punct
442 ascii
443 extend
444 graph
445 print
446 punct
448 ascii
449 extend
450 graph
451 print
452 punct
454 ascii
455 extend
456 graph
457 print
458 punct
460 ascii
461 extend
462 alpha
463 alnum
464 upper
465 graph
466 print
467 xdigit
469 ascii
470 extend
471 alpha
472 alnum
473 upper
474 graph
475 print
476 xdigit
478 ascii
479 extend
480 alpha
481 alnum
482 upper
483 graph
484 print
485 xdigit
487 ascii
488 extend
489 alpha
490 alnum
491 upper
492 graph
493 print
494 xdigit
496 ascii
497 extend
498 alpha
499 alnum
500 upper
501 graph
502 print
503 xdigit
505 ascii
506 extend
507 alpha
508 alnum
509 upper
510 graph
511 print
512 xdigit
514 ascii
515 extend
516 alpha
517 alnum
518 upper
519 graph
520 print
522 ascii
523 extend
524 alpha
525 alnum
526 upper
527 graph
528 print
530 ascii
531 extend
532 alpha
533 alnum
534 upper
535 graph
536 print
538 ascii
539 extend
540 alpha
541 alnum
542 upper
543 graph
544 print
546 ascii
547 extend
548 alpha
549 alnum
550 upper
551 graph
552 print
554 ascii
555 extend
556 alpha
557 alnum
558 upper
559 graph
560 print
562 ascii
563 extend
564 alpha
565 alnum
566 upper
567 graph
568 print
570 ascii
571 extend
572 alpha
573 alnum
574 upper
575 graph
576 print
578 ascii
579 extend
580 alpha
581 alnum
582 upper
583 graph
584 print
586 ascii
587 extend
588 alpha
589 alnum
590 upper
591 graph
592 print
594 ascii
595 extend
596 alpha
597 alnum
598 upper
599 graph
600 print
602 ascii
603 extend
604 alpha
605 alnum
606 upper
607 graph
608 print
610 ascii
611 extend
612 alpha
613 alnum
614 upper
615 graph
616 print
618 ascii
619 extend
620 alpha
621 alnum
622 upper
623 graph
624 print
626 ascii
627 extend
628 alpha
629 alnum
630 upper
631 graph
632 print
634 ascii
635 extend
636 alpha
637 alnum
638 upper
639 graph
640 print
642 ascii
643 extend
644 alpha
645 alnum
646 upper
647 graph
648 print
650 ascii
651 extend
652 alpha
653 alnum
654 upper
655 graph
656 print
658 ascii
659 extend
660 alpha
661 alnum
662 upper
663 graph
664 print
666 ascii
667 extend
668 alpha
669 alnum
670 upper
671 graph
672 print
674 ascii
675 extend
676 graph
677 print
678 punct
680 ascii
681 extend
682 graph
683 print
684 punct
686 ascii
687 extend
688 graph
689 print
690 punct
692 ascii
693 extend
694 graph
695 print
696 punct
698 ascii
699 extend
700 graph
701 print
702 punct
704 ascii
705 extend
706 graph
707 print
708 punct
710 ascii
711 extend
712 alpha
713 alnum
714 lower
715 graph
716 print
717 xdigit
719 ascii
720 extend
721 alpha
722 alnum
723 lower
724 graph
725 print
726 xdigit
728 ascii
729 extend
730 alpha
731 alnum
732 lower
733 graph
734 print
735 xdigit
737 ascii
738 extend
739 alpha
740 alnum
741 lower
742 graph
743 print
744 xdigit
746 ascii
747 extend
748 alpha
749 alnum
750 lower
751 graph
752 print
753 xdigit
755 ascii
756 extend
757 alpha
758 alnum
759 lower
760 graph
761 print
762 xdigit
764 ascii
765 extend
766 alpha
767 alnum
768 lower
769 graph
770 print
772 ascii
773 extend
774 alpha
775 alnum
776 lower
777 graph
778 print
780 ascii
781 extend
782 alpha
783 alnum
784 lower
785 graph
786 print
788 ascii
789 extend
790 alpha
791 alnum
792 lower
793 graph
794 print
796 ascii
797 extend
798 alpha
799 alnum
800 lower
801 graph
802 print
804 ascii
805 extend
806 alpha
807 alnum
808 lower
809 graph
810 print
812 ascii
813 extend
814 alpha
815 alnum
816 lower
817 graph
818 print
820 ascii
821 extend
822 alpha
823 alnum
824 lower
825 graph
826 print
828 ascii
829 extend
830 alpha
831 alnum
832 lower
833 graph
834 print
836 ascii
837 extend
838 alpha
839 alnum
840 lower
841 graph
842 print
844 ascii
845 extend
846 alpha
847 alnum
848 lower
849 graph
850 print
852 ascii
853 extend
854 alpha
855 alnum
856 lower
857 graph
858 print
860 ascii
861 extend
862 alpha
863 alnum
864 lower
865 graph
866 print
868 ascii
869 extend
870 alpha
871 alnum
872 lower
873 graph
874 print
876 ascii
877 extend
878 alpha
879 alnum
880 lower
881 graph
882 print
884 ascii
885 extend
886 alpha
887 alnum
888 lower
889 graph
890 print
892 ascii
893 extend
894 alpha
895 alnum
896 lower
897 graph
898 print
900 ascii
901 extend
902 alpha
903 alnum
904 lower
905 graph
906 print
908 ascii
909 extend
910 alpha
911 alnum
912 lower
913 graph
914 print
916 ascii
917 extend
918 alpha
919 alnum
920 lower
921 graph
922 print
924 ascii
925 extend
926 graph
927 print
928 punct
930 ascii
931 extend
932 graph
933 print
934 punct
936 ascii
937 extend
938 graph
939 print
940 punct
942 ascii
943 extend
944 graph
945 print
946 punct
948 ascii
949 extend
950 cntrl
952 extend
954 extend
956 extend
958 extend
960 extend
962 extend
964 extend
966 extend
968 extend
970 extend
972 extend
974 extend
976 extend
978 extend
980 extend
982 extend
984 extend
986 extend
988 extend
990 extend
992 extend
994 extend
996 extend
998 extend
1000 extend
1002 extend
1004 extend
1006 extend
1008 extend
1010 extend
1012 extend
1014 extend
1016 extend
1018 extend
1020 extend
1022 extend
1024 extend
1026 extend
1028 extend
1030 extend
1032 extend
1034 extend
1036 extend
1038 extend
1040 extend
1042 extend
1044 extend
1046 extend
1048 extend
1050 extend
1052 extend
1054 extend
1056 extend
1058 extend
1060 extend
1062 extend
1064 extend
1066 extend
1068 extend
1070 extend
1072 extend
1074 extend
1076 extend
1078 extend
1080 extend
1082 extend
1084 extend
1086 extend
1088 extend
1090 extend
1092 extend
1094 extend
1096 extend
1098 extend
1100 extend
1102 extend
1104 extend
1106 extend
1108 extend
1110 extend
1112 extend
1114 extend
1116 extend
1118 extend
1120 extend
1122 extend
1124 extend
1126 extend
1128 extend
1130 extend
1132 extend
1134 extend
1136 extend
1138 extend
1140 extend
1142 extend
1144 extend
1146 extend
1148 extend
1150 extend
1152 extend
1154 extend
1156 extend
1158 extend
1160 extend
1162 extend
1164 extend
1166 extend
1168 extend
1170 extend
1172 extend
1174 extend
1176 extend
1178 extend
1180 extend
1182 extend
1184 extend
1186 extend
1188 extend
1190 extend
1192 extend
1194 extend
1196 extend
1198 extend
1200 extend
1202 extend
1204 extend
1206 extend
1208 ACCEPT
1209 #endif