added item.
[ragel.git] / test / langtrans_java.sh
blob69a6f90799e78ef09de0ed116db58a4ffed21c2e
1 #!/bin/bash
4 file=$1
6 [ -f $file ] || exit 1
7 root=${file%.rl}
8 class=${root}_java
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
13 # Begin writing out the test case.
14 cat << EOF
16 * @LANG: java
17 * @GENERATED: yes
18 EOF
20 grep '@ALLOW_GENFLAGS:' $file
21 grep '@ALLOW_MINFLAGS:' $file
23 cat << EOF
26 class $class
28 EOF
30 # Write the data declarations
31 sed -n '/^%%$/q;{s/^/\t/;p}' $file.pr
33 # Write out the machine specification.
34 sed -n '/^%%{$/,/^}%%/{s/^/\t/;p}' $file.pr
36 # Write out the init and execute routines.
37 cat << EOF
39 int cs;
40 %% write data;
42 void init()
44 EOF
46 sed -n '0,/^%%$/d; /^%%{$/q; {s/^/\t\t/;p}' $file.pr
48 cat << EOF
49 %% write init;
52 void exec( char data[], int len )
54 int p = 0;
55 int pe = len;
56 int eof = len;
57 String _s;
58 %% write exec;
61 void finish( )
63 if ( cs >= ${class}_first_final )
64 System.out.println( "ACCEPT" );
65 else
66 System.out.println( "FAIL" );
69 EOF
71 # Write out the test data.
72 sed -n '0,/\/\* _____INPUT_____/d; /_____INPUT_____ \*\//q; p;' $file | awk '
73 BEGIN {
74 print " static final String inp[] = {"
77 print " " $0 ","
79 END {
80 print " };"
81 print ""
82 print " static final int inplen = " NR ";"
86 # Write out the main routine.
87 cat << EOF
89 public static void main (String[] args)
91 $class machine = new $class();
92 for ( int i = 0; i < inplen; i++ ) {
93 machine.init();
94 machine.exec( inp[i].toCharArray(), inp[i].length() );
95 machine.finish();
102 # Write out the expected output.
103 sed -n '/\/\* _____OUTPUT_____/,/_____OUTPUT_____ \*\//p;' $file
105 # Don't need this language-specific file anymore.
106 rm $file.pr