Initialize Tizen 2.3
[external/ragel.git] / test / cond3.rl
1 /* 
2  * @LANG: c++
3  */
4
5 #include <iostream>
6 #include <string.h>
7 using std::cout;
8 using std::endl;
9
10 %%{
11         machine foo;
12
13         action hit_5 {c == 5}
14         action done { cout << "  done" << endl; }
15         action inc {c++;}
16
17         # The any* includes '\n' when hit_5 is true, so use guarded concatenation.
18         main := (any @inc)* :> '\n' when hit_5 @done;
19 }%%
20
21 %% write data noerror;
22
23 void test( const char *str )
24 {
25         int cs = foo_start;
26         int c = 0;
27         const char *p = str;
28         const char *pe = str + strlen( str );
29
30         cout << "run:" << endl;
31         %% write exec;
32         if ( cs >= foo_first_final )
33                 cout << "  success" << endl;
34         else
35                 cout << "  failure" << endl;
36         cout << endl;
37 }
38
39 int main()
40 {
41         test( "12345\n" );  // success
42         test( "\n2345\n" ); // success, first newline ignored
43         test( "1234\n" );   // failure, didn't get 5 chars before newline.
44         return 0;
45 }
46
47 #ifdef _____OUTPUT_____
48 run:
49   done
50   success
51
52 run:
53   done
54   success
55
56 run:
57   failure
58
59 #endif