24875
|
1 |
#
|
|
2 |
# $Id$
|
|
3 |
# Author: Makarius
|
|
4 |
#
|
|
5 |
# keywords.pl - generate outer syntax keyword files from session logs
|
|
6 |
#
|
|
7 |
|
24886
|
8 |
## arguments
|
24875
|
9 |
|
24886
|
10 |
my ($keywords_name, $target_tool, $sessions) = @ARGV;
|
24875
|
11 |
|
|
12 |
|
|
13 |
## keywords
|
|
14 |
|
|
15 |
my %keywords;
|
|
16 |
|
|
17 |
sub set_keyword {
|
|
18 |
my ($name, $kind) = @_;
|
|
19 |
if (defined $keywords{$name} and $keywords{$name} ne $kind) {
|
|
20 |
print STDERR "### Inconsistent declaration of keyword \"${name}\": $keywords{$name} vs ${kind}\n";
|
|
21 |
}
|
|
22 |
$keywords{$name} = $kind;
|
|
23 |
}
|
|
24 |
|
|
25 |
sub collect_keywords {
|
|
26 |
while(<STDIN>) {
|
|
27 |
if (m/^Outer syntax keyword:\s*"(.*)"/) {
|
|
28 |
my $name = $1;
|
|
29 |
&set_keyword($name, "minor");
|
|
30 |
}
|
|
31 |
elsif (m/^Outer syntax command:\s*"(.*)"\s*\((.*)\)/) {
|
|
32 |
my $name = $1;
|
|
33 |
my $kind = $2;
|
|
34 |
&set_keyword($name, $kind);
|
|
35 |
}
|
|
36 |
}
|
|
37 |
}
|
|
38 |
|
|
39 |
|
|
40 |
## Emacs output
|
|
41 |
|
|
42 |
sub emacs_output {
|
24886
|
43 |
my @kinds = (
|
|
44 |
"major",
|
|
45 |
"minor",
|
|
46 |
"control",
|
|
47 |
"diag",
|
|
48 |
"theory-begin",
|
|
49 |
"theory-switch",
|
|
50 |
"theory-end",
|
|
51 |
"theory-heading",
|
|
52 |
"theory-decl",
|
|
53 |
"theory-script",
|
|
54 |
"theory-goal",
|
|
55 |
"qed",
|
|
56 |
"qed-block",
|
|
57 |
"qed-global",
|
|
58 |
"proof-heading",
|
|
59 |
"proof-goal",
|
|
60 |
"proof-block",
|
|
61 |
"proof-open",
|
|
62 |
"proof-close",
|
|
63 |
"proof-chain",
|
|
64 |
"proof-decl",
|
|
65 |
"proof-asm",
|
|
66 |
"proof-asm-goal",
|
|
67 |
"proof-script"
|
|
68 |
);
|
24875
|
69 |
my $file = $keywords_name eq "" ? "isar-keywords.el" : "isar-keywords-${keywords_name}.el";
|
|
70 |
open (OUTPUT, "> ${file}") || die "$!";
|
|
71 |
select OUTPUT;
|
|
72 |
|
|
73 |
print ";;\n";
|
|
74 |
print ";; Keyword classification tables for Isabelle/Isar.\n";
|
24912
|
75 |
print ";; Generated from ${sessions}.\n";
|
24905
|
76 |
print ";; *** DO NOT EDIT *** DO NOT EDIT *** DO NOT EDIT ***\n";
|
24875
|
77 |
print ";;\n";
|
|
78 |
print ";; \$", "Id\$\n";
|
|
79 |
print ";;\n";
|
|
80 |
|
|
81 |
for my $kind (@kinds) {
|
|
82 |
my @names;
|
|
83 |
for my $name (keys(%keywords)) {
|
|
84 |
if ($kind eq "major" ? $keywords{$name} ne "minor" : $keywords{$name} eq $kind) {
|
|
85 |
if ($kind ne "minor" or $name =~ m/^[A-Za-z0-9_]+$/) {
|
|
86 |
push @names, $name;
|
|
87 |
}
|
|
88 |
}
|
|
89 |
}
|
|
90 |
@names = sort(@names);
|
|
91 |
|
|
92 |
print "\n(defconst isar-keywords-${kind}";
|
|
93 |
print "\n '(";
|
|
94 |
my $first = 1;
|
|
95 |
for my $name (@names) {
|
|
96 |
$name =~ s/([\.\*\+\?\[\]\^\$])/\\\\$1/g;
|
|
97 |
if ($first) {
|
|
98 |
print "\"${name}\"";
|
|
99 |
$first = 0;
|
|
100 |
}
|
|
101 |
else {
|
|
102 |
print "\n \"${name}\"";
|
|
103 |
}
|
|
104 |
}
|
|
105 |
print "))\n";
|
|
106 |
}
|
|
107 |
print "\n(provide 'isar-keywords)\n";
|
|
108 |
|
|
109 |
close OUTPUT;
|
|
110 |
select;
|
24886
|
111 |
print STDERR "${target_tool}: ${file}\n";
|
|
112 |
}
|
|
113 |
|
|
114 |
|
|
115 |
## jEdit output
|
|
116 |
|
|
117 |
sub jedit_output {
|
|
118 |
my %keyword_types = (
|
|
119 |
"minor" => "KEYWORD4",
|
|
120 |
"control" => "INVALID",
|
|
121 |
"diag" => "LABEL",
|
|
122 |
"theory-begin" => "KEYWORD3",
|
|
123 |
"theory-switch" => "KEYWORD3",
|
|
124 |
"theory-end" => "KEYWORD3",
|
|
125 |
"theory-heading" => "OPERATOR",
|
|
126 |
"theory-decl" => "OPERATOR",
|
|
127 |
"theory-script" => "KEYWORD1",
|
|
128 |
"theory-goal" => "OPERATOR",
|
|
129 |
"qed" => "OPERATOR",
|
|
130 |
"qed-block" => "OPERATOR",
|
|
131 |
"qed-global" => "OPERATOR",
|
|
132 |
"proof-heading" => "OPERATOR",
|
|
133 |
"proof-goal" => "OPERATOR",
|
|
134 |
"proof-block" => "OPERATOR",
|
|
135 |
"proof-open" => "OPERATOR",
|
|
136 |
"proof-close" => "OPERATOR",
|
|
137 |
"proof-chain" => "OPERATOR",
|
|
138 |
"proof-decl" => "OPERATOR",
|
|
139 |
"proof-asm" => "KEYWORD2",
|
|
140 |
"proof-asm-goal" => "KEYWORD2",
|
|
141 |
"proof-script" => "KEYWORD1"
|
|
142 |
);
|
|
143 |
my $file = "isabelle.xml";
|
|
144 |
open (OUTPUT, "> ${file}") || die "$!";
|
|
145 |
select OUTPUT;
|
|
146 |
|
|
147 |
print <<'EOF';
|
|
148 |
<?xml version="1.0"?>
|
|
149 |
<!DOCTYPE MODE SYSTEM "xmode.dtd">
|
24890
|
150 |
EOF
|
24912
|
151 |
print "<!-- Generated from ${sessions}. -->\n";
|
24905
|
152 |
print "<!-- *** DO NOT EDIT *** DO NOT EDIT *** DO NOT EDIT *** -->\n";
|
24912
|
153 |
print "<!-- \$", "Id\$ -->\n";
|
24890
|
154 |
print <<'EOF';
|
24886
|
155 |
<MODE>
|
|
156 |
<PROPS>
|
|
157 |
<PROPERTY NAME="commentStart" VALUE="(*"/>
|
|
158 |
<PROPERTY NAME="commentEnd" VALUE="*)"/>
|
|
159 |
<PROPERTY NAME="noWordSep" VALUE="_'.?"/>
|
|
160 |
<PROPERTY NAME="indentOpenBrackets" VALUE="{"/>
|
|
161 |
<PROPERTY NAME="indentCloseBrackets" VALUE="}"/>
|
|
162 |
<PROPERTY NAME="unalignedOpenBrackets" VALUE="(" />
|
|
163 |
<PROPERTY NAME="unalignedCloseBrackets" VALUE=")" />
|
|
164 |
<PROPERTY NAME="tabSize" VALUE="2" />
|
|
165 |
<PROPERTY NAME="indentSize" VALUE="2" />
|
|
166 |
</PROPS>
|
|
167 |
<RULES IGNORE_CASE="FALSE" HIGHLIGHT_DIGITS="FALSE" ESCAPE="\">
|
|
168 |
<SPAN TYPE="COMMENT1" NO_ESCAPE="TRUE">
|
|
169 |
<BEGIN>(*</BEGIN>
|
|
170 |
<END>*)</END>
|
|
171 |
</SPAN>
|
|
172 |
<SPAN TYPE="COMMENT3" NO_ESCAPE="TRUE">
|
|
173 |
<BEGIN>{*</BEGIN>
|
|
174 |
<END>*}</END>
|
|
175 |
</SPAN>
|
|
176 |
<SPAN TYPE="LITERAL1">
|
|
177 |
<BEGIN>`</BEGIN>
|
|
178 |
<END>`</END>
|
|
179 |
</SPAN>
|
|
180 |
<SPAN TYPE="LITERAL3">
|
|
181 |
<BEGIN>"</BEGIN>
|
|
182 |
<END>"</END>
|
|
183 |
</SPAN>
|
|
184 |
<KEYWORDS>
|
|
185 |
EOF
|
|
186 |
|
|
187 |
for my $name (sort(keys(%keywords))) {
|
|
188 |
my $kind = $keywords{$name};
|
|
189 |
my $type = $keyword_types{$kind};
|
|
190 |
if ($kind ne "minor" or $name =~ m/^[A-Za-z0-9_]+$/) {
|
|
191 |
$name =~ s/&/&/g;
|
|
192 |
$name =~ s/</</g;
|
|
193 |
$name =~ s/>/</g;
|
|
194 |
print " <${type}>${name}</${type}>\n";
|
|
195 |
}
|
|
196 |
}
|
|
197 |
|
|
198 |
print <<'EOF';
|
|
199 |
</KEYWORDS>
|
|
200 |
</RULES>
|
|
201 |
</MODE>
|
|
202 |
EOF
|
|
203 |
|
|
204 |
close OUTPUT;
|
|
205 |
select;
|
|
206 |
print STDERR "${target_tool}: ${file}\n";
|
24875
|
207 |
}
|
|
208 |
|
|
209 |
|
|
210 |
## main
|
|
211 |
|
|
212 |
&collect_keywords();
|
24886
|
213 |
eval "${target_tool}_output()";
|
24875
|
214 |
|