annotate tools/make_template.ml @ 41:d45ba7e9b266

Improve template generation; craft template for InductiveTypes
author Adam Chlipala <adamc@hcoop.net>
date Sat, 13 Sep 2008 14:31:51 -0400
parents c8070689f5ca
children 827d7e8a7d9e
rev   line source
adamc@23 1 let read_line () =
adamc@22 2 try
adamc@23 3 Some (read_line ())
adamc@22 4 with End_of_file -> None
adamc@22 5
adamc@22 6 let rec initial last_was_empty =
adamc@23 7 match read_line () with
adamc@22 8 | None -> ()
adamc@22 9 | Some "(* begin thide *)" -> thide last_was_empty
adamc@22 10 | Some "" ->
adamc@22 11 if not (last_was_empty) then
adamc@22 12 print_newline ();
adamc@22 13 initial true
adamc@22 14 | Some line ->
adamc@41 15 let idx = try Some (String.index line '(') with Not_found -> None in
adamc@41 16 match idx with
adamc@41 17 | Some idx ->
adamc@41 18 if String.length line > idx+1 && line.[idx+1] = '*' then
adamc@41 19 if line.[String.length line - 2] = '*' && line.[String.length line - 1] = ')' then
adamc@41 20 initial last_was_empty
adamc@41 21 else
adamc@41 22 comment last_was_empty
adamc@41 23 else begin
adamc@41 24 print_endline line;
adamc@41 25 initial false
adamc@41 26 end
adamc@41 27 | None ->
adamc@41 28 print_endline line;
adamc@41 29 initial false
adamc@22 30
adamc@22 31 and comment last_was_empty =
adamc@23 32 match read_line () with
adamc@22 33 | None -> ()
adamc@22 34 | Some line ->
adamc@22 35 if String.length line >= 2 && line.[String.length line - 2] = '*'
adamc@22 36 && line.[String.length line - 1] = ')' then
adamc@22 37 initial last_was_empty
adamc@22 38 else
adamc@22 39 comment last_was_empty
adamc@22 40
adamc@22 41 and thide last_was_empty =
adamc@23 42 match read_line () with
adamc@22 43 | None -> ()
adamc@22 44 | Some "(* end thide *)" -> initial last_was_empty
adamc@22 45 | Some _ -> thide last_was_empty
adamc@22 46
adamc@22 47 let () = initial false