A fix to the documentation makefile from John D. Mitchell.
[ragel.git] / test / langtrans_csharp.sh
blob3980f48e721187946182f246655b92e89216c8ca
1 #!/bin/bash
4 file=$1
6 [ -f $file ] || exit 1
7 root=${file%.rl}
8 class=${root}_csharp
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
13 # Begin writing out the test case.
14 cat << EOF
16 * @LANG: csharp
17 * @GENERATED: yes
18 EOF
20 grep '@ALLOW_GENFLAGS:' $file | sed 's/-G2//g'
21 grep '@ALLOW_MINFLAGS:' $file
23 cat << EOF
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
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
42 int cs;
43 %% write data;
45 void init()
47 EOF
49 sed -n '0,/^%%$/d; /^%%{$/q; {s/^/\t\t/;p}' $file.pr
51 cat << EOF
52 %% write init;
55 void exec( char[] data, int len )
57 int p = 0;
58 int pe = len;
59 int eof = len;
60 string _s;
61 %% write exec;
64 void finish( )
66 if ( cs >= ${class}_first_final )
67 Console.WriteLine( "ACCEPT" );
68 else
69 Console.WriteLine( "FAIL" );
72 EOF
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 = {"
80 print " " $0 ","
82 END {
83 print " };"
84 print ""
85 print " static readonly int inplen = " NR ";"
89 # Write out the main routine.
90 cat << EOF
92 public static void Main (string[] args)
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();
105 # Write out the expected output.
106 sed -n '/\/\* _____OUTPUT_____/,/_____OUTPUT_____ \*\//p;' $file
108 # Don't need this language-specific file anymore.
109 rm $file.pr