src/Pure/Thy/to_html.ML
author paulson
Fri, 11 Aug 1995 12:36:15 +0200
changeset 1227 c9f7848bc5ee
permissions -rw-r--r--
Mateja Jamnik's theory to html converter
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1227
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
     1
(*  ID:         $Id$
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
     2
    Author:	Mateja Jamnik, University of Cambridge
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
     3
    Copyright   1995  University of Cambridge
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
     4
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
     5
   Convert the Isabelle theory files to .html format for hypertext browsing
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
     6
*)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
     7
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
     8
val htmlpath = "/homes/lcp/html_isa/";
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
     9
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    10
(* --------------------
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    11
   Exception declaration in case that there is a lexical
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    12
   error occurs.
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    13
   -------------------- *)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    14
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    15
exception lex_err;
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    16
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    17
(* --------------------
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    18
   Get the list of all the theory files and the
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    19
   path to access them in their directories
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    20
   -------------------- *)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    21
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    22
print_depth 1000;
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    23
val theory_list = !loaded_thys;
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    24
val files = Symtab.alist_of (theory_list);
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    25
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    26
(* --------------------
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    27
   The function move_eachf is going to move all the theory
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    28
   files in isabelle to their html format. It takes 
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    29
   for arguments the name of the theory (tname) and
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    30
   other theory information such as path (path), theorems (thms)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    31
   proved, ... It is the main driver of the program, and basically
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    32
   contains all other functions. It contains the following
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    33
   subfunctions:
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    34
     - create_pure
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    35
     - gettext
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    36
     - move_onef
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    37
     - transform
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    38
   -------------------- *)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    39
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    40
fun move_eachf (tname, ThyInfo{path,thms,...}) =
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    41
    let val intext = path^tname^".thy";
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    42
	val outtext = htmlpath^tname^".html";
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    43
	    
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    44
(* --------------------
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    45
   The function gettext takes an instrem from the auxilliary 
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    46
   file .thy whose name and path are specified in the existent
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    47
   Isabelle structure, treats the inputted string with all the
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    48
   necessary modifications for html format and puts it into the
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    49
   file with the same name but .html extension. The subfunctions
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    50
   it contains are:
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    51
      - after_first_c
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    52
      - filter
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    53
      - first_comment
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    54
      - format_link
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    55
      - getstring
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    56
      - get_word
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    57
      - he
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    58
      - html
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    59
      - html_escape
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    60
      - insert_link
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    61
      - leading_comment
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    62
      - lc_exists
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    63
      - modify_body
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    64
      - remove_lc
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    65
      - rest
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    66
      - thy_name
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    67
   -------------------- *)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    68
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    69
	fun gettext is  =
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    70
	    let 
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    71
		val head = "<HTML>\n<HEAD>\n<TITLE>"^intext^
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    72
		    "</TITLE>\n</HEAD>\n\n"^"<BODY>\n";
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    73
		val title = "<H1>"^tname^".thy"^"</H1></P>\n\n"^
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    74
		    "<BR>\n<A HREF = \""^htmlpath^
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    75
		    "00-chart.html\">Dependency Chart</A>\n"^
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    76
		    ": display of dependencies between the theories.\n"^
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    77
		    "<BR>\n<HR>\n\n<PRE>\n";
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    78
		val tail = "</PRE>"^"</BODY>\n"^"</HTML>";
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    79
		
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    80
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    81
	     (* --------------------
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    82
		The function he (html escape) is going to take
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    83
		every single characterof the input stream and check
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    84
		for ">", "<" and "&" characters that have a special
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    85
		meaning in html and convert them into their corresponding
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    86
		escape sequences.   
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    87
		-------------------- *)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    88
		fun he [] r = r
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    89
		  | he ("<"::sl) r = he sl (r@["&","l","t"])
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    90
		  | he (">"::sl) r = he sl (r@["&","g","t"])
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    91
		  | he ("&"::sl) r = he sl (r@["&","a","m","p"])
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    92
		  | he (c::sl) r = he sl (r@[c]);
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    93
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    94
		fun html_escape sl = he sl [];
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    95
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    96
	     (* --------------------
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    97
		The function first_comment is a pattern checking for
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    98
		nested comments. The argument d will keep track of how
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
    99
		deep we are in the nested comment. The function will
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   100
		return the first comment extracted from the input stream,
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   101
		so that we can copy it into the output stream. Lexical
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   102
		error is raised if we open an empty file to read from.
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   103
		-------------------- *)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   104
		fun first_comment ("*"::")"::cs) co 1 = co@["*",")"]
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   105
		  | first_comment ("*"::")"::cs) co d =
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   106
		    first_comment cs (co@["*",")"]) (d-1)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   107
		  | first_comment ("("::"*"::cs) co d =
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   108
		    first_comment cs (co@["(","*"]) (d+1)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   109
		  | first_comment (c::cs) co d =
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   110
		    if d>0 then first_comment cs (co@[c]) d
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   111
		    else first_comment cs co d
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   112
		  | first_comment [] _ _ = raise lex_err;
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   113
		    
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   114
	     (* --------------------
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   115
	        The function lc_exists leading comment exists?)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   116
		checks whether in the input file at the very beginning
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   117
		there is a comment, which needs to be extracted and put
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   118
		into the output file. We also need to check whether there
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   119
		might be a space, a new line or a tab, which do not
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   120
		exclude the possibility that there is a leading comment.
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   121
		The function returns a boolean value. 
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   122
		-------------------- *)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   123
		fun lc_exists ("("::"*"::_) = true
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   124
		  | lc_exists (" "::cs) = lc_exists cs
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   125
		  | lc_exists ("\n"::cs) = lc_exists cs
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   126
		  | lc_exists ("\t"::cs) = lc_exists cs
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   127
		  | lc_exists _ = false;
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   128
		    
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   129
	     (* --------------------
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   130
	        In the case that there is a leading comment, this
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   131
		function leading_comment extracts it> It also need
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   132
		to check for any html escape sequences in the comment.
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   133
		-------------------- *)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   134
		fun leading_comment sl =
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   135
		    if (lc_exists sl) then
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   136
			(html_escape (first_comment sl [] 0))
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   137
		    else
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   138
			[""];
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   139
			
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   140
	     (* --------------------
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   141
	        The function thy_name checks for the parent theory
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   142
		names apearing after the leading comment. The function
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   143
		returns a boolean value indicating if the word is a
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   144
		theory name, so that a link can be inserted and can look
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   145
		for another potential theory name. If the word is not a
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   146
		theory name then continue to modify the rest of the body.
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   147
		-------------------- *)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   148
		fun thy_name word = 
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   149
		    is_some (Symtab.lookup (theory_list, word));
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   150
		    
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   151
	     (* --------------------
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   152
	        Creates the right html format when inserting the link.
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   153
		-------------------- *)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   154
		fun format_link s = 
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   155
		    let in
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   156
			output(std_out,"\n"^s);
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   157
			"<A HREF = \""^htmlpath^s^".html\">"^s^"</A>"
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   158
		    end;
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   159
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   160
	     (* --------------------
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   161
		-------------------- *)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   162
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   163
		fun insert_link w = (explode (format_link (implode w)))
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   164
	     (* --------------------
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   165
		-------------------- *)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   166
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   167
		fun html ( " "::l) r = html l (r@[ " "])
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   168
		  | html ( "+"::l) r = html l (r@[ "+"])
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   169
		  | html ("\n"::l) r = html l (r@["\n"])
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   170
		  | html ("\t"::l) r = html l (r@["\t"])
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   171
		  | html l r = r@(get_word l [])
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   172
	     (* --------------------
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   173
		-------------------- *)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   174
		and get_word ( " "::l) w = 
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   175
		    if (thy_name (implode w)) 
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   176
			then (insert_link w)@[ " "]@(html l [])
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   177
		    else w@[" "]@(html_escape l)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   178
		  | get_word ( "+"::l) w = 
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   179
		    if (thy_name (implode w))
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   180
			then (insert_link w)@[ "+"]@(html l [])
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   181
		    else w@["+"]@(html_escape l)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   182
		  | get_word ("\n"::l) w = 
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   183
		    if (thy_name (implode w))
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   184
			then (insert_link w)@[ "\n"]@(html l [])
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   185
		    else w@["\n"]@(html_escape l)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   186
		  | get_word ("\t"::l) w = 
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   187
		    if (thy_name (implode w))
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   188
			then (insert_link w)@[ "\t"]@(html l [])
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   189
		    else w@["\t"]@(html_escape l)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   190
		  | get_word (c::l) w = (get_word l (w@[c]))
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   191
		  | get_word [] [] = []
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   192
		  | get_word [] w = 
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   193
		    if (thy_name (implode w))
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   194
			then (insert_link w)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   195
		    else w;
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   196
			
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   197
	     (* --------------------
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   198
		-------------------- *)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   199
		fun modify_body ("="::l) r = r@["="]@(html l [])
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   200
		  | modify_body (c::l) r = modify_body l (r@[c])
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   201
		  | modify_body [] r = r;
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   202
		    
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   203
	     (* --------------------
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   204
		-------------------- *)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   205
		fun after_first_c ("*"::")"::cs) 1 = cs
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   206
		  | after_first_c ("*"::")"::cs) d = after_first_c cs (d-1)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   207
		  | after_first_c ("("::"*"::cs) d = after_first_c cs (d+1)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   208
		  | after_first_c (c::cs) d = after_first_c cs d
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   209
		  | after_first_c cs 0 = cs
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   210
		  | after_first_c [] _ = raise lex_err;
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   211
		    
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   212
	     (* --------------------
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   213
		-------------------- *)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   214
		fun remove_lc sl =
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   215
		    if (lc_exists sl) then (after_first_c sl 0) else sl;
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   216
			
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   217
	     (* --------------------
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   218
		-------------------- *)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   219
		fun rest sl = modify_body (remove_lc sl) [];
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   220
		    
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   221
	     (* --------------------
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   222
		-------------------- *)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   223
		fun filter sl = (leading_comment sl) @ (rest sl);
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   224
		    
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   225
	     (* --------------------
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   226
		-------------------- *)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   227
		fun getstring s =
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   228
		    case input (is, 1) of
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   229
			"" => head^title^(implode(filter(explode(s))))^tail
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   230
		      | "\n" => getstring (s^"\n")
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   231
		      | c  => getstring (s^c)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   232
	    in
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   233
		getstring ""
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   234
	    end;
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   235
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   236
     (* --------------------
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   237
      	-------------------- *)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   238
	fun transform t =
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   239
	    let
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   240
		val infile = open_in intext;
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   241
		val outfile = open_out outtext
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   242
	    in
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   243
		output(std_out,"\nTheory: "^t);
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   244
		output (outfile, gettext(infile));
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   245
		close_in (infile);
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   246
		close_out (outfile)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   247
	    end;
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   248
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   249
     (* --------------------
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   250
      	-------------------- *)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   251
	fun create_pure p =
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   252
	    let
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   253
		val outfile = open_out outtext
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   254
	    in
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   255
		output(std_out, "\nCreating Pure.html ...");
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   256
		output (outfile, "<HTML>\n<HEAD>\n<TITLE>"^intext^
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   257
			"</TITLE>\n</HEAD>\n\n"^"<BODY>\n"^
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   258
			"<H1>"^tname^".thy"^"</H1></P>\n\n"^"<PRE>\n"^
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   259
			"This is a theory file called Pure.\n"^
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   260
			"Its children are all other Isabelle theories."^
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   261
			"</PRE>"^"</BODY>\n"^"</HTML>");
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   262
		close_out (outfile)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   263
	    end
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   264
	
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   265
    in
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   266
	if (tname <> "Pure") then (transform tname)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   267
	else (create_pure tname)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   268
    end;
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   269
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   270
(* --------------------
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   271
   -------------------- *)
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   272
map move_eachf (files);
c9f7848bc5ee Mateja Jamnik's theory to html converter
paulson
parents:
diff changeset
   273