]> matita.cs.unibo.it Git - helm.git/blob - matita/components/binaries/transcript/grafite.ml
Propagation of changes to grafiteAst.
[helm.git] / matita / components / binaries / transcript / grafite.ml
1 (* Copyright (C) 2000, HELM Team.
2  * 
3  * This file is part of HELM, an Hypertextual, Electronic
4  * Library of Mathematics, developed at the Computer Science
5  * Department, University of Bologna, Italy.
6  * 
7  * HELM is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * 
12  * HELM is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with HELM; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://cs.unibo.it/helm/.
24  *)
25
26 module T = Types
27 module O = Options
28
29 module UM = UriManager
30 module NP = NotationPp
31 module GP = GrafiteAstPp
32 module G  = GrafiteAst
33 module H  = HExtlib
34
35 let floc = H.dummy_floc
36
37 let out_verbatim och s =
38    Printf.fprintf och "%s" s
39
40 let out_comment och s =
41    let s = if s <> "" && s.[0] = '*' then "#" ^ s else s in 
42    Printf.fprintf och "%s%s%s\n\n" "(*" s "*)"
43
44 let out_unexported och head s =
45    let s = Printf.sprintf " %s\n%s\n" head s in
46    out_comment och s
47
48 let out_line_comment och s =
49    let l = 70 - String.length s in
50    let l = if l < 0 then 0 else l in
51    let s = Printf.sprintf " %s %s" s (String.make l '*') in
52    out_comment och s
53
54 let out_preamble och (path, lines) =
55    let ich = open_in path in
56    let rec print i =
57       if i > 0 then 
58          let s = input_line ich in
59          begin Printf.fprintf och "%s\n" s; print (pred i) end
60    in 
61    print lines;
62    out_line_comment och "This file was automatically generated: do not edit"
63       
64 let out_command och cmd =
65    let term_pp = NP.pp_term in
66    let lazy_term_pp = NP.pp_term in
67    let obj_pp = NP.pp_obj NP.pp_term in
68    let s = GP.pp_statement cmd ~map_unicode_to_tex:false in
69    Printf.fprintf och "%s\n\n" s
70
71 let command_of_obj obj =
72    G.Executable (floc, G.Command (floc, obj))
73
74 let require moo value =
75    command_of_obj (G.Include (floc, value ^ ".ma"))
76
77 let out_alias och name uri =
78    Printf.fprintf och "alias id \"%s\" = \"%s\".\n\n" name uri
79
80 let check och src =
81    if Http_getter.exists ~local:false src then () else
82    let msg = "UNAVAILABLE OBJECT: " ^ src in
83    out_line_comment och msg;
84    prerr_endline msg
85
86 let commit kind och items =
87    let trd (_, _, x) = x in
88    let commit = function
89       | T.Heading heading       -> out_preamble och heading
90       | T.Line line             ->
91          if !O.comments then out_line_comment och line
92       | T.Include (moo, script) -> out_command och (require moo script)
93       | T.Coercion specs        -> 
94          if !O.comments then out_unexported och "COERCION" (snd specs)
95       | T.Notation specs        -> 
96          if !O.comments then out_unexported och "NOTATION" (snd specs) (**)
97       | T.Inline (_, T.Var, src, _, _) ->
98          if !O.comments then out_unexported och "UNEXPORTED" src
99       | T.Section specs     -> 
100          if !O.comments then out_unexported och "UNEXPORTED" (trd specs)
101       | T.Comment comment   -> 
102          if !O.comments then out_comment och comment
103       | T.Unexport unexport -> 
104          if !O.comments then out_unexported och "UNEXPORTED" unexport 
105       | T.Verbatim verbatim -> out_verbatim och verbatim
106       | T.Discard _         -> ()
107    in 
108    List.iter commit (List.rev items)
109
110 let string_of_inline_kind = function
111    | T.Con -> ".con"
112    | T.Var -> ".var"
113    | T.Ind -> ".ind"