Added tests for exports and entry points. For machine exports, added "ex_" in
authorthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Mon, 12 Mar 2007 16:38:57 +0000 (16:38 +0000)
committerthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Mon, 12 Mar 2007 16:38:57 +0000 (16:38 +0000)
between the machine name and the export name.

git-svn-id: http://svn.complang.org/ragel/trunk@139 052ea7fc-9027-0410-9066-f65837a77df0

rlgen-cd/fsmcodegen.cpp
rlgen-java/javacodegen.cpp
rlgen-ruby/rubycodegen.cpp
test/export1.rl [new file with mode: 0644]
test/export2.rl [new file with mode: 0644]
test/export3.rl [new file with mode: 0644]

index 190ef02..33b1efa 100644 (file)
@@ -535,7 +535,7 @@ void FsmCodeGen::writeExports()
 {
        if ( exportList.length() > 0 ) {
                for ( ExportList::Iter ex = exportList; ex.lte(); ex++ ) {
-                       out << "#define " << DATA_PREFIX() << ex->name << " " << 
+                       out << "#define " << DATA_PREFIX() << "ex_" << ex->name << " " << 
                                        KEY(ex->key) << "\n";
                }
                out << "\n";
index fd88eeb..acfe436 100644 (file)
@@ -772,8 +772,8 @@ void JavaTabCodeGen::writeExports()
 {
        if ( exportList.length() > 0 ) {
                for ( ExportList::Iter ex = exportList; ex.lte(); ex++ ) {
-                       STATIC_VAR( ALPH_TYPE(), DATA_PREFIX() + ex->name ) 
-                                       << " = " << KEY(ex->key) << "\n";
+                       STATIC_VAR( ALPH_TYPE(), DATA_PREFIX() + "ex_" + ex->name ) 
+                                       << " = " << KEY(ex->key) << ";\n";
                }
                out << "\n";
        }
index 0c0f7fc..0fe2c9a 100644 (file)
@@ -1025,7 +1025,7 @@ void RubyCodeGen::writeExports()
 {
        if ( exportList.length() > 0 ) {
                for ( ExportList::Iter ex = exportList; ex.lte(); ex++ ) {
-                       STATIC_VAR( ALPH_TYPE(), DATA_PREFIX() + ex->name ) 
+                       STATIC_VAR( ALPH_TYPE(), DATA_PREFIX() + "ex_" + ex->name ) 
                                        << " = " << KEY(ex->key) << "\n";
                }
                out << "\n";
diff --git a/test/export1.rl b/test/export1.rl
new file mode 100644 (file)
index 0000000..1fec2e7
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * @LANG: c
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+%%{
+       machine test;
+
+       export c1 = 'c';
+       export c2 = 'z';
+       export c3 = 't';
+
+       commands := (
+               c1 . digit* '\n' @{ printf( "c1\n" );} |
+               c2 . alpha* '\n' @{ printf( "c2\n" );}|
+               c3 . '.'* '\n' @{ printf( "c3\n" );}
+       )*;
+               
+       main := any*;
+}%%
+
+%% write exports;
+%% write data;
+
+int test( const char *data, int len )
+{
+       int cs;
+       const char *p = data, *pe = data + len;
+
+       cs = test_en_commands;
+       %% write exec;
+
+       if ( cs >= test_first_final )
+               printf("ACCEPT\n");
+       else
+               printf("ERROR\n");
+       return 0;
+}
+
+char data[] = { 
+       test_ex_c1, '1', '2', '\n', 
+       test_ex_c2, 'a', 'b', '\n', 
+       test_ex_c3, '.', '.', '\n', 0 
+};
+
+int main()
+{
+       test( data, strlen( data ) );
+       return 0;
+}
+
+#ifdef _____OUTPUT_____
+c1
+c2
+c3
+ACCEPT
+#endif
diff --git a/test/export2.rl b/test/export2.rl
new file mode 100644 (file)
index 0000000..3eef0dd
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * @LANG: java
+ * @ALLOW_GENFLAGS: -T0
+ */
+
+class export2
+{
+       %%{
+               machine test;
+
+               export c1 = 'c';
+               export c2 = 'z';
+               export c3 = 't';
+
+               commands := (
+                       c1 . digit* '\n' @{ System.out.println( "c1" );} |
+                       c2 . alpha* '\n' @{ System.out.println( "c2" );}|
+                       c3 . '.'* '\n' @{ System.out.println( "c3" );}
+               )*;
+                       
+               main := any*;
+       }%%
+
+       %% write exports;
+       %% write data;
+
+       static void test( char data[] )
+       {
+               int cs, p = 0, pe = data.length;
+               int top;
+
+               cs = test_en_commands;
+               %% write exec;
+
+               if ( cs >= test_first_final )
+                       System.out.println( "ACCEPT" );
+               else
+                       System.out.println( "FAIL" );
+       }
+
+       public static void main( String args[] )
+       {
+               char data[] = { 
+                       test_ex_c1, '1', '2', '\n', 
+                       test_ex_c2, 'a', 'b', '\n', 
+                       test_ex_c3, '.', '.', '\n',
+               };
+               test( data );
+       }
+}
+
+
+/* _____OUTPUT_____
+c1
+c2
+c3
+ACCEPT
+*/
diff --git a/test/export3.rl b/test/export3.rl
new file mode 100644 (file)
index 0000000..39603d6
--- /dev/null
@@ -0,0 +1,56 @@
+#
+# @LANG: ruby
+# @ALLOW_GENFLAGS: -T0
+#
+
+%%{
+       machine test;
+
+       export c1 = 'c';
+       export c2 = 'z';
+       export c3 = 't';
+
+       commands := (
+               c1 . digit* '\n' @{ puts "c1"; } |
+               c2 . alpha* '\n' @{ puts "c2"; }|
+               c3 . '.'* '\n' @{ puts "c3"; }
+       )*;
+                       
+       main := any*;
+}%%
+
+%% write exports;
+%% write data;
+
+def run_machine( data )
+       p = 0;
+       pe = data.length
+       cs = 0
+       cs = 0
+       val = 0;
+       neg = false;
+
+       cs = test_en_commands;
+       %% write exec;
+       %% write eof;
+       if  cs >= test_first_final
+               puts "ACCEPT"
+       else
+               puts "FAIL"
+       end
+end
+
+inp = [
+               test_ex_c1, ?1, ?2, ?\n, 
+               test_ex_c2, ?a, ?b, ?\n, 
+               test_ex_c3, ?., ?., ?\n
+]
+
+run_machine( inp );
+
+=begin _____OUTPUT_____
+c1
+c2
+c3
+ACCEPT
+=end _____OUTPUT_____