]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/binaries/tptp2grafite/main.ml
more work to produce well formed .ma files
[helm.git] / helm / software / components / binaries / tptp2grafite / main.ml
index cbdddf851c9d2a9233e68f5c9465429ffd01c0a9..4ae496b1da3270ac7c8ff92330d8d586356094e5 100644 (file)
@@ -4,6 +4,15 @@ module PT = CicNotationPt;;
 module A = Ast;;
 let floc = HExtlib.dummy_floc;;
 
+let kw = [
+ "and","myand"
+];;
+
+let mk_ident s =
+  PT.Ident ((try List.assoc s kw with Not_found -> s),None)
+;;
+
+
 let rec collect_arities_from_term = function
   | A.Constant name -> [name,0]
   | A.Variable name -> []
@@ -43,10 +52,10 @@ let collect_fv_from_atom a =
 ;;  
 
 let rec convert_term = function
-  | A.Variable x -> PT.Ident (x,None)
-  | A.Constant x -> PT.Ident (x,None)
+  | A.Variable x -> mk_ident x
+  | A.Constant x -> mk_ident x
   | A.Function (name, args) -> 
-      PT.Appl (PT.Ident (name,None) :: List.map convert_term args)
+      PT.Appl (mk_ident name :: List.map convert_term args)
 ;;
 
 let atom_of_formula = function
@@ -56,11 +65,11 @@ let atom_of_formula = function
 ;;
   
 let rec mk_arrow component = function
-  | 0 -> PT.Ident (component,None)
+  | 0 -> mk_ident component
   | n -> 
       PT.Binder 
         (`Forall,
-          ((PT.Ident ("_",None)),Some (PT.Ident (component,None))),
+          ((mk_ident "_"),Some (mk_ident component)),
           mk_arrow component (n-1))
 ;;
 
@@ -70,7 +79,7 @@ let build_ctx_for_arities arities t =
     | (name,nargs)::tl ->
         PT.Binder 
           (`Forall,
-            (PT.Ident (name,None),Some (mk_arrow "A" nargs)),
+            (mk_ident name,Some (mk_arrow "A" nargs)),
             aux tl)
   in
   aux arities
@@ -79,13 +88,14 @@ let build_ctx_for_arities arities t =
 let convert_atom a = 
   let aux = function
   | A.Proposition _ -> assert false
-  | A.Predicate (name,params) -> assert false
-  | A.True -> PT.Ident ("True",None)
-  | A.False -> PT.Ident ("False",None)
+  | A.Predicate (name,params) -> 
+      prerr_endline ("Predicate is unsupported: " ^ name);
+      assert false
+  | A.True -> mk_ident "True"
+  | A.False -> mk_ident "False"
   | A.Eq (l,r) 
   | A.NotEq (l,r) -> (* removes the negation *)
-      PT.Appl [
-        PT.Ident ("eq",None); PT.Ident ("A",None); convert_term l; convert_term r]
+      PT.Appl [mk_ident "eq";mk_ident "A";convert_term l;convert_term r]
   in
   build_ctx_for_arities (List.map (fun x -> (x,0)) (collect_fv_from_atom a)) (aux a)
 ;;
@@ -104,7 +114,7 @@ let rec convert_formula no_arities context f =
     | hp::tl -> 
         PT.Binder 
           (`Forall,
-            (PT.Ident ("H" ^ string_of_int n,None), 
+            (mk_ident ("H" ^ string_of_int n), 
                        Some (convert_formula true [] hp)), 
             build_ctx (n+1) tl)
   in
@@ -137,7 +147,7 @@ let convert_ast statements context = function
           let f = 
             PT.Binder 
              (`Forall,
-               (PT.Ident ("A",None),Some (PT.Sort `Set)), 
+               (mk_ident "A",Some (PT.Sort `Set)), 
                convert_formula false context f)
           in
           let o = PT.Theorem (`Theorem,name,f,None) in
@@ -215,7 +225,10 @@ let _ =
   in
   let pp t = 
     (* for a correct pp we should disambiguate the term... *)
-    let term_pp = CicNotationPp.pp_term in 
+    let term_pp x = 
+      BoxPp.render_to_string 80 (CicNotationPres.render (Hashtbl.create 1)
+        (TermContentPres.pp_ast x))
+    in
     let lazy_term_pp = fun x -> assert false in
     let obj_pp = CicNotationPp.pp_obj in
     print_endline