1 module T = CicNotationPt
5 let floc = HExtlib.dummy_floc;;
8 let tptppath = ref "./";;
11 ("-ng",Arg.Set ng,"Matita ng syntax");
13 Arg.String (fun x -> tptppath := x),
14 "Where to find the Axioms/ and Problems/ directory")
17 let resolve ~tptppath s =
18 if s.[0] = '/' then s else
20 if Filename.check_suffix s ".p" then
21 (assert (String.length s > 5);
22 let prefix = String.sub s 0 3 in
23 tptppath ^ "/Problems/" ^ prefix ^ "/" ^ s)
27 if HExtlib.is_regular resolved_name then
31 prerr_endline ("Unable to find " ^ s ^ " (" ^ resolved_name ^ ")");
38 HExtlib.filter_map_monad
40 | A.ThfDefinition (_,did,dbody) when did = id -> Some dbody, None
41 | A.ThfType (_,did,dtype) when did = id -> Some dtype, None
47 let usage = "Usage: tptpTHF2grafite [options] file" in
48 let inputfile = ref "" in
49 Arg.parse spec (fun s -> inputfile := s) usage;
50 if !inputfile = "" then
55 let tptppath = !tptppath in
57 let rec aux = function
59 | ((A.Inclusion (file,_)) as hd) :: tl ->
60 let file = resolve ~tptppath file in
61 let lexbuf = Lexing.from_channel (open_in file) in
62 let statements = ParserTHF.main LexerTHF.yylex lexbuf in
63 hd :: aux (statements @ tl)
64 | hd::tl -> hd :: aux tl
66 aux [A.Inclusion (!inputfile,[])]
69 let rec aux = function
71 | A.Comment s :: tl ->
72 let s = Pcre.replace ~pat:"\n" ~templ:"" s in
73 let s = Pcre.replace ~pat:"\\*\\)" ~templ:"" s in
74 GA.Comment (floc,GA.Note (floc,s)) :: aux tl
75 | A.Inclusion (s,_) :: tl ->
78 floc,"Inclusion of: " ^ s)) :: aux tl
79 | A.ThfType(name,id,ty) :: tl ->
80 let body, tl = find_related id None tl in
81 let what = match body with None -> `Axiom | _ -> `Definition in
85 T.Theorem(what, id,ty,body,`Regular)))) :: aux tl
86 | A.ThfDefinition(name,id,body) :: tl ->
87 let ty, tl = find_related id None tl in
88 let ty = match ty with Some x -> x | None -> T.Implicit `JustOne in
92 T.Theorem(`Definition,
93 id,ty,Some body,`Regular)))):: aux tl
94 | A.ThfFormula(name,(A.Axiom|A.Hypothesis|A.Assumption),term) :: tl ->
98 T.Theorem(`Axiom, name,term,None,`Regular)))):: aux tl
99 | A.ThfFormula(name,A.Conjecture,term) :: tl ->
103 T.Theorem(`Theorem, name,
104 term,None,`Regular)))):: aux tl
105 | A.ThfFormula _ :: tl -> assert false
110 (* ZACK: setting width to 80 will trigger a bug of BoxPp.render_to_string
111 * which will show up using the following command line:
112 * ./tptp2grafite -tptppath ~tassi/TPTP-v3.1.1 GRP170-1 *)
113 let width = max_int in
114 let term_pp prec content_term =
115 let pres_term = TermContentPres.pp_ast content_term in
116 let lookup_uri = fun _ -> None in
117 let markup = CicNotationPres.render ~lookup_uri ~prec pres_term in
118 let s = BoxPp.render_to_string List.hd width markup ~map_unicode_to_tex:false in
120 ~rex:(Pcre.regexp ~flags:[`UTF8] "∀[Ha-z][a-z0-9_]*") ~subst:(fun x -> "\n" ^ x)
123 CicNotationPp.set_pp_term (term_pp 90);
124 let lazy_term_pp = fun x -> assert false in
125 let obj_pp = CicNotationPp.pp_obj CicNotationPp.pp_term in
126 Pcre.replace ~pat:"^theorem" ~templ:"ntheorem"
127 (Pcre.replace ~pat:"^axiom" ~templ:"naxiom"
128 (Pcre.replace ~pat:"^definition" ~templ:"ndefinition"
129 (Pcre.replace ~pat:"Type \\\\sub ([0-9]+)" ~templ:"Type[$1]"
130 (GrafiteAstPp.pp_statement
131 ~map_unicode_to_tex:false
132 ~term_pp:(term_pp 19) ~lazy_term_pp ~obj_pp t))))
134 print_endline (pp (GA.Executable (floc,
135 GA.Command(floc,GA.Include(floc,true,`OldAndNew,"TPTP.ma")))));
136 List.iter (fun x -> print_endline (pp x)) statements;