summaryrefslogtreecommitdiff
path: root/test/cond2.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/cond2.rl
downloadragel-tarball-eafd7a3974e8605fd02794269db6114a3446e016.tar.gz
ragel-6.9ragel-6.9
Diffstat (limited to 'test/cond2.rl')
-rw-r--r--test/cond2.rl91
1 files changed, 91 insertions, 0 deletions
diff --git a/test/cond2.rl b/test/cond2.rl
new file mode 100644
index 0000000..7e49ab8
--- /dev/null
+++ b/test/cond2.rl
@@ -0,0 +1,91 @@
+/*
+ * @LANG: c++
+ */
+
+#include <iostream>
+#include <string.h>
+using std::cout;
+using std::endl;
+
+%%{
+ machine foo;
+
+ action c1 {i}
+ action c2 {j}
+
+ action one { cout << " one" << endl;}
+ action two { cout << " two" << endl;}
+
+ main := (
+ [a-z] |
+ ('\n' when c1 @one)
+ )*
+ ('\n' when c2 @two);
+}%%
+
+%% write data noerror;
+
+void test( int i, int j, const char *str )
+{
+ int cs = foo_start;
+ const char *p = str;
+ const char *pe = str + strlen( str );
+
+ cout << "run:" << endl;
+ %% write exec;
+ if ( cs >= foo_first_final )
+ cout << " success" << endl;
+ else
+ cout << " failure" << endl;
+ cout << endl;
+}
+
+int main()
+{
+ test( 0, 0, "hi\n\n" );
+ test( 1, 0, "hi\n\n" );
+ test( 0, 1, "hi\n" );
+ test( 0, 1, "hi\n\n" );
+ test( 1, 1, "hi\n" );
+ test( 1, 1, "hi\n\n" );
+ test( 1, 1, "hi\n\nx" );
+ return 0;
+}
+
+#ifdef _____OUTPUT_____
+run:
+ failure
+
+run:
+ one
+ one
+ failure
+
+run:
+ two
+ success
+
+run:
+ two
+ failure
+
+run:
+ one
+ two
+ success
+
+run:
+ one
+ two
+ one
+ two
+ success
+
+run:
+ one
+ two
+ one
+ two
+ failure
+
+#endif