author | wenzelm |
Wed, 03 Mar 2010 00:33:02 +0100 | |
changeset 35431 | 8758fe1fc9f8 |
parent 35022 | c844b93dd147 |
child 36316 | f9b45eac4c60 |
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 |
||
33 |
sub collect_keywords { |
|
34 |
while(<STDIN>) { |
|
35 |
if (m/^Outer syntax keyword:\s*"(.*)"/) { |
|
36 |
my $name = $1; |
|
37 |
&set_keyword($name, "minor"); |
|
38 |
} |
|
39 |
elsif (m/^Outer syntax command:\s*"(.*)"\s*\((.*)\)/) { |
|
40 |
my $name = $1; |
|
41 |
my $kind = $2; |
|
42 |
&set_keyword($name, $kind); |
|
43 |
} |
|
44 |
} |
|
45 |
} |
|
46 |
||
47 |
||
48 |
## Emacs output |
|
49 |
||
50 |
sub emacs_output { |
|
24886 | 51 |
my @kinds = ( |
52 |
"major", |
|
53 |
"minor", |
|
54 |
"control", |
|
55 |
"diag", |
|
56 |
"theory-begin", |
|
57 |
"theory-switch", |
|
58 |
"theory-end", |
|
59 |
"theory-heading", |
|
60 |
"theory-decl", |
|
61 |
"theory-script", |
|
62 |
"theory-goal", |
|
63 |
"qed", |
|
64 |
"qed-block", |
|
65 |
"qed-global", |
|
66 |
"proof-heading", |
|
67 |
"proof-goal", |
|
68 |
"proof-block", |
|
69 |
"proof-open", |
|
70 |
"proof-close", |
|
71 |
"proof-chain", |
|
72 |
"proof-decl", |
|
73 |
"proof-asm", |
|
74 |
"proof-asm-goal", |
|
75 |
"proof-script" |
|
76 |
); |
|
24875 | 77 |
my $file = $keywords_name eq "" ? "isar-keywords.el" : "isar-keywords-${keywords_name}.el"; |
78 |
open (OUTPUT, "> ${file}") || die "$!"; |
|
79 |
select OUTPUT; |
|
80 |
||
81 |
print ";;\n"; |
|
82 |
print ";; Keyword classification tables for Isabelle/Isar.\n"; |
|
24912 | 83 |
print ";; Generated from ${sessions}.\n"; |
24905 | 84 |
print ";; *** DO NOT EDIT *** DO NOT EDIT *** DO NOT EDIT ***\n"; |
24875 | 85 |
print ";;\n"; |
86 |
||
87 |
for my $kind (@kinds) { |
|
88 |
my @names; |
|
89 |
for my $name (keys(%keywords)) { |
|
90 |
if ($kind eq "major" ? $keywords{$name} ne "minor" : $keywords{$name} eq $kind) { |
|
91 |
if ($kind ne "minor" or $name =~ m/^[A-Za-z0-9_]+$/) { |
|
92 |
push @names, $name; |
|
93 |
} |
|
94 |
} |
|
95 |
} |
|
96 |
@names = sort(@names); |
|
97 |
||
98 |
print "\n(defconst isar-keywords-${kind}"; |
|
99 |
print "\n '("; |
|
100 |
my $first = 1; |
|
101 |
for my $name (@names) { |
|
102 |
$name =~ s/([\.\*\+\?\[\]\^\$])/\\\\$1/g; |
|
103 |
if ($first) { |
|
104 |
print "\"${name}\""; |
|
105 |
$first = 0; |
|
106 |
} |
|
107 |
else { |
|
108 |
print "\n \"${name}\""; |
|
109 |
} |
|
110 |
} |
|
111 |
print "))\n"; |
|
112 |
} |
|
113 |
print "\n(provide 'isar-keywords)\n"; |
|
114 |
||
115 |
close OUTPUT; |
|
116 |
select; |
|
33684 | 117 |
print STDERR "${file}\n"; |
24875 | 118 |
} |
119 |
||
120 |
||
121 |
## main |
|
122 |
||
123 |
&collect_keywords(); |
|
33684 | 124 |
&emacs_output(); |