X-Git-Url: http://git.nguyen.vg/gitweb/?p=tatoo.git;a=blobdiff_plain;f=src%2Fxpath%2Fast.ml;h=64c6c8da6214b7b863feaa28be40c883b5fd4aed;hp=d70227bed900fd4421bf2892570e489200109685;hb=53a0fd29a20e7f4550e0eb5fa5b0d5af6191c36d;hpb=7c1d3641c4c5d7bde075df20863ab4242df3b763 diff --git a/src/xpath/ast.ml b/src/xpath/ast.ml index d70227b..64c6c8d 100644 --- a/src/xpath/ast.ml +++ b/src/xpath/ast.ml @@ -14,7 +14,7 @@ (***********************************************************************) (* - Time-stamp: + Time-stamp: *) open Utils @@ -30,7 +30,7 @@ and axis = Self | Attribute | Child | PrecedingSibling | Preceding | Following -and test = QNameSet.t +and test = QNameSet.t * Tree.Common.NodeKind.t and binop = Eq | Neq | Lt | Gt | Lte | Gte | Or | And | Add | Sub | Mult | Div | Mod and unop = Neg @@ -52,7 +52,6 @@ let star = QNameSet.complement ( QNameSet.from_list [ QName.text; QName.document; - QName.cdata_section; QName.comment]) @@ -128,18 +127,24 @@ and print_axis fmt a = pp fmt "%s" begin | 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.Common.NodeKind in + match kind with + Text -> pp fmt "%s" "text()" + | Element | Attribute -> + pp fmt "%s" begin + if ts == star then "*" + else QName.to_string (QNameSet.choose ts) + 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 @@ -171,7 +176,8 @@ and print_expr fmt = function let invert_axis = function -| Self | Attribute as a -> a +| Self -> Self +| Attribute -> Parent (* Improve *) | Child -> Parent | Descendant (b) -> Ancestor (b) | FollowingSibling -> PrecedingSibling