From 8aa30d200433c2518b42f4b25d4b429e4cf44372 Mon Sep 17 00:00:00 2001 From: Stefano Zacchiroli Date: Tue, 14 Jun 2005 13:47:23 +0000 Subject: [PATCH] uses XmlPushParser instead of PXP --- helm/ocaml/utf8_macros/Makefile | 3 +- helm/ocaml/utf8_macros/make_table.ml | 64 ++++++++-------------------- 2 files changed, 20 insertions(+), 47 deletions(-) diff --git a/helm/ocaml/utf8_macros/Makefile b/helm/ocaml/utf8_macros/Makefile index fcc712cb8..31a1939ce 100644 --- a/helm/ocaml/utf8_macros/Makefile +++ b/helm/ocaml/utf8_macros/Makefile @@ -1,6 +1,7 @@ PACKAGE = utf8_macros REQUIRES = PREDICATES = +MAKE_TABLE_PACKAGES = helm-xml # modules which have both a .ml and a .mli INTERFACE_FILES = utf8Macro.mli @@ -11,7 +12,7 @@ EXTRA_OBJECTS_TO_CLEAN = all: utf8_macros.cma pa_unicode_macro.cma make_table: make_table.ml - $(OCAMLFIND) ocamlc -package helm-pxp -linkpkg -o $@ $^ + $(OCAMLFIND) ocamlc -package $(MAKE_TABLE_PACKAGES) -linkpkg -o $@ $^ utf8MacroTable.ml: ./make_table $@ diff --git a/helm/ocaml/utf8_macros/make_table.ml b/helm/ocaml/utf8_macros/make_table.ml index 2e3740943..89b928605 100644 --- a/helm/ocaml/utf8_macros/make_table.ml +++ b/helm/ocaml/utf8_macros/make_table.ml @@ -24,8 +24,6 @@ *) open Printf -open Pxp_types -open Pxp_ev_parser let debug = false let debug_print s = if debug then prerr_endline s @@ -41,44 +39,24 @@ let xml_tables = [ `Entities, "data/extra-entities.xml"; ] - -let rec find_first_tag pull_parser = - match pull_parser () with - | Some (E_start_tag _ as e) -> e - | None -> assert false - | _ -> find_first_tag pull_parser - -let iter_entities_file f pull_parser = - ignore (find_first_tag pull_parser); (* *) - let rec aux () = - match pull_parser () with - | Some (E_start_tag ("entity", attrs, _, _)) -> - (try - let name = List.assoc "name" attrs in - let value = List.assoc "value" attrs in - f name value - with Not_found -> ()); - aux () - | None -> () - | _ -> aux () +let iter_gen record_tag name_field value_field f fname = + let start_element tag attrs = + if tag = record_tag then + try + let name = List.assoc name_field attrs in + let value = List.assoc value_field attrs in + f name value + with Not_found -> () in - aux () + let callbacks = { + XmlPushParser.default_callbacks with + XmlPushParser.start_element = Some start_element + } in + let xml_parser = XmlPushParser.create_parser callbacks in + XmlPushParser.parse xml_parser (`File fname) -let iter_dictionary_file f pull_parser = - ignore (find_first_tag pull_parser); (* *) - let rec aux () = - match pull_parser () with - | Some (E_start_tag ("entry", attrs, _, _)) -> - (try - let name = List.assoc "name" attrs in - let value = List.assoc "val" attrs in - f name value - with Not_found -> ()); - aux () - | None -> () - | _ -> aux () - in - aux () +let iter_entities_file = iter_gen "entity" "name" "value" +let iter_dictionary_file = iter_gen "entry" "name" "val" let parse_from_xml () = let (macro2utf8, utf82macro) = (Hashtbl.create 2000, Hashtbl.create 2000) in @@ -90,15 +68,9 @@ let parse_from_xml () = 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) + | `Entities -> iter_entities_file add_macro fname + | `Dictionary -> iter_dictionary_file add_macro fname) xml_tables in fill_table (); -- 2.39.2