]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/cic_transformations/sequentPp.ml
first moogle template checkin
[helm.git] / helm / ocaml / cic_transformations / sequentPp.ml
1 (* Copyright (C) 2000-2002, 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 TextualPp =
27  struct
28   (* It also returns the pretty-printing context! *)
29   let print_context ctx =
30     let print_name =
31      function
32         Cic.Name n -> n
33       | Cic.Anonymous -> "_"
34     in
35      List.fold_right
36       (fun i (output,context) ->
37         let (newoutput,context') =
38          match i with
39             Some (n,Cic.Decl t) ->
40               print_name n ^ ":" ^ CicPp.pp t context ^ "\n", (Some n)::context
41           | Some (n,Cic.Def (t,None)) ->
42               print_name n ^ ":=" ^ CicPp.pp t context ^ "\n", (Some n)::context
43           | None ->
44               "_ ?= _\n", None::context
45           | Some (_,Cic.Def (_,Some _)) -> assert false
46         in
47          output^newoutput,context'
48       ) ctx ("",[])
49   ;;
50
51   exception NotImplemented;;
52
53   let print_sequent (metano,context,goal) =
54    "\n" ^
55     let (output,pretty_printer_context_of_context) = print_context context in
56      output ^
57       "---------------------- ?" ^ string_of_int metano ^ "\n" ^
58        CicPp.pp goal pretty_printer_context_of_context
59   ;;
60  end
61 ;;
62
63 module XmlPp =
64  struct
65   let dtdname = "http://localhost:8081/getdtd?uri=cic.dtd";;
66
67   let print_sequent metasenv (metano,context,goal) =
68    let module X = Xml in
69     let ids_to_terms = Hashtbl.create 503 in
70     let ids_to_father_ids = Hashtbl.create 503 in
71     let ids_to_inner_sorts = Hashtbl.create 503 in
72     let ids_to_inner_types = Hashtbl.create 503 in
73     let ids_to_hypotheses = Hashtbl.create 11 in
74     let hypotheses_seed = ref 0 in
75     let sequent_id = "i0" in
76     let seed = ref 1 in  (* 'i0' is used for the whole sequent *)
77      let acic_of_cic_context =
78       Cic2acic.acic_of_cic_context' seed ids_to_terms ids_to_father_ids
79        ids_to_inner_sorts ids_to_inner_types metasenv
80      in
81       let final_s,_,final_idrefs =
82        (List.fold_right
83          (fun binding (s,context,idrefs) ->
84            let hid = "h" ^ string_of_int !hypotheses_seed in
85             Hashtbl.add ids_to_hypotheses hid binding ;
86             incr hypotheses_seed ;
87             match binding with
88                (Some (n,(Cic.Def (t,None) as b)) as entry)
89              | (Some (n,(Cic.Decl t as b)) as entry) ->
90                 let acic = acic_of_cic_context context idrefs t None in
91                  [< s ;
92                     X.xml_nempty
93                      (match b with Cic.Decl _ -> "Decl" | Cic.Def _ -> "Def")
94                      [None,"name",(match n with Cic.Name n -> n | _ -> assert false);
95                       None,"id",hid]
96                      (Cic2Xml.print_term ~ids_to_inner_sorts acic)
97                  >], (entry::context), (hid::idrefs)
98              | None ->
99                 (* Invariant: "" is never looked up *)
100                 [< s ; X.xml_empty "Hidden" [] >], (None::context), ""::idrefs
101              | Some (_,Cic.Def (_,Some _)) -> assert false
102          ) context ([<>],[],[])
103        )
104       in
105        let acic = acic_of_cic_context context final_idrefs goal None in
106          [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
107             X.xml_cdata ("<!DOCTYPE Sequent SYSTEM \"" ^ dtdname ^ "\">\n");
108             X.xml_nempty "Sequent"
109              [None,"no",string_of_int metano;None,"id",sequent_id]
110              [< final_s ;
111                 Xml.xml_nempty "Goal" []
112                  (Cic2Xml.print_term ~ids_to_inner_sorts acic)
113              >]
114          >],
115          ids_to_terms,ids_to_father_ids,ids_to_hypotheses
116   ;;
117  end
118 ;;