7065
|
1 |
#
|
|
2 |
# $Id$
|
|
3 |
#
|
|
4 |
# fixnumerals.pl - fix occurences of numerals in HOL/ZF terms
|
|
5 |
#
|
|
6 |
# tries to be smart; may produce garbage if nested comments and
|
|
7 |
# solitary quotes (") are intermixed badly;
|
|
8 |
#
|
|
9 |
|
|
10 |
sub fixdots {
|
|
11 |
my ($constr, $file) = @_;
|
|
12 |
|
|
13 |
open (FILE, $file) || die $!;
|
|
14 |
undef $/; $text = <FILE>; $/ = "\n"; # slurp whole file
|
|
15 |
close FILE || die $!;
|
|
16 |
|
|
17 |
|
|
18 |
$result = "";
|
|
19 |
$rest = $text;
|
|
20 |
|
|
21 |
while (1) {
|
|
22 |
$_ = $rest;
|
|
23 |
($pre, $str, $rest) =
|
|
24 |
m/^((?: \(\*.*?\*\) | [^"] )*) # pre: text or (non-nested!) comments
|
|
25 |
"((?: [^"\\] | \\\S | \\\s+\\ )*)" # quoted string
|
|
26 |
(.*)$/sx; # rest of file
|
|
27 |
if ($str) {
|
|
28 |
$_ = $str;
|
|
29 |
if (!m/^[a-zA-Z0-9_\/\.]*$/s && !m/\.ML/s && !m/\.thy/s) { # exclude filenames!
|
|
30 |
if ($constr eq "true") {
|
|
31 |
s/#([0-9]+)/($1::int)/sg;
|
|
32 |
s/#-([0-9]+)/(~$1::int)/sg;
|
|
33 |
} else {
|
|
34 |
s/#([0-9]+)/$1/sg;
|
|
35 |
s/#-([0-9]+)/~$1/sg;
|
|
36 |
}
|
|
37 |
}
|
|
38 |
$result = $result . $pre . '"' . $_ . '"';
|
|
39 |
} else {
|
|
40 |
$result = $result . $_;
|
|
41 |
last;
|
|
42 |
}
|
|
43 |
}
|
|
44 |
|
|
45 |
if ($text ne $result) {
|
|
46 |
print STDERR "fixing $file\n";
|
|
47 |
if (! -f "$file~~") {
|
|
48 |
rename $file, "$file~~" || die $!;
|
|
49 |
}
|
|
50 |
open (FILE, "> $file") || die $!;
|
|
51 |
print FILE $result;
|
|
52 |
close FILE || die $!;
|
|
53 |
}
|
|
54 |
}
|
|
55 |
|
|
56 |
|
|
57 |
## main
|
|
58 |
|
|
59 |
$constr = shift;
|
|
60 |
|
|
61 |
foreach $file (@ARGV) {
|
|
62 |
eval { &fixdots($constr, $file); };
|
|
63 |
if ($@) { print STDERR "*** fixdots $file: ", $@, "\n"; }
|
|
64 |
}
|