]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/cic_disambiguation/make_table.ml
use PxpHelmConf
[helm.git] / helm / ocaml / cic_disambiguation / make_table.ml
index 50780759d50a6be2a27b8543907b02a620b98ad5..9aaa4a06c8bd28fa10c89de8104a2885d4ab0583 100644 (file)
@@ -27,12 +27,11 @@ open Printf
 open Pxp_types
 open Pxp_ev_parser
 
-(* Usage: make_table <hashtbls_dump_file> *)
-
 let debug = false
 let debug_print s = if debug then prerr_endline s
 
-let tables = [
+  (* source files for tables xml parsing (if unmarshall=false) *)
+let xml_tables = [
 (*
   `Entities, "/usr/share/gtkmathview/entities-table.xml";
   `Dictionary, "/usr/share/editex/dictionary-tex.xml"
@@ -42,13 +41,6 @@ let tables = [
   `Entities, "macros/extra-entities.xml";
 ]
 
-let macro2utf8 = Hashtbl.create 2000
-let utf82macro = Hashtbl.create 2000
-
-let add_macro macro utf8 =
-  debug_print (sprintf "Adding macro %s = '%s'" macro utf8);
-  Hashtbl.add macro2utf8 macro utf8;
-  Hashtbl.add utf82macro utf8 macro
 
 let rec find_first_tag pull_parser =
   match pull_parser () with
@@ -88,24 +80,40 @@ let iter_dictionary_file f pull_parser =
   in
   aux ()
 
-let fill_table () =
-  List.iter
-    (fun (typ, fname) ->
-      let entry = `Entry_document [ `Extend_dtd_fully; `Parse_xml_decl ] in
-      let config = { default_config with encoding = `Enc_utf8 } in
-      let entity_manager =
-       create_entity_manager ~is_document:true config (from_file fname)
-      in
-      let pull_parser = create_pull_parser config entry entity_manager in
-      match typ with
-      | `Entities -> iter_entities_file add_macro pull_parser
-      | `Dictionary -> iter_dictionary_file add_macro pull_parser)
-    tables
+let parse_from_xml () =
+  let (macro2utf8, utf82macro) = (Hashtbl.create 2000, Hashtbl.create 2000) in
+  let add_macro macro utf8 =
+    debug_print (sprintf "Adding macro %s = '%s'" macro utf8);
+    Hashtbl.add macro2utf8 macro utf8;
+(*     Hashtbl.add utf82macro utf8 macro *)
+  in
+  let fill_table () =
+    List.iter
+      (fun (typ, fname) ->
+        let entry = `Entry_document [ `Extend_dtd_fully; `Parse_xml_decl ] in
+        let config = PxpHelmConf.pxp_config in
+        let entity_manager =
+          create_entity_manager ~is_document:true config (from_file fname)
+        in
+        let pull_parser = create_pull_parser config entry entity_manager in
+        match typ with
+        | `Entities -> iter_entities_file add_macro pull_parser
+        | `Dictionary -> iter_dictionary_file add_macro pull_parser)
+      xml_tables
+  in
+  fill_table ();
+  macro2utf8
 
 let main () =
   let oc = open_out Sys.argv.(1) in
-  fill_table ();
-  Marshal.to_channel oc (macro2utf8, utf82macro) [];
+  output_string oc "(* GENERATED by make_table: DO NOT EDIT! *)\n";
+  output_string oc "let macro2utf8 = Hashtbl.create 2000\n";
+  let macro2utf8 = parse_from_xml () in
+  Hashtbl.iter
+    (fun macro utf8 ->
+      fprintf oc "let _ = Hashtbl.add macro2utf8 \"%s\" \"%s\"\n"
+        macro (String.escaped utf8))
+    macro2utf8;
   close_out oc
 
 let _ = main ()