Removed arg passing from frontend to backend functions.
[ragel.git] / test / cond6.rl
blobede9ed827c9c734fb20134081364cc6c8acc5419
1 /* 
2  * @LANG: c++
3  */
5 /* Balanced parenthesis with conditions. */
7 #include <iostream>
8 #include <string.h>
9 using std::cout;
10 using std::endl;
12 %%{
13         machine cond;
14         write data noerror;
15 }%%
17 void test( const char *str )
19         int cs = cond_start, n = 0;
20         const char *p = str;
21         const char *pe = str + strlen( str );
23         %%{
24                 comment = '(' @{n=0;} 
25                         ( '('@{n++;} | ')'@{n--;} | [^()] )*
26                 :> ')' when{!n};
28                 main := ' '* comment ' '* '\n' @{cout << "success";};
30                 write exec;
31         }%%
32         if ( cs < cond_first_final )
33                 cout << "failure";
34         cout << endl;
37 int main()
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;
51 #ifdef _____OUTPUT_____
52 failure
53 failure
54 failure
55 failure
56 failure
57 success
58 success
59 success
60 success
61 #endif