The runtests script was improved so that the Java and Ruby test cases don't
[external/ragel.git] / test / langtrans_d.sh
1 #!/bin/bash
2 #
3
4 file=$1
5
6 [ -f $file ] || exit 1
7
8 # Get the amchine name.
9 machine=`sed -n 's/^[\t ]*machine[\t ]*\([a-zA-Z_0-9]*\)[\t ]*;[\t ]*$/\1/p' $file`
10
11 # Make a temporary version of the test case the D language translations.
12 sed -n '/\/\*/,/\*\//d;p' $file | txl -q stdin langtrans_d.txl > $file.pr
13
14 # Begin writing out the test case.
15 cat << EOF
16 /*
17  * @LANG: d
18  * @GENERATED: yes
19  */
20 import std.stdio;
21 import std.string;
22
23 class $machine
24 {
25 EOF
26
27 # Write the data declarations
28 sed -n '/^%%$/q;{s/^/\t/;p}' $file.pr
29
30 # Write out the machine specification.
31 sed -n '/^%%{$/,/^}%%/{s/^/\t/;p}' $file.pr
32
33 # Write out the init and execute routines.
34 cat << EOF
35         int cs;
36         %% write data;
37         void init()
38         {
39 EOF
40
41 sed -n '0,/^%%$/d; /^%%{$/q; {s/^/\t\t/;p}' $file.pr
42
43 cat << EOF
44                 %% write init;
45         }
46
47         void exec( char *data, int len )
48         {
49                 char *p = data;
50                 char *pe = data + len;
51                 %% write exec;
52         }
53
54         void finish( )
55         {
56                 %% write eof;
57                 if ( cs >= ${machine}_first_final )
58                         writefln( "ACCEPT" );
59                 else
60                         writefln( "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 " char[][] inp = ["
69 }
70 {
71         print "         " $0 ","
72 }
73 END {
74         print " ];"
75         print ""
76         print " int inplen = " NR ";"
77 }'
78
79 # Write out the main routine.
80 cat << EOF
81 }
82
83 int main( )
84 {
85         $machine m = new $machine();
86         int i;
87         for ( i = 0; i < m.inplen; i++ ) {
88                 m.init();
89                 m.exec( m.inp[i], m.inp[i].length );
90                 m.finish();
91         }
92         return 0;
93 }
94 /* _____OUTPUT_____
95 EOF
96
97 # Write out the expected output.
98 sed -n '0,/\/\* _____OUTPUT_____/d; /_____OUTPUT_____ \*\//q; p;' $file
99 echo "*/"
100
101 # Don't need this language-specific file anymore.
102 rm $file.pr