lib/scripts/keywords.pl
changeset 33684 29d8aaeb56e5
parent 29145 b1c6f4563df7
equal deleted inserted replaced
33683:8d43e5e0588d 33684:29d8aaeb56e5
     4 # keywords.pl - generate outer syntax keyword files from session logs
     4 # keywords.pl - generate outer syntax keyword files from session logs
     5 #
     5 #
     6 
     6 
     7 ## arguments
     7 ## arguments
     8 
     8 
     9 my ($keywords_name, $target_tool, $sessions) = @ARGV;
     9 my ($keywords_name, $sessions) = @ARGV;
    10 
    10 
    11 
    11 
    12 ## keywords
    12 ## keywords
    13 
    13 
    14 my %keywords;
    14 my %keywords;
   107   }
   107   }
   108   print "\n(provide 'isar-keywords)\n";
   108   print "\n(provide 'isar-keywords)\n";
   109 
   109 
   110   close OUTPUT;
   110   close OUTPUT;
   111   select;
   111   select;
   112   print STDERR "${target_tool}: ${file}\n";
   112   print STDERR "${file}\n";
   113 }
       
   114 
       
   115 
       
   116 ## jEdit output
       
   117 
       
   118 sub jedit_output {
       
   119   my %keyword_types = (
       
   120     "minor"           => "KEYWORD4",
       
   121     "control"         => "INVALID",
       
   122     "diag"            => "LABEL",
       
   123     "theory-begin"    => "KEYWORD3",
       
   124     "theory-switch"   => "KEYWORD3",
       
   125     "theory-end"      => "KEYWORD3",
       
   126     "theory-heading"  => "OPERATOR",
       
   127     "theory-decl"     => "OPERATOR",
       
   128     "theory-script"   => "KEYWORD1",
       
   129     "theory-goal"     => "OPERATOR",
       
   130     "qed"             => "OPERATOR",
       
   131     "qed-block"       => "OPERATOR",
       
   132     "qed-global"      => "OPERATOR",
       
   133     "proof-heading"   => "OPERATOR",
       
   134     "proof-goal"      => "OPERATOR",
       
   135     "proof-block"     => "OPERATOR",
       
   136     "proof-open"      => "OPERATOR",
       
   137     "proof-close"     => "OPERATOR",
       
   138     "proof-chain"     => "OPERATOR",
       
   139     "proof-decl"      => "OPERATOR",
       
   140     "proof-asm"       => "KEYWORD2",
       
   141     "proof-asm-goal"  => "KEYWORD2",
       
   142     "proof-script"    => "KEYWORD1"
       
   143   );
       
   144   my $file = "isabelle.xml";
       
   145   open (OUTPUT, "> ${file}") || die "$!";
       
   146   select OUTPUT;
       
   147 
       
   148   print <<'EOF';
       
   149 <?xml version="1.0"?>
       
   150 <!DOCTYPE MODE SYSTEM "xmode.dtd">
       
   151 EOF
       
   152   print "<!-- Generated from ${sessions}. -->\n";
       
   153   print "<!-- *** DO NOT EDIT *** DO NOT EDIT *** DO NOT EDIT *** -->\n";
       
   154   print <<'EOF';
       
   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/&/&amp;/g;
       
   192       $name =~ s/</&lt;/g;
       
   193       $name =~ s/>/&lt;/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";
       
   207 }
   113 }
   208 
   114 
   209 
   115 
   210 ## main
   116 ## main
   211 
   117 
   212 &collect_keywords();
   118 &collect_keywords();
   213 eval "${target_tool}_output()";
   119 &emacs_output();
   214 
   120