Fixed an unintentional concatenation of two patterns due to a missing
[external/ragel.git] / test / call1.rl
1 /*
2  * @LANG: c
3  */
4
5 #include <stdio.h>
6 #include <string.h>
7
8 int num = 0;
9
10 struct test
11 {
12         int cs, top, stack[32];
13 };
14
15 %%{ 
16         machine test;
17         access fsm->;
18
19         action check_num {
20                 if ( num & 1 )
21                         fcall *fentry(odd);
22                 else
23                         fcall even;
24         }
25
26         # Test call and return functionality.
27         even := 'even' any @{fhold; fret;};
28         odd := 'odd' any @{fhold; fret;};
29         num = [0-9]+ ${ num = num * 10 + (fc - '0'); };
30         even_odd = num ' ' @check_num "\n";
31
32         # Test calls in out actions.
33         fail := !(any*);
34         out_acts = 'OA ok\n' | 
35                 'OA error1\n' |
36                 'OA error2\n';
37
38         main := even_odd | out_acts;
39 }%%
40
41 %% write data;
42
43 void test_init( struct test *fsm )
44 {
45         num = 0;
46         %% write init;
47 }
48
49 void test_execute( struct test *fsm, const char *data, int len )
50 {
51         const char *p = data;
52         const char *pe = data+len;
53
54         %% write exec;
55 }
56
57 int test_finish( struct test *fsm )
58 {
59         %% write eof;
60
61         if ( fsm->cs == test_error )
62                 return -1;
63         if ( fsm->cs >= test_first_final )
64                 return 1;
65         return 0;
66 }
67
68 #define BUFSIZE 1024
69
70 void test( char *buf )
71 {   
72         struct test test;
73         test_init( &test );
74         test_execute( &test, buf, strlen(buf) );
75         if ( test_finish( &test ) > 0 )
76                 printf( "ACCEPT\n" );
77         else
78                 printf( "FAIL\n" );
79 }
80
81 int main()
82 {
83         test( "78 even\n" );
84         test( "89 odd\n" );
85         test( "1 even\n" );
86         test( "0 odd\n" );
87         test( "OA ok\n" );
88         test( "OA error1\n" );
89         test( "OA error2\n" );
90         
91         return 0;
92 }
93
94
95 #ifdef _____OUTPUT_____
96 ACCEPT
97 ACCEPT
98 FAIL
99 FAIL
100 ACCEPT
101 ACCEPT
102 ACCEPT
103 #endif