- let _ = _flush_str_fmt () in
-
- let m, b, s = a.node in
- let dir,num =
- match m with
- | `Left -> Pretty.down_arrow, Pretty.subscript 1
- | `Right -> Pretty.down_arrow, Pretty.subscript 2
- | `Epsilon -> Pretty.epsilon, ""
- | `Up1 -> Pretty.up_arrow, Pretty.subscript 1
- | `Up2 -> Pretty.up_arrow, Pretty.subscript 2
- in
- fprintf _str_fmt "%s%s" dir num;
- State.print _str_fmt s;
- let str = _flush_str_fmt () in
- if b then fprintf ppf "%s" str
- else Pretty.pp_overline ppf str
-
- let neg p =
- let l, b, s = p.node in
- make (l, not b, s)
- exception NegativeAtom of (move*State.t)
- let eval ctx p =
- let l, b, s = p.node in
- if b then raise (NegativeAtom(l,s));
- StateSet.mem s begin
- match l with
- `Left -> ctx.left
- | `Right -> ctx.right
- | `Up1 -> ctx.up1
- | `Up2 -> ctx.up2
- | `Epsilon -> ctx.epsilon
- end
+ let p, b, q = a.node in
+ if not b then fprintf ppf "%s" Pretty.lnot;
+ match p with
+ | First_child -> fprintf ppf "FC(%a)" State.print q
+ | Next_sibling -> fprintf ppf "NS(%a)" State.print q
+ | Parent -> fprintf ppf "FC%s(%a)" Pretty.inverse State.print q
+ | Previous_sibling -> fprintf ppf "NS%s(%a)" Pretty.inverse State.print q
+ | Stay -> fprintf ppf "%s(%a)" Pretty.epsilon State.print q
+ | Is_first_child -> fprintf ppf "FC%s?" Pretty.inverse
+ | Is_next_sibling -> fprintf ppf "NS%s?" Pretty.inverse
+ | Is k -> fprintf ppf "is-%a?" Tree.Common.NodeKind.print k
+ | Has_first_child -> fprintf ppf "FC?"
+ | Has_next_sibling -> fprintf ppf "NS?"
+
+ let neg a =
+ let p, b, q = a.node in
+ make (p, not b, q)
+
+
+end
+
+module SFormula =
+struct
+ include Formula.Make(Atom)
+ open Tree.Common.NodeKind
+ let mk_atom a b c = atom_ (Atom.make (a,b,c))
+ let mk_kind k = mk_atom (Is k) true State.dummy
+ let has_first_child =
+ (mk_atom Has_first_child true State.dummy)
+
+ let has_next_sibling =
+ (mk_atom Has_next_sibling true State.dummy)
+
+ let is_first_child =
+ (mk_atom Is_first_child true State.dummy)
+
+ let is_next_sibling =
+ (mk_atom Is_next_sibling true State.dummy)
+
+ let is_attribute =
+ (mk_atom (Is Attribute) true State.dummy)
+
+ let is_element =
+ (mk_atom (Is Element) true State.dummy)
+
+ let is_processing_instruction =
+ (mk_atom (Is ProcessingInstruction) true State.dummy)
+
+ let is_comment =
+ (mk_atom (Is Comment) true State.dummy)
+
+ let first_child q =
+ and_
+ (mk_atom First_child true q)
+ has_first_child
+
+ let next_sibling q =
+ and_
+ (mk_atom Next_sibling true q)
+ has_next_sibling
+
+ let parent q =
+ and_
+ (mk_atom Parent true q)
+ is_first_child
+
+ let previous_sibling q =
+ and_
+ (mk_atom Previous_sibling true q)
+ is_next_sibling
+
+ let stay q =
+ (mk_atom Stay true q)
+
+ let get_states phi =
+ fold (fun phi acc ->
+ match expr phi with
+ | Formula.Atom a -> let _, _, q = Atom.node a in
+ if q != State.dummy then StateSet.add q acc else acc
+ | _ -> acc
+ ) phi StateSet.empty
+