Fixed an unintentional concatenation of two patterns due to a missing
[external/ragel.git] / test / minimize1.rl
1 /*
2  * @LANG: c
3  */
4
5 #include <stdio.h>
6 #include <string.h>
7
8 struct min
9 {
10         int cs;
11 };
12
13 %%{
14         machine min;
15         variable curstate fsm->cs;
16
17         action a_or_b { printf("a or b\n"); }
18
19         main := (
20                 ( 'a' . [ab]* @a_or_b ) |
21                 ( 'b' . [ab]* @a_or_b ) 
22         ) . '\n';
23 }%%
24
25 %% write data;
26
27 void min_init( struct min *fsm )
28 {
29         %% write init;
30 }
31
32 void min_execute( struct min *fsm, const char *_data, int _len )
33 {
34         const char *p = _data;
35         const char *pe = _data+_len;
36
37         %% write exec;
38 }
39
40 int min_finish( struct min *fsm )
41 {
42         %% write eof;
43
44         if ( fsm->cs == min_error )
45                 return -1;
46         if ( fsm->cs >= min_first_final )
47                 return 1;
48         return 0;
49 }
50
51 struct min fsm;
52
53 void test( char *buf )
54 {
55         int len = strlen( buf );
56         min_init( &fsm );
57         min_execute( &fsm, buf, len );
58         if ( min_finish( &fsm ) > 0 )
59                 printf("ACCEPT\n");
60         else
61                 printf("FAIL\n");
62 }
63
64
65 int main()
66 {
67         test( "aaaaaa\n" );
68         test( "a\n" );
69         test( "abc\n" );
70         return 0;
71 }
72
73 #ifdef _____OUTPUT_____
74 a or b
75 a or b
76 a or b
77 a or b
78 a or b
79 ACCEPT
80 ACCEPT
81 a or b
82 FAIL
83 #endif