test case to debug : in predicates, only recurse on left child for the first step,
[SXSI/xpathcomp.git] / xPath.ml
index 727c25e..661863d 100644 (file)
--- a/xPath.ml
+++ b/xPath.ml
@@ -211,11 +211,20 @@ module Functions = struct
 
   let rec eval_expr tree (e:expr) : value = match e with 
     | `Call (f,args) -> (List.assoc f globals) (List.map (eval_expr tree) args)
-    | `Auto(a) -> `NodeSet(ignore (Automaton.BottomUp.accept a tree);a.Automaton.result)
+    | `Auto(a) -> `NodeSet(ignore (Automaton.dump Format.err_formatter a;
+                                 Tree.Binary.print_xml_fast stderr tree;
+                                 Printf.eprintf "\n=======================\n%!";
+                                 Automaton.TopDown.run a tree);
+                         Printf.eprintf "Results : %i\n%!" 
+                           (Automaton.BST.cardinal a.Automaton.result);
+                         Automaton.BST.iter (fun t -> Tree.Binary.print_xml_fast stderr t;
+                                               Printf.eprintf "^^^^^^^^^^^^^^^^^^^^^^^^\n%!") 
+                         a.Automaton.result;
+                         a.Automaton.result)
     | #value as x  -> x
        
   let truth_value = 
-    function `NodeSet s -> Automaton.BST.is_empty s
+    function `NodeSet s -> not (Automaton.BST.is_empty s)
       |`Bool(b) -> b
       | _ -> failwith "truth_value"
     
@@ -321,6 +330,7 @@ module Compile = struct
              (* q' is not returned and thus not added to the set of final states.
                 It's ok since we should never be in a final state on a node
                 <@> *)
+
        | Attribute,ts -> let q'' = State.mk() in
            (mk_tag_t Left q (TagSet.Xml.attribute) q' ignore)::
              (mk_tag_t Left q' (ts) q'' ignore)::( q==> any @@ (ignore,q))::trs, q''::q'::final,initial
@@ -346,7 +356,8 @@ module Compile = struct
       | Expr e -> match compile_expr e with
          | `True -> `Label (TagSet.Xml.any)
          | `False -> `Label (TagSet.Xml.empty)
-         | e -> `Fun (fun t -> Functions.truth_value (Functions.eval_expr t e))
+         | e -> `Fun (fun t -> let r = Functions.truth_value (Functions.eval_expr t e) 
+                     in Printf.eprintf "Truth value is %b\n%!" r;r)
 
     in match pred_rec p with
        `Fun f -> mk_pred_trs f tkeep tchange