author | wenzelm |
Wed, 21 Nov 2012 15:50:54 +0100 | |
changeset 50149 | aaf276a28551 |
parent 48864 | 3ee314ae1e0a |
child 50714 | 2af9e4614ba4 |
permissions | -rwxr-xr-x |
35022
c844b93dd147
modernized perl scripts: prefer standalone executables;
wenzelm
parents:
33684
diff
changeset
|
1 |
#!/usr/bin/env perl |
24875 | 2 |
# |
3 |
# Author: Makarius |
|
4 |
# |
|
5 |
# keywords.pl - generate outer syntax keyword files from session logs |
|
6 |
# |
|
7 |
||
35022
c844b93dd147
modernized perl scripts: prefer standalone executables;
wenzelm
parents:
33684
diff
changeset
|
8 |
use warnings; |
c844b93dd147
modernized perl scripts: prefer standalone executables;
wenzelm
parents:
33684
diff
changeset
|
9 |
use strict; |
c844b93dd147
modernized perl scripts: prefer standalone executables;
wenzelm
parents:
33684
diff
changeset
|
10 |
|
c844b93dd147
modernized perl scripts: prefer standalone executables;
wenzelm
parents:
33684
diff
changeset
|
11 |
|
24886 | 12 |
## arguments |
24875 | 13 |
|
33684 | 14 |
my ($keywords_name, $sessions) = @ARGV; |
24875 | 15 |
|
16 |
||
17 |
## keywords |
|
18 |
||
19 |
my %keywords; |
|
20 |
||
21 |
sub set_keyword { |
|
22 |
my ($name, $kind) = @_; |
|
27386 | 23 |
if (defined $keywords{$name} and $keywords{$name} ne $kind and $keywords{$name} ne "minor") { |
24 |
if ($kind ne "minor") { |
|
25 |
print STDERR "### Inconsistent declaration of keyword \"${name}\": $keywords{$name} vs ${kind}\n"; |
|
26 |
$keywords{$name} = $kind; |
|
27 |
} |
|
28 |
} else { |
|
29 |
$keywords{$name} = $kind; |
|
24875 | 30 |
} |
31 |
} |
|
32 |
||
46967
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
33 |
my %convert_kinds = ( |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
34 |
"thy_begin" => "theory-begin", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
35 |
"thy_end" => "theory-end", |
46969 | 36 |
"thy_heading1" => "theory-heading", |
37 |
"thy_heading2" => "theory-heading", |
|
38 |
"thy_heading3" => "theory-heading", |
|
39 |
"thy_heading4" => "theory-heading", |
|
48864
3ee314ae1e0a
added keyword kind "thy_load" (with optional list of file extensions);
wenzelm
parents:
46969
diff
changeset
|
40 |
"thy_load" => "theory-decl", |
46967
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
41 |
"thy_decl" => "theory-decl", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
42 |
"thy_script" => "theory-script", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
43 |
"thy_goal" => "theory-goal", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
44 |
"thy_schematic_goal" => "theory-goal", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
45 |
"qed_block" => "qed-block", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
46 |
"qed_global" => "qed-global", |
46969 | 47 |
"prf_heading2" => "proof-heading", |
48 |
"prf_heading3" => "proof-heading", |
|
49 |
"prf_heading4" => "proof-heading", |
|
46967
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
50 |
"prf_goal" => "proof-goal", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
51 |
"prf_block" => "proof-block", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
52 |
"prf_open" => "proof-open", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
53 |
"prf_close" => "proof-close", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
54 |
"prf_chain" => "proof-chain", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
55 |
"prf_decl" => "proof-decl", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
56 |
"prf_asm" => "proof-asm", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
57 |
"prf_asm_goal" => "proof-asm-goal", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
58 |
"prf_script" => "proof-script" |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
59 |
); |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
60 |
|
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
61 |
my @emacs_kinds = ( |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
62 |
"major", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
63 |
"minor", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
64 |
"control", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
65 |
"diag", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
66 |
"theory-begin", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
67 |
"theory-switch", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
68 |
"theory-end", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
69 |
"theory-heading", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
70 |
"theory-decl", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
71 |
"theory-script", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
72 |
"theory-goal", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
73 |
"qed", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
74 |
"qed-block", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
75 |
"qed-global", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
76 |
"proof-heading", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
77 |
"proof-goal", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
78 |
"proof-block", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
79 |
"proof-open", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
80 |
"proof-close", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
81 |
"proof-chain", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
82 |
"proof-decl", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
83 |
"proof-asm", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
84 |
"proof-asm-goal", |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
85 |
"proof-script" |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
86 |
); |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
87 |
|
24875 | 88 |
sub collect_keywords { |
89 |
while(<STDIN>) { |
|
46967
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
90 |
if (m/^Outer syntax keyword "([^"]*)" :: (\S*)/) { |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
91 |
my $name = $1; |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
92 |
my $kind = $2; |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
93 |
if (defined $convert_kinds{$kind}) { $kind = $convert_kinds{$kind} } |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
94 |
&set_keyword($name, $kind); |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
95 |
} |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
96 |
elsif (m/^Outer syntax keyword "([^"]*)"/) { |
24875 | 97 |
my $name = $1; |
98 |
&set_keyword($name, "minor"); |
|
99 |
} |
|
100 |
} |
|
101 |
} |
|
102 |
||
103 |
||
104 |
## Emacs output |
|
105 |
||
106 |
sub emacs_output { |
|
107 |
my $file = $keywords_name eq "" ? "isar-keywords.el" : "isar-keywords-${keywords_name}.el"; |
|
108 |
open (OUTPUT, "> ${file}") || die "$!"; |
|
109 |
select OUTPUT; |
|
110 |
||
111 |
print ";;\n"; |
|
112 |
print ";; Keyword classification tables for Isabelle/Isar.\n"; |
|
24912 | 113 |
print ";; Generated from ${sessions}.\n"; |
24905 | 114 |
print ";; *** DO NOT EDIT *** DO NOT EDIT *** DO NOT EDIT ***\n"; |
24875 | 115 |
print ";;\n"; |
116 |
||
46967
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
36316
diff
changeset
|
117 |
for my $kind (@emacs_kinds) { |
24875 | 118 |
my @names; |
119 |
for my $name (keys(%keywords)) { |
|
120 |
if ($kind eq "major" ? $keywords{$name} ne "minor" : $keywords{$name} eq $kind) { |
|
121 |
if ($kind ne "minor" or $name =~ m/^[A-Za-z0-9_]+$/) { |
|
122 |
push @names, $name; |
|
123 |
} |
|
124 |
} |
|
125 |
} |
|
126 |
@names = sort(@names); |
|
127 |
||
128 |
print "\n(defconst isar-keywords-${kind}"; |
|
129 |
print "\n '("; |
|
130 |
my $first = 1; |
|
131 |
for my $name (@names) { |
|
132 |
$name =~ s/([\.\*\+\?\[\]\^\$])/\\\\$1/g; |
|
133 |
if ($first) { |
|
134 |
print "\"${name}\""; |
|
135 |
$first = 0; |
|
136 |
} |
|
137 |
else { |
|
138 |
print "\n \"${name}\""; |
|
139 |
} |
|
140 |
} |
|
141 |
print "))\n"; |
|
142 |
} |
|
143 |
print "\n(provide 'isar-keywords)\n"; |
|
144 |
||
145 |
close OUTPUT; |
|
146 |
select; |
|
33684 | 147 |
print STDERR "${file}\n"; |
24875 | 148 |
} |
149 |
||
150 |
||
151 |
## main |
|
152 |
||
153 |
&collect_keywords(); |
|
33684 | 154 |
&emacs_output(); |