#! /usr/bin/perl use strict; ## Get the mission while (<>) { last if /
/;
}
my $mission = $_;
while (<>) {
last if / /; $mission .= $_; } $mission =~ s/<[^>]*>//g; ## Get the package name my $package = `pwd`; chomp $package; $package =~ s|/$||; $package =~ s|.*/||; ## Get the prototype of the function to run while (<>) { last if /spellcheck="false"/} chomp; my $proto = $_; $proto =~ s/<[^>]*>//g; $proto =~ s/public //; ## Get the tests while (<>) { last if /Expected/;} my $name; my @worlds; while (<>) { chomp; next unless / |
([^(]*)\(//; #)
if (defined $name && $1 ne $name) {
die "name redefined from $name to $1\n";
}
$name=$1;
s/&.*//;
s/{/new int[] {/g;
# print "w:$_\n";
push @worlds,$_;
}
my $upname= ucfirst $name;
print "Write $upname.java\n";
open J,">$upname.java" || die "Cannot open $upname.java: $!\n";
print J "/* automatically converted from the Nick Parlante's excellent exercising site http://javabat.com/ */\n\n";
print J "package lessons.bat.$package;\n";
print J "import plm.lesson.Lesson;\n";
print J "import plm.universe.World;\n";
print J "import universe.bat.BatExercise;\n";
print J "import universe.bat.BatWorld;\n\n";
print J "public class $upname extends BatExercise {\n";
print J " public $upname(Lesson lesson) {\n";
print J " super(lesson);\n";
print J " \n";
my $count = scalar @worlds;
print J ' World[] myWorlds = new BatWorld['.$count."];\n";
for (my $i=0;$i$upname\n"; print H "$mission\n"; print H "\nThis exercise was converted to PLM from the excellent exercising site http://javabat.com/ \n"; close H; |