From 12056158053532946b53b6249cb0e6cfd4580051 Mon Sep 17 00:00:00 2001 From: thurston Date: Sun, 21 Jan 2007 22:58:22 +0000 Subject: Import from my private repository. Snapshot after version 5.16, immediately following the rewrite of the parsers. Repository revision number 3961. git-svn-id: http://svn.complang.org/ragel/trunk@2 052ea7fc-9027-0410-9066-f65837a77df0 --- test/langtrans_java.sh | 100 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100755 test/langtrans_java.sh (limited to 'test/langtrans_java.sh') diff --git a/test/langtrans_java.sh b/test/langtrans_java.sh new file mode 100755 index 0000000..65b6184 --- /dev/null +++ b/test/langtrans_java.sh @@ -0,0 +1,100 @@ +#!/bin/bash +# + +file=$1 + +[ -f $file ] || exit 1 +root=${file%.rl} +class=${root}_java + +# Make a temporary version of the test case 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 + * @ALLOW_GENFLAGS: -T0 + * @GENERATED: yes + */ + +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 '1,/^%%$/d; /^%%{$/q; {s/^/\t\t/;p}' $file.pr + +cat << EOF + %% write init; + } + + void exec( char data[], int len ) + { + int p = 0; + int pe = len; + %% write exec; + } + + void finish( ) + { + %% write eof; + if ( cs >= ${class}_first_final ) + System.out.println( "ACCEPT" ); + else + System.out.println( "FAIL" ); + } + +EOF + +# Write out the test data. +sed -n '1,/\/\* _____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 -- cgit v1.2.3