diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2014-10-13 19:14:30 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2014-10-13 19:14:30 +0000 |
commit | eafd7a3974e8605fd02794269db6114a3446e016 (patch) | |
tree | 064737b35dbe10f2995753ead92f95bac30ba048 /test/langtrans_java.sh | |
download | ragel-tarball-eafd7a3974e8605fd02794269db6114a3446e016.tar.gz |
ragel-6.9ragel-6.9
Diffstat (limited to 'test/langtrans_java.sh')
-rwxr-xr-x | test/langtrans_java.sh | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/test/langtrans_java.sh b/test/langtrans_java.sh new file mode 100755 index 0000000..69a6f90 --- /dev/null +++ b/test/langtrans_java.sh @@ -0,0 +1,106 @@ +#!/bin/bash +# + +file=$1 + +[ -f $file ] || exit 1 +root=${file%.rl} +class=${root}_java + +# Make a temporary version of the test case using the Java language translations. +sed -n '/\/\*/,/\*\//d;p' $file | txl -q stdin langtrans_java.txl - $class > $file.pr + +# Begin writing out the test case. +cat << EOF +/* + * @LANG: java + * @GENERATED: yes +EOF + +grep '@ALLOW_GENFLAGS:' $file +grep '@ALLOW_MINFLAGS:' $file + +cat << EOF + */ + +class $class +{ +EOF + +# Write the data declarations +sed -n '/^%%$/q;{s/^/\t/;p}' $file.pr + +# Write out the machine specification. +sed -n '/^%%{$/,/^}%%/{s/^/\t/;p}' $file.pr + +# Write out the init and execute routines. +cat << EOF + + int cs; + %% write data; + + void init() + { +EOF + +sed -n '0,/^%%$/d; /^%%{$/q; {s/^/\t\t/;p}' $file.pr + +cat << EOF + %% write init; + } + + void exec( char data[], int len ) + { + int p = 0; + int pe = len; + int eof = len; + String _s; + %% write exec; + } + + void finish( ) + { + if ( cs >= ${class}_first_final ) + System.out.println( "ACCEPT" ); + else + System.out.println( "FAIL" ); + } + +EOF + +# Write out the test data. +sed -n '0,/\/\* _____INPUT_____/d; /_____INPUT_____ \*\//q; p;' $file | awk ' +BEGIN { + print " static final String inp[] = {" +} +{ + print " " $0 "," +} +END { + print " };" + print "" + print " static final int inplen = " NR ";" +}' + + +# Write out the main routine. +cat << EOF + + public static void main (String[] args) + { + $class machine = new $class(); + for ( int i = 0; i < inplen; i++ ) { + machine.init(); + machine.exec( inp[i].toCharArray(), inp[i].length() ); + machine.finish(); + } + } +} + +EOF + +# Write out the expected output. +sed -n '/\/\* _____OUTPUT_____/,/_____OUTPUT_____ \*\//p;' $file + +# Don't need this language-specific file anymore. +rm $file.pr |