X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=src%2Fcompil.ml;h=b15b06960295129d37bf1fcff557e1c895b0ecd7;hb=07a2770a48f51b2e09b3be2d1608516b2377618e;hp=4633057d28ae52da88a8b56a323117bcbe46be63;hpb=64d7d77a886a9fb00d62156b6dd1a43487b30772;p=tatoo.git diff --git a/src/compil.ml b/src/compil.ml index 4633057..b15b069 100644 --- a/src/compil.ml +++ b/src/compil.ml @@ -47,7 +47,7 @@ let trans query = (* A selecting state is needed *) and trans_last (ax,test,pred) = - let fo_p = trans_pr pred in + let fo_p = trans_pr pred in (* TODO (if ax=Self, only q *) let q,q' = Asta.new_state(), Asta.new_state() in Asta.add_selec asta q'; Asta.add_quer asta q; @@ -103,19 +103,24 @@ let trans query = (* Builds asta for predicate and gives the formula which must be satsified *) and trans_pr_path posi = function | Relative [] -> if posi then Formula.true_ else Formula.false_ - | Relative steps -> List.fold_left - (fun acc x -> if posi then (`Left *+ x) +| acc else (`Left *- x) +| acc) - Formula.false_ (trans_pr_step_l steps) + | Relative steps -> + let dir = match ax_ (List.hd steps) with + | Self -> `Self + | FollowingSibling -> `Right + | _ -> `Left in + List.fold_left + (fun acc x -> if posi then (dir *+ x) +| acc else (dir *- x) +| acc) + Formula.false_ (trans_pr_step_l steps) | AbsoluteDoS steps as x -> print pr_er x; raise Not_core_XPath | Absolute steps as x -> print pr_er x; raise Not_core_XPath - + (* Builds asta for a predicate query and give the formula *) and trans_pr_step_l = function | [step] -> trans_pr_step [] step (Self) (* Self doesn't matter since [] *) | step :: tl -> let list_top = trans_pr_step_l tl in - trans_pr_step list_top step (ax_ (List.hd tl)) + trans_pr_step list_top step (ax_ (List.hd tl)) | [] -> failwith "Can not happened! 1" - + (* Add a step on the top of a list of states in a predicate *) and trans_pr_step list (ax,test,pred) ax_next = let form_next = @@ -144,7 +149,7 @@ let trans query = | Child -> `Right *+ q +| `Right *+ q' | Descendant -> (`Left *+ q +| `Right *+ q) +| (`Left *+ q' +| `Right *+ q') | Self -> `Self *+ q' - | FollowingSibling -> `Right *+ q +| `Self *+ q' + | FollowingSibling -> `Right *+ q +| `Right *+ q' | x -> print_axis pr_er x; raise Not_core_XPath in