]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/binaries/transcript/grafite.ml
Preparing for 0.5.9 release.
[helm.git] / helm / software / 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 = CicNotationPp
31 module GP = GrafiteAstPp
32 module G  = GrafiteAst
33 module H  = HExtlib
34 module HG = Http_getter
35
36 let floc = H.dummy_floc
37
38 let out_verbatim och s =
39    Printf.fprintf och "%s" s
40
41 let out_comment och s =
42    let s = if s <> "" && s.[0] = '*' then "#" ^ s else s in 
43    Printf.fprintf och "%s%s%s\n\n" "(*" s "*)"
44
45 let out_unexported och head s =
46    let s = Printf.sprintf " %s\n%s\n" head s in
47    out_comment och s
48
49 let out_line_comment och s =
50    let l = 70 - String.length s in
51    let l = if l < 0 then 0 else l in
52    let s = Printf.sprintf " %s %s" s (String.make l '*') in
53    out_comment och s
54
55 let out_preamble och (path, lines) =
56    let ich = open_in path in
57    let rec print i =
58       if i > 0 then 
59          let s = input_line ich in
60          begin Printf.fprintf och "%s\n" s; print (pred i) end
61    in 
62    print lines;
63    out_line_comment och "This file was automatically generated: do not edit"
64       
65 let out_command och cmd =
66    let term_pp = NP.pp_term in
67    let lazy_term_pp = NP.pp_term in
68    let obj_pp = NP.pp_obj NP.pp_term in
69    let s = GP.pp_statement ~map_unicode_to_tex:false ~term_pp ~lazy_term_pp ~obj_pp cmd in
70    Printf.fprintf och "%s\n\n" s
71
72 let command_of_obj obj =
73    G.Executable (floc, G.Command (floc, obj))
74
75 let command_of_macro macro =
76    G.Executable (floc, G.Macro (floc, macro))
77
78 let require moo value =
79    command_of_obj (G.Include (floc, moo, `OldAndNew, 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 kind uri prefix flavour params =
85     let params = match prefix with
86        | ""     -> params
87        | prefix -> G.IPPrefix prefix :: params
88     in
89     let params = match flavour with
90        | None         -> params
91        | Some flavour -> G.IPAs flavour :: params
92     in
93     let params = match kind with
94        | T.Declarative -> params
95        | T.Procedural  -> G.IPProcedural :: params 
96     in    
97     command_of_macro (G.Inline (floc, uri, params))
98
99 let out_alias och name uri =
100    Printf.fprintf och "alias id \"%s\" = \"%s\".\n\n" name uri
101
102 let check och src =
103    if HG.exists ~local:false src then () else
104    let msg = "UNAVAILABLE OBJECT: " ^ src in
105    out_line_comment och msg;
106    prerr_endline msg
107
108 let commit kind och items =
109    let trd (_, _, x) = x in
110    let commit = function
111       | T.Heading heading       -> out_preamble och heading
112       | T.Line line             ->
113          if !O.comments then out_line_comment och line
114       | T.Include (moo, script) -> out_command och (require moo script)
115       | T.Coercion specs        -> 
116          if !O.comments then out_unexported och "COERCION" (snd specs)
117       | T.Notation specs        -> 
118          if !O.comments then out_unexported och "NOTATION" (snd specs) (**)
119       | T.Inline (_, T.Var, src, _, _, _) ->
120          if !O.comments then out_unexported och "UNEXPORTED" src
121 (* FG: we do not export variables because we cook the other objects         
122  *       let name = UriManager.name_of_uri (UriManager.uri_of_string src) in
123  *       out_alias och name src
124  *)
125       | T.Inline (_, _, src, pre, fl, params) -> 
126          if !O.getter then check och src; 
127          out_command och (inline kind src pre fl params)
128       | T.Section specs     -> 
129          if !O.comments then out_unexported och "UNEXPORTED" (trd specs)
130       | T.Comment comment   -> 
131          if !O.comments then out_comment och comment
132       | T.Unexport unexport -> 
133          if !O.comments then out_unexported och "UNEXPORTED" unexport 
134       | T.Verbatim verbatim -> out_verbatim och verbatim
135       | T.Discard _         -> ()
136    in 
137    List.iter commit (List.rev items)
138
139 let string_of_inline_kind = function
140    | T.Con -> ".con"
141    | T.Var -> ".var"
142    | T.Ind -> ".ind"