Introcuded the "eof" variable for indicating the end of file. The p variable is
[external/ragel.git] / test / langtrans_java.sh
1 #!/bin/bash
2 #
3
4 file=$1
5
6 [ -f $file ] || exit 1
7 root=${file%.rl}
8 class=${root}_java
9
10 # Make a temporary version of the test case using the Java language translations.
11 sed -n '/\/\*/,/\*\//d;p' $file | txl -q stdin langtrans_java.txl - $class > $file.pr
12
13 # Begin writing out the test case.
14 cat << EOF
15 /*
16  * @LANG: java
17  * @GENERATED: yes
18  */
19
20 class $class
21 {
22 EOF
23
24 # Write the data declarations
25 sed -n '/^%%$/q;{s/^/\t/;p}' $file.pr
26
27 # Write out the machine specification.
28 sed -n '/^%%{$/,/^}%%/{s/^/\t/;p}' $file.pr
29
30 # Write out the init and execute routines.
31 cat << EOF
32
33         int cs;
34         %% write data;
35
36         void init()
37         {
38 EOF
39
40 sed -n '0,/^%%$/d; /^%%{$/q; {s/^/\t\t/;p}' $file.pr
41
42 cat << EOF
43                 %% write init;
44         }
45
46         void exec( char data[], int len )
47         {
48                 int p = 0;
49                 int pe = len;
50                 int eof = len;
51                 String _s;
52                 %% write exec;
53         }
54
55         void finish( )
56         {
57                 if ( cs >= ${class}_first_final )
58                         System.out.println( "ACCEPT" );
59                 else
60                         System.out.println( "FAIL" );
61         }
62
63 EOF
64
65 # Write out the test data.
66 sed -n '0,/\/\* _____INPUT_____/d; /_____INPUT_____ \*\//q; p;' $file | awk '
67 BEGIN {
68         print " static final String inp[] = {"
69 }
70 {
71         print "         " $0 ","
72 }
73 END {
74         print " };"
75         print ""
76         print " static final int inplen = " NR ";"
77 }'
78
79
80 # Write out the main routine.
81 cat << EOF
82
83         public static void main (String[] args)
84         {
85                 $class machine = new $class();
86                 for ( int i = 0; i < inplen; i++ ) {
87                         machine.init();
88                         machine.exec( inp[i].toCharArray(), inp[i].length() );
89                         machine.finish();
90                 }
91         }
92 }
93
94 EOF
95
96 # Write out the expected output.
97 sed -n '/\/\* _____OUTPUT_____/,/_____OUTPUT_____ \*\//p;' $file
98
99 # Don't need this language-specific file anymore.
100 rm $file.pr