]> matita.cs.unibo.it Git - helm.git/blob - components/binaries/transcript/grafite.ml
tagged 0.5.0-rc1
[helm.git] / 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
28 module UM = UriManager
29 module NP = CicNotationPp
30 module GP = GrafiteAstPp
31 module G = GrafiteAst
32 module H = HExtlib
33
34 let floc = H.dummy_floc
35
36 let out_verbatim och s =
37    Printf.fprintf och "%s" s
38
39 let out_comment och s =
40    let s = if s <> "" && s.[0] = '*' then "#" ^ s else s in 
41    Printf.fprintf och "%s%s%s\n\n" "(*" s "*)"
42
43 let out_unexported och head s =
44    let s = Printf.sprintf " %s\n%s\n" head s in
45    out_comment och s
46
47 let out_line_comment och s =
48    let l = 70 - String.length s in
49    let s = Printf.sprintf " %s %s" s (String.make l '*') in
50    out_comment och s
51
52 let out_preamble och (path, lines) =
53    let ich = open_in path in
54    let rec print i =
55       if i > 0 then 
56          let s = input_line ich in
57          begin Printf.fprintf och "%s\n" s; print (pred i) end
58    in 
59    print lines;
60    out_line_comment och "This file was automatically generated: do not edit"
61       
62 let out_command och cmd =
63    let term_pp = NP.pp_term in
64    let lazy_term_pp = NP.pp_term in
65    let obj_pp = NP.pp_obj NP.pp_term in
66    let s = GP.pp_statement ~map_unicode_to_tex:false ~term_pp ~lazy_term_pp ~obj_pp cmd in
67    Printf.fprintf och "%s\n\n" s
68
69 let command_of_obj obj =
70    G.Executable (floc, G.Command (floc, obj))
71
72 let command_of_macro macro =
73    G.Executable (floc, G.Macro (floc, macro))
74
75 let set key value =
76    command_of_obj (G.Set (floc, key, value))
77
78 let require value =
79    command_of_obj (G.Include (floc, value ^ ".ma"))
80
81 let coercion value =
82    command_of_obj (G.Coercion (floc, UM.uri_of_string value, true, 0, 0))
83
84 let inline (uri, prefix) =
85     command_of_macro (G.Inline (floc, G.Declarative, uri, prefix))
86
87 let out_alias och name uri =
88    Printf.fprintf och "alias id \"%s\" = \"%s\".\n\n" name uri
89
90 let commit och items =
91    let trd (_, _, x) = x in
92    let trd_rth (_, _, x, y) = x, y in
93    let commit = function
94       | T.Heading heading   -> out_preamble och heading
95       | T.Line line         -> out_line_comment och line
96       | T.BaseUri uri       -> out_command och (set "baseuri" uri)
97       | T.Include script    -> out_command och (require script)
98       | T.Coercion specs    -> out_command och (coercion (snd specs))
99       | T.Notation specs    -> out_unexported och "NOTATION" (snd specs) (**)
100       | T.Inline (_, T.Var, src, _) -> out_alias och (UriManager.name_of_uri (UriManager.uri_of_string src)) src 
101       | T.Inline specs      -> out_command och (inline (trd_rth specs))
102       | T.Section specs     -> out_unexported och "UNEXPORTED" (trd specs)
103       | T.Comment comment   -> out_comment och comment
104       | T.Unexport unexport -> 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"