.
[SXSI/xpathcomp.git] / tree.ml
diff --git a/tree.ml b/tree.ml
index 53872b3..219ee4b 100644 (file)
--- a/tree.ml
+++ b/tree.ml
@@ -240,10 +240,17 @@ struct
     (* Todo *)
     external nullt : unit -> [`Text ] node = "caml_xml_tree_nullt"
     let nil = nullt ()
-    external get_text : t -> [`Text] node -> string = "caml_text_collection_get_text"
-    let is_empty _ (n : [`Text] node) = equal nil n
+    external get_text1 : t -> [`Text] node -> string = "caml_text_collection_get_text"
+
+    let get_text t n = Printf.printf "@@@@@@%i\n%!" (Obj.magic n);
+      if equal nil n then "" 
+      else  get_text1 t n
+
+    let is_empty t (n : [`Text] node) = (get_text t n) = ""
+
+  end
+
 
-    end
   module Tree = 
   struct
 
@@ -271,17 +278,42 @@ struct
     let is_last t n = equal nil (next_sibling t n)
     
     external prev_text : t -> [`Tree] node -> [`Text ] node = "caml_xml_tree_prev_text"
+    let prev_text t id = Printf.eprintf "Calling PrevText for node %i with result" (Obj.magic id);
+      let did = if is_nil id then Text.nil else prev_text t id
+      in Printf.eprintf " %i!!!\n%!" (Obj.magic did); did
+         
+
+
     external my_text : t -> [`Tree] node -> [`Text ] node = "caml_xml_tree_my_text"
     external next_text : t -> [`Tree] node -> [`Text ] node = "caml_xml_tree_next_text"
-      
+
+    let next_text t id = Printf.eprintf "Calling NextText for node %i with result" (Obj.magic id);
+      let did = if is_nil id then Text.nil else next_text t id
+      in Printf.eprintf " %i!!!\n%!" (Obj.magic did); did
+
     external text_xml_id : t -> [`Text ] node -> int = "caml_xml_tree_text_xml_id"
     external node_xml_id : t -> [`Tree ] node -> int = "caml_xml_tree_node_xml_id"
-            
+      
+
+    let print_skel t =
+      let rec aux id = 
+       if (is_nil id)
+       then Printf.eprintf "#"
+       else 
+         begin
+           Printf.eprintf "%s(" (Tag.to_string (tag t id));
+           aux(first_child t id);
+           Printf.eprintf ",\n";
+           aux(next_sibling t id);
+           Printf.eprintf ")\n";
+         end
+      in
+       aux (root t)
   end
       
       
-  module Binary : BINARY = struct
-    
+  module Binary  = struct
+
     type node_content = 
        [ `Node of [`Tree ] node 
        | `String of [`Text ] node * [`Tree ] node ]
@@ -296,7 +328,7 @@ struct
     type t = { doc : doc;
               node : descr }
        
-
+    let dump { doc=t } = Tree.print_skel t       
     open Tree                 
     let node_of_t t = { doc= t; node= Node(`Node (root t)) }
 
@@ -319,7 +351,7 @@ struct
     let equal a b = (compare a b) == 0
 
     let string t = match t.node with
-      | String i -> Text.get_text (text_collection t.doc) i
+      | String i ->  Text.get_text (text_collection t.doc) i
       | _ -> assert false
          
     let norm (n : [`Tree ] node ) =  if is_nil n then Nil else Node (`Node n)
@@ -327,6 +359,7 @@ struct
     let descr t = t.node
 
     let first_child n = 
+      Printf.eprintf "first_child!\n%!";
       let node' = 
        match n.node with
          | Nil | String _ -> failwith "first_child"
@@ -342,6 +375,7 @@ struct
        { n with node = node'}
          
     let next_sibling n = 
+      Printf.eprintf "next_sibling!\n%!";
       let node' =
        match n.node with
          | Nil | String _  -> failwith "next_sibling"
@@ -385,6 +419,7 @@ struct
              output_string outc  tg;
              ( match l.node with
                    Nil -> output_string outc  "/>"
+                 | String _ -> assert false
                  | Node(_) when Tag.equal (tag l) Tag.attribute -> 
                      (loop_attributes (left l);
                       match (right l).node with
@@ -397,8 +432,8 @@ struct
                             output_char outc '>' )
                  | _ ->
                      output_char outc  '>'; 
-                     loop (left l);            
-                     output_string outc  "</";
+                     loop l;
+                     output_string outc "</";
                      output_string outc tg;
                      output_char outc '>'
              );if print_right then loop r
@@ -413,8 +448,13 @@ struct
        | _ -> ()
       in
        loop ~print_right:false t
-         
+
+
+
   end
-    
+
 end
+
+
+let dump = XML.Binary.dump
 include XML