Implement command line options, clean-up screen output.
[tatoo.git] / src / naive_tree.ml
index b7c0be6..65ef334 100644 (file)
@@ -14,7 +14,7 @@
 (***********************************************************************)
 
 (*
-  Time-stamp: <Last modified on 2013-04-04 18:47:30 CEST by Kim Nguyen>
+  Time-stamp: <Last modified on 2013-04-22 16:42:50 CEST by Kim Nguyen>
 *)
 
 type node = {
@@ -208,20 +208,29 @@ struct
        let node = top ctx in
        node.next_sibling <- nil;
        consume_closing ctx node;
-       match ctx.stack with
-         [ root ] ->
-           root.next_sibling <- nil;
-           { root = root;
-             size = ctx.current_preorder
-           }
-       | _ -> raise (Expat.Expat_error Expat.UNCLOSED_TOKEN)
+       Expat.final psr;
+       let root = List.hd ctx.stack in
+       root.next_sibling <- nil;
+       { root = root;
+         size = ctx.current_preorder
+       }
     )
 
+  let error e parser_ =
+    let msg = Printf.sprintf "%i.%i %s"
+      (Expat.get_current_line_number parser_)
+      (Expat.get_current_column_number parser_)
+      (Expat.xml_error_to_string e)
+    in
+    raise (Tree.Parse_error msg)
 
   let parse_string s =
     let parser_, finalize = create_parser () in
-    Expat.parse parser_ s;
-    finalize ()
+    try
+      Expat.parse parser_ s;
+      finalize ()
+    with
+      Expat.Expat_error e -> error e parser_
 
   let parse_file fd =
     let buffer = String.create 4096 in
@@ -231,7 +240,10 @@ struct
       if read != 0 then
         let () = Expat.parse_sub parser_ buffer 0 read in
         loop ()
-    in loop (); finalize ()
+    in try
+         loop (); finalize ()
+      with
+        Expat.Expat_error e -> error e parser_
 
 end