Added missing operators.
[ragel.git] / test / langtrans_d.sh
blob3ea9c8a554a0f3633f73527a7408034bdf98911d
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
20 import std.stdio;
21 import std.string;
23 class $machine
25 EOF
27 # Write the data declarations
28 sed -n '/^%%$/q;{s/^/\t/;p}' $file.pr
30 # Write out the machine specification.
31 sed -n '/^%%{$/,/^}%%/{s/^/\t/;p}' $file.pr
33 # Write out the init and execute routines.
34 cat << EOF
35 int cs;
36 %% write data;
37 void init()
39 EOF
41 sed -n '0,/^%%$/d; /^%%{$/q; {s/^/\t\t/;p}' $file.pr
43 cat << EOF
44 %% write init;
47 void exec( char data[] )
49 char *p = data.ptr;
50 char *pe = data.ptr + data.length;
51 char *eof = pe;
52 char _s[];
54 %% write exec;
57 void finish( )
59 if ( cs >= ${machine}_first_final )
60 writefln( "ACCEPT" );
61 else
62 writefln( "FAIL" );
65 EOF
67 # Write out the test data.
68 sed -n '0,/\/\* _____INPUT_____/d; /_____INPUT_____ \*\//q; p;' $file | awk '
69 BEGIN {
70 print " char[][] inp = ["
73 print " " $0 ","
75 END {
76 print " ];"
77 print ""
78 print " int inplen = " NR ";"
81 # Write out the main routine.
82 cat << EOF
85 int main( )
87 $machine m = new $machine();
88 int i;
89 for ( i = 0; i < m.inplen; i++ ) {
90 m.init();
91 m.exec( m.inp[i] );
92 m.finish();
94 return 0;
96 /* _____OUTPUT_____
97 EOF
99 # Write out the expected output.
100 sed -n '0,/\/\* _____OUTPUT_____/d; /_____OUTPUT_____ \*\//q; p;' $file
101 echo "*/"
103 # Don't need this language-specific file anymore.
104 rm $file.pr