1 (***********************************************************************)
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 *)
14 (***********************************************************************)
19 exception Not_core_XPath
20 (** Raised whenever the XPath query contains not implemented structures *)
22 let pr_er = Format.err_formatter
25 let asta = Asta.empty in
26 (* Buidling of the ASTA step by step with a special case for the last
27 step. Then add a top most state. Each function modifies asta. *)
28 let rec trans = function
30 | s :: tl -> trans tl; trans_step s
33 and trans_init () = (* add THE top most state *)
34 let top_st = Asta.new_state () in
36 List.fold_left (fun acc x -> ((`Left *+ x) +| acc))
37 (Formula.false_) (Asta.top_states asta)
39 Asta.add_quer asta top_st;
41 Asta.add_top asta top_st;
42 Asta.add_tr asta (top_st, Asta.any_label, or_top)
44 and trans_last (ax,test,pred) = (* a selecting state is needed *)
45 let fo_p = trans_pr pred in
46 let q,q' = Asta.new_state(), Asta.new_state() in
47 Asta.add_selec asta q';
49 Asta.add_quer asta q';
54 let Simple lab = test in
55 let tr_selec = (q', lab, fo_p)
56 and tr_q = (q, Asta.any_label, form_propa_selec q q' ax) in
57 Asta.add_tr asta tr_selec;
60 and trans_step (ax,test,pred) =
61 let fo_p = trans_pr pred
62 and q = Asta.new_state() in
63 let Simple label = test
64 and form_next = (fo_p) *& (* (\/ top_next) /\ predicat *)
65 (List.fold_left (fun acc x -> (`Left *+ x ) +| acc)
66 Formula.false_ (Asta.top_states asta)) in
67 let tr_next = (q, label, form_next)
68 and tr_propa = (q, Asta.any_label, form_propa q ax) in
72 Asta.add_tr asta tr_next;
73 Asta.add_tr asta tr_propa;
77 and trans_pr = function (* either we apply De Morgan rules
78 in xPath:parse or here *)
79 | Expr True -> Formula.true_
80 | Expr False -> Formula.false_
81 | Or (p_1,p_2) -> trans_pr(p_1) +| trans_pr(p_2)
82 | And (p_1,p_2) -> trans_pr(p_1) *& trans_pr(p_2)
83 | Not (Expr Path q) -> Formula.true_ (* todo *)
84 | Expr Path q -> Formula.true_ (* todo *)
85 | x -> print_predicate pr_er x; raise Not_core_XPath
87 and form_propa q = function
88 | Child -> `Right *+ q
89 | Descendant -> (`Left *+ q +| `Right *+ q)
90 | x -> print_axis pr_er x; raise Not_core_XPath
92 and form_propa_selec q q' = function
93 | Child -> `Right *+ q +| `Right *+ q'
94 | Descendant -> (`Left *+ q +| `Right *+ q) +| (`Left *+ q' +| `Right *+ q')
95 | x -> print_axis pr_er x; raise Not_core_XPath
99 | Absolute steps -> trans steps; trans_init(); asta
100 | AbsoluteDoS steps as x -> print pr_er x; raise Not_core_XPath
101 | Relative steps as x -> print pr_er x; raise Not_core_XPath