Initialize Tizen 2.3
[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;
15         variable cs 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         if ( fsm->cs == range_error )
38                 return -1;
39         if ( fsm->cs >= range_first_final )
40                 return 1;
41         return 0;
42 }
43
44 struct range fsm;
45
46 void test( char *buf )
47 {
48         int len = strlen( buf );
49         range_init( &fsm );
50         range_execute( &fsm, buf, len );
51         if ( range_finish( &fsm ) > 0 )
52                 printf("ACCEPT\n");
53         else
54                 printf("FAIL\n");
55 }
56
57 int main()
58 {
59         test( "a\n" );
60         test( "z\n" );
61         test( "g\n" );
62         test( "no\n" );
63         test( "1\n" );
64
65         return 0;
66 }
67
68 #ifdef _____OUTPUT_____
69 ACCEPT
70 ACCEPT
71 ACCEPT
72 FAIL
73 FAIL
74 #endif