e2db1d11983935c09e229f1458c9826254620ed3
[tatoo.git] / src / tree / sig.ml
1 (***********************************************************************)
2 (*                                                                     *)
3 (*                               TAToo                                 *)
4 (*                                                                     *)
5 (*                     Kim Nguyen, LRI UMR8623                         *)
6 (*                   Université Paris-Sud & CNRS                       *)
7 (*                                                                     *)
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   *)
12 (*  ../LICENSE.                                                        *)
13 (*                                                                     *)
14 (***********************************************************************)
15
16 (*
17   Time-stamp: <Last modified on 2013-03-13 18:46:18 CET by Kim Nguyen>
18 *)
19
20 (** Implementation of documents as binary trees *)
21
22 module type S =
23 sig
24   type node
25   (** The type of a tree node *)
26
27   type t
28   (** The type of trees *)
29
30   val size : t -> int
31   (** Return the number of nodes *)
32
33   val nil : node
34   (** Nil node, denoting the first/second child of a leaf or the parent of
35       the root *)
36
37   val dummy : node
38   (** Dummy node that is guaranteed to never occur in any tree *)
39
40   val load_xml_file : in_channel -> t
41   (** Takes a file descriptor and returns the XML data stored in the
42       corresponding file. Start at the current position in the file
43       descriptor (which is not necessarily the begining of file)
44   *)
45
46   val load_xml_string : string -> t
47   (** Loads XML data stored in a string *)
48
49   val print_xml : out_channel -> t -> node -> unit
50   (** Outputs the tree as an XML document on the given output_channel *)
51
52   val root : t -> node
53   (** Returns the root of the tree *)
54
55   val first_child : t -> node -> node
56   (** [first_child t n] returns the first child of node [n] in tree [t].
57       Returns [nil] if [n] is a leaf. Returns [nil] if [n == nil].
58   *)
59
60   val next_sibling : t -> node -> node
61   (** [next_sibling t n] returns the next_sibling of node [n] in tree [t].
62       Returns [nil] if [n] is the last child of a node.
63       Returns [nil] if [n == nil].
64   *)
65
66   val parent : t -> node -> node
67   (** [next_sibling t n] returns the parent of node [n] in tree [t].
68       Returns [nil] if [n] is the root of the tree.
69       Returns [nil] if [n == nil].
70   *)
71
72   val tag : t -> node -> Utils.QName.t
73   (** Returns the label of a given node *)
74
75   val data : t -> node -> string
76   (** Returns the character data associated with a node.
77       The only node having character data are those whose label is
78       QName.text, QName.cdata_section or QName.comment
79   *)
80
81   val kind : t -> node -> Common.NodeKind.t
82   (** Returns the kind of the given node *)
83
84   val preorder : t -> node -> int
85   (** Returns the position of a node in pre-order in the tree. The
86     root has preorder 0. [nil] has pre-order [-1].
87   *)
88
89   val print_node : Format.formatter -> node -> unit
90 end