The runtests script was improved so that the Java and Ruby test cases don't
[external/ragel.git] / test / langtrans_ruby.sh
1 #!/bin/bash
2 #
3
4 file=$1
5
6 [ -f $file ] || exit 1
7
8 # Get the machine name.
9 machine=`sed -n 's/^[\t ]*machine[\t ]*\([a-zA-Z_0-9]*\)[\t ]*;[\t ]*$/\1/p' \
10         $file | tr '[A-Z]' '[a-z]'`
11
12 # Make a temporary version of the test case using the Ruby language translations.
13 sed -n '/\/\*/,/\*\//d;p' $file | txl -q stdin langtrans_ruby.txl > $file.pr
14
15 # Begin writing out the test case.
16 cat << EOF
17 #
18 # @LANG: ruby
19 # @GENERATED: yes
20 #
21
22 EOF
23
24 # Write out the machine specification.
25 sed -n '/^%%{$/,/^}%%/{s/^/\t/;p}' $file.pr
26
27 # Write out the init and execute routines.
28 cat << EOF
29
30         %% write data;
31
32         def run_machine( data )
33                 p = 0
34                 pe = data.length
35                 cs = 0;
36 EOF
37
38 # Write the data declarations
39 sed -n '/^%%$/q;{s/^/\t/;p}' $file.pr
40
41 # Write the data initializations
42 sed -n '0,/^%%$/d; /^%%{$/q; {s/^/\t\t/;p}' $file.pr
43
44 cat << EOF
45
46                 %% write init;
47                 %% write exec;
48                 %% write eof;
49                 if cs >= ${machine}_first_final
50                         puts "ACCEPT"
51                 else
52                         puts "FAIL"
53                 end
54         end
55
56 EOF
57
58 # Write out the test data.
59 sed -n '0,/\/\* _____INPUT_____/d; /_____INPUT_____ \*\//q; p;' $file | awk '
60 BEGIN {
61         print " inp = ["
62 }
63 {
64         print "         " $0 ","
65 }
66 END {
67         print " ]"
68         print ""
69         print " inplen = " NR ";"
70 }'
71
72
73 # Write out the main routine.
74 cat << EOF
75
76         inp.each { |str| 
77                 run_machine(str)
78         }
79
80 EOF
81
82 # Write out the expected output.
83 echo "=begin _____OUTPUT_____"
84
85 sed -n '/\/\* _____OUTPUT_____/,/_____OUTPUT_____ \*\//{/_____OUTPUT_____/d;p;};' $file
86
87 echo "=end _____OUTPUT_____"
88
89 # Don't need this language-specific file anymore.
90 #rm $file.pr