Added missing operators.
[ragel.git] / test / strings1.rl
blob0d5eea811d5bb21ba6b2df1e1e4bbab42807e534
1 /*
2  * @LANG: c
3  */
5 #include <string.h>
6 #include <stdio.h>
8 struct strs
10         int cs;
13 %%{
14         machine strs;
15         variable cs fsm->cs;
17         main := 
18                 "__gmon_start__\n" |
19                 "cerr\n" |
20                 "__cp_push_exception\n" |
21                 "_DYNAMIC\n" |
22                 "__rtti_user\n" |
23                 "__rtti_si\n" |
24                 "_init\n" |
25                 "__throw\n" |
26                 "__deregister_frame_info\n" |
27                 "terminate__Fv\n" |
28                 "__builtin_vec_new\n" |
29                 "_fini\n" |
30                 "__builtin_vec_delete\n" |
31                 "_GLOBAL_OFFSET_TABLE_\n" |
32                 "__nw__FUiPv\n" |
33                 "__builtin_delete\n" |
34                 "__builtin_new\n" |
35                 "cout\n" |
36                 "__register_frame_info\n" |
37                 "__eh_alloc\n" |
38                 "strcpy\n" |
39                 "stdout\n" |
40                 "memmove\n" |
41                 "memcpy\n" |
42                 "malloc\n" |
43                 "isatty\n" |
44                 "strtoul\n" |
45                 "fprintf\n" |
46                 "stdin\n" |
47                 "ferror\n" |
48                 "strncpy\n" |
49                 "unlink\n" |
50                 "strcasecmp\n" |
51                 "realloc\n" |
52                 "_IO_getc\n" |
53                 "fread\n" |
54                 "memset\n" |
55                 "__assert_fail\n" |
56                 "strcmp\n" |
57                 "stderr\n" |
58                 "fwrite\n" |
59                 "exit\n" |
60                 "fopen\n" |
61                 "atoi\n" |
62                 "fileno\n" |
63                 "_IO_stdin_used\n" |
64                 "__libc_start_main\n" |
65                 "strlen\n" |
66                 "free\n" |
67                 "_edata\n" |
68                 "__bss_start\n" |
69                 "_end\n" |
70                 "QVhl\n" |
71                 "BPPh\n" |
72                 "PHRV\n" |
73                 "PHRj\n" |
74                 "PHRj\n" |
75                 "jphy\n" |
76                 "jqhy\n" |
77                 "PHRj\n" |
78                 "PHRj\n" |
79                 "LWVS\n" |
80                 "LWVS\n" |
81                 "bad_alloc\n" |
82                 "main\n" |
83                 "false\n" |
84                 "help\n" |
85                 "bad_alloc\n" |
86                 "bad_alloc\n" |
87                 "bad_alloc\n" |
88                 "ascii\n" |
89                 "extend\n" |
90                 "alnum\n" |
91                 "alpha\n" |
92                 "cntrl\n" |
93                 "digit\n" |
94                 "graph\n" |
95                 "lower\n" |
96                 "print\n" |
97                 "punct\n" |
98                 "space\n" |
99                 "upper\n" |
100                 "xdigit\n" |
101                 "false\n" |
102                 "bad_alloc\n" |
103                 "bad_alloc\n" |
104                 "bad_alloc\n" |
105                 "TransStruct\n" |
106                 "StateStruct\n" |
107                 "Struct\n" |
108                 "Init\n" |
109                 "bad_alloc\n" |
110                 "TransStruct\n" |
111                 "StateStruct\n" |
112                 "Struct\n" |
113                 "Init\n" |
114                 "Accept\n" |
115                 "Finish\n" |
116                 "bad_alloc\n" |
117                 "Struct\n" |
118                 "Init\n" |
119                 "Finish\n" |
120                 "Accept\n" |
121                 "bad_alloc\n" |
122                 "Struct\n" |
123                 "Init\n" |
124                 "bad_alloc\n" |
125                 "Struct\n" |
126                 "Init\n" |
127                 "Finish\n" |
128                 "Accept\n" |
129                 "bad_alloc\n" |
130                 "Struct\n" |
131                 "Init\n" |
132                 "Finish\n" |
133                 "Accept";
136 %% write data;
138 void strs_init( struct strs *fsm )
140         %% write init;
143 void strs_execute( struct strs *fsm, const char *_data, int _len )
145         const char *p = _data;
146         const char *pe = _data+_len;
148         %% write exec;
151 int strs_finish( struct strs *fsm )
153         if ( fsm->cs == strs_error )
154                 return -1;
155         if ( fsm->cs >= strs_first_final )
156                 return 1;
157         return 0;
160 struct strs fsm;
161 void test( char *buf )
163         int len = strlen( buf );
164         strs_init( &fsm );
165         strs_execute( &fsm, buf, len );
166         if ( strs_finish( &fsm ) > 0 )
167                 printf("ACCEPT\n");
168         else
169                 printf("FAIL\n");
173 int main()
175         test( "stdin\n" );
176         test( "bad_alloc\n" );
177         test( "_GLOBAL_OFFSET_TABLE_\n" );
178         test( "not in\n" );
179         test(
180                 "isatty\n"
181                 "junk on end.\n"
182         );
184         return 0;
187 #ifdef _____OUTPUT_____
188 ACCEPT
189 ACCEPT
190 ACCEPT
191 FAIL
192 FAIL
193 #endif