34bc43023ae2a50f25d24a1b3e318f37826a9f44
[external/ragel.git] / test / range.rl
1 /*
2  * @LANG: c
3  */
4
5 #include <stdio.h>
6 #include <string.h>
7
8 struct range
9 {
10         int cs;
11 };
12
13 %%{
14         machine range_fsm;
15         variable curstate fsm->cs;
16
17         main := ( 'a' .. 'c' | 'c' .. 'e' | 'm' .. 'n' | 'a' .. 'z' ) '\n';
18 }%%
19
20 %% write data;
21
22 void range_init( struct range *fsm )
23 {
24         %% write init;
25 }
26
27 void range_execute( struct range *fsm, const char *_data, int _len )
28 {
29         const char *p = _data;
30         const char *pe = _data+_len;
31
32         %% write exec;
33 }
34
35 int range_finish( struct range *fsm )
36 {
37         %% write eof;
38
39         if ( fsm->cs == range_fsm_error )
40                 return -1;
41         if ( fsm->cs >= range_fsm_first_final )
42                 return 1;
43         return 0;
44 }
45
46 struct range fsm;
47
48 void test( char *buf )
49 {
50         int len = strlen( buf );
51         range_init( &fsm );
52         range_execute( &fsm, buf, len );
53         if ( range_finish( &fsm ) > 0 )
54                 printf("ACCEPT\n");
55         else
56                 printf("FAIL\n");
57 }
58
59 int main()
60 {
61         test( "a\n" );
62         test( "z\n" );
63         test( "g\n" );
64         test( "no\n" );
65         test( "1\n" );
66
67         return 0;
68 }
69
70 #ifdef _____OUTPUT_____
71 ACCEPT
72 ACCEPT
73 ACCEPT
74 FAIL
75 FAIL
76 #endif