First cut of a test-suite transformation for Ruby. Some of the tests work.
[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 # @ALLOW_GENFLAGS: -T0
20 # @GENERATED: yes
21 #
22
23 EOF
24
25 # Write out the machine specification.
26 sed -n '/^%%{$/,/^}%%/{s/^/\t/;p}' $file.pr
27
28 # Write out the init and execute routines.
29 cat << EOF
30
31         %% write data;
32
33         def run_machine( data )
34                 p = 0
35                 pe = data.length
36                 cs = 0;
37 EOF
38
39 # Write the data declarations
40 sed -n '/^%%$/q;{s/^/\t/;p}' $file.pr
41
42 # Write the data initializations
43 sed -n '0,/^%%$/d; /^%%{$/q; {s/^/\t\t/;p}' $file.pr
44
45 cat << EOF
46
47                 %% write init;
48                 %% write exec;
49                 %% write eof;
50                 if cs >= ${machine}_first_final
51                         puts "ACCEPT"
52                 else
53                         puts "FAIL"
54                 end
55         end
56
57 EOF
58
59 # Write out the test data.
60 sed -n '0,/\/\* _____INPUT_____/d; /_____INPUT_____ \*\//q; p;' $file | awk '
61 BEGIN {
62         print " inp = ["
63 }
64 {
65         print "         " $0 ","
66 }
67 END {
68         print " ]"
69         print ""
70         print " inplen = " NR ";"
71 }'
72
73
74 # Write out the main routine.
75 cat << EOF
76
77         inp.each { |str| 
78                 run_machine(str)
79         }
80
81 EOF
82
83 # Write out the expected output.
84 echo "=begin _____OUTPUT_____"
85
86 sed -n '/\/\* _____OUTPUT_____/,/_____OUTPUT_____ \*\//{/_____OUTPUT_____/d;p;};' $file
87
88 echo "=end _____OUTPUT_____"
89
90 # Don't need this language-specific file anymore.
91 #rm $file.pr