From 59f76964d65d638f6729d8dda41afac82f7a2901 Mon Sep 17 00:00:00 2001 From: Stefano Zacchiroli Date: Wed, 11 May 2005 16:34:48 +0000 Subject: [PATCH] added Parse_error exception and pretty printing of Expat errors --- helm/ocaml/xml/xmlPushParser.ml | 8 ++++++++ helm/ocaml/xml/xmlPushParser.mli | 11 +++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/helm/ocaml/xml/xmlPushParser.ml b/helm/ocaml/xml/xmlPushParser.ml index ae93f4e6a..6cab0ead3 100644 --- a/helm/ocaml/xml/xmlPushParser.ml +++ b/helm/ocaml/xml/xmlPushParser.ml @@ -53,6 +53,8 @@ type position = int * int type xml_parser = Expat.expat_parser +exception Parse_error of string + let create_parser callbacks = let expat_parser = Expat.parser_create ~encoding:None in (match callbacks.start_element with @@ -106,3 +108,9 @@ let parse expat_parser = in aux +let parse expat_parser xml_source = + try + parse expat_parser xml_source + with Expat.Expat_error xml_error -> + raise (Parse_error (Expat.xml_error_to_string xml_error)) + diff --git a/helm/ocaml/xml/xmlPushParser.mli b/helm/ocaml/xml/xmlPushParser.mli index 0bbd2203d..cbad83c72 100644 --- a/helm/ocaml/xml/xmlPushParser.mli +++ b/helm/ocaml/xml/xmlPushParser.mli @@ -55,15 +55,22 @@ type position = int * int type xml_parser + (** raised when a parse error occurs, argument is an error message. + * This exception carries no position information, but it should be get using + * get_position below *) +exception Parse_error of string + (** Create a push parser which invokes the given callbacks *) val create_parser: callbacks -> xml_parser - (** Parse XML data from a given source with a given parser *) + (** Parse XML data from a given source with a given parser + * @raise Parse_error *) val parse: xml_parser -> xml_source -> unit (** Inform the farser that parsing is completed, needed only when source is * `String, for other sources it is automatically invoked when the end of file - * is reached *) + * is reached + * @raise Parse_error *) val final: xml_parser -> unit (** @return current pair *) -- 2.39.2