A fix to the documentation makefile from John D. Mitchell.
[ragel.git] / test / langtrans_d.sh
blob764afd778ba1a4e3a884ce2ed3837a6f251c6d7c
1 #!/bin/bash
4 file=$1
6 [ -f $file ] || exit 1
8 # Get the amchine name.
9 machine=`sed -n 's/^[\t ]*machine[\t ]*\([a-zA-Z_0-9]*\)[\t ]*;[\t ]*$/\1/p' $file`
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
14 # Begin writing out the test case.
15 cat << EOF
17 * @LANG: d
18 * @GENERATED: yes
19 EOF
21 grep '@ALLOW_GENFLAGS:' $file
22 grep '@ALLOW_MINFLAGS:' $file
24 cat << EOF
26 import std.stdio;
27 import std.string;
29 class $machine
31 EOF
33 # Write the data declarations
34 sed -n '/^%%$/q;{s/^/\t/;p}' $file.pr
36 # Write out the machine specification.
37 sed -n '/^%%{$/,/^}%%/{s/^/\t/;p}' $file.pr
39 # Write out the init and execute routines.
40 cat << EOF
41 int cs;
42 %% write data;
43 void init()
45 EOF
47 sed -n '0,/^%%$/d; /^%%{$/q; {s/^/\t\t/;p}' $file.pr
49 cat << EOF
50 %% write init;
53 void exec( char data[] )
55 char *p = data.ptr;
56 char *pe = data.ptr + data.length;
57 char *eof = pe;
58 char _s[];
60 %% write exec;
63 void finish( )
65 if ( cs >= ${machine}_first_final )
66 writefln( "ACCEPT" );
67 else
68 writefln( "FAIL" );
71 EOF
73 # Write out the test data.
74 sed -n '0,/\/\* _____INPUT_____/d; /_____INPUT_____ \*\//q; p;' $file | awk '
75 BEGIN {
76 print " char[][] inp = ["
79 print " " $0 ","
81 END {
82 print " ];"
83 print ""
84 print " int inplen = " NR ";"
87 # Write out the main routine.
88 cat << EOF
91 int main( )
93 $machine m = new $machine();
94 int i;
95 for ( i = 0; i < m.inplen; i++ ) {
96 m.init();
97 m.exec( m.inp[i] );
98 m.finish();
100 return 0;
102 /* _____OUTPUT_____
105 # Write out the expected output.
106 sed -n '0,/\/\* _____OUTPUT_____/d; /_____OUTPUT_____ \*\//q; p;' $file
107 echo "*/"
109 # Don't need this language-specific file anymore.
110 rm $file.pr