Structure run + Print run
[tatoo.git] / src / asta.ml
index 9682bd1..06396be 100644 (file)
@@ -13,6 +13,8 @@
 (*                                                                     *)
 (***********************************************************************)
 
+(* utils.ml-> INCLUDE "utils.ml" HASHINT2 () *)
+
 type state = State.t
 
 type label = QNameSet.t
@@ -52,16 +54,19 @@ type t = {
   mutable selec : StateSet.t;
   mutable bottom : StateSet.t;
   mutable top : StateSet.t;
-  mutable trans : SetT.t;
+  mutable trans_q : SetT.t;
+  mutable trans_r : SetT.t;
 }
 
 exception Not_found_transition
 exception Transition_not_injective
-
+  
 let transition asta st lab =
   let filter (s,l,f) =
     (State.compare s st = 0) && (QNameSet.compare l lab = 0) in
-  let tr_set = SetT.elements (SetT.filter filter asta.trans) in
+  let tr_set = (SetT.elements (SetT.filter filter asta.trans_q)) @
+    (SetT.elements (SetT.filter filter asta.trans_r))
+  in
   match tr_set with
     | [] -> raise Not_found_transition
     | x::y::z -> raise Transition_not_injective
@@ -72,7 +77,8 @@ let transitions asta st =
   let rec remove_states l = match l with
     | [] -> []
     | (a,s,l) :: tl -> (s,l) :: (remove_states tl) in
-  remove_states (SetT.elements (SetT.filter filter asta.trans))
+  (remove_states (SetT.elements (SetT.filter filter asta.trans_q)),
+   (remove_states (SetT.elements (SetT.filter filter asta.trans_r))))
 
 let empty = {
   quer = StateSet.empty;
@@ -80,14 +86,18 @@ let empty = {
   selec = StateSet.empty;
   bottom = StateSet.empty;
   top = StateSet.empty;
-  trans = SetT.empty;
+  trans_q = SetT.empty;
+  trans_r = SetT.empty
 }
 
 let any_label = QNameSet.complement (QNameSet.empty)
 
 let new_state () = State.make()
 
-let add_tr ast tr = ast.trans <- (SetT.add tr (ast.trans))
+let add_tr ast tr flag =
+  if flag
+  then ast.trans_q <- (SetT.add tr (ast.trans_q))
+  else ast.trans_r <- (SetT.add tr (ast.trans_r))
 
 let add_quer ast st = ast.quer <- (StateSet.add st (ast.quer))
 
@@ -104,24 +114,29 @@ let init_top ast  = ast.top <- (StateSet.empty)
 let top_states ast = StateSet.elements ast.top
 
 let print fmt asta =
-  let pp = Format.fprintf fmt in
-  pp "Query states: ";
-  StateSet.print fmt asta.quer;
-  pp "\nRecognizing states: ";
-  StateSet.print fmt asta.reco;
-  pp "\nSelecting states: ";
-  StateSet.print fmt asta.selec;
-  pp "\nBottom states: ";
-  StateSet.print fmt asta.bottom;
-  pp "\nTop states: ";
-  StateSet.print fmt asta.top;
-  pp "\nTransitions: \n";
-  Format.fprintf fmt "{";
-  Format.open_vbox 20;
-  SetT.iter (fun x -> Format.fprintf fmt "%a @." Transition.print x)
-    (asta.trans);
-  Format.print_flush ();
-  Format.fprintf fmt "}"
-    
+  let print_box fmt flag = 
+    let pp = Format.fprintf fmt in
+    pp "@[<v 0># Query states: %a@ @]"
+      StateSet.print asta.quer;
+    pp "@[<v 0># Recognizing states: %a@ @]"
+      StateSet.print asta.reco;
+    pp "@[<v 0># Selecting states: %a@ @]"
+      StateSet.print asta.selec;
+    pp "@[<v 0># Bottom states: %a@ @]"
+      StateSet.print asta.bottom;
+    pp "@[<v 0># Top states: %a@ @]"
+      StateSet.print asta.top;
+    let print_list_tr fmt z =
+      if SetT.is_empty z 
+      then Format.fprintf fmt "ΓΈ"
+      else
+       SetT.iter (fun x -> Format.fprintf fmt "|  %a  @ "  Transition.print x) z in
+    let print_box_list fmt trans =
+      Format.fprintf fmt "  @[<hov 0>%a @]" print_list_tr trans in
+    Format.fprintf fmt "@[<v 0># Queries transitions:@ %a@ @]"
+      print_box_list asta.trans_q;
+    Format.fprintf fmt "@[<v 0># Recognizing transitions:@ %a@]"
+      print_box_list asta.trans_r in
+  Format.fprintf fmt "@[<v 1>##### ASTA #####@, %a@ @]@." print_box 0
 
 let to_file out asta = ()