Initialize Tizen 2.3
[external/ragel.git] / test / cond5.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         write data noerror;
13 }%%
14
15 void test( const char *str )
16 {
17         int cs = foo_start;
18         int c = 0;
19         const char *p = str;
20         const char *pe = str + strlen( str );
21         char last = '0';
22
23         cout << "run:";
24         %%{
25                 action d1 { cout << " d1"; }
26                 action see_five { cout << " see_five"; }
27
28                 see_five = ([0-9] when{c++ < 5} @d1)* '\n' @see_five;
29
30                 action in_sequence { cout << " in_sequence"; }
31                 action d2 { last = *p; cout << " d2"; }
32                 in_sequence = ( [0-9] when { *p == last+1 } @d2 )* '\n' @in_sequence;
33
34                 main := ( see_five | in_sequence ) ${cout << " |";};
35
36                 write exec;
37         }%%
38         if ( cs < foo_first_final )
39                 cout << " failure";
40         cout << endl;
41 }
42
43 int main()
44 {
45         test( "123456789012\n" );  // fails both
46         test( "123456789\n" );  // fails five
47         test( "1234\n" );  // fails five
48         test( "13245\n" );  // fails sequence
49         test( "12345\n" );  // succeeds in both
50         return 0;
51 }
52
53 #ifdef _____OUTPUT_____
54 run: d1 d2 | d1 d2 | d1 d2 | d1 d2 | d1 d2 | d2 | d2 | d2 | d2 | failure
55 run: d1 d2 | d1 d2 | d1 d2 | d1 d2 | d1 d2 | d2 | d2 | d2 | d2 | in_sequence |
56 run: d1 d2 | d1 d2 | d1 d2 | d1 d2 | see_five in_sequence |
57 run: d1 d2 | d1 | d1 | d1 | d1 | see_five |
58 run: d1 d2 | d1 d2 | d1 d2 | d1 d2 | d1 d2 | see_five in_sequence |
59 #endif