Some cleanup and fixes to the runtests script. The -P option will be changing.
[external/ragel.git] / test / erract3.rl
1 /*
2  * @LANG: c
3  */
4
5 #include <stdio.h>
6 #define IDENT_BUFLEN 256
7
8 struct erract
9 {
10         int cs;
11 };
12
13 %%{
14         machine erract;
15         variable curstate fsm->cs;
16
17         # The data that is to go into the fsm structure.
18         action hello_fails { printf("hello fails\n");}
19
20         newline = ( any | '\n' @{printf("newline\n");} )*;
21         hello = 'hello\n'* $lerr hello_fails @eof hello_fails;
22         main := newline | hello;
23 }%%
24
25 %% write data;
26
27 void erract_init( struct erract *fsm )
28 {
29         %% write init;
30 }
31
32 void erract_execute( struct erract *fsm, const char *_data, int _len )
33 {
34         const char *p = _data;
35         const char *pe = _data+_len;
36         %% write exec;
37 }
38
39 int erract_finish( struct erract *fsm )
40 {
41         %% write eof;
42
43         if ( fsm->cs == erract_error )
44                 return -1;
45         else if ( fsm->cs >= erract_first_final )
46                 return 1;
47         return 0;
48 }
49
50 #include <stdio.h>
51 #include <string.h>
52
53 struct erract fsm;
54
55 void test( char *buf )
56 {
57         int len = strlen(buf);
58         erract_init( &fsm );
59         erract_execute( &fsm, buf, len );
60         if ( erract_finish( &fsm ) > 0 )
61                 printf("ACCEPT\n");
62         else
63                 printf("FAIL\n");
64 }
65
66 int main()
67 {
68         test(
69                 "hello\n"
70                 "hello\n"
71                 "hello\n"
72         );
73
74         test(
75                 "hello\n"
76                 "hello\n"
77                 "hello there\n"
78         );
79
80         test(
81                 "hello\n"
82                 "hello\n"
83                 "he"    );
84
85         test( "" );
86
87         return 0;
88 }
89
90 #ifdef _____OUTPUT_____
91 newline
92 newline
93 newline
94 ACCEPT
95 newline
96 newline
97 hello fails
98 newline
99 ACCEPT
100 newline
101 newline
102 hello fails
103 ACCEPT
104 ACCEPT
105 #endif