X-Git-Url: http://git.nguyen.vg/gitweb/?p=tatoo.git;a=blobdiff_plain;f=src%2Fxpath%2Fast.ml;h=5b322a4af56a28c2d01c596756820aaa7ee4f128;hp=c3c00d9d1ee551f85f00290dd8658ff9b253084a;hb=fe2ba1820282783ae8c10fbbbd2b65d3dc4c67f2;hpb=30bc0bb1291426e5e26eb2dee1ffc41e4c246349 diff --git a/src/xpath/ast.ml b/src/xpath/ast.ml index c3c00d9..5b322a4 100644 --- a/src/xpath/ast.ml +++ b/src/xpath/ast.ml @@ -13,19 +13,18 @@ (* *) (***********************************************************************) -(* - Time-stamp: -*) - -open Utils - type path = single_path list and single_path = Absolute of step list | Relative of step list and step = axis * test * expr list -and axis = Self | Attribute | Child | Descendant | DescendantOrSelf | FollowingSibling - | Parent | Ancestor | AncestorOrSelf | PrecedingSibling | Preceding | Following +and axis = Self | Attribute | Child + | Descendant of bool (* true = descendant-or-self, false = descendant *) + | FollowingSibling + | Parent + | Ancestor of bool (* true = ancestor-or-self, false = ancestor *) + | PrecedingSibling + | Preceding | Following -and test = QNameSet.t +and test = QNameSet.t * Tree.NodeKind.t and binop = Eq | Neq | Lt | Gt | Lte | Gte | Or | And | Add | Sub | Mult | Div | Mod and unop = Neg @@ -47,7 +46,6 @@ let star = QNameSet.complement ( QNameSet.from_list [ QName.text; QName.document; - QName.cdata_section; QName.comment]) @@ -111,30 +109,37 @@ and print_axis fmt a = pp fmt "%s" begin match a with Self -> "self" | Child -> "child" - | Descendant -> "descendant" - | DescendantOrSelf -> "descendant-or-self" + | Descendant false -> "descendant" + | Descendant true -> "descendant-or-self" | FollowingSibling -> "following-sibling" | Attribute -> "attribute" - | Ancestor -> "ancestor" - | AncestorOrSelf -> "ancestor-or-self" + | Ancestor false -> "ancestor" + | Ancestor true -> "ancestor-or-self" | PrecedingSibling -> "preceding-sibling" | Parent -> "parent" | Preceding -> "preceding" | Following -> "following" end -and print_test fmt ts = - try - pp fmt "%s" (List.assoc ts - [ text,"text()"; - node,"node()"; - star, "*" ] ) - with - Not_found -> pp fmt "%s" - (if QNameSet.is_finite ts - then QName.to_string (QNameSet.choose ts) - else "" - ) +and print_test fmt (ts,kind) = + let open Tree.NodeKind in + match kind with + Text -> pp fmt "%s" "text()" + | Element | Attribute -> + pp fmt "%s" begin + if QNameSet.is_finite ts then + QName.to_string (QNameSet.choose ts) + else "*" + end + | Comment -> pp fmt "%s" "comment()" + | ProcessingInstruction -> + pp fmt "processing-instruction(%s)" + begin + if ts == star then "" + else "\"" ^ (QName.to_string (QNameSet.choose ts)) ^ "\"" + end + | Node -> pp fmt "%s" "node()" + | Document -> pp fmt "%s" "" and print_expr fmt = function | Number (`Int(i)) -> pp fmt "%i" i @@ -163,3 +168,17 @@ and print_expr fmt = function print_expr fmt e0; if need_par0 then pp fmt ")" + + +let invert_axis = function +| Self -> Self +| Attribute -> Parent (* Improve *) +| Child -> Parent +| Descendant (b) -> Ancestor (b) +| FollowingSibling -> PrecedingSibling +| Parent -> Child +| Ancestor (b) -> Descendant (b) +| PrecedingSibling -> FollowingSibling +| Preceding -> Following +| Following -> Preceding +;;