Initialize Tizen 2.3
[external/ragel.git] / test / cond6.rl
1 /* 
2  * @LANG: c++
3  */
4
5 /* Balanced parenthesis with conditions. */
6
7 #include <iostream>
8 #include <string.h>
9 using std::cout;
10 using std::endl;
11
12 %%{
13         machine cond;
14         write data noerror;
15 }%%
16
17 void test( const char *str )
18 {
19         int cs = cond_start, n = 0;
20         const char *p = str;
21         const char *pe = str + strlen( str );
22
23         %%{
24                 comment = '(' @{n=0;} 
25                         ( '('@{n++;} | ')'@{n--;} | [^()] )*
26                 :> ')' when{!n};
27
28                 main := ' '* comment ' '* '\n' @{cout << "success";};
29
30                 write exec;
31         }%%
32         if ( cs < cond_first_final )
33                 cout << "failure";
34         cout << endl;
35 }
36
37 int main()
38 {
39         test( "( ( )\n" );
40         test( "()()\n" );
41         test( "(((\n" );
42         test( "((()\n" );
43         test( "((())\n" );
44         test( "()\n" );
45         test( "((()))\n" );
46         test( "(()())\n" );
47         test( "((())()(((()))))\n" );
48         return 0;
49 }
50
51 #ifdef _____OUTPUT_____
52 failure
53 failure
54 failure
55 failure
56 failure
57 success
58 success
59 success
60 success
61 #endif