X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=src%2Fnaive_tree.ml;h=a13a56dd21b1616283df446ad9fe383c39ba2728;hb=72818d02fb469c39a3d8043300152beae3e7e162;hp=33c953df3e85cf3197a4a503eeb1768e4138e2cf;hpb=75375a8bc02893080745ab38768b7ee48f5c4153;p=tatoo.git diff --git a/src/naive_tree.ml b/src/naive_tree.ml index 33c953d..a13a56d 100644 --- a/src/naive_tree.ml +++ b/src/naive_tree.ml @@ -72,7 +72,9 @@ struct "NODE " ^ string_of_int n.preorder) let debug_node fmt node = - Format.fprintf fmt "{ tag=%s; preorder=%i; data=%S; first_child=%a; next_sibling=%a; parent=%a }" + Format.fprintf fmt + "{ tag=%s; preorder=%i; data=%S;\ +first_child=%a; next_sibling=%a; parent=%a }" (QName.to_string node.tag) node.preorder node.data @@ -82,7 +84,8 @@ struct let debug_ctx fmt ctx = - Format.fprintf fmt "Current context: { preorder = %i\n; stack = \n%a\n }\n-------------\n" + Format.fprintf fmt "Current context: { preorder = %i\n; stack = \n%a\n }\ +\n-------------\n" ctx.current_preorder (Pretty.print_list ~sep:";\n" debug_node) ctx.stack @@ -324,6 +327,13 @@ let root t = t.root let size t = t.size let first_child _ n = n.first_child let next_sibling _ n = n.next_sibling + +let is_first_child _ n = n.parent.first_child == n +let is_next_sibling _ n = n.parent.next_sibling == n + +let prev_sibling t n = if is_next_sibling t n then n.parent else nil +let parent_of_first t n = if is_first_child t n then n.parent else nil + let parent _ n = n.parent let tag _ n = n.tag let data _ n = n.data