Implem of Asta.print
[tatoo.git] / src / asta.ml
1 (***********************************************************************)
2 (*                                                                     *)
3 (*                               TAToo                                 *)
4 (*                                                                     *)
5 (*                  Lucca Hirschi, ?   *)
6 (*                  ?   *)
7 (*                                                                     *)
8 (*  Copyright 2010-2012 Université Paris-Sud and Centre National de la *)
9 (*  Recherche Scientifique. All rights reserved.  This file is         *)
10 (*  distributed under the terms of the GNU Lesser General Public       *)
11 (*  License, with the special exception on linking described in file   *)
12 (*  ../LICENSE.                                                        *)
13 (*                                                                     *)
14 (***********************************************************************)
15
16 open Format
17
18 type state = State.t
19
20 type label = QNameSet.t
21   
22 type formula = Formula.t
23
24 module Transition = 
25 struct
26   type t = state * label * formula
27
28   let compare (st,la,f) (st',la',f') =
29     let x_1 = State.compare st st' in
30     if x_1 != 0 then x_1
31     else let x_2 = QNameSet.compare la la' in
32          if x_2 != 0 then x_2
33          else Formula.compare f f'
34   let st (st,la,f) = st
35   let la (st,la,f) = la
36   let fo (st,la,f) = f
37   let print fmt (st,la,f) =
38     Format.fprintf fmt "(%a,%s,%a)"
39       State.print st
40       "TODO la"
41       Formula.print f
42 end
43
44 module  SetT = 
45 struct
46   include Set.Make(Transition)
47 end
48
49 type t = {
50   mutable reco : StateSet.t;
51   mutable selec : StateSet.t;
52   mutable bottom : StateSet.t;
53   mutable top : StateSet.t;
54   mutable trans : SetT.t;
55 }
56
57 exception Not_found_transition
58 exception Transition_not_injective
59
60 let transition asta st lab =
61   let filter (s,l,f) =
62     (State.compare s st = 0) && (QNameSet.compare l lab = 0) in
63   let tr_set = SetT.elements (SetT.filter filter asta.trans) in
64   match tr_set with
65     | [] -> raise Not_found_transition
66     | x::y::z -> raise Transition_not_injective
67     | [l] -> Transition.fo l
68
69 let transitions asta st =
70   let filter (s,l,f) = State.compare s st = 0 in
71   let rec remove_states l = match l with
72     | [] -> []
73     | (a,s,l) :: tl -> (s,l) :: (remove_states tl) in
74   remove_states (SetT.elements (SetT.filter filter asta.trans))
75
76
77 let print fmt asta =
78   let pp = Format.fprintf fmt in
79   pp "Recognizing states: ";
80   StateSet.print fmt asta.reco;
81   pp "\nSelecting states: ";
82   StateSet.print fmt asta.selec;
83   pp "\nBottom states: ";
84   StateSet.print fmt asta.bottom;
85   pp "\nTop states: ";
86   StateSet.print fmt asta.top;
87   pp "\nTransitions: \n";
88   Format.fprintf fmt "{@[<hov n> %a @]}" (* todo: check boxes *)
89     (Pretty.print_list ~sep:"@, " (Transition.print))
90     (SetT.elements (asta.trans))
91
92
93 let to_file out asta = ()