Re-add CQLLexer#main
[cql-java-moved-to-github.git] / test / regression / mkanswers
1 #!/usr/bin/perl -w
2
3
4 use IO::File;
5 use strict;
6
7 $ENV{CLASSPATH} .= ":../../lib/cql-java.jar";
8
9 if (@ARGV != 1) {
10     print STDERR "Usage: $0 <trusted-CQL-compiler>\n";
11     exit(1);
12 }
13 my $compiler = $ARGV[0];
14
15 while (<sections/*>) {
16     my $sdir = $_;
17     s@sections/@@;
18     next if /^CVS$/ || /^10$/;  # I _can't_ get CVS to stop extracting "10"
19     print "answering section $_ - ", read_file("$sdir/name"), "\n";
20
21     while (<$sdir/*.cql>) {
22         my $qfile = $_;
23         s@sections/([0-9]+/.*)\.cql@$1@;
24         my $query = read_file($qfile);
25         my $afile = $qfile;
26         $afile =~ s/\.cql$/.xcql/;
27         print "  wrote $_ - $query\n";
28         my $fh = new IO::File("| $compiler > $afile")
29             or die "can't run compiler '$compiler': $!";
30         print $fh $query;
31         $fh->close();
32     }
33 }
34
35 sub read_file {
36     my($name) = @_;
37
38     my $fh = new IO::File("<$name")
39         or die "can't read '$name': $!";
40     my $contents = join('', <$fh>);
41     $fh->close();
42     return $contents;
43 }