From: Kim Nguyễn Date: Wed, 13 Mar 2013 10:19:02 +0000 (+0100) Subject: Put the node_kind type into a NodeKind module in the Common module. X-Git-Tag: v0.1~135 X-Git-Url: http://git.nguyen.vg/gitweb/?p=tatoo.git;a=commitdiff_plain;h=3f530996e51732a419f226bd0ed94f9ca94cd1a7 Put the node_kind type into a NodeKind module in the Common module. --- diff --git a/src/tree.mlpack b/src/tree.mlpack index 599b18f..6dd2e12 100644 --- a/src/tree.mlpack +++ b/src/tree.mlpack @@ -1,2 +1,3 @@ tree/Naive tree/Sig +tree/Common diff --git a/src/tree/common.ml b/src/tree/common.ml new file mode 100644 index 0000000..099d751 --- /dev/null +++ b/src/tree/common.ml @@ -0,0 +1,40 @@ +(***********************************************************************) +(* *) +(* TAToo *) +(* *) +(* Kim Nguyen, LRI UMR8623 *) +(* Université Paris-Sud & CNRS *) +(* *) +(* Copyright 2010-2012 Université Paris-Sud and Centre National de la *) +(* Recherche Scientifique. All rights reserved. This file is *) +(* distributed under the terms of the GNU Lesser General Public *) +(* License, with the special exception on linking described in file *) +(* ../LICENSE. *) +(* *) +(***********************************************************************) + +(* + Time-stamp: +*) + +module NodeKind = + struct + type t = + Document | Element | Text | Comment | Attribute | ProcessingInstruction + | Node + + let to_string = + function + Document -> "document" + | Element -> "element" + | Attribute -> "attribute" + | Text -> "text" + | Comment -> "comment" + | ProcessingInstruction -> "processing-instruction" + | Node -> "node" + let print ppf k = Format.fprintf ppf "%s" (to_string k) + + + let is_a k1 k2 = + k1 == Node || k2 == Node || k1 == k2 +end diff --git a/src/tree/sig.ml b/src/tree/sig.ml index f9bd0b7..aba5917 100644 --- a/src/tree/sig.ml +++ b/src/tree/sig.ml @@ -14,10 +14,11 @@ (***********************************************************************) (* - Time-stamp: + Time-stamp: *) (** Implementation of documents as binary trees *) + module type S = sig type node @@ -45,7 +46,6 @@ sig val print_xml : out_channel -> t -> node -> unit (** Outputs the tree as an XML document on the given output_channel *) - val root : t -> node (** Returns the root of the tree *) @@ -75,6 +75,9 @@ sig QName.text, QName.cdata_section or QName.comment *) + val kind : t -> node -> Common.NodeKind.t + (** Returns the kind of the given node *) + val preorder : t -> node -> int (** Returns the position of a node in pre-order in the tree. The root has preorder 0. [nil] has pre-order [-1].