1 (* Copyright (C) 2000, HELM Team.
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.
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.
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.
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,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
29 module UM = UriManager
30 module NP = CicNotationPp
31 module GP = GrafiteAstPp
35 let floc = H.dummy_floc
37 let out_verbatim och s =
38 Printf.fprintf och "%s" s
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 "*)"
44 let out_unexported och head s =
45 let s = Printf.sprintf " %s\n%s\n" head s in
48 let out_line_comment och s =
49 let l = 70 - String.length s in
50 let s = Printf.sprintf " %s %s" s (String.make l '*') in
53 let out_preamble och (path, lines) =
54 let ich = open_in path in
57 let s = input_line ich in
58 begin Printf.fprintf och "%s\n" s; print (pred i) end
61 out_line_comment och "This file was automatically generated: do not edit"
63 let out_command och cmd =
64 let term_pp = NP.pp_term in
65 let lazy_term_pp = NP.pp_term in
66 let obj_pp = NP.pp_obj NP.pp_term in
67 let s = GP.pp_statement ~map_unicode_to_tex:false ~term_pp ~lazy_term_pp ~obj_pp cmd in
68 Printf.fprintf och "%s\n\n" s
70 let command_of_obj obj =
71 G.Executable (floc, G.Command (floc, obj))
73 let command_of_macro macro =
74 G.Executable (floc, G.Macro (floc, macro))
77 command_of_obj (G.Include (floc, value ^ ".ma"))
80 command_of_obj (G.Coercion (floc, UM.uri_of_string value, true, 0, 0))
82 let inline (kind, uri, prefix, flavour) =
83 let kind = match kind with
84 | T.Declarative -> G.Declarative
85 | T.Procedural -> G.Procedural None
87 command_of_macro (G.Inline (floc, kind, uri, prefix, flavour))
89 let out_alias och name uri =
90 Printf.fprintf och "alias id \"%s\" = \"%s\".\n\n" name uri
92 let commit kind och items =
93 let trd (_, _, x) = x in
94 let trd_rth kind (_, _, x, y, z) = kind, x, y, z in
96 | T.Heading heading -> out_preamble och heading
98 if !O.comments then out_line_comment och line
99 | T.Include script -> out_command och (require script)
100 | T.Coercion specs ->
101 if !O.comments then out_unexported och "COERCION" (snd specs)
102 | T.Notation specs ->
103 if !O.comments then out_unexported och "NOTATION" (snd specs) (**)
104 | T.Inline (_, T.Var, src, _, _) ->
105 if !O.comments then out_unexported och "UNEXPORTED" src
106 (* FG: we do not export variables because we cook the other object
107 * let name = UriManager.name_of_uri (UriManager.uri_of_string src) in
108 * out_alias och name src
110 | T.Inline specs -> out_command och (inline (trd_rth kind specs))
112 if !O.comments then out_unexported och "UNEXPORTED" (trd specs)
113 | T.Comment comment ->
114 if !O.comments then out_comment och comment
115 | T.Unexport unexport ->
116 if !O.comments then out_unexported och "UNEXPORTED" unexport
117 | T.Verbatim verbatim -> out_verbatim och verbatim
120 List.iter commit (List.rev items)
122 let string_of_inline_kind = function