summaryrefslogtreecommitdiff
path: root/test/cond6.rl
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2014-10-13 19:14:30 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2014-10-13 19:14:30 +0000
commiteafd7a3974e8605fd02794269db6114a3446e016 (patch)
tree064737b35dbe10f2995753ead92f95bac30ba048 /test/cond6.rl
downloadragel-tarball-eafd7a3974e8605fd02794269db6114a3446e016.tar.gz
ragel-6.9ragel-6.9
Diffstat (limited to 'test/cond6.rl')
-rw-r--r--test/cond6.rl61
1 files changed, 61 insertions, 0 deletions
diff --git a/test/cond6.rl b/test/cond6.rl
new file mode 100644
index 0000000..ede9ed8
--- /dev/null
+++ b/test/cond6.rl
@@ -0,0 +1,61 @@
+/*
+ * @LANG: c++
+ */
+
+/* Balanced parenthesis with conditions. */
+
+#include <iostream>
+#include <string.h>
+using std::cout;
+using std::endl;
+
+%%{
+ machine cond;
+ write data noerror;
+}%%
+
+void test( const char *str )
+{
+ int cs = cond_start, n = 0;
+ const char *p = str;
+ const char *pe = str + strlen( str );
+
+ %%{
+ comment = '(' @{n=0;}
+ ( '('@{n++;} | ')'@{n--;} | [^()] )*
+ :> ')' when{!n};
+
+ main := ' '* comment ' '* '\n' @{cout << "success";};
+
+ write exec;
+ }%%
+ if ( cs < cond_first_final )
+ cout << "failure";
+ cout << endl;
+}
+
+int main()
+{
+ test( "( ( )\n" );
+ test( "()()\n" );
+ test( "(((\n" );
+ test( "((()\n" );
+ test( "((())\n" );
+ test( "()\n" );
+ test( "((()))\n" );
+ test( "(()())\n" );
+ test( "((())()(((()))))\n" );
+ return 0;
+}
+
+#ifdef _____OUTPUT_____
+failure
+failure
+failure
+failure
+failure
+success
+success
+success
+success
+#endif