Refactor xpath parser and ast in a submodule.
[tatoo.git] / src / formula.ml
index 14fd76f..7bd8ca6 100644 (file)
@@ -5,23 +5,30 @@
 (*                     Kim Nguyen, LRI UMR8623                         *)
 (*                   Université Paris-Sud & CNRS                       *)
 (*                                                                     *)
-(*  Copyright 2010-2012 Université Paris-Sud and Centre National de la *)
+(*  Copyright 2010-2013 Université Paris-Sud and Centre National de la *)
 (*  Recherche Scientifique. All rights reserved.  This file is         *)
 (*  distributed under the terms of the GNU Lesser General Public       *)
 (*  License, with the special exception on linking described in file   *)
 (*  ../LICENSE.                                                        *)
 (*                                                                     *)
 (***********************************************************************)
+
+(*
+  Time-stamp: <Last modified on 2013-02-04 16:03:28 CET by Kim Nguyễn>
+*)
+
 INCLUDE "utils.ml"
 
 open Format
+
+
 type move = [ `Left | `Right | `Epsilon | `Up1 | `Up2 ]
 type 'formula expr =
   | False
   | True
   | Or of 'formula * 'formula
   | And of 'formula * 'formula
-  | Move of move * bool * State.t
+  | Atom of move * bool * State.t
 
 type 'hcons node = {
   pos : 'hcons expr;
@@ -36,12 +43,12 @@ module rec Node : Hcons.S
   and Data : Hashtbl.HashedType  with type t = Node.t node =
   struct
     type t =  Node.t node
-    let equal x y = (*x.size == y.size &&*)
+    let equal x y =
       match x.pos, y.pos with
       | a,b when a == b -> true
       | Or(xf1, xf2), Or(yf1, yf2)
       | And(xf1, xf2), And(yf1,yf2)  -> (xf1 == yf1) && (xf2 == yf2)
-      | Move(d1, p1, s1), Move(d2 ,p2 ,s2) -> d1 == d2 && p1 == p2 && s1 == s2
+      | Atom(d1, p1, s1), Atom(d2 ,p2 ,s2) -> d1 == d2 && p1 == p2 && s1 == s2
       | _ -> false
 
     let hash f =
@@ -53,7 +60,7 @@ module rec Node : Hcons.S
       | And (f1, f2) ->
         HASHINT3(PRIME3, Uid.to_int f1.Node.id, Uid.to_int f2.Node.id)
 
-      | Move(d, p, s) -> HASHINT4(PRIME5, hash_const_variant d,vb p,s)
+      | Atom(d, p, s) -> HASHINT4(PRIME5, hash_const_variant d,vb p,s)
   end
 
 type t = Node.t
@@ -66,7 +73,7 @@ let compare f1 f2 = compare f1.Node.id  f2.Node.id
 let prio f =
   match expr f with
     | True | False -> 10
-    | Move _ -> 8
+    | Atom _ -> 8
     | And _ -> 6
     | Or _ -> 1
 
@@ -83,7 +90,7 @@ let rec print ?(parent=false) ppf f =
       (print ppf f1);
       fprintf ppf " %s " Pretty.vee;
       (print ppf f2);
-    | Move(dir, b, s) ->
+    | Atom(dir, b, s) ->
       let _ = flush_str_formatter() in
       let fmt = str_formatter in
         let a_str, d_str =
@@ -118,7 +125,7 @@ let cons pos neg =
 
 let true_,false_ = cons True False
 let atom_ d p s =
-  fst (cons (Move(d,p,s)) (Move(d,not p,s)))
+  fst (cons (Atom(d,p,s)) (Atom(d,not p,s)))
 
 let not_ f = f.Node.node.neg