type node = {
tag : QName.t;
preorder : int;
- mutable kind : Tree.NodeKind.t;
+ mutable summary : Tree.NodeSummary.t;
mutable data : string;
mutable first_child : node;
mutable next_sibling : node;
let rec nil = {
tag = QName.nil;
- kind = Tree.NodeKind.Element;
+ summary = Tree.NodeSummary.dummy;
preorder = -1;
data = "";
first_child = nil;
let dummy_tag = QName.of_string "#dummy"
let rec dummy = {
tag = dummy_tag;
- kind = Tree.NodeKind.Element;
+ summary = Tree.NodeSummary.dummy;
preorder = -1;
data = "";
first_child = dummy;
do_text parser_ ctx;
let parent = top ctx in
let n = { tag = QName.of_string tag;
- kind = Tree.NodeKind.Element;
+ summary = Tree.NodeSummary.make false false false false Tree.NodeKind.Element;
preorder = next ctx;
data = "";
first_child = dummy;
start_element_handler parser_ ctx att [];
let n = top ctx in
n.data <- value;
- n.kind <- Tree.NodeKind.Attribute;
+ n.summary <- Tree.NodeSummary.make false false false false Tree.NodeKind.Attribute;
end_element_handler parser_ ctx att
and consume_closing ctx n =
start_element_handler parser_ ctx text_string [];
let node = top ctx in
node.data <- s;
- node.kind <- Tree.NodeKind.Text;
+ node.summary <- Tree.NodeSummary.make false false false false Tree.NodeKind.Text;
end_element_handler parser_ ctx text_string
and comment_handler parser_ ctx s =
start_element_handler parser_ ctx comment_string [];
let node = top ctx in
node.data <- s;
- node.kind <- Tree.NodeKind.Comment;
+ node.summary <- Tree.NodeSummary.make false false false false Tree.NodeKind.Comment;
end_element_handler parser_ ctx comment_string
and processing_instruction_handler parser_ ctx tag data =
start_element_handler parser_ ctx tag [];
let node = top ctx in
node.data <- data;
- node.kind <- Tree.NodeKind.ProcessingInstruction;
+ node.summary <- Tree.NodeSummary.make false false false false Tree.NodeKind.ProcessingInstruction;
end_element_handler parser_ ctx tag
(processing_instruction_handler psr ctx);
push { tag = QName.document;
preorder = next ctx;
- kind = Tree.NodeKind.Document;
+ summary = Tree.NodeSummary.make false false false false Tree.NodeKind.Document;
data = "";
first_child = dummy;
next_sibling = dummy;
let rec loop n =
if n != nil then
begin
+ n.summary <-
+ Tree.NodeSummary.make
+ (n == n.parent.first_child)
+ (n == n.parent.next_sibling)
+ (n.first_child != nil)
+ (n.next_sibling != nil)
+ (Tree.NodeSummary.kind n.summary);
a.(n.preorder) <- n;
loop n.first_child;
loop n.next_sibling;
| c -> output_char out c
done
+let kind _ n = Tree.NodeSummary.kind n.summary
+let summary _ n = n.summary
let rec print_attributes ?(sep=true) out tree_ node =
- if (node.kind == Tree.NodeKind.Attribute) then
+ if (kind tree_ node == Tree.NodeKind.Attribute) then
let tag = QName.to_string node.tag in
if sep then output_char out ' ';
output_string out tag;
if node != nil then
let () =
let open Tree.NodeKind in
- match node.kind with
+ match kind tree_ node with
| Node -> ()
| Text -> output_escape_string out node.data
| Element | Document ->
let parent _ n = n.parent
let tag _ n = n.tag
let data _ n = n.data
-let kind _ n = n.kind
let preorder _ n = n.preorder
let by_preorder t i =
if i >= 0 && i < t.size then Array.unsafe_get t.by_preorder i