Removed arg passing from frontend to backend functions.
[ragel.git] / test / erract3.rl
blobadfe76cec90658cd5291d2c6ff6985ca9da41303
1 /*
2  * @LANG: c
3  */
5 #include <stdio.h>
6 #define IDENT_BUFLEN 256
8 struct erract
10         int cs;
13 %%{
14         machine erract;
15         variable cs fsm->cs;
17         # The data that is to go into the fsm structure.
18         action hello_fails { printf("hello fails\n");}
20         newline = ( any | '\n' @{printf("newline\n");} )*;
21         hello = 'hello\n'* $lerr hello_fails @eof hello_fails;
22         main := newline | hello;
23 }%%
25 %% write data;
27 void erract_init( struct erract *fsm )
29         %% write init;
32 void erract_execute( struct erract *fsm, const char *_data, int _len )
34         const char *p = _data;
35         const char *pe = _data+_len;
36         const char *eof = pe;
37         %% write exec;
40 int erract_finish( struct erract *fsm )
42         if ( fsm->cs == erract_error )
43                 return -1;
44         else if ( fsm->cs >= erract_first_final )
45                 return 1;
46         return 0;
49 #include <stdio.h>
50 #include <string.h>
52 struct erract fsm;
54 void test( char *buf )
56         int len = strlen(buf);
57         erract_init( &fsm );
58         erract_execute( &fsm, buf, len );
59         if ( erract_finish( &fsm ) > 0 )
60                 printf("ACCEPT\n");
61         else
62                 printf("FAIL\n");
65 int main()
67         test(
68                 "hello\n"
69                 "hello\n"
70                 "hello\n"
71         );
73         test(
74                 "hello\n"
75                 "hello\n"
76                 "hello there\n"
77         );
79         test(
80                 "hello\n"
81                 "hello\n"
82                 "he"    );
84         test( "" );
86         return 0;
89 #ifdef _____OUTPUT_____
90 newline
91 newline
92 newline
93 ACCEPT
94 newline
95 newline
96 hello fails
97 newline
98 ACCEPT
99 newline
100 newline
101 hello fails
102 ACCEPT
103 ACCEPT
104 #endif