24875
|
1 |
#
|
|
2 |
# Author: Makarius
|
|
3 |
#
|
|
4 |
# keywords.pl - generate outer syntax keyword files from session logs
|
|
5 |
#
|
|
6 |
|
24886
|
7 |
## arguments
|
24875
|
8 |
|
33684
|
9 |
my ($keywords_name, $sessions) = @ARGV;
|
24875
|
10 |
|
|
11 |
|
|
12 |
## keywords
|
|
13 |
|
|
14 |
my %keywords;
|
|
15 |
|
|
16 |
sub set_keyword {
|
|
17 |
my ($name, $kind) = @_;
|
27386
|
18 |
if (defined $keywords{$name} and $keywords{$name} ne $kind and $keywords{$name} ne "minor") {
|
|
19 |
if ($kind ne "minor") {
|
|
20 |
print STDERR "### Inconsistent declaration of keyword \"${name}\": $keywords{$name} vs ${kind}\n";
|
|
21 |
$keywords{$name} = $kind;
|
|
22 |
}
|
|
23 |
} else {
|
|
24 |
$keywords{$name} = $kind;
|
24875
|
25 |
}
|
|
26 |
}
|
|
27 |
|
|
28 |
sub collect_keywords {
|
|
29 |
while(<STDIN>) {
|
|
30 |
if (m/^Outer syntax keyword:\s*"(.*)"/) {
|
|
31 |
my $name = $1;
|
|
32 |
&set_keyword($name, "minor");
|
|
33 |
}
|
|
34 |
elsif (m/^Outer syntax command:\s*"(.*)"\s*\((.*)\)/) {
|
|
35 |
my $name = $1;
|
|
36 |
my $kind = $2;
|
|
37 |
&set_keyword($name, $kind);
|
|
38 |
}
|
|
39 |
}
|
|
40 |
}
|
|
41 |
|
|
42 |
|
|
43 |
## Emacs output
|
|
44 |
|
|
45 |
sub emacs_output {
|
24886
|
46 |
my @kinds = (
|
|
47 |
"major",
|
|
48 |
"minor",
|
|
49 |
"control",
|
|
50 |
"diag",
|
|
51 |
"theory-begin",
|
|
52 |
"theory-switch",
|
|
53 |
"theory-end",
|
|
54 |
"theory-heading",
|
|
55 |
"theory-decl",
|
|
56 |
"theory-script",
|
|
57 |
"theory-goal",
|
|
58 |
"qed",
|
|
59 |
"qed-block",
|
|
60 |
"qed-global",
|
|
61 |
"proof-heading",
|
|
62 |
"proof-goal",
|
|
63 |
"proof-block",
|
|
64 |
"proof-open",
|
|
65 |
"proof-close",
|
|
66 |
"proof-chain",
|
|
67 |
"proof-decl",
|
|
68 |
"proof-asm",
|
|
69 |
"proof-asm-goal",
|
|
70 |
"proof-script"
|
|
71 |
);
|
24875
|
72 |
my $file = $keywords_name eq "" ? "isar-keywords.el" : "isar-keywords-${keywords_name}.el";
|
|
73 |
open (OUTPUT, "> ${file}") || die "$!";
|
|
74 |
select OUTPUT;
|
|
75 |
|
|
76 |
print ";;\n";
|
|
77 |
print ";; Keyword classification tables for Isabelle/Isar.\n";
|
24912
|
78 |
print ";; Generated from ${sessions}.\n";
|
24905
|
79 |
print ";; *** DO NOT EDIT *** DO NOT EDIT *** DO NOT EDIT ***\n";
|
24875
|
80 |
print ";;\n";
|
|
81 |
|
|
82 |
for my $kind (@kinds) {
|
|
83 |
my @names;
|
|
84 |
for my $name (keys(%keywords)) {
|
|
85 |
if ($kind eq "major" ? $keywords{$name} ne "minor" : $keywords{$name} eq $kind) {
|
|
86 |
if ($kind ne "minor" or $name =~ m/^[A-Za-z0-9_]+$/) {
|
|
87 |
push @names, $name;
|
|
88 |
}
|
|
89 |
}
|
|
90 |
}
|
|
91 |
@names = sort(@names);
|
|
92 |
|
|
93 |
print "\n(defconst isar-keywords-${kind}";
|
|
94 |
print "\n '(";
|
|
95 |
my $first = 1;
|
|
96 |
for my $name (@names) {
|
|
97 |
$name =~ s/([\.\*\+\?\[\]\^\$])/\\\\$1/g;
|
|
98 |
if ($first) {
|
|
99 |
print "\"${name}\"";
|
|
100 |
$first = 0;
|
|
101 |
}
|
|
102 |
else {
|
|
103 |
print "\n \"${name}\"";
|
|
104 |
}
|
|
105 |
}
|
|
106 |
print "))\n";
|
|
107 |
}
|
|
108 |
print "\n(provide 'isar-keywords)\n";
|
|
109 |
|
|
110 |
close OUTPUT;
|
|
111 |
select;
|
33684
|
112 |
print STDERR "${file}\n";
|
24875
|
113 |
}
|
|
114 |
|
|
115 |
|
|
116 |
## main
|
|
117 |
|
|
118 |
&collect_keywords();
|
33684
|
119 |
&emacs_output();
|
24875
|
120 |
|