Initialize Tizen 2.3
[external/ragel.git] / test / langtrans_csharp.sh
1 #!/bin/bash
2 #
3
4 file=$1
5
6 [ -f $file ] || exit 1
7 root=${file%.rl}
8 class=${root}_csharp
9
10 # Make a temporary version of the test case using the Java language translations.
11 sed -n '/\/\*/,/\*\//d;p' $file | txl -q stdin langtrans_csharp.txl - $class > $file.pr
12
13 # Begin writing out the test case.
14 cat << EOF
15 /*
16  * @LANG: csharp
17  * @GENERATED: yes
18 EOF
19
20 grep '@ALLOW_GENFLAGS:' $file | sed 's/-G2//g'
21 grep '@ALLOW_MINFLAGS:' $file
22
23 cat << EOF
24  */
25 using System;
26 // Disables lots of warnings that appear in the test suite
27 #pragma warning disable 0168, 0169, 0219, 0162, 0414
28 namespace Test {
29 class $class
30 {
31 EOF
32
33 # Write the data declarations
34 sed -n '/^%%$/q;{s/^/\t/;p}' $file.pr
35
36 # Write out the machine specification.
37 sed -n '/^%%{$/,/^}%%/{s/^/\t/;p}' $file.pr
38
39 # Write out the init and execute routines.
40 cat << EOF
41
42         int cs;
43         %% write data;
44
45         void init()
46         {
47 EOF
48
49 sed -n '0,/^%%$/d; /^%%{$/q; {s/^/\t\t/;p}' $file.pr
50
51 cat << EOF
52                 %% write init;
53         }
54
55         void exec( char[] data, int len )
56         {
57                 int p = 0;
58                 int pe = len;
59                 int eof = len;
60                 string _s;
61                 %% write exec;
62         }
63
64         void finish( )
65         {
66                 if ( cs >= ${class}_first_final )
67                         Console.WriteLine( "ACCEPT" );
68                 else
69                         Console.WriteLine( "FAIL" );
70         }
71
72 EOF
73
74 # Write out the test data.
75 sed -n '0,/\/\* _____INPUT_____/d; /_____INPUT_____ \*\//q; p;' $file | awk '
76 BEGIN {
77         print " static readonly string[] inp = {"
78 }
79 {
80         print "         " $0 ","
81 }
82 END {
83         print " };"
84         print ""
85         print " static readonly int inplen = " NR ";"
86 }'
87
88
89 # Write out the main routine.
90 cat << EOF
91
92         public static void Main (string[] args)
93         {
94                 $class machine = new $class();
95                 for ( int i = 0; i < inplen; i++ ) {
96                         machine.init();
97                         machine.exec( inp[i].ToCharArray(), inp[i].Length );
98                         machine.finish();
99                 }
100         }
101 }
102 }
103 EOF
104
105 # Write out the expected output.
106 sed -n '/\/\* _____OUTPUT_____/,/_____OUTPUT_____ \*\//p;' $file
107
108 # Don't need this language-specific file anymore.
109 rm $file.pr